diff --git a/Assets/Fungus/Editor/SetVariableCommandEditor.cs b/Assets/Fungus/Editor/SetVariableCommandEditor.cs index c1a35d7f..2e85580b 100644 --- a/Assets/Fungus/Editor/SetVariableCommandEditor.cs +++ b/Assets/Fungus/Editor/SetVariableCommandEditor.cs @@ -1,6 +1,7 @@ using UnityEditor; using UnityEngine; using System.Collections; +using System.Collections.Generic; [CustomEditor (typeof(SetVariableCommand))] public class SetVariableCommandEditor : FungusCommandEditor @@ -9,7 +10,48 @@ public class SetVariableCommandEditor : FungusCommandEditor { SetVariableCommand t = target as SetVariableCommand; - t.variableKey = EditorGUILayout.TextField(new GUIContent("Variable Key", "The name of the variable to set"), t.variableKey); - t.booleanValue = EditorGUILayout.Toggle(new GUIContent("Boolean Value", "The boolean value to set the variable with"), t.booleanValue); + SequenceController sc = t.GetParentSequenceController(); + if (sc == null) + { + return; + } + + int index = -1; + List keys = new List(); + for (int i = 0; i < sc.variables.Count; ++i) + { + Variable v = sc.variables[i]; + keys.Add(v.key); + if (v.key == t.variableKey && + index == -1) + { + index = i; + } + } + + index = EditorGUILayout.Popup("Variable", index, keys.ToArray()); + + Variable variable = sc.variables[index]; + + t.variableKey = variable.key; + + switch (variable.type) + { + case VariableType.Boolean: + t.booleanValue = EditorGUILayout.Toggle(new GUIContent("Boolean Value", "The boolean value to set the variable with"), t.booleanValue); + break; + case VariableType.Integer: + t.integerValue = EditorGUILayout.IntField(new GUIContent("Integer Value", "The integer value to set the variable with"), t.integerValue); + break; + case VariableType.Float: + t.floatValue = EditorGUILayout.FloatField(new GUIContent("Float Value", "The float value to set the variable with"), t.floatValue); + break; + case VariableType.String: + t.stringValue = EditorGUILayout.TextField(new GUIContent("String Value", "The string value to set the variable with"), t.stringValue); + break; + } + } + + } diff --git a/Assets/Fungus/VisualScripting/FungusCommand.cs b/Assets/Fungus/VisualScripting/FungusCommand.cs index bac61cd0..dfb0179a 100644 --- a/Assets/Fungus/VisualScripting/FungusCommand.cs +++ b/Assets/Fungus/VisualScripting/FungusCommand.cs @@ -7,7 +7,7 @@ using System.Collections.Generic; namespace Fungus { - + [RequireComponent(typeof(Sequence))] public class FungusCommand : MonoBehaviour { [HideInInspector] @@ -22,17 +22,24 @@ namespace Fungus public virtual void Start() { parentSequence = GetComponent(); + parentSequenceController = GetParentSequenceController(); + } + + public SequenceController GetParentSequenceController() + { + SequenceController sc = null; - // Populate sequenceController reference Transform parent = transform.parent; while (parent != null) { - parentSequenceController = parent.gameObject.GetComponent(); - if (parentSequenceController != null) + sc = parent.gameObject.GetComponent(); + if (sc != null) { break; } + parent = parent.transform.parent; } + return sc; } public bool IsExecuting()