// Animancer // Copyright 2020 Kybernetik // using System; using UnityEngine; using UnityEngine.Playables; namespace Animancer { /// [Pro-Only] /// A which manages three float parameters. /// /// /// See also: and . /// public sealed class Float3ControllerState : ControllerState { /************************************************************************************************************************/ private Parameter _ParameterX; /// /// The name of the parameter which will get and set. /// This will be null if the was assigned directly. /// public string ParameterNameX { get { return _ParameterX.Name; } set { _ParameterX.Name = value; _ParameterX.ValidateHasParameter(Controller, AnimatorControllerParameterType.Float); } } /// /// The name hash of the parameter which will get and set. /// public int ParameterHashX { get { return _ParameterX.Hash; } set { _ParameterX.Hash = value; _ParameterX.ValidateHasParameter(Controller, AnimatorControllerParameterType.Float); } } /// /// Gets and sets a float parameter in the using the /// as the id. /// public float ParameterX { get { return Playable.GetFloat(_ParameterX); } set { Playable.SetFloat(_ParameterX, value); } } /************************************************************************************************************************/ private Parameter _ParameterY; /// /// The name of the parameter which will get and set. /// This will be null if the was assigned directly. /// public string ParameterNameY { get { return _ParameterY.Name; } set { _ParameterY.Name = value; _ParameterY.ValidateHasParameter(Controller, AnimatorControllerParameterType.Float); } } /// /// The name hash of the parameter which will get and set. /// public int ParameterHashY { get { return _ParameterY.Hash; } set { _ParameterY.Hash = value; _ParameterY.ValidateHasParameter(Controller, AnimatorControllerParameterType.Float); } } /// /// Gets and sets a float parameter in the using the /// as the id. /// public float ParameterY { get { return Playable.GetFloat(_ParameterY); } set { Playable.SetFloat(_ParameterY, value); } } /************************************************************************************************************************/ private Parameter _ParameterZ; /// /// The name of the parameter which will get and set. /// This will be null if the was assigned directly. /// public string ParameterNameZ { get { return _ParameterZ.Name; } set { _ParameterZ.Name = value; _ParameterZ.ValidateHasParameter(Controller, AnimatorControllerParameterType.Float); } } /// /// The name hash of the parameter which will get and set. /// public int ParameterHashZ { get { return _ParameterZ.Hash; } set { _ParameterZ.Hash = value; _ParameterZ.ValidateHasParameter(Controller, AnimatorControllerParameterType.Float); } } /// /// Gets and sets a float parameter in the using the /// as the id. /// public float ParameterZ { get { return Playable.GetFloat(_ParameterZ); } set { Playable.SetFloat(_ParameterZ, value); } } /************************************************************************************************************************/ /// /// Gets and sets , , and . /// public new Vector3 Parameter { get { return new Vector3(ParameterX, ParameterY, ParameterZ); } set { ParameterX = value.x; ParameterY = value.y; ParameterZ = value.z; } } /************************************************************************************************************************/ /// /// Constructs a new to play the `controller` without connecting /// it to the . /// private Float3ControllerState(AnimancerPlayable root, RuntimeAnimatorController controller, Parameter parameterX, Parameter parameterY, Parameter parameterZ, bool resetStatesOnStop = true) : base(root, controller, resetStatesOnStop) { _ParameterX = parameterX; _ParameterX.ValidateHasParameter(Controller, AnimatorControllerParameterType.Float); _ParameterY = parameterY; _ParameterY.ValidateHasParameter(Controller, AnimatorControllerParameterType.Float); _ParameterZ = parameterZ; _ParameterZ.ValidateHasParameter(Controller, AnimatorControllerParameterType.Float); } /// /// Constructs a new to play the `controller` and connects it to the /// the `layer`. /// public Float3ControllerState(AnimancerLayer layer, RuntimeAnimatorController controller, Parameter parameterX, Parameter parameterY, Parameter parameterZ, bool resetStatesOnStop = true) : this(layer.Root, controller, parameterX, parameterY, parameterZ, resetStatesOnStop) { layer.AddChild(this); } /// /// Constructs a new to play the `controller` and /// connects it to the `parent` at the specified `index`. /// public Float3ControllerState(AnimancerNode parent, int index, RuntimeAnimatorController controller, Parameter parameterX, Parameter parameterY, Parameter parameterZ, bool resetStatesOnStop = true) : this(parent.Root, controller, parameterX, parameterY, parameterZ, resetStatesOnStop) { SetParent(parent, index); } /************************************************************************************************************************/ /// The number of parameters being wrapped by this state. public override int ParameterCount { get { return 3; } } /// Returns the hash of a parameter being wrapped by this state. public override int GetParameterHash(int index) { switch (index) { case 0: return ParameterHashX; case 1: return ParameterHashY; case 2: return ParameterHashZ; default: throw new ArgumentOutOfRangeException("index"); }; } /************************************************************************************************************************/ #region Transition /************************************************************************************************************************/ /// /// A serializable which can create a /// when passed into . /// /// /// Unfortunately the tool used to generate this documentation does not currently support nested types with /// identical names, so only one Transition class will actually have a documentation page. /// [Serializable] public new class Transition : Transition { /************************************************************************************************************************/ [SerializeField] private string _ParameterNameX; /// [] /// The that will be used for the created state. /// public string ParameterNameX { get { return _ParameterNameX; } set { _ParameterNameX = value; } } /************************************************************************************************************************/ [SerializeField] private string _ParameterNameY; /// [] /// The that will be used for the created state. /// public string ParameterNameY { get { return _ParameterNameY; } set { _ParameterNameY = value; } } /************************************************************************************************************************/ [SerializeField] private string _ParameterNameZ; /// [] /// The that will be used for the created state. /// public string ParameterNameZ { get { return _ParameterNameZ; } set { _ParameterNameZ = value; } } /************************************************************************************************************************/ /// Constructs a new . public Transition() { } /// Constructs a new with the specified Animator Controller and parameters. public Transition(RuntimeAnimatorController controller, string parameterNameX, string parameterNameY, string parameterNameZ) { Controller = controller; _ParameterNameX = parameterNameX; _ParameterNameY = parameterNameY; _ParameterNameZ = parameterNameZ; } /************************************************************************************************************************/ /// /// Creates and returns a new connected to the `layer`. /// /// This method also assigns it as the . /// public override Float3ControllerState CreateState(AnimancerLayer layer) { return new Float3ControllerState(layer, Controller, _ParameterNameX, _ParameterNameY, _ParameterNameZ, KeepStateOnStop); } /************************************************************************************************************************/ #region Drawer #if UNITY_EDITOR /************************************************************************************************************************/ /// [Editor-Only] Draws the Inspector GUI for a . [UnityEditor.CustomPropertyDrawer(typeof(Transition), true)] public class Drawer : ControllerState.Transition.Drawer { /************************************************************************************************************************/ /// /// Constructs a new and sets the /// . /// public Drawer() : base("_ParameterNameX", "_ParameterNameY", "_ParameterNameZ") { } /************************************************************************************************************************/ } /************************************************************************************************************************/ #endif #endregion /************************************************************************************************************************/ } /************************************************************************************************************************/ #endregion /************************************************************************************************************************/ } }