Browse Source

Merge pull request #668 from MeMark2/set-and-compare-variables

Set and compare other variables
master
Chris Gregan 7 years ago committed by GitHub
parent
commit
47e6a29904
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 168
      Assets/Fungus/Scripts/Commands/SetVariable.cs
  2. 164
      Assets/Fungus/Scripts/Commands/VariableCondition.cs
  3. 19
      Assets/Fungus/Scripts/Editor/SetVariableEditor.cs
  4. 15
      Assets/Fungus/Scripts/Editor/VariableConditionEditor.cs
  5. 38
      Assets/Fungus/Scripts/VariableTypes/AnimatorVariable.cs
  6. 38
      Assets/Fungus/Scripts/VariableTypes/AudioSourceVariable.cs
  7. 20
      Assets/Fungus/Scripts/VariableTypes/BooleanVariable.cs
  8. 56
      Assets/Fungus/Scripts/VariableTypes/ColorVariable.cs
  9. 43
      Assets/Fungus/Scripts/VariableTypes/FloatVariable.cs
  10. 8
      Assets/Fungus/Scripts/VariableTypes/GameObjectVariable.cs
  11. 43
      Assets/Fungus/Scripts/VariableTypes/IntegerVariable.cs
  12. 38
      Assets/Fungus/Scripts/VariableTypes/MaterialVariable.cs
  13. 38
      Assets/Fungus/Scripts/VariableTypes/ObjectVariable.cs
  14. 38
      Assets/Fungus/Scripts/VariableTypes/Rigidbody2DVariable.cs
  15. 38
      Assets/Fungus/Scripts/VariableTypes/SpriteVariable.cs
  16. 20
      Assets/Fungus/Scripts/VariableTypes/StringVariable.cs
  17. 38
      Assets/Fungus/Scripts/VariableTypes/TextureVariable.cs
  18. 38
      Assets/Fungus/Scripts/VariableTypes/TransformVariable.cs
  19. 44
      Assets/Fungus/Scripts/VariableTypes/Vector2Variable.cs
  20. 44
      Assets/Fungus/Scripts/VariableTypes/Vector3Variable.cs

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

@ -9,18 +9,29 @@ 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(GameObjectVariable))]
typeof(AnimatorVariable),
typeof(AudioSourceVariable),
typeof(ColorVariable),
typeof(GameObjectVariable),
typeof(MaterialVariable),
typeof(ObjectVariable),
typeof(Rigidbody2DVariable),
typeof(SpriteVariable),
typeof(TextureVariable),
typeof(TransformVariable),
typeof(Vector2Variable),
typeof(Vector3Variable))]
[SerializeField] protected Variable variable;
[Tooltip("The type of math operation to be performed")]
@ -38,9 +49,42 @@ namespace Fungus
[Tooltip("String value to set with")]
[SerializeField] protected StringDataMulti stringData;
[Tooltip("Animator value to set with")]
[SerializeField] protected AnimatorData animatorData;
[Tooltip("AudioSource value to set with")]
[SerializeField] protected AudioSourceData audioSourceData;
[Tooltip("Color value to set with")]
[SerializeField] protected ColorData colorData;
[Tooltip("GameObject value to set with")]
[SerializeField] protected GameObjectData gameObjectData;
[Tooltip("Material value to set with")]
[SerializeField] protected MaterialData materialData;
[Tooltip("Object value to set with")]
[SerializeField] protected ObjectData objectData;
[Tooltip("Rigidbody2D value to set with")]
[SerializeField] protected Rigidbody2DData rigidbody2DData;
[Tooltip("Sprite value to set with")]
[SerializeField] protected SpriteData spriteData;
[Tooltip("Texture value to set with")]
[SerializeField] protected TextureData textureData;
[Tooltip("Transform value to set with")]
[SerializeField] protected TransformData transformData;
[Tooltip("Vector2 value to set with")]
[SerializeField] protected Vector2Data vector2Data;
[Tooltip("Vector3 value to set with")]
[SerializeField] protected Vector3Data vector3Data;
protected virtual void DoSetOperation()
{
if (variable == null)
@ -69,11 +113,66 @@ 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(AudioSourceVariable))
{
AudioSourceVariable audioSourceVariable = (variable as AudioSourceVariable);
audioSourceVariable.Apply(setOperator, audioSourceData.Value);
}
else if (variable.GetType() == typeof(ColorVariable))
{
ColorVariable colorVariable = (variable as ColorVariable);
colorVariable.Apply(setOperator, colorData.Value);
}
else if (variable.GetType() == typeof(GameObjectVariable))
{
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);
}
else if (variable.GetType() == typeof(ObjectVariable))
{
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);
}
else if (variable.GetType() == typeof(SpriteVariable))
{
SpriteVariable spriteVariable = (variable as SpriteVariable);
spriteVariable.Apply(setOperator, spriteData.Value);
}
else if (variable.GetType() == typeof(TextureVariable))
{
TextureVariable textureVariable = (variable as TextureVariable);
textureVariable.Apply(setOperator, textureData.Value);
}
else if (variable.GetType() == typeof(TransformVariable))
{
TransformVariable transformVariable = (variable as TransformVariable);
transformVariable.Apply(setOperator, transformData.Value);
}
else if (variable.GetType() == typeof(Vector2Variable))
{
Vector2Variable vector2Variable = (variable as Vector2Variable);
vector2Variable.Apply(setOperator, vector2Data.Value);
}
else if (variable.GetType() == typeof(Vector3Variable))
{
Vector3Variable vector3Variable = (variable as Vector3Variable);
vector3Variable.Apply(setOperator, vector3Data.Value);
}
}
#region Public members
@ -83,7 +182,18 @@ namespace Fungus
{ typeof(IntegerVariable), IntegerVariable.setOperators },
{ typeof(FloatVariable), FloatVariable.setOperators },
{ typeof(StringVariable), StringVariable.setOperators },
{ typeof(GameObjectVariable), GameObjectVariable.setOperators }
{ typeof(AnimatorVariable), AnimatorVariable.setOperators },
{ typeof(AudioSourceVariable), AudioSourceVariable.setOperators },
{ typeof(ColorVariable), ColorVariable.setOperators },
{ typeof(GameObjectVariable), GameObjectVariable.setOperators },
{ typeof(MaterialVariable), MaterialVariable.setOperators },
{ typeof(ObjectVariable), ObjectVariable.setOperators },
{ typeof(Rigidbody2DVariable), Rigidbody2DVariable.setOperators },
{ typeof(SpriteVariable), SpriteVariable.setOperators },
{ typeof(TextureVariable), TextureVariable.setOperators },
{ typeof(TransformVariable), TransformVariable.setOperators },
{ typeof(Vector2Variable), Vector2Variable.setOperators },
{ typeof(Vector3Variable), Vector3Variable.setOperators }
};
/// <summary>
@ -146,10 +256,54 @@ namespace Fungus
{
description += stringData.GetDescription();
}
else if (variable.GetType() == typeof(AnimatorVariable))
{
description += animatorData.GetDescription();
}
else if (variable.GetType() == typeof(AudioSourceVariable))
{
description += audioSourceData.GetDescription();
}
else if (variable.GetType() == typeof(ColorVariable))
{
description += colorData.GetDescription();
}
else if (variable.GetType() == typeof(GameObjectVariable))
{
description += gameObjectData.GetDescription();
}
else if (variable.GetType() == typeof(MaterialVariable))
{
description += materialData.GetDescription();
}
else if (variable.GetType() == typeof(ObjectVariable))
{
description += objectData.GetDescription();
}
else if (variable.GetType() == typeof(Rigidbody2DVariable))
{
description += rigidbody2DData.GetDescription();
}
else if (variable.GetType() == typeof(SpriteVariable))
{
description += spriteData.GetDescription();
}
else if (variable.GetType() == typeof(TextureVariable))
{
description += textureData.GetDescription();
}
else if (variable.GetType() == typeof(TransformVariable))
{
description += transformData.GetDescription();
}
else if (variable.GetType() == typeof(Vector2Variable))
{
description += vector2Data.GetDescription();
}
else if (variable.GetType() == typeof(Vector3Variable))
{
description += vector3Data.GetDescription();
}
return description;
}

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

@ -13,10 +13,21 @@ namespace Fungus
[Tooltip("Variable to use in expression")]
[VariableProperty(typeof(BooleanVariable),
typeof(IntegerVariable),
typeof(FloatVariable),
typeof(IntegerVariable),
typeof(FloatVariable),
typeof(StringVariable),
typeof(GameObjectVariable))]
typeof(AnimatorVariable),
typeof(AudioSourceVariable),
typeof(ColorVariable),
typeof(GameObjectVariable),
typeof(MaterialVariable),
typeof(ObjectVariable),
typeof(Rigidbody2DVariable),
typeof(SpriteVariable),
typeof(TextureVariable),
typeof(TransformVariable),
typeof(Vector2Variable),
typeof(Vector3Variable))]
[SerializeField] protected Variable variable;
[Tooltip("Boolean value to compare against")]
@ -31,9 +42,42 @@ namespace Fungus
[Tooltip("String value to compare against")]
[SerializeField] protected StringDataMulti stringData;
[Tooltip("Animator value to compare against")]
[SerializeField] protected AnimatorData animatorData;
[Tooltip("AudioSource value to compare against")]
[SerializeField] protected AudioSourceData audioSourceData;
[Tooltip("Color value to compare against")]
[SerializeField] protected ColorData colorData;
[Tooltip("GameObject value to compare against")]
[SerializeField] protected GameObjectData gameObjectData;
[Tooltip("Material value to compare against")]
[SerializeField] protected MaterialData materialData;
[Tooltip("Object value to compare against")]
[SerializeField] protected ObjectData objectData;
[Tooltip("Rigidbody2D value to compare against")]
[SerializeField] protected Rigidbody2DData rigidbody2DData;
[Tooltip("Sprite value to compare against")]
[SerializeField] protected SpriteData spriteData;
[Tooltip("Texture value to compare against")]
[SerializeField] protected TextureData textureData;
[Tooltip("Transform value to compare against")]
[SerializeField] protected TransformData transformData;
[Tooltip("Vector2 value to compare against")]
[SerializeField] protected Vector2Data vector2Data;
[Tooltip("Vector3 value to compare against")]
[SerializeField] protected Vector3Data vector3Data;
protected override bool EvaluateCondition()
{
if (variable == null)
@ -63,11 +107,66 @@ 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(AudioSourceVariable))
{
AudioSourceVariable audioSourceVariable = (variable as AudioSourceVariable);
condition = audioSourceVariable.Evaluate(compareOperator, audioSourceData.Value);
}
else if (variable.GetType() == typeof(ColorVariable))
{
ColorVariable colorVariable = (variable as ColorVariable);
condition = colorVariable.Evaluate(compareOperator, colorData.Value);
}
else if (variable.GetType() == typeof(GameObjectVariable))
{
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);
}
else if (variable.GetType() == typeof(ObjectVariable))
{
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);
}
else if (variable.GetType() == typeof(SpriteVariable))
{
SpriteVariable spriteVariable = (variable as SpriteVariable);
condition = spriteVariable.Evaluate(compareOperator, spriteData.Value);
}
else if (variable.GetType() == typeof(TextureVariable))
{
TextureVariable textureVariable = (variable as TextureVariable);
condition = textureVariable.Evaluate(compareOperator, textureData.Value);
}
else if (variable.GetType() == typeof(TransformVariable))
{
TransformVariable transformVariable = (variable as TransformVariable);
condition = transformVariable.Evaluate(compareOperator, transformData.Value);
}
else if (variable.GetType() == typeof(Vector2Variable))
{
Vector2Variable vector2Variable = (variable as Vector2Variable);
condition = vector2Variable.Evaluate(compareOperator, vector2Data.Value);
}
else if (variable.GetType() == typeof(Vector3Variable))
{
Vector3Variable vector3Variable = (variable as Vector3Variable);
condition = vector3Variable.Evaluate(compareOperator, vector3Data.Value);
}
return condition;
}
@ -84,7 +183,18 @@ namespace Fungus
{ typeof(IntegerVariable), IntegerVariable.compareOperators },
{ typeof(FloatVariable), FloatVariable.compareOperators },
{ typeof(StringVariable), StringVariable.compareOperators },
{ typeof(GameObjectVariable), GameObjectVariable.compareOperators }
{ typeof(AnimatorVariable), AnimatorVariable.compareOperators },
{ typeof(AudioSourceVariable), AudioSourceVariable.compareOperators },
{ typeof(ColorVariable), ColorVariable.compareOperators },
{ typeof(GameObjectVariable), GameObjectVariable.compareOperators },
{ typeof(MaterialVariable), MaterialVariable.compareOperators },
{ typeof(ObjectVariable), ObjectVariable.compareOperators },
{ typeof(Rigidbody2DVariable), Rigidbody2DVariable.compareOperators },
{ typeof(SpriteVariable), SpriteVariable.compareOperators },
{ typeof(TextureVariable), TextureVariable.compareOperators },
{ typeof(TransformVariable), TransformVariable.compareOperators },
{ typeof(Vector2Variable), Vector2Variable.compareOperators },
{ typeof(Vector3Variable), Vector3Variable.compareOperators }
};
/// <summary>
@ -118,10 +228,54 @@ namespace Fungus
{
summary += stringData.GetDescription();
}
else if (variable.GetType() == typeof(AnimatorVariable))
{
summary += animatorData.GetDescription();
}
else if (variable.GetType() == typeof(AudioSourceVariable))
{
summary += audioSourceData.GetDescription();
}
else if (variable.GetType() == typeof(ColorVariable))
{
summary += colorData.GetDescription();
}
else if (variable.GetType() == typeof(GameObjectVariable))
{
summary += gameObjectData.GetDescription();
}
else if (variable.GetType() == typeof(MaterialVariable))
{
summary += materialData.GetDescription();
}
else if (variable.GetType() == typeof(ObjectVariable))
{
summary += objectData.GetDescription();
}
else if (variable.GetType() == typeof(Rigidbody2DVariable))
{
summary += rigidbody2DData.GetDescription();
}
else if (variable.GetType() == typeof(SpriteVariable))
{
summary += spriteData.GetDescription();
}
else if (variable.GetType() == typeof(TextureVariable))
{
summary += textureData.GetDescription();
}
else if (variable.GetType() == typeof(TransformVariable))
{
summary += transformData.GetDescription();
}
else if (variable.GetType() == typeof(Vector2Variable))
{
summary += vector2Data.GetDescription();
}
else if (variable.GetType() == typeof(Vector3Variable))
{
summary += vector3Data.GetDescription();
}
return summary;
}
@ -138,4 +292,4 @@ namespace Fungus
#endregion
}
}
}

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

@ -9,7 +9,7 @@ namespace Fungus.EditorUtils
{
[CustomEditor (typeof(SetVariable))]
public class SetVariableEditor : CommandEditor
public class SetVariableEditor : CommandEditor
{
protected struct VariablePropertyInfo
{
@ -44,7 +44,18 @@ 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(GameObjectVariable), new VariablePropertyInfo("GameObject", serializedObject.FindProperty("gameObjectData")) }
{ 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(MaterialVariable), new VariablePropertyInfo("Material", serializedObject.FindProperty("materialData")) },
{ typeof(ObjectVariable), new VariablePropertyInfo("Object", serializedObject.FindProperty("objectData")) },
{ typeof(Rigidbody2DVariable), new VariablePropertyInfo("Rigidbody2D", serializedObject.FindProperty("rigidbody2DData")) },
{ typeof(SpriteVariable), new VariablePropertyInfo("Sprite", serializedObject.FindProperty("spriteData")) },
{ typeof(TextureVariable), new VariablePropertyInfo("Texture", serializedObject.FindProperty("textureData")) },
{ typeof(TransformVariable), new VariablePropertyInfo("Transform", serializedObject.FindProperty("transformData")) },
{ typeof(Vector2Variable), new VariablePropertyInfo("Vector2", serializedObject.FindProperty("vector2Data")) },
{ typeof(Vector3Variable), new VariablePropertyInfo("Vector3", serializedObject.FindProperty("vector3Data")) }
};
}
@ -105,7 +116,7 @@ namespace Fungus.EditorUtils
break;
}
}
// Get previously selected operator
int selectedIndex = System.Array.IndexOf(setOperators, t._SetOperator);
if (selectedIndex < 0)
@ -117,7 +128,7 @@ namespace Fungus.EditorUtils
// Get next selected operator
selectedIndex = EditorGUILayout.Popup(new GUIContent("Operation", "Arithmetic operator to use"), selectedIndex, operatorsList.ToArray());
setOperatorProp.enumValueIndex = (int)setOperators[selectedIndex];

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

@ -8,7 +8,7 @@ using System.Collections.Generic;
namespace Fungus.EditorUtils
{
[CustomEditor (typeof(VariableCondition), true)]
public class VariableConditionEditor : CommandEditor
public class VariableConditionEditor : CommandEditor
{
protected SerializedProperty variableProp;
protected SerializedProperty compareOperatorProp;
@ -29,7 +29,18 @@ namespace Fungus.EditorUtils
{ typeof(IntegerVariable), serializedObject.FindProperty("integerData") },
{ typeof(FloatVariable), serializedObject.FindProperty("floatData") },
{ typeof(StringVariable), serializedObject.FindProperty("stringData") },
{ typeof(GameObjectVariable), serializedObject.FindProperty("gameObjectData") }
{ typeof(AnimatorVariable), serializedObject.FindProperty("animatorData") },
{ typeof(AudioSourceVariable), serializedObject.FindProperty("audioSourceData") },
{ typeof(ColorVariable), serializedObject.FindProperty("colorData") },
{ typeof(GameObjectVariable), serializedObject.FindProperty("gameObjectData") },
{ typeof(MaterialVariable), serializedObject.FindProperty("materialData") },
{ typeof(ObjectVariable), serializedObject.FindProperty("objectData") },
{ typeof(Rigidbody2DVariable), serializedObject.FindProperty("rigidbody2DData") },
{ typeof(SpriteVariable), serializedObject.FindProperty("spriteData") },
{ typeof(TextureVariable), serializedObject.FindProperty("textureData") },
{ typeof(TransformVariable), serializedObject.FindProperty("transformData") },
{ typeof(Vector2Variable), serializedObject.FindProperty("vector2Data") },
{ typeof(Vector3Variable), serializedObject.FindProperty("vector3Data") }
};
}

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.

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

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

20
Assets/Fungus/Scripts/VariableTypes/BooleanVariable.cs

@ -25,13 +25,15 @@ namespace Fungus
switch (compareOperator)
{
case CompareOperator.Equals:
condition = lhs == rhs;
break;
case CompareOperator.NotEquals:
default:
condition = lhs != rhs;
break;
case CompareOperator.Equals:
condition = lhs == rhs;
break;
case CompareOperator.NotEquals:
condition = lhs != rhs;
break;
default:
Debug.LogError("The " + compareOperator.ToString() + " comparison operator is not valid.");
break;
}
return condition;
@ -41,13 +43,15 @@ namespace Fungus
{
switch (setOperator)
{
default:
case SetOperator.Assign:
Value = value;
break;
case SetOperator.Negate:
Value = !value;
break;
default:
Debug.LogError("The " + setOperator.ToString() + " set operator is not valid.");
break;
}
}
}

56
Assets/Fungus/Scripts/VariableTypes/ColorVariable.cs

@ -13,7 +13,61 @@ namespace Fungus
[AddComponentMenu("")]
[System.Serializable]
public class ColorVariable : VariableBase<Color>
{}
{
public static readonly CompareOperator[] compareOperators = { CompareOperator.Equals, CompareOperator.NotEquals };
public static readonly SetOperator[] setOperators = {
SetOperator.Assign,
SetOperator.Add,
SetOperator.Subtract,
SetOperator.Multiply
};
protected static bool ColorsEqual(Color a, Color b) {
return ColorUtility.ToHtmlStringRGBA(a) == ColorUtility.ToHtmlStringRGBA(b);
}
public virtual bool Evaluate(CompareOperator compareOperator, Color value)
{
bool condition = false;
switch (compareOperator)
{
case CompareOperator.Equals:
condition = ColorsEqual(Value, value);
break;
case CompareOperator.NotEquals:
condition = !ColorsEqual(Value, value);
break;
default:
Debug.LogError("The " + compareOperator.ToString() + " comparison operator is not valid.");
break;
}
return condition;
}
public override void Apply(SetOperator setOperator, Color value)
{
switch (setOperator)
{
case SetOperator.Assign:
Value = value;
break;
case SetOperator.Add:
Value += value;
break;
case SetOperator.Subtract:
Value -= value;
break;
case SetOperator.Multiply:
Value *= value;
break;
default:
Debug.LogError("The " + setOperator.ToString() + " set operator is not valid.");
break;
}
}
}
/// <summary>
/// Container for a Color variable reference or constant value.

43
Assets/Fungus/Scripts/VariableTypes/FloatVariable.cs

@ -38,24 +38,27 @@ namespace Fungus
switch (compareOperator)
{
case CompareOperator.Equals:
condition = lhs == rhs;
break;
case CompareOperator.NotEquals:
condition = lhs != rhs;
break;
case CompareOperator.LessThan:
condition = lhs < rhs;
break;
case CompareOperator.GreaterThan:
condition = lhs > rhs;
break;
case CompareOperator.LessThanOrEquals:
condition = lhs <= rhs;
break;
case CompareOperator.GreaterThanOrEquals:
condition = lhs >= rhs;
break;
case CompareOperator.Equals:
condition = lhs == rhs;
break;
case CompareOperator.NotEquals:
condition = lhs != rhs;
break;
case CompareOperator.LessThan:
condition = lhs < rhs;
break;
case CompareOperator.GreaterThan:
condition = lhs > rhs;
break;
case CompareOperator.LessThanOrEquals:
condition = lhs <= rhs;
break;
case CompareOperator.GreaterThanOrEquals:
condition = lhs >= rhs;
break;
default:
Debug.LogError("The " + compareOperator.ToString() + " comparison operator is not valid.");
break;
}
return condition;
@ -65,7 +68,6 @@ namespace Fungus
{
switch (setOperator)
{
default:
case SetOperator.Assign:
Value = value;
break;
@ -81,6 +83,9 @@ namespace Fungus
case SetOperator.Divide:
Value /= value;
break;
default:
Debug.LogError("The " + setOperator.ToString() + " set operator is not valid.");
break;
}
}
}

8
Assets/Fungus/Scripts/VariableTypes/GameObjectVariable.cs

@ -30,9 +30,11 @@ namespace Fungus
condition = lhs == rhs;
break;
case CompareOperator.NotEquals:
default:
condition = lhs != rhs;
break;
default:
Debug.LogError("The " + compareOperator.ToString() + " comparison operator is not valid.");
break;
}
return condition;
@ -42,10 +44,12 @@ namespace Fungus
{
switch (setOperator)
{
default:
case SetOperator.Assign:
Value = value;
break;
default:
Debug.LogError("The " + setOperator.ToString() + " set operator is not valid.");
break;
}
}
}

43
Assets/Fungus/Scripts/VariableTypes/IntegerVariable.cs

@ -38,24 +38,27 @@ namespace Fungus
switch (compareOperator)
{
case CompareOperator.Equals:
condition = lhs == rhs;
break;
case CompareOperator.NotEquals:
condition = lhs != rhs;
break;
case CompareOperator.LessThan:
condition = lhs < rhs;
break;
case CompareOperator.GreaterThan:
condition = lhs > rhs;
break;
case CompareOperator.LessThanOrEquals:
condition = lhs <= rhs;
break;
case CompareOperator.GreaterThanOrEquals:
condition = lhs >= rhs;
break;
case CompareOperator.Equals:
condition = lhs == rhs;
break;
case CompareOperator.NotEquals:
condition = lhs != rhs;
break;
case CompareOperator.LessThan:
condition = lhs < rhs;
break;
case CompareOperator.GreaterThan:
condition = lhs > rhs;
break;
case CompareOperator.LessThanOrEquals:
condition = lhs <= rhs;
break;
case CompareOperator.GreaterThanOrEquals:
condition = lhs >= rhs;
break;
default:
Debug.LogError("The " + compareOperator.ToString() + " comparison operator is not valid.");
break;
}
return condition;
@ -65,7 +68,6 @@ namespace Fungus
{
switch (setOperator)
{
default:
case SetOperator.Assign:
Value = value;
break;
@ -81,6 +83,9 @@ namespace Fungus
case SetOperator.Divide:
Value /= value;
break;
default:
Debug.LogError("The " + setOperator.ToString() + " set operator is not valid.");
break;
}
}
}

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.

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

@ -13,7 +13,43 @@ namespace Fungus
[AddComponentMenu("")]
[System.Serializable]
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>
/// Container for an Object variable reference or constant value.

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.

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

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

20
Assets/Fungus/Scripts/VariableTypes/StringVariable.cs

@ -25,13 +25,15 @@ namespace Fungus
switch (compareOperator)
{
case CompareOperator.Equals:
condition = lhs == rhs;
break;
case CompareOperator.NotEquals:
default:
condition = lhs != rhs;
break;
case CompareOperator.Equals:
condition = lhs == rhs;
break;
case CompareOperator.NotEquals:
condition = lhs != rhs;
break;
default:
Debug.LogError("The " + compareOperator.ToString() + " comparison operator is not valid.");
break;
}
return condition;
@ -41,10 +43,12 @@ namespace Fungus
{
switch (setOperator)
{
default:
case SetOperator.Assign:
Value = value;
break;
default:
Debug.LogError("The " + setOperator.ToString() + " set operator is not valid.");
break;
}
}
}

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

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

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

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

44
Assets/Fungus/Scripts/VariableTypes/Vector2Variable.cs

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

44
Assets/Fungus/Scripts/VariableTypes/Vector3Variable.cs

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

Loading…
Cancel
Save