You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
137 lines
5.5 KiB
137 lines
5.5 KiB
8 years ago
|
// This code is part of the Fungus library (http://fungusgames.com) maintained by Chris Gregan (http://twitter.com/gofungus).
|
||
|
// It is released for free under the MIT open source license (https://github.com/snozbot/fungus/blob/master/LICENSE)
|
||
9 years ago
|
|
||
9 years ago
|
using UnityEngine;
|
||
|
using System;
|
||
|
using UnityEngine.Events;
|
||
|
|
||
|
namespace Fungus
|
||
|
{
|
||
8 years ago
|
/// <summary>
|
||
|
/// Calls a list of component methods via the Unity Event System (as used in the Unity UI)
|
||
|
/// This command is more efficient than the Invoke Method command but can only pass a single parameter and doesn't support return values.
|
||
|
/// This command uses the UnityEvent system to call methods in script. http://docs.unity3d.com/Manual/UnityEvents.html
|
||
|
/// </summary>
|
||
8 years ago
|
[CommandInfo("Scripting",
|
||
|
"Invoke Event",
|
||
|
"Calls a list of component methods via the Unity Event System (as used in the Unity UI). " +
|
||
|
"This command is more efficient than the Invoke Method command but can only pass a single parameter and doesn't support return values.")]
|
||
|
[AddComponentMenu("")]
|
||
|
public class InvokeEvent : Command
|
||
|
{
|
||
|
[Serializable] public class BooleanEvent : UnityEvent<bool> {}
|
||
|
[Serializable] public class IntegerEvent : UnityEvent<int> {}
|
||
|
[Serializable] public class FloatEvent : UnityEvent<float> {}
|
||
|
[Serializable] public class StringEvent : UnityEvent<string> {}
|
||
|
|
||
|
public enum InvokeType
|
||
|
{
|
||
|
Static, // Call a method with an optional constant value parameter
|
||
|
DynamicBoolean, // Call a method with an optional boolean constant / variable parameter
|
||
|
DynamicInteger, // Call a method with an optional integer constant / variable parameter
|
||
|
DynamicFloat, // Call a method with an optional float constant / variable parameter
|
||
|
DynamicString // Call a method with an optional string constant / variable parameter
|
||
|
}
|
||
|
|
||
|
[Tooltip("Delay (in seconds) before the methods will be called")]
|
||
8 years ago
|
[SerializeField] protected float delay;
|
||
8 years ago
|
|
||
8 years ago
|
[SerializeField] protected InvokeType invokeType;
|
||
8 years ago
|
|
||
|
[Tooltip("List of methods to call. Supports methods with no parameters or exactly one string, int, float or object parameter.")]
|
||
8 years ago
|
[SerializeField] protected UnityEvent staticEvent = new UnityEvent();
|
||
8 years ago
|
|
||
|
[Tooltip("Boolean parameter to pass to the invoked methods.")]
|
||
8 years ago
|
[SerializeField] protected BooleanData booleanParameter;
|
||
8 years ago
|
|
||
|
[Tooltip("List of methods to call. Supports methods with one boolean parameter.")]
|
||
8 years ago
|
[SerializeField] protected BooleanEvent booleanEvent = new BooleanEvent();
|
||
8 years ago
|
|
||
|
[Tooltip("Integer parameter to pass to the invoked methods.")]
|
||
8 years ago
|
[SerializeField] protected IntegerData integerParameter;
|
||
8 years ago
|
|
||
|
[Tooltip("List of methods to call. Supports methods with one integer parameter.")]
|
||
8 years ago
|
[SerializeField] protected IntegerEvent integerEvent = new IntegerEvent();
|
||
8 years ago
|
|
||
|
[Tooltip("Float parameter to pass to the invoked methods.")]
|
||
8 years ago
|
[SerializeField] protected FloatData floatParameter;
|
||
8 years ago
|
|
||
|
[Tooltip("List of methods to call. Supports methods with one float parameter.")]
|
||
8 years ago
|
[SerializeField] protected FloatEvent floatEvent = new FloatEvent();
|
||
8 years ago
|
|
||
|
[Tooltip("String parameter to pass to the invoked methods.")]
|
||
8 years ago
|
[SerializeField] protected StringDataMulti stringParameter;
|
||
8 years ago
|
|
||
|
[Tooltip("List of methods to call. Supports methods with one string parameter.")]
|
||
8 years ago
|
[SerializeField] protected StringEvent stringEvent = new StringEvent();
|
||
8 years ago
|
|
||
|
public override void OnEnter()
|
||
|
{
|
||
|
if (delay == 0f)
|
||
|
{
|
||
|
DoInvoke();
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
Invoke("DoInvoke", delay);
|
||
|
}
|
||
|
|
||
|
Continue();
|
||
|
}
|
||
|
|
||
|
protected virtual void DoInvoke()
|
||
|
{
|
||
|
switch (invokeType)
|
||
|
{
|
||
|
default:
|
||
|
case InvokeType.Static:
|
||
|
staticEvent.Invoke();
|
||
|
break;
|
||
|
case InvokeType.DynamicBoolean:
|
||
8 years ago
|
booleanEvent.Invoke(booleanParameter.Value);
|
||
8 years ago
|
break;
|
||
|
case InvokeType.DynamicInteger:
|
||
8 years ago
|
integerEvent.Invoke(integerParameter.Value);
|
||
8 years ago
|
break;
|
||
|
case InvokeType.DynamicFloat:
|
||
8 years ago
|
floatEvent.Invoke(floatParameter.Value);
|
||
8 years ago
|
break;
|
||
|
case InvokeType.DynamicString:
|
||
8 years ago
|
stringEvent.Invoke(stringParameter.Value);
|
||
8 years ago
|
break;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public override string GetSummary()
|
||
|
{
|
||
|
string summary = invokeType.ToString() + " ";
|
||
|
|
||
|
switch (invokeType)
|
||
|
{
|
||
|
default:
|
||
|
case InvokeType.Static:
|
||
|
summary += staticEvent.GetPersistentEventCount();
|
||
|
break;
|
||
|
case InvokeType.DynamicBoolean:
|
||
|
summary += booleanEvent.GetPersistentEventCount();
|
||
|
break;
|
||
|
case InvokeType.DynamicInteger:
|
||
|
summary += integerEvent.GetPersistentEventCount();
|
||
|
break;
|
||
|
case InvokeType.DynamicFloat:
|
||
|
summary += floatEvent.GetPersistentEventCount();
|
||
|
break;
|
||
|
case InvokeType.DynamicString:
|
||
|
summary += stringEvent.GetPersistentEventCount();
|
||
|
break;
|
||
|
}
|
||
|
|
||
|
return summary + " methods";
|
||
|
}
|
||
|
|
||
|
public override Color GetButtonColor()
|
||
|
{
|
||
|
return new Color32(235, 191, 217, 255);
|
||
|
}
|
||
|
}
|
||
9 years ago
|
}
|