From ee2d85a18f01784e2c3f38137fdeeaabbe7a5053 Mon Sep 17 00:00:00 2001 From: chrisgregan Date: Sun, 13 Mar 2016 18:06:59 +0000 Subject: [PATCH] Anim commands use variable datas --- .../Scripts/Commands/ResetAnimTrigger.cs | 42 ++++++++++++--- .../Animation/Scripts/Commands/SetAnimBool.cs | 42 ++++++++++++--- .../Scripts/Commands/SetAnimFloat.cs | 42 ++++++++++++--- .../Scripts/Commands/SetAnimInteger.cs | 42 ++++++++++++--- .../Scripts/Commands/SetAnimTrigger.cs | 42 ++++++++++++--- .../Fungus/Flowchart/Editor/VariableEditor.cs | 6 ++- .../Scripts/VariableTypes/AnimatorVariable.cs | 51 +++++++++++++++++++ .../VariableTypes/AnimatorVariable.cs.meta | 12 +++++ 8 files changed, 243 insertions(+), 36 deletions(-) create mode 100644 Assets/Fungus/Flowchart/Scripts/VariableTypes/AnimatorVariable.cs create mode 100644 Assets/Fungus/Flowchart/Scripts/VariableTypes/AnimatorVariable.cs.meta diff --git a/Assets/Fungus/Animation/Scripts/Commands/ResetAnimTrigger.cs b/Assets/Fungus/Animation/Scripts/Commands/ResetAnimTrigger.cs index a778d909..1976b7a7 100644 --- a/Assets/Fungus/Animation/Scripts/Commands/ResetAnimTrigger.cs +++ b/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; + } + } } } \ No newline at end of file diff --git a/Assets/Fungus/Animation/Scripts/Commands/SetAnimBool.cs b/Assets/Fungus/Animation/Scripts/Commands/SetAnimBool.cs index 1e60682b..bd91c85a 100644 --- a/Assets/Fungus/Animation/Scripts/Commands/SetAnimBool.cs +++ b/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; + } + } } } \ No newline at end of file diff --git a/Assets/Fungus/Animation/Scripts/Commands/SetAnimFloat.cs b/Assets/Fungus/Animation/Scripts/Commands/SetAnimFloat.cs index 86473f17..c0cf9fe8 100644 --- a/Assets/Fungus/Animation/Scripts/Commands/SetAnimFloat.cs +++ b/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; + } + } } } \ No newline at end of file diff --git a/Assets/Fungus/Animation/Scripts/Commands/SetAnimInteger.cs b/Assets/Fungus/Animation/Scripts/Commands/SetAnimInteger.cs index 1b1f6292..307a8374 100644 --- a/Assets/Fungus/Animation/Scripts/Commands/SetAnimInteger.cs +++ b/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; + } + } } } \ No newline at end of file diff --git a/Assets/Fungus/Animation/Scripts/Commands/SetAnimTrigger.cs b/Assets/Fungus/Animation/Scripts/Commands/SetAnimTrigger.cs index 52555254..e2a73909 100644 --- a/Assets/Fungus/Animation/Scripts/Commands/SetAnimTrigger.cs +++ b/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; + } + } } } \ No newline at end of file diff --git a/Assets/Fungus/Flowchart/Editor/VariableEditor.cs b/Assets/Fungus/Flowchart/Editor/VariableEditor.cs index bf10888b..c0f324f0 100644 --- a/Assets/Fungus/Flowchart/Editor/VariableEditor.cs +++ b/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 {} + + [CustomPropertyDrawer (typeof(AnimatorData))] + public class AnimatorDataDrawer : VariableDataDrawer + {} } \ No newline at end of file diff --git a/Assets/Fungus/Flowchart/Scripts/VariableTypes/AnimatorVariable.cs b/Assets/Fungus/Flowchart/Scripts/VariableTypes/AnimatorVariable.cs new file mode 100644 index 00000000..b233d5b7 --- /dev/null +++ b/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 + {} + + [System.Serializable] + public struct AnimatorData + { + [SerializeField] + [VariableProperty("", 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; + } + } + } + +} \ No newline at end of file diff --git a/Assets/Fungus/Flowchart/Scripts/VariableTypes/AnimatorVariable.cs.meta b/Assets/Fungus/Flowchart/Scripts/VariableTypes/AnimatorVariable.cs.meta new file mode 100644 index 00000000..c507f7e9 --- /dev/null +++ b/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: