diff --git a/Assets/Fungus/Scripts/Commands/SetVariable.cs b/Assets/Fungus/Scripts/Commands/SetVariable.cs index 4b3d9b8b..98e3f3ba 100644 --- a/Assets/Fungus/Scripts/Commands/SetVariable.cs +++ b/Assets/Fungus/Scripts/Commands/SetVariable.cs @@ -9,18 +9,29 @@ namespace Fungus /// /// Sets a Boolean, Integer, Float or String variable to a new value using a simple arithmetic operation. The value can be a constant or reference another variable of the same type. /// - [CommandInfo("Variable", - "Set Variable", + [CommandInfo("Variable", + "Set Variable", "Sets a Boolean, Integer, Float or String variable to a new value using a simple arithmetic operation. The value can be a constant or reference another variable of the same type.")] [AddComponentMenu("")] - public class SetVariable : Command + public class SetVariable : Command { [Tooltip("The variable whos value will be set")] [VariableProperty(typeof(BooleanVariable), - typeof(IntegerVariable), - typeof(FloatVariable), + typeof(IntegerVariable), + typeof(FloatVariable), typeof(StringVariable), - typeof(GameObjectVariable))] + typeof(AnimatorVariable), + typeof(AudioSourceVariable), + typeof(ColorVariable), + typeof(GameObjectVariable), + typeof(MaterialVariable), + typeof(ObjectVariable), + typeof(Rigidbody2DVariable), + typeof(SpriteVariable), + typeof(TextureVariable), + typeof(TransformVariable), + typeof(Vector2Variable), + typeof(Vector3Variable))] [SerializeField] protected Variable variable; [Tooltip("The type of math operation to be performed")] @@ -38,9 +49,42 @@ namespace Fungus [Tooltip("String value to set with")] [SerializeField] protected StringDataMulti stringData; + [Tooltip("Animator value to set with")] + [SerializeField] protected AnimatorData animatorData; + + [Tooltip("AudioSource value to set with")] + [SerializeField] protected AudioSourceData audioSourceData; + + [Tooltip("Color value to set with")] + [SerializeField] protected ColorData colorData; + [Tooltip("GameObject value to set with")] [SerializeField] protected GameObjectData gameObjectData; + [Tooltip("Material value to set with")] + [SerializeField] protected MaterialData materialData; + + [Tooltip("Object value to set with")] + [SerializeField] protected ObjectData objectData; + + [Tooltip("Rigidbody2D value to set with")] + [SerializeField] protected Rigidbody2DData rigidbody2DData; + + [Tooltip("Sprite value to set with")] + [SerializeField] protected SpriteData spriteData; + + [Tooltip("Texture value to set with")] + [SerializeField] protected TextureData textureData; + + [Tooltip("Transform value to set with")] + [SerializeField] protected TransformData transformData; + + [Tooltip("Vector2 value to set with")] + [SerializeField] protected Vector2Data vector2Data; + + [Tooltip("Vector3 value to set with")] + [SerializeField] protected Vector3Data vector3Data; + protected virtual void DoSetOperation() { if (variable == null) @@ -69,11 +113,66 @@ 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(AudioSourceVariable)) + { + AudioSourceVariable audioSourceVariable = (variable as AudioSourceVariable); + audioSourceVariable.Apply(setOperator, audioSourceData.Value); + } + else if (variable.GetType() == typeof(ColorVariable)) + { + ColorVariable colorVariable = (variable as ColorVariable); + colorVariable.Apply(setOperator, colorData.Value); + } else if (variable.GetType() == typeof(GameObjectVariable)) { GameObjectVariable gameObjectVariable = (variable as GameObjectVariable); gameObjectVariable.Apply(setOperator, gameObjectData.Value); } + else if (variable.GetType() == typeof(MaterialVariable)) + { + 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); + } + else if (variable.GetType() == typeof(Rigidbody2DVariable)) + { + Rigidbody2DVariable rigidbody2DVariable = (variable as Rigidbody2DVariable); + rigidbody2DVariable.Apply(setOperator, rigidbody2DData.Value); + } + else if (variable.GetType() == typeof(SpriteVariable)) + { + SpriteVariable spriteVariable = (variable as SpriteVariable); + spriteVariable.Apply(setOperator, spriteData.Value); + } + else if (variable.GetType() == typeof(TextureVariable)) + { + TextureVariable textureVariable = (variable as TextureVariable); + textureVariable.Apply(setOperator, textureData.Value); + } + else if (variable.GetType() == typeof(TransformVariable)) + { + TransformVariable transformVariable = (variable as TransformVariable); + transformVariable.Apply(setOperator, transformData.Value); + } + else if (variable.GetType() == typeof(Vector2Variable)) + { + Vector2Variable vector2Variable = (variable as Vector2Variable); + vector2Variable.Apply(setOperator, vector2Data.Value); + } + else if (variable.GetType() == typeof(Vector3Variable)) + { + Vector3Variable vector3Variable = (variable as Vector3Variable); + vector3Variable.Apply(setOperator, vector3Data.Value); + } } #region Public members @@ -83,7 +182,18 @@ namespace Fungus { typeof(IntegerVariable), IntegerVariable.setOperators }, { typeof(FloatVariable), FloatVariable.setOperators }, { typeof(StringVariable), StringVariable.setOperators }, - { typeof(GameObjectVariable), GameObjectVariable.setOperators } + { typeof(AnimatorVariable), AnimatorVariable.setOperators }, + { typeof(AudioSourceVariable), AudioSourceVariable.setOperators }, + { typeof(ColorVariable), ColorVariable.setOperators }, + { typeof(GameObjectVariable), GameObjectVariable.setOperators }, + { typeof(MaterialVariable), MaterialVariable.setOperators }, + { typeof(ObjectVariable), ObjectVariable.setOperators }, + { typeof(Rigidbody2DVariable), Rigidbody2DVariable.setOperators }, + { typeof(SpriteVariable), SpriteVariable.setOperators }, + { typeof(TextureVariable), TextureVariable.setOperators }, + { typeof(TransformVariable), TransformVariable.setOperators }, + { typeof(Vector2Variable), Vector2Variable.setOperators }, + { typeof(Vector3Variable), Vector3Variable.setOperators } }; /// @@ -146,10 +256,54 @@ namespace Fungus { description += stringData.GetDescription(); } + else if (variable.GetType() == typeof(AnimatorVariable)) + { + description += animatorData.GetDescription(); + } + else if (variable.GetType() == typeof(AudioSourceVariable)) + { + description += audioSourceData.GetDescription(); + } + else if (variable.GetType() == typeof(ColorVariable)) + { + description += colorData.GetDescription(); + } else if (variable.GetType() == typeof(GameObjectVariable)) { description += gameObjectData.GetDescription(); } + else if (variable.GetType() == typeof(MaterialVariable)) + { + description += materialData.GetDescription(); + } + else if (variable.GetType() == typeof(ObjectVariable)) + { + description += objectData.GetDescription(); + } + else if (variable.GetType() == typeof(Rigidbody2DVariable)) + { + description += rigidbody2DData.GetDescription(); + } + else if (variable.GetType() == typeof(SpriteVariable)) + { + description += spriteData.GetDescription(); + } + else if (variable.GetType() == typeof(TextureVariable)) + { + description += textureData.GetDescription(); + } + else if (variable.GetType() == typeof(TransformVariable)) + { + description += transformData.GetDescription(); + } + else if (variable.GetType() == typeof(Vector2Variable)) + { + description += vector2Data.GetDescription(); + } + else if (variable.GetType() == typeof(Vector3Variable)) + { + description += vector3Data.GetDescription(); + } return description; } diff --git a/Assets/Fungus/Scripts/Commands/VariableCondition.cs b/Assets/Fungus/Scripts/Commands/VariableCondition.cs index e5a953b4..f69db54f 100644 --- a/Assets/Fungus/Scripts/Commands/VariableCondition.cs +++ b/Assets/Fungus/Scripts/Commands/VariableCondition.cs @@ -13,10 +13,21 @@ namespace Fungus [Tooltip("Variable to use in expression")] [VariableProperty(typeof(BooleanVariable), - typeof(IntegerVariable), - typeof(FloatVariable), + typeof(IntegerVariable), + typeof(FloatVariable), typeof(StringVariable), - typeof(GameObjectVariable))] + typeof(AnimatorVariable), + typeof(AudioSourceVariable), + typeof(ColorVariable), + typeof(GameObjectVariable), + typeof(MaterialVariable), + typeof(ObjectVariable), + typeof(Rigidbody2DVariable), + typeof(SpriteVariable), + typeof(TextureVariable), + typeof(TransformVariable), + typeof(Vector2Variable), + typeof(Vector3Variable))] [SerializeField] protected Variable variable; [Tooltip("Boolean value to compare against")] @@ -31,9 +42,42 @@ namespace Fungus [Tooltip("String value to compare against")] [SerializeField] protected StringDataMulti stringData; + [Tooltip("Animator value to compare against")] + [SerializeField] protected AnimatorData animatorData; + + [Tooltip("AudioSource value to compare against")] + [SerializeField] protected AudioSourceData audioSourceData; + + [Tooltip("Color value to compare against")] + [SerializeField] protected ColorData colorData; + [Tooltip("GameObject value to compare against")] [SerializeField] protected GameObjectData gameObjectData; + [Tooltip("Material value to compare against")] + [SerializeField] protected MaterialData materialData; + + [Tooltip("Object value to compare against")] + [SerializeField] protected ObjectData objectData; + + [Tooltip("Rigidbody2D value to compare against")] + [SerializeField] protected Rigidbody2DData rigidbody2DData; + + [Tooltip("Sprite value to compare against")] + [SerializeField] protected SpriteData spriteData; + + [Tooltip("Texture value to compare against")] + [SerializeField] protected TextureData textureData; + + [Tooltip("Transform value to compare against")] + [SerializeField] protected TransformData transformData; + + [Tooltip("Vector2 value to compare against")] + [SerializeField] protected Vector2Data vector2Data; + + [Tooltip("Vector3 value to compare against")] + [SerializeField] protected Vector3Data vector3Data; + protected override bool EvaluateCondition() { if (variable == null) @@ -63,11 +107,66 @@ 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(AudioSourceVariable)) + { + AudioSourceVariable audioSourceVariable = (variable as AudioSourceVariable); + condition = audioSourceVariable.Evaluate(compareOperator, audioSourceData.Value); + } + else if (variable.GetType() == typeof(ColorVariable)) + { + ColorVariable colorVariable = (variable as ColorVariable); + condition = colorVariable.Evaluate(compareOperator, colorData.Value); + } else if (variable.GetType() == typeof(GameObjectVariable)) { GameObjectVariable gameObjectVariable = (variable as GameObjectVariable); condition = gameObjectVariable.Evaluate(compareOperator, gameObjectData.Value); } + else if (variable.GetType() == typeof(MaterialVariable)) + { + 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); + } + else if (variable.GetType() == typeof(Rigidbody2DVariable)) + { + Rigidbody2DVariable rigidbody2DVariable = (variable as Rigidbody2DVariable); + condition = rigidbody2DVariable.Evaluate(compareOperator, rigidbody2DData.Value); + } + else if (variable.GetType() == typeof(SpriteVariable)) + { + SpriteVariable spriteVariable = (variable as SpriteVariable); + condition = spriteVariable.Evaluate(compareOperator, spriteData.Value); + } + else if (variable.GetType() == typeof(TextureVariable)) + { + TextureVariable textureVariable = (variable as TextureVariable); + condition = textureVariable.Evaluate(compareOperator, textureData.Value); + } + else if (variable.GetType() == typeof(TransformVariable)) + { + TransformVariable transformVariable = (variable as TransformVariable); + condition = transformVariable.Evaluate(compareOperator, transformData.Value); + } + else if (variable.GetType() == typeof(Vector2Variable)) + { + Vector2Variable vector2Variable = (variable as Vector2Variable); + condition = vector2Variable.Evaluate(compareOperator, vector2Data.Value); + } + else if (variable.GetType() == typeof(Vector3Variable)) + { + Vector3Variable vector3Variable = (variable as Vector3Variable); + condition = vector3Variable.Evaluate(compareOperator, vector3Data.Value); + } return condition; } @@ -84,7 +183,18 @@ namespace Fungus { typeof(IntegerVariable), IntegerVariable.compareOperators }, { typeof(FloatVariable), FloatVariable.compareOperators }, { typeof(StringVariable), StringVariable.compareOperators }, - { typeof(GameObjectVariable), GameObjectVariable.compareOperators } + { typeof(AnimatorVariable), AnimatorVariable.compareOperators }, + { typeof(AudioSourceVariable), AudioSourceVariable.compareOperators }, + { typeof(ColorVariable), ColorVariable.compareOperators }, + { typeof(GameObjectVariable), GameObjectVariable.compareOperators }, + { typeof(MaterialVariable), MaterialVariable.compareOperators }, + { typeof(ObjectVariable), ObjectVariable.compareOperators }, + { typeof(Rigidbody2DVariable), Rigidbody2DVariable.compareOperators }, + { typeof(SpriteVariable), SpriteVariable.compareOperators }, + { typeof(TextureVariable), TextureVariable.compareOperators }, + { typeof(TransformVariable), TransformVariable.compareOperators }, + { typeof(Vector2Variable), Vector2Variable.compareOperators }, + { typeof(Vector3Variable), Vector3Variable.compareOperators } }; /// @@ -118,10 +228,54 @@ namespace Fungus { summary += stringData.GetDescription(); } + else if (variable.GetType() == typeof(AnimatorVariable)) + { + summary += animatorData.GetDescription(); + } + else if (variable.GetType() == typeof(AudioSourceVariable)) + { + summary += audioSourceData.GetDescription(); + } + else if (variable.GetType() == typeof(ColorVariable)) + { + summary += colorData.GetDescription(); + } else if (variable.GetType() == typeof(GameObjectVariable)) { summary += gameObjectData.GetDescription(); } + else if (variable.GetType() == typeof(MaterialVariable)) + { + summary += materialData.GetDescription(); + } + else if (variable.GetType() == typeof(ObjectVariable)) + { + summary += objectData.GetDescription(); + } + else if (variable.GetType() == typeof(Rigidbody2DVariable)) + { + summary += rigidbody2DData.GetDescription(); + } + else if (variable.GetType() == typeof(SpriteVariable)) + { + summary += spriteData.GetDescription(); + } + else if (variable.GetType() == typeof(TextureVariable)) + { + summary += textureData.GetDescription(); + } + else if (variable.GetType() == typeof(TransformVariable)) + { + summary += transformData.GetDescription(); + } + else if (variable.GetType() == typeof(Vector2Variable)) + { + summary += vector2Data.GetDescription(); + } + else if (variable.GetType() == typeof(Vector3Variable)) + { + summary += vector3Data.GetDescription(); + } return summary; } @@ -138,4 +292,4 @@ namespace Fungus #endregion } -} \ No newline at end of file +} diff --git a/Assets/Fungus/Scripts/Editor/SetVariableEditor.cs b/Assets/Fungus/Scripts/Editor/SetVariableEditor.cs index f8b1c394..dfb18d87 100644 --- a/Assets/Fungus/Scripts/Editor/SetVariableEditor.cs +++ b/Assets/Fungus/Scripts/Editor/SetVariableEditor.cs @@ -9,7 +9,7 @@ namespace Fungus.EditorUtils { [CustomEditor (typeof(SetVariable))] - public class SetVariableEditor : CommandEditor + public class SetVariableEditor : CommandEditor { protected struct VariablePropertyInfo { @@ -44,7 +44,18 @@ 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(GameObjectVariable), new VariablePropertyInfo("GameObject", serializedObject.FindProperty("gameObjectData")) } + { typeof(AnimatorVariable), new VariablePropertyInfo("Animator", serializedObject.FindProperty("animatorData")) }, + { 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(ObjectVariable), new VariablePropertyInfo("Object", serializedObject.FindProperty("objectData")) }, + { typeof(Rigidbody2DVariable), new VariablePropertyInfo("Rigidbody2D", serializedObject.FindProperty("rigidbody2DData")) }, + { typeof(SpriteVariable), new VariablePropertyInfo("Sprite", serializedObject.FindProperty("spriteData")) }, + { typeof(TextureVariable), new VariablePropertyInfo("Texture", serializedObject.FindProperty("textureData")) }, + { typeof(TransformVariable), new VariablePropertyInfo("Transform", serializedObject.FindProperty("transformData")) }, + { typeof(Vector2Variable), new VariablePropertyInfo("Vector2", serializedObject.FindProperty("vector2Data")) }, + { typeof(Vector3Variable), new VariablePropertyInfo("Vector3", serializedObject.FindProperty("vector3Data")) } }; } @@ -105,7 +116,7 @@ namespace Fungus.EditorUtils break; } } - + // Get previously selected operator int selectedIndex = System.Array.IndexOf(setOperators, t._SetOperator); if (selectedIndex < 0) @@ -117,7 +128,7 @@ namespace Fungus.EditorUtils // Get next selected operator selectedIndex = EditorGUILayout.Popup(new GUIContent("Operation", "Arithmetic operator to use"), selectedIndex, operatorsList.ToArray()); - + setOperatorProp.enumValueIndex = (int)setOperators[selectedIndex]; diff --git a/Assets/Fungus/Scripts/Editor/VariableConditionEditor.cs b/Assets/Fungus/Scripts/Editor/VariableConditionEditor.cs index 3fd3f2fd..46001119 100644 --- a/Assets/Fungus/Scripts/Editor/VariableConditionEditor.cs +++ b/Assets/Fungus/Scripts/Editor/VariableConditionEditor.cs @@ -8,7 +8,7 @@ using System.Collections.Generic; namespace Fungus.EditorUtils { [CustomEditor (typeof(VariableCondition), true)] - public class VariableConditionEditor : CommandEditor + public class VariableConditionEditor : CommandEditor { protected SerializedProperty variableProp; protected SerializedProperty compareOperatorProp; @@ -29,7 +29,18 @@ namespace Fungus.EditorUtils { typeof(IntegerVariable), serializedObject.FindProperty("integerData") }, { typeof(FloatVariable), serializedObject.FindProperty("floatData") }, { typeof(StringVariable), serializedObject.FindProperty("stringData") }, - { typeof(GameObjectVariable), serializedObject.FindProperty("gameObjectData") } + { typeof(AnimatorVariable), serializedObject.FindProperty("animatorData") }, + { typeof(AudioSourceVariable), serializedObject.FindProperty("audioSourceData") }, + { typeof(ColorVariable), serializedObject.FindProperty("colorData") }, + { typeof(GameObjectVariable), serializedObject.FindProperty("gameObjectData") }, + { typeof(MaterialVariable), serializedObject.FindProperty("materialData") }, + { typeof(ObjectVariable), serializedObject.FindProperty("objectData") }, + { typeof(Rigidbody2DVariable), serializedObject.FindProperty("rigidbody2DData") }, + { typeof(SpriteVariable), serializedObject.FindProperty("spriteData") }, + { typeof(TextureVariable), serializedObject.FindProperty("textureData") }, + { typeof(TransformVariable), serializedObject.FindProperty("transformData") }, + { typeof(Vector2Variable), serializedObject.FindProperty("vector2Data") }, + { typeof(Vector3Variable), serializedObject.FindProperty("vector3Data") } }; } 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. diff --git a/Assets/Fungus/Scripts/VariableTypes/AudioSourceVariable.cs b/Assets/Fungus/Scripts/VariableTypes/AudioSourceVariable.cs index 5727e4a4..3cf056c9 100644 --- a/Assets/Fungus/Scripts/VariableTypes/AudioSourceVariable.cs +++ b/Assets/Fungus/Scripts/VariableTypes/AudioSourceVariable.cs @@ -12,7 +12,43 @@ namespace Fungus [AddComponentMenu("")] [System.Serializable] public class AudioSourceVariable : VariableBase - {} + { + public static readonly CompareOperator[] compareOperators = { CompareOperator.Equals, CompareOperator.NotEquals }; + public static readonly SetOperator[] setOperators = { SetOperator.Assign }; + + public virtual bool Evaluate(CompareOperator compareOperator, AudioSource 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, AudioSource value) + { + switch (setOperator) + { + case SetOperator.Assign: + Value = value; + break; + default: + Debug.LogError("The " + setOperator.ToString() + " set operator is not valid."); + break; + } + } + } /// /// Container for an AudioSource variable reference or constant value. diff --git a/Assets/Fungus/Scripts/VariableTypes/BooleanVariable.cs b/Assets/Fungus/Scripts/VariableTypes/BooleanVariable.cs index 30cb3120..2c1da160 100644 --- a/Assets/Fungus/Scripts/VariableTypes/BooleanVariable.cs +++ b/Assets/Fungus/Scripts/VariableTypes/BooleanVariable.cs @@ -25,13 +25,15 @@ namespace Fungus switch (compareOperator) { - case CompareOperator.Equals: - condition = lhs == rhs; - break; - case CompareOperator.NotEquals: - default: - condition = lhs != rhs; - break; + case CompareOperator.Equals: + condition = lhs == rhs; + break; + case CompareOperator.NotEquals: + condition = lhs != rhs; + break; + default: + Debug.LogError("The " + compareOperator.ToString() + " comparison operator is not valid."); + break; } return condition; @@ -41,13 +43,15 @@ namespace Fungus { switch (setOperator) { - default: case SetOperator.Assign: Value = value; break; case SetOperator.Negate: Value = !value; break; + default: + Debug.LogError("The " + setOperator.ToString() + " set operator is not valid."); + break; } } } diff --git a/Assets/Fungus/Scripts/VariableTypes/ColorVariable.cs b/Assets/Fungus/Scripts/VariableTypes/ColorVariable.cs index f27c32ca..eb30ba44 100644 --- a/Assets/Fungus/Scripts/VariableTypes/ColorVariable.cs +++ b/Assets/Fungus/Scripts/VariableTypes/ColorVariable.cs @@ -13,7 +13,61 @@ namespace Fungus [AddComponentMenu("")] [System.Serializable] public class ColorVariable : VariableBase - {} + { + public static readonly CompareOperator[] compareOperators = { CompareOperator.Equals, CompareOperator.NotEquals }; + public static readonly SetOperator[] setOperators = { + SetOperator.Assign, + SetOperator.Add, + SetOperator.Subtract, + SetOperator.Multiply + }; + + protected static bool ColorsEqual(Color a, Color b) { + return ColorUtility.ToHtmlStringRGBA(a) == ColorUtility.ToHtmlStringRGBA(b); + } + + public virtual bool Evaluate(CompareOperator compareOperator, Color value) + { + bool condition = false; + + switch (compareOperator) + { + case CompareOperator.Equals: + condition = ColorsEqual(Value, value); + break; + case CompareOperator.NotEquals: + condition = !ColorsEqual(Value, value); + break; + default: + Debug.LogError("The " + compareOperator.ToString() + " comparison operator is not valid."); + break; + } + + return condition; + } + + public override void Apply(SetOperator setOperator, Color value) + { + switch (setOperator) + { + case SetOperator.Assign: + Value = value; + break; + case SetOperator.Add: + Value += value; + break; + case SetOperator.Subtract: + Value -= value; + break; + case SetOperator.Multiply: + Value *= value; + break; + default: + Debug.LogError("The " + setOperator.ToString() + " set operator is not valid."); + break; + } + } + } /// /// Container for a Color variable reference or constant value. diff --git a/Assets/Fungus/Scripts/VariableTypes/FloatVariable.cs b/Assets/Fungus/Scripts/VariableTypes/FloatVariable.cs index e64464f0..083e2528 100644 --- a/Assets/Fungus/Scripts/VariableTypes/FloatVariable.cs +++ b/Assets/Fungus/Scripts/VariableTypes/FloatVariable.cs @@ -38,24 +38,27 @@ namespace Fungus switch (compareOperator) { - case CompareOperator.Equals: - condition = lhs == rhs; - break; - case CompareOperator.NotEquals: - condition = lhs != rhs; - break; - case CompareOperator.LessThan: - condition = lhs < rhs; - break; - case CompareOperator.GreaterThan: - condition = lhs > rhs; - break; - case CompareOperator.LessThanOrEquals: - condition = lhs <= rhs; - break; - case CompareOperator.GreaterThanOrEquals: - condition = lhs >= rhs; - break; + case CompareOperator.Equals: + condition = lhs == rhs; + break; + case CompareOperator.NotEquals: + condition = lhs != rhs; + break; + case CompareOperator.LessThan: + condition = lhs < rhs; + break; + case CompareOperator.GreaterThan: + condition = lhs > rhs; + break; + case CompareOperator.LessThanOrEquals: + condition = lhs <= rhs; + break; + case CompareOperator.GreaterThanOrEquals: + condition = lhs >= rhs; + break; + default: + Debug.LogError("The " + compareOperator.ToString() + " comparison operator is not valid."); + break; } return condition; @@ -65,7 +68,6 @@ namespace Fungus { switch (setOperator) { - default: case SetOperator.Assign: Value = value; break; @@ -81,6 +83,9 @@ namespace Fungus case SetOperator.Divide: Value /= value; break; + default: + Debug.LogError("The " + setOperator.ToString() + " set operator is not valid."); + break; } } } diff --git a/Assets/Fungus/Scripts/VariableTypes/GameObjectVariable.cs b/Assets/Fungus/Scripts/VariableTypes/GameObjectVariable.cs index 6b627563..f4b3538f 100644 --- a/Assets/Fungus/Scripts/VariableTypes/GameObjectVariable.cs +++ b/Assets/Fungus/Scripts/VariableTypes/GameObjectVariable.cs @@ -30,9 +30,11 @@ namespace Fungus condition = lhs == rhs; break; case CompareOperator.NotEquals: - default: condition = lhs != rhs; break; + default: + Debug.LogError("The " + compareOperator.ToString() + " comparison operator is not valid."); + break; } return condition; @@ -42,10 +44,12 @@ namespace Fungus { switch (setOperator) { - default: case SetOperator.Assign: Value = value; break; + default: + Debug.LogError("The " + setOperator.ToString() + " set operator is not valid."); + break; } } } diff --git a/Assets/Fungus/Scripts/VariableTypes/IntegerVariable.cs b/Assets/Fungus/Scripts/VariableTypes/IntegerVariable.cs index 52617eff..06726b58 100644 --- a/Assets/Fungus/Scripts/VariableTypes/IntegerVariable.cs +++ b/Assets/Fungus/Scripts/VariableTypes/IntegerVariable.cs @@ -38,24 +38,27 @@ namespace Fungus switch (compareOperator) { - case CompareOperator.Equals: - condition = lhs == rhs; - break; - case CompareOperator.NotEquals: - condition = lhs != rhs; - break; - case CompareOperator.LessThan: - condition = lhs < rhs; - break; - case CompareOperator.GreaterThan: - condition = lhs > rhs; - break; - case CompareOperator.LessThanOrEquals: - condition = lhs <= rhs; - break; - case CompareOperator.GreaterThanOrEquals: - condition = lhs >= rhs; - break; + case CompareOperator.Equals: + condition = lhs == rhs; + break; + case CompareOperator.NotEquals: + condition = lhs != rhs; + break; + case CompareOperator.LessThan: + condition = lhs < rhs; + break; + case CompareOperator.GreaterThan: + condition = lhs > rhs; + break; + case CompareOperator.LessThanOrEquals: + condition = lhs <= rhs; + break; + case CompareOperator.GreaterThanOrEquals: + condition = lhs >= rhs; + break; + default: + Debug.LogError("The " + compareOperator.ToString() + " comparison operator is not valid."); + break; } return condition; @@ -65,7 +68,6 @@ namespace Fungus { switch (setOperator) { - default: case SetOperator.Assign: Value = value; break; @@ -81,6 +83,9 @@ namespace Fungus case SetOperator.Divide: Value /= value; break; + default: + Debug.LogError("The " + setOperator.ToString() + " set operator is not valid."); + break; } } } diff --git a/Assets/Fungus/Scripts/VariableTypes/MaterialVariable.cs b/Assets/Fungus/Scripts/VariableTypes/MaterialVariable.cs index 5f36ff87..5617a655 100644 --- a/Assets/Fungus/Scripts/VariableTypes/MaterialVariable.cs +++ b/Assets/Fungus/Scripts/VariableTypes/MaterialVariable.cs @@ -13,7 +13,43 @@ namespace Fungus [AddComponentMenu("")] [System.Serializable] public class MaterialVariable : VariableBase - {} + { + public static readonly CompareOperator[] compareOperators = { CompareOperator.Equals, CompareOperator.NotEquals }; + public static readonly SetOperator[] setOperators = { SetOperator.Assign }; + + public virtual bool Evaluate(CompareOperator compareOperator, Material 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, Material value) + { + switch (setOperator) + { + case SetOperator.Assign: + Value = value; + break; + default: + Debug.LogError("The " + setOperator.ToString() + " set operator is not valid."); + break; + } + } + } /// /// Container for a Material variable reference or constant value. 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. diff --git a/Assets/Fungus/Scripts/VariableTypes/Rigidbody2DVariable.cs b/Assets/Fungus/Scripts/VariableTypes/Rigidbody2DVariable.cs index f48d6dcb..e011975a 100644 --- a/Assets/Fungus/Scripts/VariableTypes/Rigidbody2DVariable.cs +++ b/Assets/Fungus/Scripts/VariableTypes/Rigidbody2DVariable.cs @@ -9,7 +9,43 @@ namespace Fungus [AddComponentMenu("")] [System.Serializable] public class Rigidbody2DVariable : VariableBase - { } + { + public static readonly CompareOperator[] compareOperators = { CompareOperator.Equals, CompareOperator.NotEquals }; + public static readonly SetOperator[] setOperators = { SetOperator.Assign }; + + public virtual bool Evaluate(CompareOperator compareOperator, Rigidbody2D 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, Rigidbody2D value) + { + switch (setOperator) + { + case SetOperator.Assign: + Value = value; + break; + default: + Debug.LogError("The " + setOperator.ToString() + " set operator is not valid."); + break; + } + } + } /// /// Container for a Rigidbody2D variable reference or constant value. diff --git a/Assets/Fungus/Scripts/VariableTypes/SpriteVariable.cs b/Assets/Fungus/Scripts/VariableTypes/SpriteVariable.cs index ca7a0d63..fb59cc47 100644 --- a/Assets/Fungus/Scripts/VariableTypes/SpriteVariable.cs +++ b/Assets/Fungus/Scripts/VariableTypes/SpriteVariable.cs @@ -13,7 +13,43 @@ namespace Fungus [AddComponentMenu("")] [System.Serializable] public class SpriteVariable : VariableBase - {} + { + public static readonly CompareOperator[] compareOperators = { CompareOperator.Equals, CompareOperator.NotEquals }; + public static readonly SetOperator[] setOperators = { SetOperator.Assign }; + + public virtual bool Evaluate(CompareOperator compareOperator, Sprite 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, Sprite value) + { + switch (setOperator) + { + case SetOperator.Assign: + Value = value; + break; + default: + Debug.LogError("The " + setOperator.ToString() + " set operator is not valid."); + break; + } + } + } /// /// Container for a Sprite variable reference or constant value. diff --git a/Assets/Fungus/Scripts/VariableTypes/StringVariable.cs b/Assets/Fungus/Scripts/VariableTypes/StringVariable.cs index 75921ef0..b9443aa1 100644 --- a/Assets/Fungus/Scripts/VariableTypes/StringVariable.cs +++ b/Assets/Fungus/Scripts/VariableTypes/StringVariable.cs @@ -25,13 +25,15 @@ namespace Fungus switch (compareOperator) { - case CompareOperator.Equals: - condition = lhs == rhs; - break; - case CompareOperator.NotEquals: - default: - condition = lhs != rhs; - break; + case CompareOperator.Equals: + condition = lhs == rhs; + break; + case CompareOperator.NotEquals: + condition = lhs != rhs; + break; + default: + Debug.LogError("The " + compareOperator.ToString() + " comparison operator is not valid."); + break; } return condition; @@ -41,10 +43,12 @@ namespace Fungus { switch (setOperator) { - default: case SetOperator.Assign: Value = value; break; + default: + Debug.LogError("The " + setOperator.ToString() + " set operator is not valid."); + break; } } } diff --git a/Assets/Fungus/Scripts/VariableTypes/TextureVariable.cs b/Assets/Fungus/Scripts/VariableTypes/TextureVariable.cs index ad446a9f..54d6e921 100644 --- a/Assets/Fungus/Scripts/VariableTypes/TextureVariable.cs +++ b/Assets/Fungus/Scripts/VariableTypes/TextureVariable.cs @@ -13,7 +13,43 @@ namespace Fungus [AddComponentMenu("")] [System.Serializable] public class TextureVariable : VariableBase - {} + { + public static readonly CompareOperator[] compareOperators = { CompareOperator.Equals, CompareOperator.NotEquals }; + public static readonly SetOperator[] setOperators = { SetOperator.Assign }; + + public virtual bool Evaluate(CompareOperator compareOperator, Texture 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, Texture value) + { + switch (setOperator) + { + case SetOperator.Assign: + Value = value; + break; + default: + Debug.LogError("The " + setOperator.ToString() + " set operator is not valid."); + break; + } + } + } /// /// Container for a Texture variable reference or constant value. diff --git a/Assets/Fungus/Scripts/VariableTypes/TransformVariable.cs b/Assets/Fungus/Scripts/VariableTypes/TransformVariable.cs index bbc32db4..19a17232 100644 --- a/Assets/Fungus/Scripts/VariableTypes/TransformVariable.cs +++ b/Assets/Fungus/Scripts/VariableTypes/TransformVariable.cs @@ -13,7 +13,43 @@ namespace Fungus [AddComponentMenu("")] [System.Serializable] public class TransformVariable : VariableBase - {} + { + public static readonly CompareOperator[] compareOperators = { CompareOperator.Equals, CompareOperator.NotEquals }; + public static readonly SetOperator[] setOperators = { SetOperator.Assign }; + + public virtual bool Evaluate(CompareOperator compareOperator, Transform 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, Transform value) + { + switch (setOperator) + { + case SetOperator.Assign: + Value = value; + break; + default: + Debug.LogError("The " + setOperator.ToString() + " set operator is not valid."); + break; + } + } + } /// /// Container for a Transform variable reference or constant value. diff --git a/Assets/Fungus/Scripts/VariableTypes/Vector2Variable.cs b/Assets/Fungus/Scripts/VariableTypes/Vector2Variable.cs index f067aa95..6b9c3893 100644 --- a/Assets/Fungus/Scripts/VariableTypes/Vector2Variable.cs +++ b/Assets/Fungus/Scripts/VariableTypes/Vector2Variable.cs @@ -13,7 +13,49 @@ namespace Fungus [AddComponentMenu("")] [System.Serializable] public class Vector2Variable : VariableBase - {} + { + public static readonly CompareOperator[] compareOperators = { CompareOperator.Equals, CompareOperator.NotEquals }; + public static readonly SetOperator[] setOperators = { SetOperator.Assign, SetOperator.Add, SetOperator.Subtract }; + + public virtual bool Evaluate(CompareOperator compareOperator, Vector2 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, Vector2 value) + { + switch (setOperator) + { + case SetOperator.Assign: + Value = value; + break; + case SetOperator.Add: + Value += value; + break; + case SetOperator.Subtract: + Value -= value; + break; + default: + Debug.LogError("The " + setOperator.ToString() + " set operator is not valid."); + break; + } + } + } /// /// Container for a Vector2 variable reference or constant value. diff --git a/Assets/Fungus/Scripts/VariableTypes/Vector3Variable.cs b/Assets/Fungus/Scripts/VariableTypes/Vector3Variable.cs index 16c5511a..4735fe38 100644 --- a/Assets/Fungus/Scripts/VariableTypes/Vector3Variable.cs +++ b/Assets/Fungus/Scripts/VariableTypes/Vector3Variable.cs @@ -13,7 +13,49 @@ namespace Fungus [AddComponentMenu("")] [System.Serializable] public class Vector3Variable : VariableBase - {} + { + public static readonly CompareOperator[] compareOperators = { CompareOperator.Equals, CompareOperator.NotEquals }; + public static readonly SetOperator[] setOperators = { SetOperator.Assign, SetOperator.Add, SetOperator.Subtract }; + + public virtual bool Evaluate(CompareOperator compareOperator, Vector3 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, Vector3 value) + { + switch (setOperator) + { + case SetOperator.Assign: + Value = value; + break; + case SetOperator.Add: + Value += value; + break; + case SetOperator.Subtract: + Value -= value; + break; + default: + Debug.LogError("The " + setOperator.ToString() + " set operator is not valid."); + break; + } + } + } /// /// Container for a Vector3 variable reference or constant value.