Table of Contents

AutoParameters

AutoParameters is a set of attributes that minimizes any parameter-related boilerplate for animations and commands by automatically handling anything related to parameters, specifically implementing the ValidateParameters, SetParameters and GetNewCustomData methods for you.

In the vast majoritiy of cases, you should be using AutoParameters. Only when you need some special parameter handling will you be required to write custom code for it, and even then in many cases the Hooks should suffice.

Creating a class with AutoParameters

To create an animation or command using AutoParameters, create a class and make sure it derives from ITMPAnimation or ITMPCommand, or any of its sub types. Your IDE should complain that the class is not partial and doesn't implement the Animate method (or ExecuteCommand method if youre making a command); go ahead and make it partial and implement the method. You can do this either manually or using the pre-defined code fixes. Once you did your class should look somewhat like this:

using TMPEffects.AutoParameters.Attributes;
using TMPEffects.CharacterData;
using TMPEffects.TMPAnimations;

[AutoParameters]
public partial class YourClass : TMPAnimation
{
    // if youre making a command, this will of course say ExecuteCommand
    private partial void Animate(CharData cData, AutoParametersData data, IAnimationContext context)
    {
    }
}

Adding valid parameters

To any field on your class that fulfills certain requirements, you can add the AutoParameter attribute. This will automatically generate code in each of the parameter handling methods respectively, and allows you to use it in your animation / command code. Each field decorated with this attribute must:

  • Be serializable (public or decorated with SerializeField).
  • Be a valid AutoParameters type. This means it must either be a built-in parameter type (see Parameter Types) or a type decorated with the TMPParameterType attribute.

Let's add a float and a string parameter to our class:

[AutoParameters]
public partial class SomeClass : TMPAnimation
{
    [AutoParameter(required: true, name: "myFloat", aliases: "myF", "mf"), SerializeField]
    private float myFloat = "12";

    [AutoParameter("myString", "myStr"), SerializeField]
    private string myString = "default string";

    private partial void Animate(CharData cData, AutoParametersData data, IAnimationContext context)
    {
    }
}

Thats it! You can now use them through the generated AutoParametersData passed in to your Animate/ExecuteCommand method.

    private partial void Animate(CharData cData, AutoParametersData data, IAnimationContext context)
    {
        Debug.Log("myFloat: " + data.myFloat + "; myString: " + data.myString);
    }

Here's some example outputs for various tags (assuming we named our animation "myanim" in the database):

  • <myanim>: "myFloat: 12; myString: default string"
  • <myanim myFloat=23 myStr=anotherstring>: "myFloat: 23; myString: anotherstring"
  • <myanim mf=-54.34>: "myFloat: -54.34; myString: default string"

Adding valid parameters using bundles

Any class decorated with the TMPParameterBundle attribute is a parameter bundle. These classes then, when used as fields and decorated with the AutoParametersBundle attribute, define multiple parameters at once. For example, Wave is a built-in parameter bundle. Using it like so:

[AutoParameters]
public partial class SomeClass : TMPAnimation
{
    [AutoParameterBundle(prefix: ""), SerializeField]
    private Wave wave;

    [AutoParameterBundle("w2:"), SerializeField]
    private Wave wave;

    // ...
}

allows you to use any parameter defined by Wave to modify the wave.

  • <myanim amp=10 upperiod=10>: Sets the amplitude and up period of wave to ten.
  • <myanim amp=10 w2:upperiod=10>: Sets the amplitude of wave and upperiod of wave2 to ten.
  • <myanim amp=10 w2:amp=10>: Set the amplitude of both to ten.

Hooks

You can hook into each of the generated methods to still allow you some custom parameter handling even when using AutoParameters. Each of the hooks has its own code fix, so you don't need to memorize the hook method signatures. Just in case the code fixes don't work for you for some reason, here is them written out:

Hooks
  • bool ValidateParameters_Hook(IDictionary parameters, ITMPKeywordDatabase keywordDatabase)
  • void SetParameters_Hook(object customData, IDictionary parameters, ITMPKeywordDatabase keywordDatabase)
  • void GetNewCustomData_Hook(object customData)

AutoParametersStorage

The AutoParametersStorage attribute marks a type as type used to store parsed tag parameters of the class. It must, like the AutoParameter attribute, be contained in a class decorated with AutoParameters, and must also be partial. For example:

[AutoParameters]
public partial class SomeClass : TMPAnimation
{
    [AutoParametersStorage]
    private partial class MyStorage
    {
    }
}

If you do declare a type like so, AutoParameters will no longer generate the default storage type AutoParametersData. You will therefore have to change your Animate / ExecuteCommand method like so:

[AutoParameters]
public partial class SomeClass : TMPAnimation
{
    private partial void Animate(CharData cData, MyStorage data, IAnimationContext context)
    {
    }

    [AutoParametersStorage]
    private partial class MyStorage
    {
    }
}

The advantage of declaring your own AutoParametersStorage is being able to store non-parameter related per-animation data, such as a random number generator, or anything else you need really.

[AutoParameters]
public partial class SomeClass : TMPAnimation
{
    // ...
    
    [AutoParametersStorage]
    private partial class MyStorage
    {
        public System.Random rand = new System.Random();
        public Dictionary<CharData, int> someDict = new Dictionary<CharData, int>();
    }
}