chrisgregan
10 years ago
4 changed files with 208 additions and 4 deletions
@ -0,0 +1,71 @@
|
||||
using UnityEditor; |
||||
using UnityEngine; |
||||
using System.Collections; |
||||
using System.Collections.Generic; |
||||
|
||||
namespace Fungus |
||||
{ |
||||
[CustomEditor (typeof(Invoke))] |
||||
public class InvokeEditor : CommandEditor |
||||
{ |
||||
protected SerializedProperty delayProp; |
||||
protected SerializedProperty invokeTypeProp; |
||||
protected SerializedProperty staticEventProp; |
||||
protected SerializedProperty booleanParameterProp; |
||||
protected SerializedProperty booleanEventProp; |
||||
protected SerializedProperty integerParameterProp; |
||||
protected SerializedProperty integerEventProp; |
||||
protected SerializedProperty floatParameterProp; |
||||
protected SerializedProperty floatEventProp; |
||||
protected SerializedProperty stringParameterProp; |
||||
protected SerializedProperty stringEventProp; |
||||
|
||||
protected virtual void OnEnable() |
||||
{ |
||||
delayProp = serializedObject.FindProperty("delay"); |
||||
invokeTypeProp = serializedObject.FindProperty("invokeType"); |
||||
staticEventProp = serializedObject.FindProperty("staticEvent"); |
||||
booleanParameterProp = serializedObject.FindProperty("booleanParameter"); |
||||
booleanEventProp = serializedObject.FindProperty("booleanEvent"); |
||||
integerParameterProp = serializedObject.FindProperty("integerParameter"); |
||||
integerEventProp = serializedObject.FindProperty("integerEvent"); |
||||
floatParameterProp = serializedObject.FindProperty("floatParameter"); |
||||
floatEventProp = serializedObject.FindProperty("floatEvent"); |
||||
stringParameterProp = serializedObject.FindProperty("stringParameter"); |
||||
stringEventProp = serializedObject.FindProperty("stringEvent"); |
||||
} |
||||
|
||||
public override void DrawCommandGUI() |
||||
{ |
||||
serializedObject.Update(); |
||||
|
||||
EditorGUILayout.PropertyField(delayProp); |
||||
EditorGUILayout.PropertyField(invokeTypeProp); |
||||
|
||||
switch ((Invoke.InvokeType)invokeTypeProp.enumValueIndex) |
||||
{ |
||||
case Invoke.InvokeType.Static: |
||||
EditorGUILayout.PropertyField(staticEventProp); |
||||
break; |
||||
case Invoke.InvokeType.DynamicBoolean: |
||||
EditorGUILayout.PropertyField(booleanEventProp); |
||||
EditorGUILayout.PropertyField(booleanParameterProp); |
||||
break; |
||||
case Invoke.InvokeType.DynamicInteger: |
||||
EditorGUILayout.PropertyField(integerEventProp); |
||||
EditorGUILayout.PropertyField(integerParameterProp); |
||||
break; |
||||
case Invoke.InvokeType.DynamicFloat: |
||||
EditorGUILayout.PropertyField(floatEventProp); |
||||
EditorGUILayout.PropertyField(floatParameterProp); |
||||
break; |
||||
case Invoke.InvokeType.DynamicString: |
||||
EditorGUILayout.PropertyField(stringEventProp); |
||||
EditorGUILayout.PropertyField(stringParameterProp); |
||||
break; |
||||
} |
||||
|
||||
serializedObject.ApplyModifiedProperties(); |
||||
} |
||||
} |
||||
} |
@ -1,6 +1,6 @@
|
||||
fileFormatVersion: 2 |
||||
guid: 54baf7aee38a7425ca4bd2addbfcfdcf |
||||
timeCreated: 1431530474 |
||||
guid: 1de123a9a8da54ff49b112d39101366b |
||||
timeCreated: 1437051529 |
||||
licenseType: Free |
||||
MonoImporter: |
||||
serializedVersion: 2 |
@ -0,0 +1,133 @@
|
||||
using UnityEngine; |
||||
using System.Collections; |
||||
using System; |
||||
using UnityEngine.Events; |
||||
|
||||
namespace Fungus |
||||
{ |
||||
[CommandInfo("Scripting", |
||||
"Invoke", |
||||
"Calls a list of methods via the Unity UI EventSystem.")] |
||||
[AddComponentMenu("")] |
||||
|
||||
// This command uses the UnityEvent system to call methods in script. |
||||
// http://docs.unity3d.com/Manual/UnityEvents.html |
||||
public class Invoke : 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")] |
||||
public float delay; |
||||
|
||||
public InvokeType invokeType; |
||||
|
||||
[Tooltip("List of methods to call. Supports methods with no parameters or exactly one string, int, float or object parameter.")] |
||||
public UnityEvent staticEvent = new UnityEvent(); |
||||
|
||||
[Tooltip("Boolean parameter to pass to the invoked methods.")] |
||||
public BooleanData booleanParameter; |
||||
|
||||
[Tooltip("List of methods to call. Supports methods with one boolean parameter.")] |
||||
public BooleanEvent booleanEvent = new BooleanEvent(); |
||||
|
||||
[Tooltip("Integer parameter to pass to the invoked methods.")] |
||||
public IntegerData integerParameter; |
||||
|
||||
[Tooltip("List of methods to call. Supports methods with one integer parameter.")] |
||||
public IntegerEvent integerEvent = new IntegerEvent(); |
||||
|
||||
[Tooltip("Float parameter to pass to the invoked methods.")] |
||||
public FloatData floatParameter; |
||||
|
||||
[Tooltip("List of methods to call. Supports methods with one float parameter.")] |
||||
public FloatEvent floatEvent = new FloatEvent(); |
||||
|
||||
[Tooltip("String parameter to pass to the invoked methods.")] |
||||
public StringData stringParameter; |
||||
|
||||
[Tooltip("List of methods to call. Supports methods with one string parameter.")] |
||||
public StringEvent stringEvent = new StringEvent(); |
||||
|
||||
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: |
||||
booleanEvent.Invoke(booleanParameter); |
||||
break; |
||||
case InvokeType.DynamicInteger: |
||||
integerEvent.Invoke(integerParameter); |
||||
break; |
||||
case InvokeType.DynamicFloat: |
||||
floatEvent.Invoke(floatParameter); |
||||
break; |
||||
case InvokeType.DynamicString: |
||||
stringEvent.Invoke(stringParameter); |
||||
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); |
||||
} |
||||
} |
||||
|
||||
} |
@ -1,6 +1,6 @@
|
||||
fileFormatVersion: 2 |
||||
guid: 7ec5abc702c3f400b91bbeb2b8328d02 |
||||
timeCreated: 1431529735 |
||||
guid: 95d9ff288f3904c05ada7ac9c9a075bb |
||||
timeCreated: 1436969477 |
||||
licenseType: Free |
||||
MonoImporter: |
||||
serializedVersion: 2 |
Loading…
Reference in new issue