> 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/2.x-ko/undefined-1/undefined-3/c.md).

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

내장 이펙트를 사용하거나 검사기에서 커스텀 이펙트를 만드는 것 외에도, C#을 통해 커스텀 이펙트를 쉽게 프로그래밍할 수 있습니다.

***

## 1. 이펙트 기본 클래스 <a href="#id-1-effect-base-class" id="id-1-effect-base-class"></a>

해야 할 일은 기본 클래스를 상속받는 것입니다 `Febucci.UI.Effects.AnimationScriptableBase` 클래스 ([스크립팅 API](https://www.api.febucci.com/tools/text-animator-unity/api/Febucci.UI.Effects.AnimationScriptableBase.html)).

```csharp
public class CustomEffect : AnimationScriptableBase
{
    //[...]
```

API에서 확인할 수 있는 유용한 클래스들이 이미 몇 가지 있습니다. 예를 들어 각 이펙트 카테고리를 위한 “BehaviorScriptableBase”나 “AppearanceScriptableBase”, 그리고 “a, f, w” 같은 수정자를 이미 처리하는 “BehaviorSineBase” 등이 있습니다.

## 2. 속성(Attributes) <a href="#id-2-attributes" id="id-2-attributes"></a>

Actions와 마찬가지로 ScriptableObject를 생성하므로, 인스턴스화 및 직렬화를 위해 필요한 속성들을 추가해야 합니다:

```csharp
[CreateAssetMenu(fileName = "YourCustomEffect", menuName = "Text Animator/Custom/YourCustomEffect")]
[System.Serializable]
public class CustomEffect : AnimationScriptableBase
{
    //[...]
```

이렇게 하면 프로젝트 창에서 해당 오브젝트들을 생성할 수 있습니다.

***

를 상속하면 `AnimationScriptableBase`상속받는 상위 클래스에 따라 오버라이드할 몇몇 메소드들이 있으며, 일부는 필수(abstract)이고 다른 일부는 선택적(virtual)입니다. 문서(스크립팅 API와 IDE 모두)에서 새로운 메소드들에 대한 더 많은 예제와 정보를 찾을 수 있습니다.

## 3. 수정자(Modifier) 메소드 <a href="#id-3-modifier-methods" id="id-3-modifier-methods"></a>

이펙트는 “[수정자(Modifiers)](about:/text-animator-unity/docs/how-to-add-effects-to-your-texts/#modifiers)”의 영향을 받을 수 있으므로, 애니메이션에서 이를 처리하기 위해 다음 메소드들을 오버라이드할 수 있습니다:

이 메소드들은 애니메이션 전에 순서대로 적용됩니다.

### 3.1 ResetContext <a href="#id-31-resetcontext" id="id-31-resetcontext"></a>

```csharp
void ResetContext(TAnimCore animator)
```

이 메소드를 사용하여 애니메이션 변수들을 초기 상태로 재설정할 수 있습니다.\
예를 들어, 검사기에서 baseSpeed라는 변수를 공개적으로 노출하지만, 이펙트 내부에서는 currentSpeed만 사용하고 이 메소드 안에서 `baseSpeed`를 사용한다고 가정할 수 있습니다. `currentSpeed` 그리고 해당 변수를 `currentSpeed=baseSpeed` 로 이 메소드 내에서 설정할 수 있습니다.

### 3.2 SetModifierTo <a href="#id-32-setmodifierto" id="id-32-setmodifierto"></a>

```csharp
void SetModifier(ModifierInfo modifier)
```

이 메소드를 사용해 수정자를 변수에 적용할 수 있습니다.

예를 들어 이것은 `currentSpeed` 값을 `s` 수정자(있다면)에 의해 곱할 것입니다.

```csharp
public override void SetModifier(ModifierInfo modifier)
{
    switch (modifier.name)
    {
        case "s": currentSpeed *= modifier.value; break;
    }
}
```

👍🏻 만약 “amplitude”, “frequency”, “waveSize” 같은 세 가지 수정자를 갖는 Behavior 이펙트를 만들고 싶다면, 이를 처리해주는 클래스를 상속받아 만들 수 있습니다. `BehaviorSineBase` 가 그것들을 처리해 줄 것입니다.

## 4. 애니메이션 메소드 <a href="#id-4-animation-methods" id="id-4-animation-methods"></a>

여기 커스텀 애니메이션을 만들기 위해 오버라이드할 수 있는 몇 가지 메소드가 있습니다.<br>

### 4.1 GetMaxDuration <a href="#id-41-getmaxduration" id="id-41-getmaxduration"></a>

이펙트의 최대 지속 시간입니다. 이는 애니메이션의 총 지속 시간을 계산하고 부드러운 전환을 위해 사용됩니다. 그러나 끝나지 않는 이펙트라면 -1을 반환해야 합니다;

### 4.2 CanApplyEffectTo <a href="#id-42-canapplyeffectto" id="id-42-canapplyeffectto"></a>

```csharp
bool CanApplyEffectTo(CharacterData character, TAnimCore animator)
```

현재 문자에 이펙트를 적용할 수 있는지 확인하는 데 사용됩니다. 예를 들어, 문자 통과 시간이 이펙트의 지속 시간 내에 있을 때만 적용되는 appearance 이펙트를 만드는 경우(하지만 그런 경우에는 “AppearanceScriptableBase”를 상속받아 처리하게 할 수 있습니다).

더 나아가 문자가 숫자인지 문자(알파벳)인지, 또는 단어 인덱스 등 여러 조건을 검사할 수 있습니다.

### 4.3 ApplyEffect <a href="#id-43-applyeffect" id="id-43-applyeffect"></a>

```csharp
void ApplyEffectTo(ref CharacterData character, TAnimCore animator)
```

문자에 애니메이션을 적용하는 주요 메소드로, “CanApplyEffectTo”가 true를 반환할 때 호출됩니다.

* `character.current` 은 매 프레임 리셋됩니다 ( `character.source`와 일치), 따라서 문자를 애니메이션하려면 해당 값들을 수정해야 합니다.
* `character.source` 는 문자의 원래 위치 및 색상으로, 수정되면 기본적으로 문자를 영구적으로 변경하는 것(새 텍스트가 설정될 때까지)입니다. 이것을 기반으로만 사용하고 대신 `character.current` 를 수정하는 것이 권장됩니다.

## ✅ 완료! <a href="#done" id="done"></a>

**모든 필요한 단계를 완료했습니다, 축하합니다!**\
이펙트를 더 많이 추가할수록 이 과정이 더 익숙하고 단순하게 느껴질 것입니다.

{% hint style="warning" %}
프로젝트 뷰에서 효과 ScriptableObject를 생성하고 데이터베이스에 추가하는 것을 잊지 마세요.

자세한 내용은 여기에서 읽을 수 있습니다: [데이터베이스](/text-animator-unity/2.x-ko/undefined-1/undefined/undefined-1.md)
{% endhint %}

{% hint style="success" %}
👍🏻 내장 이펙트 클래스를 항상 살펴보고 어떻게 구현되어 있는지 확인할 수 있습니다.
{% 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, and the optional `goal` query parameter:

```
GET https://docs.febucci.com/text-animator-unity/2.x-ko/undefined-1/undefined-3/c.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
