// Animancer // Copyright 2020 Kybernetik //
using System;
using UnityEngine;
using UnityEngine.Playables;
namespace Animancer
{
/// [Pro-Only]
/// A which manages one float parameter.
///
///
/// See also: and .
///
public sealed class Float1ControllerState : ControllerState
{
/************************************************************************************************************************/
private Parameter _Parameter;
///
/// The name of the parameter which will get and set.
/// This will be null if the was assigned directly.
///
public string ParameterName
{
get { return _Parameter.Name; }
set
{
_Parameter.Name = value;
_Parameter.ValidateHasParameter(Controller, AnimatorControllerParameterType.Float);
}
}
///
/// The name hash of the parameter which will get and set.
///
public int ParameterHash
{
get { return _Parameter.Hash; }
set
{
_Parameter.Hash = value;
_Parameter.ValidateHasParameter(Controller, AnimatorControllerParameterType.Float);
}
}
///
/// Gets and sets a float parameter in the using the
/// as the id.
///
public new float Parameter
{
get { return Playable.GetFloat(_Parameter); }
set { Playable.SetFloat(_Parameter, value); }
}
/************************************************************************************************************************/
///
/// Constructs a new to play the `controller` without connecting
/// it to the .
///
private Float1ControllerState(AnimancerPlayable root, RuntimeAnimatorController controller, Parameter parameter,
bool resetStatesOnStop = true)
: base(root, controller, resetStatesOnStop)
{
_Parameter = parameter;
_Parameter.ValidateHasParameter(controller, AnimatorControllerParameterType.Float);
}
///
/// Constructs a new to play the `controller` and connects it to the
/// the `layer`.
///
public Float1ControllerState(AnimancerLayer layer, RuntimeAnimatorController controller, Parameter parameter,
bool resetStatesOnStop = true)
: this(layer.Root, controller, parameter, resetStatesOnStop)
{
layer.AddChild(this);
}
///
/// Constructs a new to play the `controller` and connects
/// connects it to the `parent` at the specified `index`.
///
public Float1ControllerState(AnimancerNode parent, int index, RuntimeAnimatorController controller, Parameter parameter,
bool resetStatesOnStop = true)
: this(parent.Root, controller, parameter, resetStatesOnStop)
{
SetParent(parent, index);
}
/************************************************************************************************************************/
/// The number of parameters being wrapped by this state.
public override int ParameterCount { get { return 1; } }
/// Returns the hash of a parameter being wrapped by this state.
public override int GetParameterHash(int index) { return ParameterHash; }
/************************************************************************************************************************/
#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 _ParameterName;
/// []
/// The that will be used for the created state.
///
public string ParameterName
{
get { return _ParameterName; }
set { _ParameterName = value; }
}
/************************************************************************************************************************/
/// Constructs a new .
public Transition() { }
/// Constructs a new with the specified Animator Controller and parameter.
public Transition(RuntimeAnimatorController controller, string parameterName)
{
Controller = controller;
_ParameterName = parameterName;
}
/************************************************************************************************************************/
///
/// Creates and returns a new connected to the `layer`.
///
/// This method also assigns it as the .
///
public override Float1ControllerState CreateState(AnimancerLayer layer)
{
return new Float1ControllerState(layer, Controller, _ParameterName, 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("_ParameterName") { }
/************************************************************************************************************************/
}
/************************************************************************************************************************/
#endif
#endregion
/************************************************************************************************************************/
}
/************************************************************************************************************************/
#endregion
/************************************************************************************************************************/
}
}