From 30354463368cabb8e9771ecdc6d9363c8d4f16ae Mon Sep 17 00:00:00 2001 From: Jorge Ramirez Date: Sun, 8 Apr 2018 20:05:29 -0400 Subject: [PATCH] Add comparison and setting functionality for the Texture variable --- Assets/Fungus/Scripts/Commands/SetVariable.cs | 18 ++++++++- .../Scripts/Commands/VariableCondition.cs | 18 ++++++++- .../Scripts/Editor/SetVariableEditor.cs | 3 +- .../Scripts/Editor/VariableConditionEditor.cs | 3 +- .../Scripts/VariableTypes/TextureVariable.cs | 38 ++++++++++++++++++- 5 files changed, 73 insertions(+), 7 deletions(-) diff --git a/Assets/Fungus/Scripts/Commands/SetVariable.cs b/Assets/Fungus/Scripts/Commands/SetVariable.cs index dc89bee9..8376be82 100644 --- a/Assets/Fungus/Scripts/Commands/SetVariable.cs +++ b/Assets/Fungus/Scripts/Commands/SetVariable.cs @@ -27,7 +27,8 @@ namespace Fungus typeof(MaterialVariable), typeof(ObjectVariable), typeof(Rigidbody2DVariable), - typeof(SpriteVariable))] + typeof(SpriteVariable), + typeof(TextureVariable))] [SerializeField] protected Variable variable; [Tooltip("The type of math operation to be performed")] @@ -69,6 +70,9 @@ namespace Fungus [Tooltip("Sprite value to set with")] [SerializeField] protected SpriteData spriteData; + [Tooltip("Texture value to set with")] + [SerializeField] protected TextureData textureData; + protected virtual void DoSetOperation() { if (variable == null) @@ -137,6 +141,11 @@ namespace Fungus 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); + } } #region Public members @@ -153,7 +162,8 @@ namespace Fungus { typeof(MaterialVariable), MaterialVariable.setOperators }, { typeof(ObjectVariable), ObjectVariable.setOperators }, { typeof(Rigidbody2DVariable), Rigidbody2DVariable.setOperators }, - { typeof(SpriteVariable), SpriteVariable.setOperators } + { typeof(SpriteVariable), SpriteVariable.setOperators }, + { typeof(TextureVariable), TextureVariable.setOperators } }; /// @@ -248,6 +258,10 @@ namespace Fungus { description += spriteData.GetDescription(); } + else if (variable.GetType() == typeof(TextureVariable)) + { + description += textureData.GetDescription(); + } return description; } diff --git a/Assets/Fungus/Scripts/Commands/VariableCondition.cs b/Assets/Fungus/Scripts/Commands/VariableCondition.cs index 64acafba..35335034 100644 --- a/Assets/Fungus/Scripts/Commands/VariableCondition.cs +++ b/Assets/Fungus/Scripts/Commands/VariableCondition.cs @@ -23,7 +23,8 @@ namespace Fungus typeof(MaterialVariable), typeof(ObjectVariable), typeof(Rigidbody2DVariable), - typeof(SpriteVariable))] + typeof(SpriteVariable), + typeof(TextureVariable))] [SerializeField] protected Variable variable; [Tooltip("Boolean value to compare against")] @@ -62,6 +63,9 @@ namespace Fungus [Tooltip("Sprite value to compare against")] [SerializeField] protected SpriteData spriteData; + [Tooltip("Texture value to compare against")] + [SerializeField] protected TextureData textureData; + protected override bool EvaluateCondition() { if (variable == null) @@ -131,6 +135,11 @@ namespace Fungus 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); + } return condition; } @@ -154,7 +163,8 @@ namespace Fungus { typeof(MaterialVariable), MaterialVariable.compareOperators }, { typeof(ObjectVariable), ObjectVariable.compareOperators }, { typeof(Rigidbody2DVariable), Rigidbody2DVariable.compareOperators }, - { typeof(SpriteVariable), SpriteVariable.compareOperators } + { typeof(SpriteVariable), SpriteVariable.compareOperators }, + { typeof(TextureVariable), TextureVariable.compareOperators } }; /// @@ -220,6 +230,10 @@ namespace Fungus { summary += spriteData.GetDescription(); } + else if (variable.GetType() == typeof(TextureVariable)) + { + summary += textureData.GetDescription(); + } return summary; } diff --git a/Assets/Fungus/Scripts/Editor/SetVariableEditor.cs b/Assets/Fungus/Scripts/Editor/SetVariableEditor.cs index ae81d38f..994472aa 100644 --- a/Assets/Fungus/Scripts/Editor/SetVariableEditor.cs +++ b/Assets/Fungus/Scripts/Editor/SetVariableEditor.cs @@ -51,7 +51,8 @@ namespace Fungus.EditorUtils { 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(SpriteVariable), new VariablePropertyInfo("Sprite", serializedObject.FindProperty("spriteData")) }, + { typeof(TextureVariable), new VariablePropertyInfo("Texture", serializedObject.FindProperty("textureData")) } }; } diff --git a/Assets/Fungus/Scripts/Editor/VariableConditionEditor.cs b/Assets/Fungus/Scripts/Editor/VariableConditionEditor.cs index ed588974..e93595cb 100644 --- a/Assets/Fungus/Scripts/Editor/VariableConditionEditor.cs +++ b/Assets/Fungus/Scripts/Editor/VariableConditionEditor.cs @@ -36,7 +36,8 @@ namespace Fungus.EditorUtils { typeof(MaterialVariable), serializedObject.FindProperty("materialData") }, { typeof(ObjectVariable), serializedObject.FindProperty("objectData") }, { typeof(Rigidbody2DVariable), serializedObject.FindProperty("rigidbody2DData") }, - { typeof(SpriteVariable), serializedObject.FindProperty("spriteData") } + { typeof(SpriteVariable), serializedObject.FindProperty("spriteData") }, + { typeof(TextureVariable), serializedObject.FindProperty("textureData") } }; } 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.