Browse Source

Add comparison and setting functionality for the Transform variable

master
Jorge Ramirez 7 years ago
parent
commit
57776a67da
  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/TransformVariable.cs

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

@ -28,7 +28,8 @@ namespace Fungus
typeof(ObjectVariable), typeof(ObjectVariable),
typeof(Rigidbody2DVariable), typeof(Rigidbody2DVariable),
typeof(SpriteVariable), typeof(SpriteVariable),
typeof(TextureVariable))] typeof(TextureVariable),
typeof(TransformVariable))]
[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")]
@ -73,6 +74,9 @@ namespace Fungus
[Tooltip("Texture value to set with")] [Tooltip("Texture value to set with")]
[SerializeField] protected TextureData textureData; [SerializeField] protected TextureData textureData;
[Tooltip("Transform value to set with")]
[SerializeField] protected TransformData transformData;
protected virtual void DoSetOperation() protected virtual void DoSetOperation()
{ {
if (variable == null) if (variable == null)
@ -146,6 +150,11 @@ namespace Fungus
TextureVariable textureVariable = (variable as TextureVariable); TextureVariable textureVariable = (variable as TextureVariable);
textureVariable.Apply(setOperator, textureData.Value); textureVariable.Apply(setOperator, textureData.Value);
} }
else if (variable.GetType() == typeof(TransformVariable))
{
TransformVariable transformVariable = (variable as TransformVariable);
transformVariable.Apply(setOperator, transformData.Value);
}
} }
#region Public members #region Public members
@ -163,7 +172,8 @@ namespace Fungus
{ 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 } { typeof(TextureVariable), TextureVariable.setOperators },
{ typeof(TransformVariable), TransformVariable.setOperators }
}; };
/// <summary> /// <summary>
@ -262,6 +272,10 @@ namespace Fungus
{ {
description += textureData.GetDescription(); description += textureData.GetDescription();
} }
else if (variable.GetType() == typeof(TransformVariable))
{
description += transformData.GetDescription();
}
return description; return description;
} }

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

@ -24,7 +24,8 @@ namespace Fungus
typeof(ObjectVariable), typeof(ObjectVariable),
typeof(Rigidbody2DVariable), typeof(Rigidbody2DVariable),
typeof(SpriteVariable), typeof(SpriteVariable),
typeof(TextureVariable))] typeof(TextureVariable),
typeof(TransformVariable))]
[SerializeField] protected Variable variable; [SerializeField] protected Variable variable;
[Tooltip("Boolean value to compare against")] [Tooltip("Boolean value to compare against")]
@ -66,6 +67,9 @@ namespace Fungus
[Tooltip("Texture value to compare against")] [Tooltip("Texture value to compare against")]
[SerializeField] protected TextureData textureData; [SerializeField] protected TextureData textureData;
[Tooltip("Transform value to compare against")]
[SerializeField] protected TransformData transformData;
protected override bool EvaluateCondition() protected override bool EvaluateCondition()
{ {
if (variable == null) if (variable == null)
@ -140,6 +144,11 @@ namespace Fungus
TextureVariable textureVariable = (variable as TextureVariable); TextureVariable textureVariable = (variable as TextureVariable);
condition = textureVariable.Evaluate(compareOperator, textureData.Value); condition = textureVariable.Evaluate(compareOperator, textureData.Value);
} }
else if (variable.GetType() == typeof(TransformVariable))
{
TransformVariable transformVariable = (variable as TransformVariable);
condition = transformVariable.Evaluate(compareOperator, transformData.Value);
}
return condition; return condition;
} }
@ -164,7 +173,8 @@ namespace Fungus
{ 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 } { typeof(TextureVariable), TextureVariable.compareOperators },
{ typeof(TransformVariable), TransformVariable.compareOperators }
}; };
/// <summary> /// <summary>
@ -234,6 +244,10 @@ namespace Fungus
{ {
summary += textureData.GetDescription(); summary += textureData.GetDescription();
} }
else if (variable.GetType() == typeof(TransformVariable))
{
summary += transformData.GetDescription();
}
return summary; return summary;
} }

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

@ -52,7 +52,8 @@ namespace Fungus.EditorUtils
{ 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")) } { typeof(TextureVariable), new VariablePropertyInfo("Texture", serializedObject.FindProperty("textureData")) },
{ typeof(TransformVariable), new VariablePropertyInfo("Transform", serializedObject.FindProperty("transformData")) }
}; };
} }

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

@ -37,7 +37,8 @@ namespace Fungus.EditorUtils
{ 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") } { typeof(TextureVariable), serializedObject.FindProperty("textureData") },
{ typeof(TransformVariable), serializedObject.FindProperty("transformData") }
}; };
} }

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

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

Loading…
Cancel
Save