// Animancer // Copyright 2020 Kybernetik //
using System;
using UnityEngine;
using UnityEngine.Playables;
namespace Animancer
{
/// [Pro-Only]
/// A which manages two float parameters.
///
///
/// See also: and .
///
public sealed class Float2ControllerState : 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); }
}
/************************************************************************************************************************/
///
/// Gets and sets and .
///
public new Vector2 Parameter
{
get
{
return new Vector2(ParameterX, ParameterY);
}
set
{
ParameterX = value.x;
ParameterY = value.y;
}
}
/************************************************************************************************************************/
///
/// Constructs a new to play the `controller` without connecting
/// it to the .
///
private Float2ControllerState(AnimancerPlayable root, RuntimeAnimatorController controller,
Parameter parameterX, Parameter parameterY, bool resetStatesOnStop = true)
: base(root, controller, resetStatesOnStop)
{
_ParameterX = parameterX;
_ParameterX.ValidateHasParameter(Controller, AnimatorControllerParameterType.Float);
_ParameterY = parameterY;
_ParameterY.ValidateHasParameter(Controller, AnimatorControllerParameterType.Float);
}
///
/// Constructs a new to play the `controller` and connects it to the
/// the `layer`.
///
public Float2ControllerState(AnimancerLayer layer, RuntimeAnimatorController controller,
Parameter parameterX, Parameter parameterY, bool resetStatesOnStop = true)
: this(layer.Root, controller, parameterX, parameterY, resetStatesOnStop)
{
layer.AddChild(this);
}
///
/// Constructs a new to play the `controller` and
/// connects it to the `parent` at the specified `index`.
///
public Float2ControllerState(AnimancerNode parent, int index, RuntimeAnimatorController controller,
Parameter parameterX, Parameter parameterY, bool resetStatesOnStop = true)
: this(parent.Root, controller, parameterX, parameterY, resetStatesOnStop)
{
SetParent(parent, index);
}
/************************************************************************************************************************/
/// The number of parameters being wrapped by this state.
public override int ParameterCount { get { return 2; } }
/// 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;
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; }
}
/************************************************************************************************************************/
/// Constructs a new .
public Transition() { }
/// Constructs a new with the specified Animator Controller and parameters.
public Transition(RuntimeAnimatorController controller, string parameterNameX, string parameterNameY)
{
Controller = controller;
_ParameterNameX = parameterNameX;
_ParameterNameY = parameterNameY;
}
/************************************************************************************************************************/
///
/// Creates and returns a new connected to the `layer`.
///
/// This method also assigns it as the .
///
public override Float2ControllerState CreateState(AnimancerLayer layer)
{
return new Float2ControllerState(layer, Controller, _ParameterNameX, _ParameterNameY, 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") { }
/************************************************************************************************************************/
}
/************************************************************************************************************************/
#endif
#endregion
/************************************************************************************************************************/
}
/************************************************************************************************************************/
#endregion
/************************************************************************************************************************/
}
}