You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
75 lines
2.3 KiB
75 lines
2.3 KiB
8 years ago
|
// This code is part of the Fungus library (http://fungusgames.com) maintained by Chris Gregan (http://twitter.com/gofungus).
|
||
|
// It is released for free under the MIT open source license (https://github.com/snozbot/fungus/blob/master/LICENSE)
|
||
9 years ago
|
|
||
10 years ago
|
using UnityEngine;
|
||
9 years ago
|
using UnityEngine.Serialization;
|
||
10 years ago
|
|
||
10 years ago
|
namespace Fungus
|
||
10 years ago
|
{
|
||
8 years ago
|
/// <summary>
|
||
|
/// Sets a boolean parameter on an Animator component to control a Unity animation"
|
||
|
/// </summary>
|
||
8 years ago
|
[CommandInfo("Animation",
|
||
|
"Set Anim Bool",
|
||
|
"Sets a boolean parameter on an Animator component to control a Unity animation")]
|
||
|
[AddComponentMenu("")]
|
||
|
[ExecuteInEditMode]
|
||
|
public class SetAnimBool : Command
|
||
|
{
|
||
|
[Tooltip("Reference to an Animator component in a game object")]
|
||
8 years ago
|
[SerializeField] protected AnimatorData _animator;
|
||
10 years ago
|
|
||
8 years ago
|
[Tooltip("Name of the boolean Animator parameter that will have its value changed")]
|
||
8 years ago
|
[SerializeField] protected StringData _parameterName;
|
||
10 years ago
|
|
||
8 years ago
|
[Tooltip("The boolean value to set the parameter to")]
|
||
8 years ago
|
[SerializeField] protected BooleanData value;
|
||
10 years ago
|
|
||
8 years ago
|
public override void OnEnter()
|
||
|
{
|
||
|
if (_animator.Value != null)
|
||
|
{
|
||
|
_animator.Value.SetBool(_parameterName.Value, value.Value);
|
||
|
}
|
||
10 years ago
|
|
||
8 years ago
|
Continue();
|
||
|
}
|
||
10 years ago
|
|
||
8 years ago
|
public override string GetSummary()
|
||
|
{
|
||
|
if (_animator.Value == null)
|
||
|
{
|
||
|
return "Error: No animator selected";
|
||
|
}
|
||
10 years ago
|
|
||
8 years ago
|
return _animator.Value.name + " (" + _parameterName.Value + ")";
|
||
|
}
|
||
10 years ago
|
|
||
8 years ago
|
public override Color GetButtonColor()
|
||
|
{
|
||
|
return new Color32(170, 204, 169, 255);
|
||
|
}
|
||
9 years ago
|
|
||
8 years ago
|
#region Backwards compatibility
|
||
9 years ago
|
|
||
8 years ago
|
[HideInInspector] [FormerlySerializedAs("animator")] public Animator animatorOLD;
|
||
|
[HideInInspector] [FormerlySerializedAs("parameterName")] public string parameterNameOLD = "";
|
||
9 years ago
|
|
||
8 years ago
|
protected virtual void OnEnable()
|
||
|
{
|
||
|
if (animatorOLD != null)
|
||
|
{
|
||
|
_animator.Value = animatorOLD;
|
||
|
animatorOLD = null;
|
||
|
}
|
||
9 years ago
|
|
||
8 years ago
|
if (parameterNameOLD != "")
|
||
|
{
|
||
|
_parameterName.Value = parameterNameOLD;
|
||
|
parameterNameOLD = "";
|
||
|
}
|
||
|
}
|
||
9 years ago
|
|
||
8 years ago
|
#endregion
|
||
|
}
|
||
10 years ago
|
}
|