Browse Source

Add comparison and setting functionality for the Material variable

master
Jorge Ramirez 7 years ago
parent
commit
e8a19dbcc5
  1. 28
      Assets/Fungus/Scripts/Commands/SetVariable.cs
  2. 24
      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/MaterialVariable.cs

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

@ -9,21 +9,22 @@ namespace Fungus
/// <summary>
/// Sets a Boolean, Integer, Float or String variable to a new value using a simple arithmetic operation. The value can be a constant or reference another variable of the same type.
/// </summary>
[CommandInfo("Variable",
"Set Variable",
[CommandInfo("Variable",
"Set Variable",
"Sets a Boolean, Integer, Float or String variable to a new value using a simple arithmetic operation. The value can be a constant or reference another variable of the same type.")]
[AddComponentMenu("")]
public class SetVariable : Command
public class SetVariable : Command
{
[Tooltip("The variable whos value will be set")]
[VariableProperty(typeof(BooleanVariable),
typeof(IntegerVariable),
typeof(FloatVariable),
typeof(IntegerVariable),
typeof(FloatVariable),
typeof(StringVariable),
typeof(AnimatorVariable),
typeof(AudioSourceVariable),
typeof(ColorVariable),
typeof(GameObjectVariable))]
typeof(GameObjectVariable),
typeof(MaterialVariable))]
[SerializeField] protected Variable variable;
[Tooltip("The type of math operation to be performed")]
@ -53,6 +54,9 @@ namespace Fungus
[Tooltip("GameObject value to set with")]
[SerializeField] protected GameObjectData gameObjectData;
[Tooltip("Material value to set with")]
[SerializeField] protected MaterialData materialData;
protected virtual void DoSetOperation()
{
if (variable == null)
@ -101,6 +105,11 @@ namespace Fungus
GameObjectVariable gameObjectVariable = (variable as GameObjectVariable);
gameObjectVariable.Apply(setOperator, gameObjectData.Value);
}
else if (variable.GetType() == typeof(MaterialVariable))
{
MaterialVariable materialVariable = (variable as MaterialVariable);
materialVariable.Apply(setOperator, materialData.Value);
}
}
#region Public members
@ -113,7 +122,8 @@ namespace Fungus
{ typeof(AnimatorVariable), AnimatorVariable.setOperators },
{ typeof(AudioSourceVariable), AudioSourceVariable.setOperators },
{ typeof(ColorVariable), ColorVariable.setOperators },
{ typeof(GameObjectVariable), GameObjectVariable.setOperators }
{ typeof(GameObjectVariable), GameObjectVariable.setOperators },
{ typeof(MaterialVariable), MaterialVariable.setOperators }
};
/// <summary>
@ -192,6 +202,10 @@ namespace Fungus
{
description += gameObjectData.GetDescription();
}
else if (variable.GetType() == typeof(MaterialVariable))
{
description += materialData.GetDescription();
}
return description;
}

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

@ -13,13 +13,14 @@ namespace Fungus
[Tooltip("Variable to use in expression")]
[VariableProperty(typeof(BooleanVariable),
typeof(IntegerVariable),
typeof(FloatVariable),
typeof(IntegerVariable),
typeof(FloatVariable),
typeof(StringVariable),
typeof(AnimatorVariable),
typeof(AudioSourceVariable),
typeof(ColorVariable),
typeof(GameObjectVariable))]
typeof(GameObjectVariable),
typeof(MaterialVariable))]
[SerializeField] protected Variable variable;
[Tooltip("Boolean value to compare against")]
@ -46,6 +47,9 @@ namespace Fungus
[Tooltip("GameObject value to compare against")]
[SerializeField] protected GameObjectData gameObjectData;
[Tooltip("Material value to compare against")]
[SerializeField] protected MaterialData materialData;
protected override bool EvaluateCondition()
{
if (variable == null)
@ -95,6 +99,11 @@ namespace Fungus
GameObjectVariable gameObjectVariable = (variable as GameObjectVariable);
condition = gameObjectVariable.Evaluate(compareOperator, gameObjectData.Value);
}
else if (variable.GetType() == typeof(MaterialVariable))
{
MaterialVariable materialVariable = (variable as MaterialVariable);
condition = materialVariable.Evaluate(compareOperator, materialData.Value);
}
return condition;
}
@ -114,7 +123,8 @@ namespace Fungus
{ typeof(AnimatorVariable), AnimatorVariable.compareOperators },
{ typeof(AudioSourceVariable), AudioSourceVariable.compareOperators },
{ typeof(ColorVariable), ColorVariable.compareOperators },
{ typeof(GameObjectVariable), GameObjectVariable.compareOperators }
{ typeof(GameObjectVariable), GameObjectVariable.compareOperators },
{ typeof(MaterialVariable), MaterialVariable.compareOperators }
};
/// <summary>
@ -164,6 +174,10 @@ namespace Fungus
{
summary += gameObjectData.GetDescription();
}
else if (variable.GetType() == typeof(MaterialVariable))
{
summary += materialData.GetDescription();
}
return summary;
}
@ -180,4 +194,4 @@ namespace Fungus
#endregion
}
}
}

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

@ -47,7 +47,8 @@ namespace Fungus.EditorUtils
{ typeof(AnimatorVariable), new VariablePropertyInfo("Animator", serializedObject.FindProperty("animatorData")) },
{ typeof(AudioSourceVariable), new VariablePropertyInfo("AudioSource", serializedObject.FindProperty("audioSourceData")) },
{ 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")) }
};
}

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

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

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

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

Loading…
Cancel
Save