diff --git a/Assets/Fungus/Scripts/Commands/SetVariable.cs b/Assets/Fungus/Scripts/Commands/SetVariable.cs index dc48f645..e0eed681 100644 --- a/Assets/Fungus/Scripts/Commands/SetVariable.cs +++ b/Assets/Fungus/Scripts/Commands/SetVariable.cs @@ -24,7 +24,8 @@ namespace Fungus typeof(AudioSourceVariable), typeof(ColorVariable), typeof(GameObjectVariable), - typeof(MaterialVariable))] + typeof(MaterialVariable), + typeof(ObjectVariable))] [SerializeField] protected Variable variable; [Tooltip("The type of math operation to be performed")] @@ -57,6 +58,9 @@ namespace Fungus [Tooltip("Material value to set with")] [SerializeField] protected MaterialData materialData; + [Tooltip("Object value to set with")] + [SerializeField] protected ObjectData objectData; + protected virtual void DoSetOperation() { if (variable == null) @@ -110,6 +114,11 @@ namespace Fungus MaterialVariable materialVariable = (variable as MaterialVariable); materialVariable.Apply(setOperator, materialData.Value); } + else if (variable.GetType() == typeof(ObjectVariable)) + { + ObjectVariable objectVariable = (variable as ObjectVariable); + objectVariable.Apply(setOperator, objectData.Value); + } } #region Public members @@ -123,7 +132,8 @@ namespace Fungus { typeof(AudioSourceVariable), AudioSourceVariable.setOperators }, { typeof(ColorVariable), ColorVariable.setOperators }, { typeof(GameObjectVariable), GameObjectVariable.setOperators }, - { typeof(MaterialVariable), MaterialVariable.setOperators } + { typeof(MaterialVariable), MaterialVariable.setOperators }, + { typeof(ObjectVariable), ObjectVariable.setOperators } }; /// @@ -206,6 +216,10 @@ namespace Fungus { description += materialData.GetDescription(); } + else if (variable.GetType() == typeof(ObjectVariable)) + { + description += objectData.GetDescription(); + } return description; } diff --git a/Assets/Fungus/Scripts/Commands/VariableCondition.cs b/Assets/Fungus/Scripts/Commands/VariableCondition.cs index 45904051..f0b1c3c3 100644 --- a/Assets/Fungus/Scripts/Commands/VariableCondition.cs +++ b/Assets/Fungus/Scripts/Commands/VariableCondition.cs @@ -20,7 +20,8 @@ namespace Fungus typeof(AudioSourceVariable), typeof(ColorVariable), typeof(GameObjectVariable), - typeof(MaterialVariable))] + typeof(MaterialVariable), + typeof(ObjectVariable))] [SerializeField] protected Variable variable; [Tooltip("Boolean value to compare against")] @@ -50,6 +51,9 @@ namespace Fungus [Tooltip("Material value to compare against")] [SerializeField] protected MaterialData materialData; + [Tooltip("Object value to compare against")] + [SerializeField] protected ObjectData objectData; + protected override bool EvaluateCondition() { if (variable == null) @@ -104,6 +108,11 @@ namespace Fungus MaterialVariable materialVariable = (variable as MaterialVariable); condition = materialVariable.Evaluate(compareOperator, materialData.Value); } + else if (variable.GetType() == typeof(ObjectVariable)) + { + ObjectVariable objectVariable = (variable as ObjectVariable); + condition = objectVariable.Evaluate(compareOperator, objectData.Value); + } return condition; } @@ -124,7 +133,8 @@ namespace Fungus { typeof(AudioSourceVariable), AudioSourceVariable.compareOperators }, { typeof(ColorVariable), ColorVariable.compareOperators }, { typeof(GameObjectVariable), GameObjectVariable.compareOperators }, - { typeof(MaterialVariable), MaterialVariable.compareOperators } + { typeof(MaterialVariable), MaterialVariable.compareOperators }, + { typeof(ObjectVariable), ObjectVariable.compareOperators } }; /// @@ -178,6 +188,10 @@ namespace Fungus { summary += materialData.GetDescription(); } + else if (variable.GetType() == typeof(ObjectVariable)) + { + summary += objectData.GetDescription(); + } return summary; } diff --git a/Assets/Fungus/Scripts/Editor/SetVariableEditor.cs b/Assets/Fungus/Scripts/Editor/SetVariableEditor.cs index f7dc590a..003afba0 100644 --- a/Assets/Fungus/Scripts/Editor/SetVariableEditor.cs +++ b/Assets/Fungus/Scripts/Editor/SetVariableEditor.cs @@ -48,7 +48,8 @@ namespace Fungus.EditorUtils { typeof(AudioSourceVariable), new VariablePropertyInfo("AudioSource", serializedObject.FindProperty("audioSourceData")) }, { typeof(ColorVariable), new VariablePropertyInfo("Color", serializedObject.FindProperty("colorData")) }, { typeof(GameObjectVariable), new VariablePropertyInfo("GameObject", serializedObject.FindProperty("gameObjectData")) }, - { typeof(MaterialVariable), new VariablePropertyInfo("Material", serializedObject.FindProperty("materialData")) } + { typeof(MaterialVariable), new VariablePropertyInfo("Material", serializedObject.FindProperty("materialData")) }, + { typeof(ObjectVariable), new VariablePropertyInfo("Object", serializedObject.FindProperty("objectData")) } }; } diff --git a/Assets/Fungus/Scripts/Editor/VariableConditionEditor.cs b/Assets/Fungus/Scripts/Editor/VariableConditionEditor.cs index 80324288..a7c992d4 100644 --- a/Assets/Fungus/Scripts/Editor/VariableConditionEditor.cs +++ b/Assets/Fungus/Scripts/Editor/VariableConditionEditor.cs @@ -33,7 +33,8 @@ namespace Fungus.EditorUtils { typeof(AudioSourceVariable), serializedObject.FindProperty("audioSourceData") }, { typeof(ColorVariable), serializedObject.FindProperty("colorData") }, { typeof(GameObjectVariable), serializedObject.FindProperty("gameObjectData") }, - { typeof(MaterialVariable), serializedObject.FindProperty("materialData") } + { typeof(MaterialVariable), serializedObject.FindProperty("materialData") }, + { typeof(ObjectVariable), serializedObject.FindProperty("objectData") } }; } diff --git a/Assets/Fungus/Scripts/VariableTypes/ObjectVariable.cs b/Assets/Fungus/Scripts/VariableTypes/ObjectVariable.cs index 1d3fcb9d..39d6df3f 100644 --- a/Assets/Fungus/Scripts/VariableTypes/ObjectVariable.cs +++ b/Assets/Fungus/Scripts/VariableTypes/ObjectVariable.cs @@ -13,7 +13,43 @@ namespace Fungus [AddComponentMenu("")] [System.Serializable] public class ObjectVariable : VariableBase - {} + { + public static readonly CompareOperator[] compareOperators = { CompareOperator.Equals, CompareOperator.NotEquals }; + public static readonly SetOperator[] setOperators = { SetOperator.Assign }; + + public virtual bool Evaluate(CompareOperator compareOperator, Object 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, Object value) + { + switch (setOperator) + { + case SetOperator.Assign: + Value = value; + break; + default: + Debug.LogError("The " + setOperator.ToString() + " set operator is not valid."); + break; + } + } + } /// /// Container for an Object variable reference or constant value.