Browse Source

Add comparison and setting functionality for the Animator variable

master
Jorge Ramirez 7 years ago
parent
commit
88711d84a6
  1. 14
      Assets/Fungus/Scripts/Commands/SetVariable.cs
  2. 14
      Assets/Fungus/Scripts/Commands/VariableCondition.cs
  3. 1
      Assets/Fungus/Scripts/Editor/SetVariableEditor.cs
  4. 1
      Assets/Fungus/Scripts/Editor/VariableConditionEditor.cs
  5. 38
      Assets/Fungus/Scripts/VariableTypes/AnimatorVariable.cs

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

@ -20,6 +20,7 @@ namespace Fungus
typeof(IntegerVariable),
typeof(FloatVariable),
typeof(StringVariable),
typeof(AnimatorVariable),
typeof(GameObjectVariable))]
[SerializeField] protected Variable variable;
@ -38,6 +39,9 @@ namespace Fungus
[Tooltip("String value to set with")]
[SerializeField] protected StringDataMulti stringData;
[Tooltip("Animator value to set with")]
[SerializeField] protected AnimatorData animatorData;
[Tooltip("GameObject value to set with")]
[SerializeField] protected GameObjectData gameObjectData;
@ -69,6 +73,11 @@ namespace Fungus
var flowchart = GetFlowchart();
stringVariable.Apply(setOperator, flowchart.SubstituteVariables(stringData.Value));
}
else if (variable.GetType() == typeof(AnimatorVariable))
{
AnimatorVariable animatorVariable = (variable as AnimatorVariable);
animatorVariable.Apply(setOperator, animatorData.Value);
}
else if (variable.GetType() == typeof(GameObjectVariable))
{
GameObjectVariable gameObjectVariable = (variable as GameObjectVariable);
@ -83,6 +92,7 @@ namespace Fungus
{ typeof(IntegerVariable), IntegerVariable.setOperators },
{ typeof(FloatVariable), FloatVariable.setOperators },
{ typeof(StringVariable), StringVariable.setOperators },
{ typeof(AnimatorVariable), AnimatorVariable.setOperators },
{ typeof(GameObjectVariable), GameObjectVariable.setOperators }
};
@ -146,6 +156,10 @@ namespace Fungus
{
description += stringData.GetDescription();
}
else if (variable.GetType() == typeof(AnimatorVariable))
{
description += animatorData.GetDescription();
}
else if (variable.GetType() == typeof(GameObjectVariable))
{
description += gameObjectData.GetDescription();

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

@ -16,6 +16,7 @@ namespace Fungus
typeof(IntegerVariable),
typeof(FloatVariable),
typeof(StringVariable),
typeof(AnimatorVariable),
typeof(GameObjectVariable))]
[SerializeField] protected Variable variable;
@ -31,6 +32,9 @@ namespace Fungus
[Tooltip("String value to compare against")]
[SerializeField] protected StringDataMulti stringData;
[Tooltip("Animator value to compare against")]
[SerializeField] protected AnimatorData animatorData;
[Tooltip("GameObject value to compare against")]
[SerializeField] protected GameObjectData gameObjectData;
@ -63,6 +67,11 @@ namespace Fungus
StringVariable stringVariable = (variable as StringVariable);
condition = stringVariable.Evaluate(compareOperator, stringData.Value);
}
else if (variable.GetType() == typeof(AnimatorVariable))
{
AnimatorVariable animatorVariable = (variable as AnimatorVariable);
condition = animatorVariable.Evaluate(compareOperator, animatorData.Value);
}
else if (variable.GetType() == typeof(GameObjectVariable))
{
GameObjectVariable gameObjectVariable = (variable as GameObjectVariable);
@ -84,6 +93,7 @@ namespace Fungus
{ typeof(IntegerVariable), IntegerVariable.compareOperators },
{ typeof(FloatVariable), FloatVariable.compareOperators },
{ typeof(StringVariable), StringVariable.compareOperators },
{ typeof(AnimatorVariable), AnimatorVariable.compareOperators },
{ typeof(GameObjectVariable), GameObjectVariable.compareOperators }
};
@ -118,6 +128,10 @@ namespace Fungus
{
summary += stringData.GetDescription();
}
else if (variable.GetType() == typeof(AnimatorVariable))
{
summary += animatorData.GetDescription();
}
else if (variable.GetType() == typeof(GameObjectVariable))
{
summary += gameObjectData.GetDescription();

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

@ -44,6 +44,7 @@ namespace Fungus.EditorUtils
{ typeof(IntegerVariable), new VariablePropertyInfo("Integer", serializedObject.FindProperty("integerData")) },
{ typeof(FloatVariable), new VariablePropertyInfo("Float", serializedObject.FindProperty("floatData")) },
{ typeof(StringVariable), new VariablePropertyInfo("String", serializedObject.FindProperty("stringData")) },
{ typeof(AnimatorVariable), new VariablePropertyInfo("Animator", serializedObject.FindProperty("animatorData")) },
{ typeof(GameObjectVariable), new VariablePropertyInfo("GameObject", serializedObject.FindProperty("gameObjectData")) }
};
}

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

@ -29,6 +29,7 @@ namespace Fungus.EditorUtils
{ typeof(IntegerVariable), serializedObject.FindProperty("integerData") },
{ typeof(FloatVariable), serializedObject.FindProperty("floatData") },
{ typeof(StringVariable), serializedObject.FindProperty("stringData") },
{ typeof(AnimatorVariable), serializedObject.FindProperty("animatorData") },
{ typeof(GameObjectVariable), serializedObject.FindProperty("gameObjectData") }
};
}

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

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

Loading…
Cancel
Save