Browse Source

Add comparison and setting functionality for the Vector2 and Vector3 variables

master
Jorge Ramirez 7 years ago
parent
commit
60bfe84399
  1. 32
      Assets/Fungus/Scripts/Commands/SetVariable.cs
  2. 32
      Assets/Fungus/Scripts/Commands/VariableCondition.cs
  3. 4
      Assets/Fungus/Scripts/Editor/SetVariableEditor.cs
  4. 4
      Assets/Fungus/Scripts/Editor/VariableConditionEditor.cs
  5. 38
      Assets/Fungus/Scripts/VariableTypes/Vector2Variable.cs
  6. 38
      Assets/Fungus/Scripts/VariableTypes/Vector3Variable.cs

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

@ -29,7 +29,9 @@ namespace Fungus
typeof(Rigidbody2DVariable),
typeof(SpriteVariable),
typeof(TextureVariable),
typeof(TransformVariable))]
typeof(TransformVariable),
typeof(Vector2Variable),
typeof(Vector3Variable))]
[SerializeField] protected Variable variable;
[Tooltip("The type of math operation to be performed")]
@ -77,6 +79,12 @@ namespace Fungus
[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)
@ -155,6 +163,16 @@ namespace Fungus
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
@ -173,7 +191,9 @@ namespace Fungus
{ typeof(Rigidbody2DVariable), Rigidbody2DVariable.setOperators },
{ typeof(SpriteVariable), SpriteVariable.setOperators },
{ typeof(TextureVariable), TextureVariable.setOperators },
{ typeof(TransformVariable), TransformVariable.setOperators }
{ typeof(TransformVariable), TransformVariable.setOperators },
{ typeof(Vector2Variable), Vector2Variable.setOperators },
{ typeof(Vector3Variable), Vector3Variable.setOperators }
};
/// <summary>
@ -276,6 +296,14 @@ namespace Fungus
{
description += transformData.GetDescription();
}
else if (variable.GetType() == typeof(Vector2Variable))
{
description += vector2Data.GetDescription();
}
else if (variable.GetType() == typeof(Vector3Variable))
{
description += vector3Data.GetDescription();
}
return description;
}

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

@ -25,7 +25,9 @@ namespace Fungus
typeof(Rigidbody2DVariable),
typeof(SpriteVariable),
typeof(TextureVariable),
typeof(TransformVariable))]
typeof(TransformVariable),
typeof(Vector2Variable),
typeof(Vector3Variable))]
[SerializeField] protected Variable variable;
[Tooltip("Boolean value to compare against")]
@ -70,6 +72,12 @@ namespace Fungus
[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)
@ -149,6 +157,16 @@ namespace Fungus
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;
}
@ -174,7 +192,9 @@ namespace Fungus
{ typeof(Rigidbody2DVariable), Rigidbody2DVariable.compareOperators },
{ typeof(SpriteVariable), SpriteVariable.compareOperators },
{ typeof(TextureVariable), TextureVariable.compareOperators },
{ typeof(TransformVariable), TransformVariable.compareOperators }
{ typeof(TransformVariable), TransformVariable.compareOperators },
{ typeof(Vector2Variable), Vector2Variable.compareOperators },
{ typeof(Vector3Variable), Vector3Variable.compareOperators }
};
/// <summary>
@ -248,6 +268,14 @@ namespace Fungus
{
summary += transformData.GetDescription();
}
else if (variable.GetType() == typeof(Vector2Variable))
{
summary += vector2Data.GetDescription();
}
else if (variable.GetType() == typeof(Vector3Variable))
{
summary += vector3Data.GetDescription();
}
return summary;
}

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

@ -53,7 +53,9 @@ namespace Fungus.EditorUtils
{ 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(TransformVariable), new VariablePropertyInfo("Transform", serializedObject.FindProperty("transformData")) },
{ typeof(Vector2Variable), new VariablePropertyInfo("Vector2", serializedObject.FindProperty("vector2Data")) },
{ typeof(Vector3Variable), new VariablePropertyInfo("Vector3", serializedObject.FindProperty("vector3Data")) }
};
}

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

@ -38,7 +38,9 @@ namespace Fungus.EditorUtils
{ typeof(Rigidbody2DVariable), serializedObject.FindProperty("rigidbody2DData") },
{ typeof(SpriteVariable), serializedObject.FindProperty("spriteData") },
{ typeof(TextureVariable), serializedObject.FindProperty("textureData") },
{ typeof(TransformVariable), serializedObject.FindProperty("transformData") }
{ typeof(TransformVariable), serializedObject.FindProperty("transformData") },
{ typeof(Vector2Variable), serializedObject.FindProperty("vector2Data") },
{ typeof(Vector3Variable), serializedObject.FindProperty("vector3Data") }
};
}

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

@ -13,7 +13,43 @@ namespace Fungus
[AddComponentMenu("")]
[System.Serializable]
public class Vector2Variable : VariableBase<Vector2>
{}
{
public static readonly CompareOperator[] compareOperators = { CompareOperator.Equals, CompareOperator.NotEquals };
public static readonly SetOperator[] setOperators = { SetOperator.Assign };
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;
default:
Debug.LogError("The " + setOperator.ToString() + " set operator is not valid.");
break;
}
}
}
/// <summary>
/// Container for a Vector2 variable reference or constant value.

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

@ -13,7 +13,43 @@ namespace Fungus
[AddComponentMenu("")]
[System.Serializable]
public class Vector3Variable : VariableBase<Vector3>
{}
{
public static readonly CompareOperator[] compareOperators = { CompareOperator.Equals, CompareOperator.NotEquals };
public static readonly SetOperator[] setOperators = { SetOperator.Assign };
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;
default:
Debug.LogError("The " + setOperator.ToString() + " set operator is not valid.");
break;
}
}
}
/// <summary>
/// Container for a Vector3 variable reference or constant value.

Loading…
Cancel
Save