diff --git a/Assets/Fungus/Scripts/Commands/SetVariable.cs b/Assets/Fungus/Scripts/Commands/SetVariable.cs index 4b3d9b8b..ee8df49b 100644 --- a/Assets/Fungus/Scripts/Commands/SetVariable.cs +++ b/Assets/Fungus/Scripts/Commands/SetVariable.cs @@ -20,6 +20,7 @@ namespace Fungus typeof(IntegerVariable), typeof(FloatVariable), typeof(StringVariable), + typeof(AnimatorVariable), typeof(GameObjectVariable))] [SerializeField] protected Variable variable; @@ -38,6 +39,9 @@ namespace Fungus [Tooltip("String value to set with")] [SerializeField] protected StringDataMulti stringData; + [Tooltip("Animator value to set with")] + [SerializeField] protected AnimatorData animatorData; + [Tooltip("GameObject value to set with")] [SerializeField] protected GameObjectData gameObjectData; @@ -69,6 +73,11 @@ namespace Fungus var flowchart = GetFlowchart(); stringVariable.Apply(setOperator, flowchart.SubstituteVariables(stringData.Value)); } + else if (variable.GetType() == typeof(AnimatorVariable)) + { + AnimatorVariable animatorVariable = (variable as AnimatorVariable); + animatorVariable.Apply(setOperator, animatorData.Value); + } else if (variable.GetType() == typeof(GameObjectVariable)) { GameObjectVariable gameObjectVariable = (variable as GameObjectVariable); @@ -83,6 +92,7 @@ namespace Fungus { typeof(IntegerVariable), IntegerVariable.setOperators }, { typeof(FloatVariable), FloatVariable.setOperators }, { typeof(StringVariable), StringVariable.setOperators }, + { typeof(AnimatorVariable), AnimatorVariable.setOperators }, { typeof(GameObjectVariable), GameObjectVariable.setOperators } }; @@ -146,6 +156,10 @@ namespace Fungus { description += stringData.GetDescription(); } + else if (variable.GetType() == typeof(AnimatorVariable)) + { + description += animatorData.GetDescription(); + } else if (variable.GetType() == typeof(GameObjectVariable)) { description += gameObjectData.GetDescription(); diff --git a/Assets/Fungus/Scripts/Commands/VariableCondition.cs b/Assets/Fungus/Scripts/Commands/VariableCondition.cs index e5a953b4..58ce1e02 100644 --- a/Assets/Fungus/Scripts/Commands/VariableCondition.cs +++ b/Assets/Fungus/Scripts/Commands/VariableCondition.cs @@ -16,6 +16,7 @@ namespace Fungus typeof(IntegerVariable), typeof(FloatVariable), typeof(StringVariable), + typeof(AnimatorVariable), typeof(GameObjectVariable))] [SerializeField] protected Variable variable; @@ -31,6 +32,9 @@ namespace Fungus [Tooltip("String value to compare against")] [SerializeField] protected StringDataMulti stringData; + [Tooltip("Animator value to compare against")] + [SerializeField] protected AnimatorData animatorData; + [Tooltip("GameObject value to compare against")] [SerializeField] protected GameObjectData gameObjectData; @@ -63,6 +67,11 @@ namespace Fungus StringVariable stringVariable = (variable as StringVariable); condition = stringVariable.Evaluate(compareOperator, stringData.Value); } + else if (variable.GetType() == typeof(AnimatorVariable)) + { + AnimatorVariable animatorVariable = (variable as AnimatorVariable); + condition = animatorVariable.Evaluate(compareOperator, animatorData.Value); + } else if (variable.GetType() == typeof(GameObjectVariable)) { GameObjectVariable gameObjectVariable = (variable as GameObjectVariable); @@ -84,6 +93,7 @@ namespace Fungus { typeof(IntegerVariable), IntegerVariable.compareOperators }, { typeof(FloatVariable), FloatVariable.compareOperators }, { typeof(StringVariable), StringVariable.compareOperators }, + { typeof(AnimatorVariable), AnimatorVariable.compareOperators }, { typeof(GameObjectVariable), GameObjectVariable.compareOperators } }; @@ -118,6 +128,10 @@ namespace Fungus { summary += stringData.GetDescription(); } + else if (variable.GetType() == typeof(AnimatorVariable)) + { + summary += animatorData.GetDescription(); + } else if (variable.GetType() == typeof(GameObjectVariable)) { summary += gameObjectData.GetDescription(); diff --git a/Assets/Fungus/Scripts/Editor/SetVariableEditor.cs b/Assets/Fungus/Scripts/Editor/SetVariableEditor.cs index f8b1c394..a604b4a1 100644 --- a/Assets/Fungus/Scripts/Editor/SetVariableEditor.cs +++ b/Assets/Fungus/Scripts/Editor/SetVariableEditor.cs @@ -44,6 +44,7 @@ namespace Fungus.EditorUtils { typeof(IntegerVariable), new VariablePropertyInfo("Integer", serializedObject.FindProperty("integerData")) }, { typeof(FloatVariable), new VariablePropertyInfo("Float", serializedObject.FindProperty("floatData")) }, { typeof(StringVariable), new VariablePropertyInfo("String", serializedObject.FindProperty("stringData")) }, + { typeof(AnimatorVariable), new VariablePropertyInfo("Animator", serializedObject.FindProperty("animatorData")) }, { typeof(GameObjectVariable), new VariablePropertyInfo("GameObject", serializedObject.FindProperty("gameObjectData")) } }; } diff --git a/Assets/Fungus/Scripts/Editor/VariableConditionEditor.cs b/Assets/Fungus/Scripts/Editor/VariableConditionEditor.cs index 3fd3f2fd..b2c02858 100644 --- a/Assets/Fungus/Scripts/Editor/VariableConditionEditor.cs +++ b/Assets/Fungus/Scripts/Editor/VariableConditionEditor.cs @@ -29,6 +29,7 @@ namespace Fungus.EditorUtils { typeof(IntegerVariable), serializedObject.FindProperty("integerData") }, { typeof(FloatVariable), serializedObject.FindProperty("floatData") }, { typeof(StringVariable), serializedObject.FindProperty("stringData") }, + { typeof(AnimatorVariable), serializedObject.FindProperty("animatorData") }, { typeof(GameObjectVariable), serializedObject.FindProperty("gameObjectData") } }; } diff --git a/Assets/Fungus/Scripts/VariableTypes/AnimatorVariable.cs b/Assets/Fungus/Scripts/VariableTypes/AnimatorVariable.cs index 39a411e0..d564385d 100644 --- a/Assets/Fungus/Scripts/VariableTypes/AnimatorVariable.cs +++ b/Assets/Fungus/Scripts/VariableTypes/AnimatorVariable.cs @@ -12,7 +12,43 @@ namespace Fungus [AddComponentMenu("")] [System.Serializable] public class AnimatorVariable : VariableBase - {} + { + public static readonly CompareOperator[] compareOperators = { CompareOperator.Equals, CompareOperator.NotEquals }; + public static readonly SetOperator[] setOperators = { SetOperator.Assign }; + + public virtual bool Evaluate(CompareOperator compareOperator, Animator value) + { + bool condition = false; + + switch (compareOperator) + { + case CompareOperator.Equals: + condition = Value == value; + break; + case CompareOperator.NotEquals: + condition = Value != value; + break; + default: + Debug.LogError("The " + compareOperator.ToString() + " comparison operator is not valid."); + break; + } + + return condition; + } + + public override void Apply(SetOperator setOperator, Animator value) + { + switch (setOperator) + { + case SetOperator.Assign: + Value = value; + break; + default: + Debug.LogError("The " + setOperator.ToString() + " set operator is not valid."); + break; + } + } + } /// /// Container for an Animator variable reference or constant value.