Browse Source

Add comparison and setting functionality for the Texture variable

master
Jorge Ramirez 7 years ago
parent
commit
3035446336
  1. 18
      Assets/Fungus/Scripts/Commands/SetVariable.cs
  2. 18
      Assets/Fungus/Scripts/Commands/VariableCondition.cs
  3. 3
      Assets/Fungus/Scripts/Editor/SetVariableEditor.cs
  4. 3
      Assets/Fungus/Scripts/Editor/VariableConditionEditor.cs
  5. 38
      Assets/Fungus/Scripts/VariableTypes/TextureVariable.cs

18
Assets/Fungus/Scripts/Commands/SetVariable.cs

@ -27,7 +27,8 @@ namespace Fungus
typeof(MaterialVariable), typeof(MaterialVariable),
typeof(ObjectVariable), typeof(ObjectVariable),
typeof(Rigidbody2DVariable), typeof(Rigidbody2DVariable),
typeof(SpriteVariable))] typeof(SpriteVariable),
typeof(TextureVariable))]
[SerializeField] protected Variable variable; [SerializeField] protected Variable variable;
[Tooltip("The type of math operation to be performed")] [Tooltip("The type of math operation to be performed")]
@ -69,6 +70,9 @@ namespace Fungus
[Tooltip("Sprite value to set with")] [Tooltip("Sprite value to set with")]
[SerializeField] protected SpriteData spriteData; [SerializeField] protected SpriteData spriteData;
[Tooltip("Texture value to set with")]
[SerializeField] protected TextureData textureData;
protected virtual void DoSetOperation() protected virtual void DoSetOperation()
{ {
if (variable == null) if (variable == null)
@ -137,6 +141,11 @@ namespace Fungus
SpriteVariable spriteVariable = (variable as SpriteVariable); SpriteVariable spriteVariable = (variable as SpriteVariable);
spriteVariable.Apply(setOperator, spriteData.Value); spriteVariable.Apply(setOperator, spriteData.Value);
} }
else if (variable.GetType() == typeof(TextureVariable))
{
TextureVariable textureVariable = (variable as TextureVariable);
textureVariable.Apply(setOperator, textureData.Value);
}
} }
#region Public members #region Public members
@ -153,7 +162,8 @@ namespace Fungus
{ typeof(MaterialVariable), MaterialVariable.setOperators }, { typeof(MaterialVariable), MaterialVariable.setOperators },
{ typeof(ObjectVariable), ObjectVariable.setOperators }, { typeof(ObjectVariable), ObjectVariable.setOperators },
{ typeof(Rigidbody2DVariable), Rigidbody2DVariable.setOperators }, { typeof(Rigidbody2DVariable), Rigidbody2DVariable.setOperators },
{ typeof(SpriteVariable), SpriteVariable.setOperators } { typeof(SpriteVariable), SpriteVariable.setOperators },
{ typeof(TextureVariable), TextureVariable.setOperators }
}; };
/// <summary> /// <summary>
@ -248,6 +258,10 @@ namespace Fungus
{ {
description += spriteData.GetDescription(); description += spriteData.GetDescription();
} }
else if (variable.GetType() == typeof(TextureVariable))
{
description += textureData.GetDescription();
}
return description; return description;
} }

18
Assets/Fungus/Scripts/Commands/VariableCondition.cs

@ -23,7 +23,8 @@ namespace Fungus
typeof(MaterialVariable), typeof(MaterialVariable),
typeof(ObjectVariable), typeof(ObjectVariable),
typeof(Rigidbody2DVariable), typeof(Rigidbody2DVariable),
typeof(SpriteVariable))] typeof(SpriteVariable),
typeof(TextureVariable))]
[SerializeField] protected Variable variable; [SerializeField] protected Variable variable;
[Tooltip("Boolean value to compare against")] [Tooltip("Boolean value to compare against")]
@ -62,6 +63,9 @@ namespace Fungus
[Tooltip("Sprite value to compare against")] [Tooltip("Sprite value to compare against")]
[SerializeField] protected SpriteData spriteData; [SerializeField] protected SpriteData spriteData;
[Tooltip("Texture value to compare against")]
[SerializeField] protected TextureData textureData;
protected override bool EvaluateCondition() protected override bool EvaluateCondition()
{ {
if (variable == null) if (variable == null)
@ -131,6 +135,11 @@ namespace Fungus
SpriteVariable spriteVariable = (variable as SpriteVariable); SpriteVariable spriteVariable = (variable as SpriteVariable);
condition = spriteVariable.Evaluate(compareOperator, spriteData.Value); 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; return condition;
} }
@ -154,7 +163,8 @@ namespace Fungus
{ typeof(MaterialVariable), MaterialVariable.compareOperators }, { typeof(MaterialVariable), MaterialVariable.compareOperators },
{ typeof(ObjectVariable), ObjectVariable.compareOperators }, { typeof(ObjectVariable), ObjectVariable.compareOperators },
{ typeof(Rigidbody2DVariable), Rigidbody2DVariable.compareOperators }, { typeof(Rigidbody2DVariable), Rigidbody2DVariable.compareOperators },
{ typeof(SpriteVariable), SpriteVariable.compareOperators } { typeof(SpriteVariable), SpriteVariable.compareOperators },
{ typeof(TextureVariable), TextureVariable.compareOperators }
}; };
/// <summary> /// <summary>
@ -220,6 +230,10 @@ namespace Fungus
{ {
summary += spriteData.GetDescription(); summary += spriteData.GetDescription();
} }
else if (variable.GetType() == typeof(TextureVariable))
{
summary += textureData.GetDescription();
}
return summary; return summary;
} }

3
Assets/Fungus/Scripts/Editor/SetVariableEditor.cs

@ -51,7 +51,8 @@ namespace Fungus.EditorUtils
{ typeof(MaterialVariable), new VariablePropertyInfo("Material", serializedObject.FindProperty("materialData")) }, { typeof(MaterialVariable), new VariablePropertyInfo("Material", serializedObject.FindProperty("materialData")) },
{ typeof(ObjectVariable), new VariablePropertyInfo("Object", serializedObject.FindProperty("objectData")) }, { typeof(ObjectVariable), new VariablePropertyInfo("Object", serializedObject.FindProperty("objectData")) },
{ typeof(Rigidbody2DVariable), new VariablePropertyInfo("Rigidbody2D", serializedObject.FindProperty("rigidbody2DData")) }, { 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")) }
}; };
} }

3
Assets/Fungus/Scripts/Editor/VariableConditionEditor.cs

@ -36,7 +36,8 @@ namespace Fungus.EditorUtils
{ typeof(MaterialVariable), serializedObject.FindProperty("materialData") }, { typeof(MaterialVariable), serializedObject.FindProperty("materialData") },
{ typeof(ObjectVariable), serializedObject.FindProperty("objectData") }, { typeof(ObjectVariable), serializedObject.FindProperty("objectData") },
{ typeof(Rigidbody2DVariable), serializedObject.FindProperty("rigidbody2DData") }, { typeof(Rigidbody2DVariable), serializedObject.FindProperty("rigidbody2DData") },
{ typeof(SpriteVariable), serializedObject.FindProperty("spriteData") } { typeof(SpriteVariable), serializedObject.FindProperty("spriteData") },
{ typeof(TextureVariable), serializedObject.FindProperty("textureData") }
}; };
} }

38
Assets/Fungus/Scripts/VariableTypes/TextureVariable.cs

@ -13,7 +13,43 @@ namespace Fungus
[AddComponentMenu("")] [AddComponentMenu("")]
[System.Serializable] [System.Serializable]
public class TextureVariable : VariableBase<Texture> public class TextureVariable : VariableBase<Texture>
{} {
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;
}
}
}
/// <summary> /// <summary>
/// Container for a Texture variable reference or constant value. /// Container for a Texture variable reference or constant value.

Loading…
Cancel
Save