Animations

The procedural Animations script contains constants corresponding to the hash codes of each animation state and parameter in every AnimatorController in your project so that instead of animator.Play("Idle") you can use animator.Play(Animations.Idle).

The [AnimationReference] attribute can be used on a serialized string or int field to show a popup menu in the inspector which lets you select an animation value name or hash respectively. Values include both states and parameters. Note that selecting a value using this attribute does not connect the field to that state or parameter. Renaming the state or parameter will not automatically update the value of the attributed field.

If you're interested in a more flexible code-oriented animation system which avoids the need for these magic strings and numbers entirely you should check out Animancer.

Animations Panel

The Animations panel in the Weaver Window allows the procedural script to be entirely disabled and shows the following options for customising it:

Option Description
Notify On New Value If enabled: the script will log a message while generating if a new value is found that wasn't present last time.
Create Parameter Wrappers [Pro-Only] If enabled: the script will include extension methods for the Animator class which get and set each animation parameter so that instead of animator.SetFloat(Animations.MoveSpeed, 10) you can use animator.SetMoveSpeed(10).

Sample Output

// This file was procedurally generated by Weaver. Any modifications will be overwritten.

#pragma warning disable // All.

namespace Weaver
{
    /// <summary>This class was procedurally generated by Weaver.</summary>
    public static class Animations
    {
        #region Hash Constants

        /// <summary>Attack</summary>
        public const int Attack = 1080829965;

        /// <summary>Die</summary>
        public const int Die = 20298039;

        /// <summary>Forward</summary>
        public const int Forward = 673977882;

        /// <summary>Idle</summary>
        public const int Idle = 2081823275;

        /// <summary>Jump</summary>
        public const int Jump = 125937960;

        /// <summary>Move</summary>
        public const int Move = 1326225478;

        /// <summary>Right</summary>
        public const int Right = 1963678224;

        /// <summary>Speed</summary>
        public const int Speed = -823668238;

        /// <summary>Get the name of the specified 'state' using HashToString.</summary>
        public static string GetName(this UnityEngine.AnimatorStateInfo state)
        {
            return HashToString(state.shortNameHash);
        }

        /// <summary>Get the state or parameter name associated with the specified 'hash' value.</summary>
        public static string HashToString(int hash)
        {
            switch (hash)
            {
                case Idle: return "Idle";
                case Jump: return "Jump";
                case Attack: return "Attack";
                case Die: return "Die";
                case Move: return "Move";
                case Forward: return "Forward";
                case Right: return "Right";
                case Speed: return "Speed";
                default: return null;
            }
        }

        #endregion

        #region Parameter Wrappers

        /// <summary>Get the value of the "Forward" parameter on the specified 'animator'.</summary>
        public static float GetForward(this UnityEngine.Animator animator) { return animator.GetFloat(Forward); }

        /// <summary>Get the value of the "Right" parameter on the specified 'animator'.</summary>
        public static float GetRight(this UnityEngine.Animator animator) { return animator.GetFloat(Right); }

        /// <summary>Get the value of the "Speed" parameter on the specified 'animator'.</summary>
        public static float GetSpeed(this UnityEngine.Animator animator) { return animator.GetFloat(Speed); }

        /// <summary>Set the value of the "Forward" parameter on the specified 'animator'.</summary>
        public static void SetForward(this UnityEngine.Animator animator, float value) { animator.SetFloat(Forward, value); }

        /// <summary>Set the value of the "Right" parameter on the specified 'animator'.</summary>
        public static void SetRight(this UnityEngine.Animator animator, float value) { animator.SetFloat(Right, value); }

        /// <summary>Set the value of the "Speed" parameter on the specified 'animator'.</summary>
        public static void SetSpeed(this UnityEngine.Animator animator, float value) { animator.SetFloat(Speed, value); }

        #endregion
    }
}