Writing Preset Scripts (C#)

BaseEffect

using Animatext.Effects; //Add "Animatext.Effects" namespace.
using UnityEngine;

//Create the asset menu of the preset.
[CreateAssetMenu(menuName = "Animatext Preset/Example/ExampleW01", fileName = "New ExampleW01 Preset", order = 369)] 
public class ExampleW01 : BaseEffect //Inherit from "BaseEffect" class.
{
    //The unit information of the info flags will be obtained after parsing.
    public override InfoFlags infoFlags
    {
        //None flag: InfoFlags.None
        //Original character flag: InfoFlags.Char
        //Visible character flag: InfoFlags.Character
        //Word flag: InfoFlags.Word
        //Line flag: InfoFlags.Line
        //Group flag: InfoFlags.Group
        //Range flag: InfoFlags.Range
        get { return InfoFlags.None; }
    }
		
    //Method to animate text. This method is called every frame when the effect is not in the stop state.
    protected override void Animate()
    {
        Debug.Log("Animatext");
    }
	
    //Method to get the waiting time of the preset. This is an optional override method.
    protected override float GetRangeInterval()
    {
        return 0f;
    }
	
    //Method to get the execution time of the preset. This is an optional override method.
    protected override float GetExecutionInterval()
    {
        return 0f;
    }
	
    //Method to get the end time of the preset. This is an optional override method.
    protected override float GetEndInterval()
    {
        return float.PositiveInfinity;
    }
}

Time

Note: After modifying the text component parameters or refreshing the Animatext component, the value of lastTime is float.NaN.

using Animatext.Effects;
using UnityEngine;

[CreateAssetMenu(menuName = "Animatext Preset/Example/ExampleW02", fileName = "New ExampleW02 Preset", order = 369)] 
public class ExampleW02 : BaseEffect
{
    public override InfoFlags infoFlags
    {
        get { return InfoFlags.None; }
    }
	
    protected override void Animate()
    {
        Debug.Log("Time :" + time + " Last Time :" + lastTime);
    }
}

Unit

using Animatext.Effects;
using UnityEngine;

[CreateAssetMenu(menuName = "Animatext Preset/Example/ExampleW03", fileName = "New ExampleW03 Preset", order = 369)] 
public class ExampleW03 : BaseEffect
{
    public override InfoFlags infoFlags
    {
        get { return InfoFlags.Character; }
    }
	
    protected override void Animate()
    {
        for (int i = 0; i < characterCount; i++)
        {
            Debug.Log("Character " + i + ": " + characters[i].text);
            
            //Move the character.
            characters[i].Move(Vector2.zero);

            //Rotate the character.
            characters[i].Rotate(0);
            characters[i].Rotate(0, characters[i].anchor.center);

            //Scale the character.
            characters[i].Scale(Vector2.one);
            characters[i].Scale(Vector2.one, characters[i].anchor.center);

            //Skew the character.
            characters[i].Skew(Vector2.zero);
            characters[i].Skew(Vector2.zero, characters[i].anchor.center);
			
            //Opacify the character.
            characters[i].Opacify(1);
            characters[i].Opacify(1, ColorMode.Multiply);
			
            //Color the character.
            characters[i].Color(Color.black);
        }
    }
}

The position of each unit anchor will be recalculated every time the preset is executed. The animation method of the unit does not change the position of the anchor.

In the following examples, the positions of the characters in Example A are different from those of Example B, but the same as those of Example C.

    //Example A
    protected override void Animate()
    {
        for (int i = 0; i < characterCount; i++)
        {
            characters[i].Rotate(90);
            characters[i].Move(Vector2.one * 100);
        }
    }
    //Example B
    protected override void Animate()
    {
        for (int i = 0; i < characterCount; i++)
        {
            characters[i].Move(Vector2.one * 100);
            characters[i].Rotate(90);
        }
    }
    //Example C
    protected override void Animate()
    {
        for (int i = 0; i < characterCount; i++)
        {
            characters[i].Move(Vector2.one * 100);
            characters[i].anchor.Move(Vector2.one * 100);
            characters[i].Rotate(90);
        }
    }

Other

Template Effect

Animatext offers two template effects: "DefaultTemplateEffect" and "SimpleTemplateEffect".

DefaultTemplateEffect

using Animatext.Effects;
using UnityEngine;

[CreateAssetMenu(menuName = "Animatext Preset/Example/ExampleW04", fileName = "New ExampleW04 Preset", order = 369)] 
public class ExampleW04 : DefaultTemplateEffect //Inherit from "DefaultTemplateEffect" class. 
{
    public float singleTime = 1;

    public override InfoFlags infoFlags
    {
        get { return InfoFlags.Character; }
    }
	
    protected override int unitCount
    {
        get { return characterCount; }
    }
	
    protected override float unitTime
    {
        get { return singleTime; }
    }
	
    protected override void Animate()
    {
        for (int i = 0; i < characterCount; i++)
        {
            //You can use the "GetCurrentProgress" method to get the progress of the unit.
            Debug.Log("Character " + i + " Progress: " + GetCurrentProgress(i));
        }
    }
}

SimpleTemplateEffect

Compared to "DefaultTemplateEffect", "SimpleTemplateEffect" lacks the loop function and gets better performance.