Browse Source

Anim commands use variable datas

master
chrisgregan 9 years ago
parent
commit
ee2d85a18f
  1. 42
      Assets/Fungus/Animation/Scripts/Commands/ResetAnimTrigger.cs
  2. 42
      Assets/Fungus/Animation/Scripts/Commands/SetAnimBool.cs
  3. 42
      Assets/Fungus/Animation/Scripts/Commands/SetAnimFloat.cs
  4. 42
      Assets/Fungus/Animation/Scripts/Commands/SetAnimInteger.cs
  5. 42
      Assets/Fungus/Animation/Scripts/Commands/SetAnimTrigger.cs
  6. 6
      Assets/Fungus/Flowchart/Editor/VariableEditor.cs
  7. 51
      Assets/Fungus/Flowchart/Scripts/VariableTypes/AnimatorVariable.cs
  8. 12
      Assets/Fungus/Flowchart/Scripts/VariableTypes/AnimatorVariable.cs.meta

42
Assets/Fungus/Animation/Scripts/Commands/ResetAnimTrigger.cs

@ -1,4 +1,5 @@
using UnityEngine;
using UnityEngine.Serialization;
using System;
using System.Collections;
@ -8,19 +9,24 @@ namespace Fungus
"Reset Anim Trigger",
"Resets a trigger parameter on an Animator component.")]
[AddComponentMenu("")]
public class ResetAnimTrigger : Command
public class ResetAnimTrigger : Command, ISerializationCallbackReceiver
{
#region Obsolete Properties
[HideInInspector] [FormerlySerializedAs("animator")] public Animator animatorOLD;
[HideInInspector] [FormerlySerializedAs("parameterName")] public string parameterNameOLD;
#endregion
[Tooltip("Reference to an Animator component in a game object")]
public Animator animator;
public AnimatorData _animator;
[Tooltip("Name of the trigger Animator parameter that will be reset")]
public string parameterName;
public StringData _parameterName;
public override void OnEnter()
{
if (animator != null)
if (_animator.Value != null)
{
animator.ResetTrigger(parameterName);
_animator.Value.ResetTrigger(_parameterName);
}
Continue();
@ -28,18 +34,40 @@ namespace Fungus
public override string GetSummary()
{
if (animator == null)
if (_animator.Value == null)
{
return "Error: No animator selected";
}
return animator.name + " (" + parameterName + ")";
return _animator.Value.name + " (" + _parameterName + ")";
}
public override Color GetButtonColor()
{
return new Color32(170, 204, 169, 255);
}
//
// ISerializationCallbackReceiver implementation
//
public void OnBeforeSerialize()
{}
public void OnAfterDeserialize()
{
if (animatorOLD != null)
{
_animator.Value = animatorOLD;
animatorOLD = null;
}
if (parameterNameOLD != null)
{
_parameterName.Value = parameterNameOLD;
parameterNameOLD = null;
}
}
}
}

42
Assets/Fungus/Animation/Scripts/Commands/SetAnimBool.cs

@ -1,4 +1,5 @@
using UnityEngine;
using UnityEngine.Serialization;
using System;
using System.Collections;
@ -8,22 +9,27 @@ namespace Fungus
"Set Anim Bool",
"Sets a boolean parameter on an Animator component to control a Unity animation")]
[AddComponentMenu("")]
public class SetAnimBool : Command
public class SetAnimBool : Command, ISerializationCallbackReceiver
{
#region Obsolete Properties
[HideInInspector] [FormerlySerializedAs("animator")] public Animator animatorOLD;
[HideInInspector] [FormerlySerializedAs("parameterName")] public string parameterNameOLD;
#endregion
[Tooltip("Reference to an Animator component in a game object")]
public Animator animator;
public AnimatorData _animator;
[Tooltip("Name of the boolean Animator parameter that will have its value changed")]
public string parameterName;
public StringData _parameterName;
[Tooltip("The boolean value to set the parameter to")]
public BooleanData value;
public override void OnEnter()
{
if (animator != null)
if (_animator.Value != null)
{
animator.SetBool(parameterName, value.Value);
_animator.Value.SetBool(_parameterName, value.Value);
}
Continue();
@ -31,18 +37,40 @@ namespace Fungus
public override string GetSummary()
{
if (animator == null)
if (_animator.Value == null)
{
return "Error: No animator selected";
}
return animator.name + " (" + parameterName + ")";
return _animator.Value.name + " (" + _parameterName + ")";
}
public override Color GetButtonColor()
{
return new Color32(170, 204, 169, 255);
}
//
// ISerializationCallbackReceiver implementation
//
public void OnBeforeSerialize()
{}
public void OnAfterDeserialize()
{
if (animatorOLD != null)
{
_animator.Value = animatorOLD;
animatorOLD = null;
}
if (parameterNameOLD != null)
{
_parameterName.Value = parameterNameOLD;
parameterNameOLD = null;
}
}
}
}

42
Assets/Fungus/Animation/Scripts/Commands/SetAnimFloat.cs

@ -1,4 +1,5 @@
using UnityEngine;
using UnityEngine.Serialization;
using System;
using System.Collections;
@ -8,22 +9,27 @@ namespace Fungus
"Set Anim Float",
"Sets a float parameter on an Animator component to control a Unity animation")]
[AddComponentMenu("")]
public class SetAnimFloat : Command
public class SetAnimFloat : Command, ISerializationCallbackReceiver
{
#region Obsolete Properties
[HideInInspector] [FormerlySerializedAs("animator")] public Animator animatorOLD;
[HideInInspector] [FormerlySerializedAs("parameterName")] public string parameterNameOLD;
#endregion
[Tooltip("Reference to an Animator component in a game object")]
public Animator animator;
public AnimatorData _animator;
[Tooltip("Name of the float Animator parameter that will have its value changed")]
public string parameterName;
public StringData _parameterName;
[Tooltip("The float value to set the parameter to")]
public FloatData value;
public override void OnEnter()
{
if (animator != null)
if (_animator.Value != null)
{
animator.SetFloat(parameterName, value.Value);
_animator.Value.SetFloat(_parameterName.Value, value.Value);
}
Continue();
@ -31,18 +37,40 @@ namespace Fungus
public override string GetSummary()
{
if (animator == null)
if (_animator.Value == null)
{
return "Error: No animator selected";
}
return animator.name + " (" + parameterName + ")";
return _animator.Value.name + " (" + _parameterName.Value + ")";
}
public override Color GetButtonColor()
{
return new Color32(170, 204, 169, 255);
}
//
// ISerializationCallbackReceiver implementation
//
public void OnBeforeSerialize()
{}
public void OnAfterDeserialize()
{
if (animatorOLD != null)
{
_animator.Value = animatorOLD;
animatorOLD = null;
}
if (parameterNameOLD != null)
{
_parameterName.Value = parameterNameOLD;
parameterNameOLD = null;
}
}
}
}

42
Assets/Fungus/Animation/Scripts/Commands/SetAnimInteger.cs

@ -1,4 +1,5 @@
using UnityEngine;
using UnityEngine.Serialization;
using System;
using System.Collections;
@ -8,22 +9,27 @@ namespace Fungus
"Set Anim Integer",
"Sets an integer parameter on an Animator component to control a Unity animation")]
[AddComponentMenu("")]
public class SetAnimInteger : Command
public class SetAnimInteger : Command, ISerializationCallbackReceiver
{
#region Obsolete Properties
[HideInInspector] [FormerlySerializedAs("animator")] public Animator animatorOLD;
[HideInInspector] [FormerlySerializedAs("parameterName")] public string parameterNameOLD;
#endregion
[Tooltip("Reference to an Animator component in a game object")]
public Animator animator;
public AnimatorData _animator;
[Tooltip("Name of the integer Animator parameter that will have its value changed")]
public string parameterName;
public StringData _parameterName;
[Tooltip("The integer value to set the parameter to")]
public IntegerData value;
public override void OnEnter()
{
if (animator != null)
if (_animator.Value != null)
{
animator.SetInteger(parameterName, value.Value);
_animator.Value.SetInteger(_parameterName.Value, value.Value);
}
Continue();
@ -31,18 +37,40 @@ namespace Fungus
public override string GetSummary()
{
if (animator == null)
if (_animator.Value == null)
{
return "Error: No animator selected";
}
return animator.name + " (" + parameterName + ")";
return _animator.Value.name + " (" + _parameterName.Value + ")";
}
public override Color GetButtonColor()
{
return new Color32(170, 204, 169, 255);
}
//
// ISerializationCallbackReceiver implementation
//
public void OnBeforeSerialize()
{}
public void OnAfterDeserialize()
{
if (animatorOLD != null)
{
_animator.Value = animatorOLD;
animatorOLD = null;
}
if (parameterNameOLD != null)
{
_parameterName.Value = parameterNameOLD;
parameterNameOLD = null;
}
}
}
}

42
Assets/Fungus/Animation/Scripts/Commands/SetAnimTrigger.cs

@ -1,4 +1,5 @@
using UnityEngine;
using UnityEngine.Serialization;
using System;
using System.Collections;
@ -8,19 +9,24 @@ namespace Fungus
"Set Anim Trigger",
"Sets a trigger parameter on an Animator component to control a Unity animation")]
[AddComponentMenu("")]
public class SetAnimTrigger : Command
public class SetAnimTrigger : Command, ISerializationCallbackReceiver
{
#region Obsolete Properties
[HideInInspector] [FormerlySerializedAs("animator")] public Animator animatorOLD;
[HideInInspector] [FormerlySerializedAs("parameterName")] public string parameterNameOLD;
#endregion
[Tooltip("Reference to an Animator component in a game object")]
public Animator animator;
public AnimatorData _animator;
[Tooltip("Name of the trigger Animator parameter that will have its value changed")]
public string parameterName;
public StringData _parameterName;
public override void OnEnter()
{
if (animator != null)
if (_animator.Value != null)
{
animator.SetTrigger(parameterName);
_animator.Value.SetTrigger(_parameterName.Value);
}
Continue();
@ -28,18 +34,40 @@ namespace Fungus
public override string GetSummary()
{
if (animator == null)
if (_animator.Value == null)
{
return "Error: No animator selected";
}
return animator.name + " (" + parameterName + ")";
return _animator.Value.name + " (" + _parameterName.Value + ")";
}
public override Color GetButtonColor()
{
return new Color32(170, 204, 169, 255);
}
//
// ISerializationCallbackReceiver implementation
//
public void OnBeforeSerialize()
{}
public void OnAfterDeserialize()
{
if (animatorOLD != null)
{
_animator.Value = animatorOLD;
animatorOLD = null;
}
if (parameterNameOLD != null)
{
_parameterName.Value = parameterNameOLD;
parameterNameOLD = null;
}
}
}
}

6
Assets/Fungus/Flowchart/Editor/VariableEditor.cs

@ -209,7 +209,7 @@ namespace Fungus
protected virtual void DrawSingleLineProperty(Rect rect, GUIContent label, SerializedProperty referenceProp, SerializedProperty valueProp, Flowchart flowchart)
{
const int popupWidth = 100;
const int popupWidth = 60;
Rect controlRect = EditorGUI.PrefixLabel(rect, label);
Rect valueRect = controlRect;
@ -319,4 +319,8 @@ namespace Fungus
[CustomPropertyDrawer (typeof(ObjectData))]
public class ObjectDataDrawer : VariableDataDrawer<ObjectVariable>
{}
[CustomPropertyDrawer (typeof(AnimatorData))]
public class AnimatorDataDrawer : VariableDataDrawer<AnimatorVariable>
{}
}

51
Assets/Fungus/Flowchart/Scripts/VariableTypes/AnimatorVariable.cs

@ -0,0 +1,51 @@
using UnityEngine;
using System.Collections;
namespace Fungus
{
[VariableInfo("Other", "Animator")]
[AddComponentMenu("")]
public class AnimatorVariable : VariableBase<Animator>
{}
[System.Serializable]
public struct AnimatorData
{
[SerializeField]
[VariableProperty("<Value>", typeof(AnimatorVariable))]
public AnimatorVariable animatorRef;
[SerializeField]
public Animator animatorVal;
public AnimatorData(Animator v)
{
animatorVal = v;
animatorRef = null;
}
public static implicit operator Animator(AnimatorData animatorData)
{
return animatorData.Value;
}
public Animator Value
{
get { return (animatorRef == null) ? animatorVal : animatorRef.value; }
set { if (animatorRef == null) { animatorVal = value; } else { animatorRef.value = value; } }
}
public string GetDescription()
{
if (animatorRef == null)
{
return animatorVal.ToString();
}
else
{
return animatorRef.key;
}
}
}
}

12
Assets/Fungus/Flowchart/Scripts/VariableTypes/AnimatorVariable.cs.meta

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 8cbd0c93fbe0e46f78685c33d82bcc7b
timeCreated: 1457886300
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
Loading…
Cancel
Save