Browse Source

Add comparison and setting functionality for the Sprite variable

master
Jorge Ramirez 7 years ago
parent
commit
27b97990d6
  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/SpriteVariable.cs

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

@ -26,7 +26,8 @@ namespace Fungus
typeof(GameObjectVariable),
typeof(MaterialVariable),
typeof(ObjectVariable),
typeof(Rigidbody2DVariable))]
typeof(Rigidbody2DVariable),
typeof(SpriteVariable))]
[SerializeField] protected Variable variable;
[Tooltip("The type of math operation to be performed")]
@ -65,6 +66,9 @@ namespace Fungus
[Tooltip("Rigidbody2D value to set with")]
[SerializeField] protected Rigidbody2DData rigidbody2DData;
[Tooltip("Sprite value to set with")]
[SerializeField] protected SpriteData spriteData;
protected virtual void DoSetOperation()
{
if (variable == null)
@ -128,6 +132,11 @@ namespace Fungus
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);
}
}
#region Public members
@ -143,7 +152,8 @@ namespace Fungus
{ typeof(GameObjectVariable), GameObjectVariable.setOperators },
{ typeof(MaterialVariable), MaterialVariable.setOperators },
{ typeof(ObjectVariable), ObjectVariable.setOperators },
{ typeof(Rigidbody2DVariable), Rigidbody2DVariable.setOperators }
{ typeof(Rigidbody2DVariable), Rigidbody2DVariable.setOperators },
{ typeof(SpriteVariable), SpriteVariable.setOperators }
};
/// <summary>
@ -234,6 +244,10 @@ namespace Fungus
{
description += rigidbody2DData.GetDescription();
}
else if (variable.GetType() == typeof(SpriteVariable))
{
description += spriteData.GetDescription();
}
return description;
}

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

@ -22,7 +22,8 @@ namespace Fungus
typeof(GameObjectVariable),
typeof(MaterialVariable),
typeof(ObjectVariable),
typeof(Rigidbody2DVariable))]
typeof(Rigidbody2DVariable),
typeof(SpriteVariable))]
[SerializeField] protected Variable variable;
[Tooltip("Boolean value to compare against")]
@ -58,6 +59,9 @@ namespace Fungus
[Tooltip("Rigidbody2D value to compare against")]
[SerializeField] protected Rigidbody2DData rigidbody2DData;
[Tooltip("Sprite value to compare against")]
[SerializeField] protected SpriteData spriteData;
protected override bool EvaluateCondition()
{
if (variable == null)
@ -122,6 +126,11 @@ namespace Fungus
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);
}
return condition;
}
@ -144,7 +153,8 @@ namespace Fungus
{ typeof(GameObjectVariable), GameObjectVariable.compareOperators },
{ typeof(MaterialVariable), MaterialVariable.compareOperators },
{ typeof(ObjectVariable), ObjectVariable.compareOperators },
{ typeof(Rigidbody2DVariable), Rigidbody2DVariable.compareOperators }
{ typeof(Rigidbody2DVariable), Rigidbody2DVariable.compareOperators },
{ typeof(SpriteVariable), SpriteVariable.compareOperators }
};
/// <summary>
@ -206,6 +216,10 @@ namespace Fungus
{
summary += rigidbody2DData.GetDescription();
}
else if (variable.GetType() == typeof(SpriteVariable))
{
summary += spriteData.GetDescription();
}
return summary;
}

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

@ -50,7 +50,8 @@ namespace Fungus.EditorUtils
{ 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(Rigidbody2DVariable), new VariablePropertyInfo("Rigidbody2D", serializedObject.FindProperty("rigidbody2DData")) },
{ typeof(SpriteVariable), new VariablePropertyInfo("Sprite", serializedObject.FindProperty("spriteData")) }
};
}

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

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

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

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

Loading…
Cancel
Save