Browse Source

Add comparison and setting functionality for the Material variable

master
Jorge Ramirez 7 years ago
parent
commit
e8a19dbcc5
  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/MaterialVariable.cs

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

@ -23,7 +23,8 @@ namespace Fungus
typeof(AnimatorVariable), typeof(AnimatorVariable),
typeof(AudioSourceVariable), typeof(AudioSourceVariable),
typeof(ColorVariable), typeof(ColorVariable),
typeof(GameObjectVariable))] typeof(GameObjectVariable),
typeof(MaterialVariable))]
[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")]
@ -53,6 +54,9 @@ namespace Fungus
[Tooltip("GameObject value to set with")] [Tooltip("GameObject value to set with")]
[SerializeField] protected GameObjectData gameObjectData; [SerializeField] protected GameObjectData gameObjectData;
[Tooltip("Material value to set with")]
[SerializeField] protected MaterialData materialData;
protected virtual void DoSetOperation() protected virtual void DoSetOperation()
{ {
if (variable == null) if (variable == null)
@ -101,6 +105,11 @@ namespace Fungus
GameObjectVariable gameObjectVariable = (variable as GameObjectVariable); GameObjectVariable gameObjectVariable = (variable as GameObjectVariable);
gameObjectVariable.Apply(setOperator, gameObjectData.Value); gameObjectVariable.Apply(setOperator, gameObjectData.Value);
} }
else if (variable.GetType() == typeof(MaterialVariable))
{
MaterialVariable materialVariable = (variable as MaterialVariable);
materialVariable.Apply(setOperator, materialData.Value);
}
} }
#region Public members #region Public members
@ -113,7 +122,8 @@ namespace Fungus
{ typeof(AnimatorVariable), AnimatorVariable.setOperators }, { typeof(AnimatorVariable), AnimatorVariable.setOperators },
{ 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 }
}; };
/// <summary> /// <summary>
@ -192,6 +202,10 @@ namespace Fungus
{ {
description += gameObjectData.GetDescription(); description += gameObjectData.GetDescription();
} }
else if (variable.GetType() == typeof(MaterialVariable))
{
description += materialData.GetDescription();
}
return description; return description;
} }

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

@ -19,7 +19,8 @@ namespace Fungus
typeof(AnimatorVariable), typeof(AnimatorVariable),
typeof(AudioSourceVariable), typeof(AudioSourceVariable),
typeof(ColorVariable), typeof(ColorVariable),
typeof(GameObjectVariable))] typeof(GameObjectVariable),
typeof(MaterialVariable))]
[SerializeField] protected Variable variable; [SerializeField] protected Variable variable;
[Tooltip("Boolean value to compare against")] [Tooltip("Boolean value to compare against")]
@ -46,6 +47,9 @@ namespace Fungus
[Tooltip("GameObject value to compare against")] [Tooltip("GameObject value to compare against")]
[SerializeField] protected GameObjectData gameObjectData; [SerializeField] protected GameObjectData gameObjectData;
[Tooltip("Material value to compare against")]
[SerializeField] protected MaterialData materialData;
protected override bool EvaluateCondition() protected override bool EvaluateCondition()
{ {
if (variable == null) if (variable == null)
@ -95,6 +99,11 @@ namespace Fungus
GameObjectVariable gameObjectVariable = (variable as GameObjectVariable); GameObjectVariable gameObjectVariable = (variable as GameObjectVariable);
condition = gameObjectVariable.Evaluate(compareOperator, gameObjectData.Value); 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; return condition;
} }
@ -114,7 +123,8 @@ namespace Fungus
{ typeof(AnimatorVariable), AnimatorVariable.compareOperators }, { typeof(AnimatorVariable), AnimatorVariable.compareOperators },
{ 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 }
}; };
/// <summary> /// <summary>
@ -164,6 +174,10 @@ namespace Fungus
{ {
summary += gameObjectData.GetDescription(); summary += gameObjectData.GetDescription();
} }
else if (variable.GetType() == typeof(MaterialVariable))
{
summary += materialData.GetDescription();
}
return summary; return summary;
} }

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

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

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

@ -32,7 +32,8 @@ namespace Fungus.EditorUtils
{ typeof(AnimatorVariable), serializedObject.FindProperty("animatorData") }, { typeof(AnimatorVariable), serializedObject.FindProperty("animatorData") },
{ 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") }
}; };
} }

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

@ -13,7 +13,43 @@ namespace Fungus
[AddComponentMenu("")] [AddComponentMenu("")]
[System.Serializable] [System.Serializable]
public class MaterialVariable : VariableBase<Material> 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> /// <summary>
/// Container for a Material variable reference or constant value. /// Container for a Material variable reference or constant value.

Loading…
Cancel
Save