diff --git a/Assets/Fungus/Editor/FungusScript/FungusVariableEditor.cs b/Assets/Fungus/Editor/FungusScript/FungusVariableEditor.cs index d200e8f3..1808facf 100644 --- a/Assets/Fungus/Editor/FungusScript/FungusVariableEditor.cs +++ b/Assets/Fungus/Editor/FungusScript/FungusVariableEditor.cs @@ -75,4 +75,296 @@ namespace Fungus.Script } } + [CustomPropertyDrawer (typeof(BooleanData))] + public class BooleanDataDrawer : PropertyDrawer + { + public override void OnGUI (Rect position, SerializedProperty property, GUIContent label) + { + EditorGUI.BeginProperty(position, label, property); + + SerializedProperty referenceProp = property.FindPropertyRelative("booleanReference"); + SerializedProperty valueProp = property.FindPropertyRelative("booleanValue"); + + const int popupWidth = 65; + + Rect controlRect = EditorGUI.PrefixLabel(position, label); + Rect valueRect = controlRect; + valueRect.width = controlRect.width - popupWidth - 5; + Rect popupRect = controlRect; + + if (referenceProp.objectReferenceValue == null) + { + valueProp.boolValue = EditorGUI.Toggle(valueRect, valueProp.boolValue); + popupRect.x += valueRect.width + 5; + popupRect.width = popupWidth; + } + + FungusScript fungusScript = property.serializedObject.targetObject as FungusScript; + if (fungusScript == null) + { + FungusCommand command = property.serializedObject.targetObject as FungusCommand; + if (command != null) + { + fungusScript = command.GetFungusScript(); + } + } + + if (fungusScript != null) + { + BooleanVariable selectedBooleanVariable = referenceProp.objectReferenceValue as BooleanVariable; + + List variableKeys = new List(); + List variableObjects = new List(); + + variableKeys.Add(""); + variableObjects.Add(null); + + FungusVariable[] variables = fungusScript.GetComponents(); + int index = 0; + int selectedIndex = 0; + foreach (FungusVariable v in variables) + { + if (v.GetType() != typeof(BooleanVariable)) + { + continue; + } + + variableKeys.Add(v.key); + variableObjects.Add(v); + + index++; + + if (v == selectedBooleanVariable) + { + selectedIndex = index; + } + } + + selectedIndex = EditorGUI.Popup(popupRect, selectedIndex, variableKeys.ToArray()); + referenceProp.objectReferenceValue = variableObjects[selectedIndex]; + } + + EditorGUI.EndProperty(); + } + } + + [CustomPropertyDrawer (typeof(IntegerData))] + public class IntegerDataDrawer : PropertyDrawer + { + public override void OnGUI (Rect position, SerializedProperty property, GUIContent label) + { + EditorGUI.BeginProperty(position, label, property); + + SerializedProperty referenceProp = property.FindPropertyRelative("integerReference"); + SerializedProperty valueProp = property.FindPropertyRelative("integerValue"); + + const int popupWidth = 65; + + Rect controlRect = EditorGUI.PrefixLabel(position, label); + Rect valueRect = controlRect; + valueRect.width = controlRect.width - popupWidth - 5; + Rect popupRect = controlRect; + + if (referenceProp.objectReferenceValue == null) + { + valueProp.intValue = EditorGUI.IntField(valueRect, valueProp.intValue); + popupRect.x += valueRect.width + 5; + popupRect.width = popupWidth; + } + + FungusScript fungusScript = property.serializedObject.targetObject as FungusScript; + if (fungusScript == null) + { + FungusCommand command = property.serializedObject.targetObject as FungusCommand; + if (command != null) + { + fungusScript = command.GetFungusScript(); + } + } + + if (fungusScript != null) + { + IntegerVariable selectedVariable = referenceProp.objectReferenceValue as IntegerVariable; + + List variableKeys = new List(); + List variableObjects = new List(); + + variableKeys.Add(""); + variableObjects.Add(null); + + FungusVariable[] variables = fungusScript.GetComponents(); + int index = 0; + int selectedIndex = 0; + foreach (FungusVariable v in variables) + { + if (v.GetType() != typeof(IntegerVariable)) + { + continue; + } + + variableKeys.Add(v.key); + variableObjects.Add(v); + + index++; + + if (v == selectedVariable) + { + selectedIndex = index; + } + } + + selectedIndex = EditorGUI.Popup(popupRect, selectedIndex, variableKeys.ToArray()); + referenceProp.objectReferenceValue = variableObjects[selectedIndex]; + } + + EditorGUI.EndProperty(); + } + } + + [CustomPropertyDrawer (typeof(FloatData))] + public class FloatDataDrawer : PropertyDrawer + { + public override void OnGUI (Rect position, SerializedProperty property, GUIContent label) + { + EditorGUI.BeginProperty(position, label, property); + + SerializedProperty referenceProp = property.FindPropertyRelative("floatReference"); + SerializedProperty valueProp = property.FindPropertyRelative("floatValue"); + + const int popupWidth = 65; + + Rect controlRect = EditorGUI.PrefixLabel(position, label); + Rect valueRect = controlRect; + valueRect.width = controlRect.width - popupWidth - 5; + Rect popupRect = controlRect; + + if (referenceProp.objectReferenceValue == null) + { + valueProp.floatValue = EditorGUI.FloatField(valueRect, valueProp.floatValue); + popupRect.x += valueRect.width + 5; + popupRect.width = popupWidth; + } + + FungusScript fungusScript = property.serializedObject.targetObject as FungusScript; + if (fungusScript == null) + { + FungusCommand command = property.serializedObject.targetObject as FungusCommand; + if (command != null) + { + fungusScript = command.GetFungusScript(); + } + } + + if (fungusScript != null) + { + FloatVariable selectedVariable = referenceProp.objectReferenceValue as FloatVariable; + + List variableKeys = new List(); + List variableObjects = new List(); + + variableKeys.Add(""); + variableObjects.Add(null); + + FungusVariable[] variables = fungusScript.GetComponents(); + int index = 0; + int selectedIndex = 0; + foreach (FungusVariable v in variables) + { + if (v.GetType() != typeof(FloatVariable)) + { + continue; + } + + variableKeys.Add(v.key); + variableObjects.Add(v); + + index++; + + if (v == selectedVariable) + { + selectedIndex = index; + } + } + + selectedIndex = EditorGUI.Popup(popupRect, selectedIndex, variableKeys.ToArray()); + referenceProp.objectReferenceValue = variableObjects[selectedIndex]; + } + + EditorGUI.EndProperty(); + } + } + + [CustomPropertyDrawer (typeof(StringData))] + public class StringDataDrawer : PropertyDrawer + { + public override void OnGUI (Rect position, SerializedProperty property, GUIContent label) + { + EditorGUI.BeginProperty(position, label, property); + + SerializedProperty referenceProp = property.FindPropertyRelative("stringReference"); + SerializedProperty valueProp = property.FindPropertyRelative("stringValue"); + + const int popupWidth = 65; + + Rect controlRect = EditorGUI.PrefixLabel(position, label); + Rect valueRect = controlRect; + valueRect.width = controlRect.width - popupWidth - 5; + Rect popupRect = controlRect; + + if (referenceProp.objectReferenceValue == null) + { + valueProp.stringValue = EditorGUI.TextField(valueRect, valueProp.stringValue); + popupRect.x += valueRect.width + 5; + popupRect.width = popupWidth; + } + + FungusScript fungusScript = property.serializedObject.targetObject as FungusScript; + if (fungusScript == null) + { + FungusCommand command = property.serializedObject.targetObject as FungusCommand; + if (command != null) + { + fungusScript = command.GetFungusScript(); + } + } + + if (fungusScript != null) + { + StringVariable selectedVariable = referenceProp.objectReferenceValue as StringVariable; + + List variableKeys = new List(); + List variableObjects = new List(); + + variableKeys.Add(""); + variableObjects.Add(null); + + FungusVariable[] variables = fungusScript.GetComponents(); + int index = 0; + int selectedIndex = 0; + foreach (FungusVariable v in variables) + { + if (v.GetType() != typeof(StringVariable)) + { + continue; + } + + variableKeys.Add(v.key); + variableObjects.Add(v); + + index++; + + if (v == selectedVariable) + { + selectedIndex = index; + } + } + + selectedIndex = EditorGUI.Popup(popupRect, selectedIndex, variableKeys.ToArray()); + referenceProp.objectReferenceValue = variableObjects[selectedIndex]; + } + + EditorGUI.EndProperty(); + } + } + } \ No newline at end of file diff --git a/Assets/Fungus/VisualScripting/BooleanVariable.cs b/Assets/Fungus/VisualScripting/BooleanVariable.cs index 2c5de2be..03427da0 100644 --- a/Assets/Fungus/VisualScripting/BooleanVariable.cs +++ b/Assets/Fungus/VisualScripting/BooleanVariable.cs @@ -1,4 +1,5 @@ using UnityEngine; +using System; using System.Collections; namespace Fungus.Script @@ -15,4 +16,11 @@ namespace Fungus.Script } } + [System.Serializable] + public class BooleanData + { + public BooleanVariable booleanReference; + public bool booleanValue; + } + } \ No newline at end of file diff --git a/Assets/Fungus/VisualScripting/FloatVariable.cs b/Assets/Fungus/VisualScripting/FloatVariable.cs index 8782690c..76166195 100644 --- a/Assets/Fungus/VisualScripting/FloatVariable.cs +++ b/Assets/Fungus/VisualScripting/FloatVariable.cs @@ -15,4 +15,11 @@ namespace Fungus.Script } } + [System.Serializable] + public class FloatData + { + public FloatVariable floatReference; + public float floatValue; + } + } \ No newline at end of file diff --git a/Assets/Fungus/VisualScripting/IntegerVariable.cs b/Assets/Fungus/VisualScripting/IntegerVariable.cs index f4aab4a8..49caf675 100644 --- a/Assets/Fungus/VisualScripting/IntegerVariable.cs +++ b/Assets/Fungus/VisualScripting/IntegerVariable.cs @@ -15,4 +15,11 @@ namespace Fungus.Script } } + [System.Serializable] + public class IntegerData + { + public IntegerVariable integerReference; + public int integerValue; + } + } \ No newline at end of file diff --git a/Assets/Fungus/VisualScripting/StringVariable.cs b/Assets/Fungus/VisualScripting/StringVariable.cs index a6395bee..9ae2b324 100644 --- a/Assets/Fungus/VisualScripting/StringVariable.cs +++ b/Assets/Fungus/VisualScripting/StringVariable.cs @@ -15,4 +15,11 @@ namespace Fungus.Script } } + [System.Serializable] + public class StringData + { + public StringVariable stringReference; + public string stringValue; + } + } \ No newline at end of file diff --git a/Assets/Shuttle/ShuttleGame.unity b/Assets/Shuttle/ShuttleGame.unity index 092d911a..dec8c2db 100644 Binary files a/Assets/Shuttle/ShuttleGame.unity and b/Assets/Shuttle/ShuttleGame.unity differ