> For the complete documentation index, see [llms.txt](https://docs.febucci.com/text-animator-unity/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.febucci.com/text-animator-unity/3.x-ko/writing-custom-classes/c.md).

# 사용자 지정 효과 작성(C#)

사용하는 것 외에도 [내장 효과](/text-animator-unity/3.x-ko/effects/built-in-effects-list.md) 또는 [인스펙터에서 사용자 지정 효과를 만드는 것](/text-animator-unity/3.x-ko/customization/create-your-own-effects.md), <mark style="color:기본값;background-color:$warning;">**C#을 통해 사용자 지정 효과를 쉽게 프로그래밍할 수 있습니다**</mark>.

{% hint style="info" %}
P.S. 다음 페이지를 읽었는지 꼭 확인하세요: [고급 개념](/text-animator-unity/3.x-ko/writing-custom-classes/advanced-concepts.md) 페이지!
{% endhint %}

효과에는 세 가지 핵심 부분이 있습니다(같은 파일에 작성할 수 있습니다).

<table data-view="cards"><thead><tr><th></th><th></th></tr></thead><tbody><tr><td><strong>Parameters 클래스/구조체</strong></td><td>효과에서 사용할 데이터/값에 대한 정보를 담고 있습니다(<strong>state)</strong> </td></tr><tr><td><strong>State</strong> 구조체</td><td>메인 효과 클래스입니다. 파라미터와 캐릭터를 받아 시간에 따라 수정합니다. 또한 다음을 처리합니다 <a data-mention href="/pages/396018f42ad39412c7e70d16eb5306b764543c5b">/pages/396018f42ad39412c7e70d16eb5306b764543c5b</a></td></tr><tr><td><strong>Scriptable 래퍼</strong></td><td>이전 요소들을 하나로 통합하고 디스크에 저장할 수 있게 해줍니다. 나머지는 우리가 할 수 있도록 몇 줄의 코드만 있으면 됩니다!</td></tr></tbody></table>

{% hint style="success" %}
이 이름들은 단지 관례일 뿐이지만, **원하는 대로 부를 수 있습니다**!

알아두세요, 필요한 것은:&#x20;

* 효과 변수를 저장하는 무언가
* 문자를 수정하는 역할을 하는 구조체
* 이 둘을 연결하고 정보를 디스크에 저장할 수 있게 해주는 Scriptable
  {% endhint %}

## 사용자 지정 스크립트 작성

{% hint style="info" %}
이 예제에서는 캐릭터를 변수에 따라 위로 이동시키는 효과를 만듭니다.
{% endhint %}

먼저 필요한 네임스페이스를 가져오세요(어차피 IDE가 알려줄 거예요 <3)

<pre class="language-csharp"><code class="lang-csharp">using UnityEngine;

// Text Animator의 네임스페이스를 가져오기
<strong>using Febucci.TextAnimatorCore;
</strong>using Febucci.TextAnimatorCore.Text;
<strong>using Febucci.Parsing;
</strong><strong>using Febucci.TextAnimatorForUnity.Effects;
</strong></code></pre>

### Parameters

문자를 수정하는 데 필요한 데이터를 만드세요(인스펙터에서 보게 되고 수정하게 될 바로 그 데이터입니다).

```csharp
// struct 또는 class일 수 있습니다
// 후자는 기본값을 둘 수 있게 해줍니다
[System.Serializable]
class CustomEffectParameters
{
    public float amount = 1.5f;
}
```

### State

효과의 "핵심" 부분입니다. 파라미터와 미리 계산된 Text Animator 데이터를 바탕으로 문자를 수정합니다.

* 구조체는 다음을 상속해야 합니다: **IEffectState**.

```csharp
// 반드시 구조체여야 합니다!
struct CustomEffectState : IEffectState
{
    readonly float defaultAmount;
    float amount;


    public CustomEffectState(CustomEffectParameters data)
    {
        // 파라미터 클래스에서 기본 amount 값을 가져옵니다
        this.defaultAmount = data.amount;
        this.amount = defaultAmount;
    }

    public void UpdateParameters(RegionParameters parameters)
    {
        // 사용자가 다음과 같이 작성한 경우를 자동으로 처리합니다 
        // 리치 텍스트 태그의 수정자, 이 경우 "a"
        // (예: <tagID a=5>는 "amount"를 5로 설정하고, 
        // a*2는 "amount"를 defaultAmount의 두 배로 만듭니다)
        amount = parameters.ModifyFloat("a", defaultAmount);
    }

    public void Apply(ref CharacterData character, in ManagedEffectContext context)
    {
        // "amount"를 사용해 문자를 위로 이동시킵니다
        // 명확하고 사용하기 쉬운 API로
        character.MovePosition(
            Vector3.Up * amount * context.progressionRange * context.intensity,
            context.isUpPositive
            );
        // 1. context.progressionRange에 주목하세요 -> 이것은 
        //     에디터에서 할당한 커브입니다!
        //     스텝, 사인, 바운스 등의 결과를 만들 수 있습니다
        // 2. 또한 context.intensity에도 주목하세요. 이는 
        //     단계 간 부드러운 전환을 위해 필요합니다.
        }
}
```

### Scriptable Object 래퍼

사용자 지정 효과를 Text Animator에 연결하는 데 필요한 로직을 만들고, Assets 폴더에도 저장합니다.

```csharp
[System.Serializable] // <-- 직렬화 가능하게 만드세요!!
[CreateAssetMenu(fileName = "Your Custom Effect")]
class CustomEffectScriptable : ManagedEffectScriptable<CustomEffectState, CustomEffectParameters>
{
    // 파라미터를 받아 새 State를 단순히 만듭니다(이미 text animator가 관리함)
    protected override CustomEffectState CreateState(CustomEffectParameters parameters)
        => new CustomEffectState(parameters);
}
```

{% hint style="info" %}
ManagedEffectScriptable의 다른 버전도 있는데, 더 많은 타입을 받을 수 있고 "Referenced" 효과 구현도 있습니다. 하지만 이는 향후 버전에서 다룰 예정입니다!
{% endhint %}

{% hint style="success" %}
이 스크립트들만 있으면 Text Animator가 다음을 보장하는 데 충분합니다:

* 자동 관리되는 커브, 재생, 수정자
* 경합 조건 없이 최적화된 효과
* AOT 플랫폼과 호환되는 효과(Reflection을 사용할 필요 없음)
* 강력한 미리보기 편집기
* UI Toolkit과 TextMesh Pro에서 동일하게 동작하는 효과, 동적 스케일링 포함

그리고 더 많은 것들! <3
{% endhint %}

<figure><img src="/files/0defbe3c2ceafbd0375cd503a836f3d1893a7855" alt=""><figcaption></figcaption></figure>

***

{% hint style="success" %}
완료!  **필요한 모든 단계를 완료했습니다, 야호!**\
효과를 더 많이 추가할수록 이 과정은 더 익숙하고 쉬워질 것입니다.
{% endhint %}

{% hint style="warning" %}
효과에 태그를 부여하고(인스펙터에서) 데이터베이스에 추가하는 것을 잊지 마세요! 그렇지 않으면 인식되지 않습니다. 자세한 내용은 여기에서 읽을 수 있습니다: [효과 데이터베이스](/text-animator-unity/3.x-ko/effects/how-to-add-effects/effects-database.md)
{% endhint %}

**효과를 적용하며 즐거운 시간 보내세요!**

***

{% hint style="info" %}
"Referenced" 효과를 만드는 가이드는 곧 제공될 예정입니다. 아직 UX/API 부분을 다듬고 있기 때문입니다.
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.febucci.com/text-animator-unity/3.x-ko/writing-custom-classes/c.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
