Browse Source

Add comparison and setting functionality for the AudioSource variable

master
Jorge Ramirez 7 years ago
parent
commit
110c11f280
  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/AudioSourceVariable.cs

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

@ -21,6 +21,7 @@ namespace Fungus
typeof(FloatVariable),
typeof(StringVariable),
typeof(AnimatorVariable),
typeof(AudioSourceVariable),
typeof(GameObjectVariable))]
[SerializeField] protected Variable variable;
@ -42,6 +43,9 @@ namespace Fungus
[Tooltip("Animator value to set with")]
[SerializeField] protected AnimatorData animatorData;
[Tooltip("AudioSource value to set with")]
[SerializeField] protected AudioSourceData audioSourceData;
[Tooltip("GameObject value to set with")]
[SerializeField] protected GameObjectData gameObjectData;
@ -78,6 +82,11 @@ namespace Fungus
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(GameObjectVariable))
{
GameObjectVariable gameObjectVariable = (variable as GameObjectVariable);
@ -93,6 +102,7 @@ namespace Fungus
{ typeof(FloatVariable), FloatVariable.setOperators },
{ typeof(StringVariable), StringVariable.setOperators },
{ typeof(AnimatorVariable), AnimatorVariable.setOperators },
{ typeof(AudioSourceVariable), AudioSourceVariable.setOperators },
{ typeof(GameObjectVariable), GameObjectVariable.setOperators }
};
@ -160,6 +170,10 @@ namespace Fungus
{
description += animatorData.GetDescription();
}
else if (variable.GetType() == typeof(AudioSourceVariable))
{
description += audioSourceData.GetDescription();
}
else if (variable.GetType() == typeof(GameObjectVariable))
{
description += gameObjectData.GetDescription();

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

@ -17,6 +17,7 @@ namespace Fungus
typeof(FloatVariable),
typeof(StringVariable),
typeof(AnimatorVariable),
typeof(AudioSourceVariable),
typeof(GameObjectVariable))]
[SerializeField] protected Variable variable;
@ -35,6 +36,9 @@ namespace Fungus
[Tooltip("Animator value to compare against")]
[SerializeField] protected AnimatorData animatorData;
[Tooltip("AudioSource value to compare against")]
[SerializeField] protected AudioSourceData audioSourceData;
[Tooltip("GameObject value to compare against")]
[SerializeField] protected GameObjectData gameObjectData;
@ -72,6 +76,11 @@ namespace Fungus
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(GameObjectVariable))
{
GameObjectVariable gameObjectVariable = (variable as GameObjectVariable);
@ -94,6 +103,7 @@ namespace Fungus
{ typeof(FloatVariable), FloatVariable.compareOperators },
{ typeof(StringVariable), StringVariable.compareOperators },
{ typeof(AnimatorVariable), AnimatorVariable.compareOperators },
{ typeof(AudioSourceVariable), AudioSourceVariable.compareOperators },
{ typeof(GameObjectVariable), GameObjectVariable.compareOperators }
};
@ -132,6 +142,10 @@ namespace Fungus
{
summary += animatorData.GetDescription();
}
else if (variable.GetType() == typeof(AudioSourceVariable))
{
summary += audioSourceData.GetDescription();
}
else if (variable.GetType() == typeof(GameObjectVariable))
{
summary += gameObjectData.GetDescription();

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

@ -45,6 +45,7 @@ namespace Fungus.EditorUtils
{ 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(AudioSourceVariable), new VariablePropertyInfo("AudioSource", serializedObject.FindProperty("audioSourceData")) },
{ typeof(GameObjectVariable), new VariablePropertyInfo("GameObject", serializedObject.FindProperty("gameObjectData")) }
};
}

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

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

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.

Loading…
Cancel
Save