Browse Source

Add comparison and setting functionality for the Rigidbody2D variable

master
Jorge Ramirez 7 years ago
parent
commit
041950b35f
  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/Rigidbody2DVariable.cs

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

@ -25,7 +25,8 @@ namespace Fungus
typeof(ColorVariable),
typeof(GameObjectVariable),
typeof(MaterialVariable),
typeof(ObjectVariable))]
typeof(ObjectVariable),
typeof(Rigidbody2DVariable))]
[SerializeField] protected Variable variable;
[Tooltip("The type of math operation to be performed")]
@ -61,6 +62,9 @@ namespace Fungus
[Tooltip("Object value to set with")]
[SerializeField] protected ObjectData objectData;
[Tooltip("Rigidbody2D value to set with")]
[SerializeField] protected Rigidbody2DData rigidbody2DData;
protected virtual void DoSetOperation()
{
if (variable == null)
@ -119,6 +123,11 @@ namespace Fungus
ObjectVariable objectVariable = (variable as ObjectVariable);
objectVariable.Apply(setOperator, objectData.Value);
}
else if (variable.GetType() == typeof(Rigidbody2DVariable))
{
Rigidbody2DVariable rigidbody2DVariable = (variable as Rigidbody2DVariable);
rigidbody2DVariable.Apply(setOperator, rigidbody2DData.Value);
}
}
#region Public members
@ -133,7 +142,8 @@ namespace Fungus
{ typeof(ColorVariable), ColorVariable.setOperators },
{ typeof(GameObjectVariable), GameObjectVariable.setOperators },
{ typeof(MaterialVariable), MaterialVariable.setOperators },
{ typeof(ObjectVariable), ObjectVariable.setOperators }
{ typeof(ObjectVariable), ObjectVariable.setOperators },
{ typeof(Rigidbody2DVariable), Rigidbody2DVariable.setOperators }
};
/// <summary>
@ -220,6 +230,10 @@ namespace Fungus
{
description += objectData.GetDescription();
}
else if (variable.GetType() == typeof(Rigidbody2DVariable))
{
description += rigidbody2DData.GetDescription();
}
return description;
}

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

@ -21,7 +21,8 @@ namespace Fungus
typeof(ColorVariable),
typeof(GameObjectVariable),
typeof(MaterialVariable),
typeof(ObjectVariable))]
typeof(ObjectVariable),
typeof(Rigidbody2DVariable))]
[SerializeField] protected Variable variable;
[Tooltip("Boolean value to compare against")]
@ -54,6 +55,9 @@ namespace Fungus
[Tooltip("Object value to compare against")]
[SerializeField] protected ObjectData objectData;
[Tooltip("Rigidbody2D value to compare against")]
[SerializeField] protected Rigidbody2DData rigidbody2DData;
protected override bool EvaluateCondition()
{
if (variable == null)
@ -113,6 +117,11 @@ namespace Fungus
ObjectVariable objectVariable = (variable as ObjectVariable);
condition = objectVariable.Evaluate(compareOperator, objectData.Value);
}
else if (variable.GetType() == typeof(Rigidbody2DVariable))
{
Rigidbody2DVariable rigidbody2DVariable = (variable as Rigidbody2DVariable);
condition = rigidbody2DVariable.Evaluate(compareOperator, rigidbody2DData.Value);
}
return condition;
}
@ -134,7 +143,8 @@ namespace Fungus
{ typeof(ColorVariable), ColorVariable.compareOperators },
{ typeof(GameObjectVariable), GameObjectVariable.compareOperators },
{ typeof(MaterialVariable), MaterialVariable.compareOperators },
{ typeof(ObjectVariable), ObjectVariable.compareOperators }
{ typeof(ObjectVariable), ObjectVariable.compareOperators },
{ typeof(Rigidbody2DVariable), Rigidbody2DVariable.compareOperators }
};
/// <summary>
@ -192,6 +202,10 @@ namespace Fungus
{
summary += objectData.GetDescription();
}
else if (variable.GetType() == typeof(Rigidbody2DVariable))
{
summary += rigidbody2DData.GetDescription();
}
return summary;
}

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

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

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

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

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

@ -9,7 +9,43 @@ namespace Fungus
[AddComponentMenu("")]
[System.Serializable]
public class Rigidbody2DVariable : VariableBase<Rigidbody2D>
{ }
{
public static readonly CompareOperator[] compareOperators = { CompareOperator.Equals, CompareOperator.NotEquals };
public static readonly SetOperator[] setOperators = { SetOperator.Assign };
public virtual bool Evaluate(CompareOperator compareOperator, Rigidbody2D 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, Rigidbody2D 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 Rigidbody2D variable reference or constant value.

Loading…
Cancel
Save