Browse Source

Add comparison and setting functionality for the Object variable

master
Jorge Ramirez 7 years ago
parent
commit
7810fecbf9
  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/ObjectVariable.cs

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

@ -24,7 +24,8 @@ namespace Fungus
typeof(AudioSourceVariable), typeof(AudioSourceVariable),
typeof(ColorVariable), typeof(ColorVariable),
typeof(GameObjectVariable), typeof(GameObjectVariable),
typeof(MaterialVariable))] typeof(MaterialVariable),
typeof(ObjectVariable))]
[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")]
@ -57,6 +58,9 @@ namespace Fungus
[Tooltip("Material value to set with")] [Tooltip("Material value to set with")]
[SerializeField] protected MaterialData materialData; [SerializeField] protected MaterialData materialData;
[Tooltip("Object value to set with")]
[SerializeField] protected ObjectData objectData;
protected virtual void DoSetOperation() protected virtual void DoSetOperation()
{ {
if (variable == null) if (variable == null)
@ -110,6 +114,11 @@ namespace Fungus
MaterialVariable materialVariable = (variable as MaterialVariable); MaterialVariable materialVariable = (variable as MaterialVariable);
materialVariable.Apply(setOperator, materialData.Value); materialVariable.Apply(setOperator, materialData.Value);
} }
else if (variable.GetType() == typeof(ObjectVariable))
{
ObjectVariable objectVariable = (variable as ObjectVariable);
objectVariable.Apply(setOperator, objectData.Value);
}
} }
#region Public members #region Public members
@ -123,7 +132,8 @@ namespace Fungus
{ typeof(AudioSourceVariable), AudioSourceVariable.setOperators }, { typeof(AudioSourceVariable), AudioSourceVariable.setOperators },
{ typeof(ColorVariable), ColorVariable.setOperators }, { typeof(ColorVariable), ColorVariable.setOperators },
{ typeof(GameObjectVariable), GameObjectVariable.setOperators }, { typeof(GameObjectVariable), GameObjectVariable.setOperators },
{ typeof(MaterialVariable), MaterialVariable.setOperators } { typeof(MaterialVariable), MaterialVariable.setOperators },
{ typeof(ObjectVariable), ObjectVariable.setOperators }
}; };
/// <summary> /// <summary>
@ -206,6 +216,10 @@ namespace Fungus
{ {
description += materialData.GetDescription(); description += materialData.GetDescription();
} }
else if (variable.GetType() == typeof(ObjectVariable))
{
description += objectData.GetDescription();
}
return description; return description;
} }

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

@ -20,7 +20,8 @@ namespace Fungus
typeof(AudioSourceVariable), typeof(AudioSourceVariable),
typeof(ColorVariable), typeof(ColorVariable),
typeof(GameObjectVariable), typeof(GameObjectVariable),
typeof(MaterialVariable))] typeof(MaterialVariable),
typeof(ObjectVariable))]
[SerializeField] protected Variable variable; [SerializeField] protected Variable variable;
[Tooltip("Boolean value to compare against")] [Tooltip("Boolean value to compare against")]
@ -50,6 +51,9 @@ namespace Fungus
[Tooltip("Material value to compare against")] [Tooltip("Material value to compare against")]
[SerializeField] protected MaterialData materialData; [SerializeField] protected MaterialData materialData;
[Tooltip("Object value to compare against")]
[SerializeField] protected ObjectData objectData;
protected override bool EvaluateCondition() protected override bool EvaluateCondition()
{ {
if (variable == null) if (variable == null)
@ -104,6 +108,11 @@ namespace Fungus
MaterialVariable materialVariable = (variable as MaterialVariable); MaterialVariable materialVariable = (variable as MaterialVariable);
condition = materialVariable.Evaluate(compareOperator, materialData.Value); condition = materialVariable.Evaluate(compareOperator, materialData.Value);
} }
else if (variable.GetType() == typeof(ObjectVariable))
{
ObjectVariable objectVariable = (variable as ObjectVariable);
condition = objectVariable.Evaluate(compareOperator, objectData.Value);
}
return condition; return condition;
} }
@ -124,7 +133,8 @@ namespace Fungus
{ typeof(AudioSourceVariable), AudioSourceVariable.compareOperators }, { typeof(AudioSourceVariable), AudioSourceVariable.compareOperators },
{ typeof(ColorVariable), ColorVariable.compareOperators }, { typeof(ColorVariable), ColorVariable.compareOperators },
{ typeof(GameObjectVariable), GameObjectVariable.compareOperators }, { typeof(GameObjectVariable), GameObjectVariable.compareOperators },
{ typeof(MaterialVariable), MaterialVariable.compareOperators } { typeof(MaterialVariable), MaterialVariable.compareOperators },
{ typeof(ObjectVariable), ObjectVariable.compareOperators }
}; };
/// <summary> /// <summary>
@ -178,6 +188,10 @@ namespace Fungus
{ {
summary += materialData.GetDescription(); summary += materialData.GetDescription();
} }
else if (variable.GetType() == typeof(ObjectVariable))
{
summary += objectData.GetDescription();
}
return summary; return summary;
} }

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

@ -48,7 +48,8 @@ namespace Fungus.EditorUtils
{ typeof(AudioSourceVariable), new VariablePropertyInfo("AudioSource", serializedObject.FindProperty("audioSourceData")) }, { typeof(AudioSourceVariable), new VariablePropertyInfo("AudioSource", serializedObject.FindProperty("audioSourceData")) },
{ typeof(ColorVariable), new VariablePropertyInfo("Color", serializedObject.FindProperty("colorData")) }, { typeof(ColorVariable), new VariablePropertyInfo("Color", serializedObject.FindProperty("colorData")) },
{ typeof(GameObjectVariable), new VariablePropertyInfo("GameObject", serializedObject.FindProperty("gameObjectData")) }, { typeof(GameObjectVariable), new VariablePropertyInfo("GameObject", serializedObject.FindProperty("gameObjectData")) },
{ typeof(MaterialVariable), new VariablePropertyInfo("Material", serializedObject.FindProperty("materialData")) } { typeof(MaterialVariable), new VariablePropertyInfo("Material", serializedObject.FindProperty("materialData")) },
{ typeof(ObjectVariable), new VariablePropertyInfo("Object", serializedObject.FindProperty("objectData")) }
}; };
} }

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

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

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

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

Loading…
Cancel
Save