diff --git a/Assets/Fungus/Editor/FungusScript/FungusScriptEditor.cs b/Assets/Fungus/Editor/FungusScript/FungusScriptEditor.cs index 1e6ca0fe..a0b68f61 100644 --- a/Assets/Fungus/Editor/FungusScript/FungusScriptEditor.cs +++ b/Assets/Fungus/Editor/FungusScript/FungusScriptEditor.cs @@ -3,74 +3,24 @@ using UnityEngine; using System.Collections; using System.Collections.Generic; using Fungus; -//using Rotorz.ReorderableList; -//using System.Linq; +using Rotorz.ReorderableList; +using System.Linq; namespace Fungus.Script { - /* - [CustomPropertyDrawer (typeof(Variable))] - public class VariableDrawer : PropertyDrawer - { - public override void OnGUI (Rect position, SerializedProperty property, GUIContent label) - { - EditorGUI.BeginProperty(position, label, property); - - SerializedProperty keyProp = property.FindPropertyRelative("key"); - SerializedProperty typeProp = property.FindPropertyRelative("type"); - SerializedProperty scopeProp = property.FindPropertyRelative("scope"); - - // Draw the text field control GUI. - EditorGUI.BeginChangeCheck(); - - float width1 = position.width * 0.5f; - float width2 = position.width * 0.25f; - float width3 = position.width * 0.25f; - - Rect keyRect = position; - keyRect.width = width1; - - Rect typeRect = position; - typeRect.x += width1; - typeRect.width = width2; - - Rect scopeRect = position; - scopeRect.x += width1 + width2; - scopeRect.width = width3; - - string keyValue = EditorGUI.TextField(keyRect, label, keyProp.stringValue); - int typeValue = (int)(VariableType)EditorGUI.EnumPopup(typeRect, (VariableType)typeProp.enumValueIndex); - int scopeValue = (int)(VariableScope)EditorGUI.EnumPopup(scopeRect, (VariableScope)scopeProp.enumValueIndex); - - if (EditorGUI.EndChangeCheck ()) - { - char[] arr = keyValue.Where(c => (char.IsLetterOrDigit(c) || c == '_')).ToArray(); - - keyValue = new string(arr); - - keyProp.stringValue = keyValue; - typeProp.enumValueIndex = typeValue; - scopeProp.enumValueIndex = scopeValue; - } - - EditorGUI.EndProperty(); - } - } - */ - [CustomEditor (typeof(FungusScript))] public class FungusScriptEditor : Editor { SerializedProperty variablesProperty; - //void OnEnable() - //{ - // variablesProperty = serializedObject.FindProperty("variables"); - //} + void OnEnable() + { + variablesProperty = serializedObject.FindProperty("variables"); + } public override void OnInspectorGUI() { - //serializedObject.Update(); + serializedObject.Update(); FungusScript t = target as FungusScript; @@ -124,10 +74,10 @@ namespace Fungus.Script EditorGUILayout.LabelField(new GUIContent("Error: Please select a Start Sequence"), style); } - //ReorderableListGUI.Title("Variables"); - //ReorderableListGUI.ListField(variablesProperty); + ReorderableListGUI.Title("Variables"); + ReorderableListGUI.ListField(variablesProperty); - //serializedObject.ApplyModifiedProperties(); + serializedObject.ApplyModifiedProperties(); } void AddBooleanVariable(object obj) diff --git a/Assets/Fungus/Editor/FungusScript/FungusVariableEditor.cs b/Assets/Fungus/Editor/FungusScript/FungusVariableEditor.cs index 1808facf..ee1c3b57 100644 --- a/Assets/Fungus/Editor/FungusScript/FungusVariableEditor.cs +++ b/Assets/Fungus/Editor/FungusScript/FungusVariableEditor.cs @@ -4,10 +4,59 @@ using UnityEngine; using System; using System.Collections; using System.Collections.Generic; +using System.Linq; namespace Fungus.Script { + [CustomPropertyDrawer (typeof(Variable))] + public class VariableDrawer : PropertyDrawer + { + public override void OnGUI (Rect position, SerializedProperty property, GUIContent label) + { + EditorGUI.BeginProperty(position, label, property); + + SerializedProperty keyProp = property.FindPropertyRelative("key"); + SerializedProperty typeProp = property.FindPropertyRelative("type"); + SerializedProperty scopeProp = property.FindPropertyRelative("scope"); + + // Draw the text field control GUI. + EditorGUI.BeginChangeCheck(); + + float width2 = 60; + float width3 = 50; + float width1 = position.width - width2 - width3; + + Rect keyRect = position; + keyRect.width = width1; + + Rect typeRect = position; + typeRect.x += width1; + typeRect.width = width2; + + Rect scopeRect = position; + scopeRect.x += width1 + width2; + scopeRect.width = width3; + + string keyValue = EditorGUI.TextField(keyRect, label, keyProp.stringValue); + int typeValue = (int)(VariableType)EditorGUI.EnumPopup(typeRect, (VariableType)typeProp.enumValueIndex); + int scopeValue = (int)(VariableScope)EditorGUI.EnumPopup(scopeRect, (VariableScope)scopeProp.enumValueIndex); + + if (EditorGUI.EndChangeCheck ()) + { + char[] arr = keyValue.Where(c => (char.IsLetterOrDigit(c) || c == '_')).ToArray(); + + keyValue = new string(arr); + + keyProp.stringValue = keyValue; + typeProp.enumValueIndex = typeValue; + scopeProp.enumValueIndex = scopeValue; + } + + EditorGUI.EndProperty(); + } + } + [CustomEditor (typeof(FungusVariable), true)] public class FungusVariableEditor : FungusCommandEditor { diff --git a/Assets/Fungus/VisualScripting/FungusScript.cs b/Assets/Fungus/VisualScripting/FungusScript.cs index 9a23ec4a..f52c858b 100644 --- a/Assets/Fungus/VisualScripting/FungusScript.cs +++ b/Assets/Fungus/VisualScripting/FungusScript.cs @@ -20,6 +20,8 @@ namespace Fungus.Script public bool startAutomatically = false; + public List variables = new List(); + void Start() { if (startAutomatically) diff --git a/Assets/Fungus/VisualScripting/FungusVariable.cs b/Assets/Fungus/VisualScripting/FungusVariable.cs index b7f3dfd3..82b982a5 100644 --- a/Assets/Fungus/VisualScripting/FungusVariable.cs +++ b/Assets/Fungus/VisualScripting/FungusVariable.cs @@ -4,12 +4,32 @@ using System.Collections; namespace Fungus.Script { + public enum VariableType + { + Boolean, + Integer, + Float, + String + } + public enum VariableScope { Local, Global - }; - + } + + [System.Serializable] + public class Variable + { + public string key; + public VariableType type; + public VariableScope scope; + public BooleanData booleanData; + public IntegerData integerData; + public FloatData floatData; + public StringData stringData; + } + public class FungusVariable : MonoBehaviour { public VariableScope scope;