From 944ada64a1ee2883f5e498a92d5eba66638afe72 Mon Sep 17 00:00:00 2001 From: chrisgregan Date: Sat, 17 Jan 2015 23:01:33 +0000 Subject: [PATCH] Change #68 Replace Save/Load Globals with Save/Load Variable Added custom property drawer for Variable properties. Updated If, Set Variable, etc. to use new property drawer. Added new Set Save Profile, Save Variable, Load Variable & Delete Save Key commands. --- Assets/Fungus/FungusScript/Editor/IfEditor.cs | 5 +- .../FungusScript/Editor/RandomFloatEditor.cs | 48 --------- .../Editor/RandomIntegerEditor.cs | 48 --------- .../FungusScript/Editor/SetVariableEditor.cs | 8 +- .../FungusScript/Editor/VariableEditor.cs | 47 ++++++++- .../Scripts/Commands/DeleteSaveKey.cs | 50 ++++++++++ .../Commands/DeleteSaveKey.cs.meta} | 2 +- .../FungusScript/Scripts/Commands/If.cs | 7 +- .../Scripts/Commands/LoadGlobals.cs | 33 ------- .../Scripts/Commands/LoadVariable.cs | 97 ++++++++++++++++++ ...adGlobals.cs.meta => LoadVariable.cs.meta} | 0 .../Scripts/Commands/RandomFloat.cs | 1 + .../Scripts/Commands/RandomInteger.cs | 1 + .../Scripts/Commands/SaveGlobals.cs | 33 ------- .../Scripts/Commands/SaveVariable.cs | 99 +++++++++++++++++++ ...veGlobals.cs.meta => SaveVariable.cs.meta} | 0 .../Scripts/Commands/SetSaveProfile.cs | 39 ++++++++ .../Commands/SetSaveProfile.cs.meta} | 2 +- .../Scripts/Commands/SetVariable.cs | 4 + .../Fungus/FungusScript/Scripts/Variable.cs | 10 ++ 20 files changed, 355 insertions(+), 179 deletions(-) delete mode 100644 Assets/Fungus/FungusScript/Editor/RandomFloatEditor.cs delete mode 100644 Assets/Fungus/FungusScript/Editor/RandomIntegerEditor.cs create mode 100644 Assets/Fungus/FungusScript/Scripts/Commands/DeleteSaveKey.cs rename Assets/Fungus/FungusScript/{Editor/RandomFloatEditor.cs.meta => Scripts/Commands/DeleteSaveKey.cs.meta} (78%) delete mode 100644 Assets/Fungus/FungusScript/Scripts/Commands/LoadGlobals.cs create mode 100644 Assets/Fungus/FungusScript/Scripts/Commands/LoadVariable.cs rename Assets/Fungus/FungusScript/Scripts/Commands/{LoadGlobals.cs.meta => LoadVariable.cs.meta} (100%) delete mode 100644 Assets/Fungus/FungusScript/Scripts/Commands/SaveGlobals.cs create mode 100644 Assets/Fungus/FungusScript/Scripts/Commands/SaveVariable.cs rename Assets/Fungus/FungusScript/Scripts/Commands/{SaveGlobals.cs.meta => SaveVariable.cs.meta} (100%) create mode 100644 Assets/Fungus/FungusScript/Scripts/Commands/SetSaveProfile.cs rename Assets/Fungus/FungusScript/{Editor/RandomIntegerEditor.cs.meta => Scripts/Commands/SetSaveProfile.cs.meta} (78%) diff --git a/Assets/Fungus/FungusScript/Editor/IfEditor.cs b/Assets/Fungus/FungusScript/Editor/IfEditor.cs index dec961e6..29da556d 100644 --- a/Assets/Fungus/FungusScript/Editor/IfEditor.cs +++ b/Assets/Fungus/FungusScript/Editor/IfEditor.cs @@ -39,10 +39,7 @@ namespace Fungus return; } - VariableEditor.VariableField(variableProp, - new GUIContent("Variable", "Variable to use in operation"), - t.GetFungusScript(), - null); + EditorGUILayout.PropertyField(variableProp); if (variableProp.objectReferenceValue == null) { diff --git a/Assets/Fungus/FungusScript/Editor/RandomFloatEditor.cs b/Assets/Fungus/FungusScript/Editor/RandomFloatEditor.cs deleted file mode 100644 index c54cd937..00000000 --- a/Assets/Fungus/FungusScript/Editor/RandomFloatEditor.cs +++ /dev/null @@ -1,48 +0,0 @@ -using UnityEditor; -using UnityEngine; -using System.Collections; -using System.Collections.Generic; -using System.Reflection; - -namespace Fungus -{ - - [CustomEditor (typeof(RandomFloat))] - public class RandomFloatEditor : CommandEditor - { - protected SerializedProperty variableProp; - protected SerializedProperty minValueProp; - protected SerializedProperty maxValueProp; - - protected virtual void OnEnable() - { - variableProp = serializedObject.FindProperty("variable"); - minValueProp = serializedObject.FindProperty("minValue"); - maxValueProp = serializedObject.FindProperty("maxValue"); - } - - public override void DrawCommandGUI() - { - serializedObject.Update(); - - RandomFloat t = target as RandomFloat; - - FungusScript fungusScript = t.GetFungusScript(); - if (fungusScript == null) - { - return; - } - - VariableEditor.VariableField(variableProp, - new GUIContent("Variable", "Variable to use in operation"), - t.GetFungusScript(), - (v) => (v.GetType() == typeof(FloatVariable))); - - EditorGUILayout.PropertyField(minValueProp); - EditorGUILayout.PropertyField(maxValueProp); - - serializedObject.ApplyModifiedProperties(); - } - } - -} diff --git a/Assets/Fungus/FungusScript/Editor/RandomIntegerEditor.cs b/Assets/Fungus/FungusScript/Editor/RandomIntegerEditor.cs deleted file mode 100644 index 0e95cceb..00000000 --- a/Assets/Fungus/FungusScript/Editor/RandomIntegerEditor.cs +++ /dev/null @@ -1,48 +0,0 @@ -using UnityEditor; -using UnityEngine; -using System.Collections; -using System.Collections.Generic; -using System.Reflection; - -namespace Fungus -{ - - [CustomEditor (typeof(RandomInteger))] - public class RandomIntegerEditor : CommandEditor - { - protected SerializedProperty variableProp; - protected SerializedProperty minValueProp; - protected SerializedProperty maxValueProp; - - protected virtual void OnEnable() - { - variableProp = serializedObject.FindProperty("variable"); - minValueProp = serializedObject.FindProperty("minValue"); - maxValueProp = serializedObject.FindProperty("maxValue"); - } - - public override void DrawCommandGUI() - { - serializedObject.Update(); - - RandomInteger t = target as RandomInteger; - - FungusScript fungusScript = t.GetFungusScript(); - if (fungusScript == null) - { - return; - } - - VariableEditor.VariableField(variableProp, - new GUIContent("Variable", "Variable to use in operation"), - t.GetFungusScript(), - (v) => (v.GetType() == typeof(IntegerVariable))); - - EditorGUILayout.PropertyField(minValueProp); - EditorGUILayout.PropertyField(maxValueProp); - - serializedObject.ApplyModifiedProperties(); - } - } - -} diff --git a/Assets/Fungus/FungusScript/Editor/SetVariableEditor.cs b/Assets/Fungus/FungusScript/Editor/SetVariableEditor.cs index d35b0acc..af849ceb 100644 --- a/Assets/Fungus/FungusScript/Editor/SetVariableEditor.cs +++ b/Assets/Fungus/FungusScript/Editor/SetVariableEditor.cs @@ -38,13 +38,7 @@ namespace Fungus return; } - VariableEditor.VariableField(variableProp, - new GUIContent("Set Variable", "Variable to set"), - fungusScript, - (v) => (v.GetType() == typeof(BooleanVariable) || - v.GetType() == typeof(IntegerVariable) || - v.GetType() == typeof(FloatVariable) || - v.GetType() == typeof(StringVariable))); + EditorGUILayout.PropertyField(variableProp); if (variableProp.objectReferenceValue == null) { diff --git a/Assets/Fungus/FungusScript/Editor/VariableEditor.cs b/Assets/Fungus/FungusScript/Editor/VariableEditor.cs index 9d4dfbf4..645a5cf7 100644 --- a/Assets/Fungus/FungusScript/Editor/VariableEditor.cs +++ b/Assets/Fungus/FungusScript/Editor/VariableEditor.cs @@ -32,7 +32,11 @@ namespace Fungus return null; } - static public void VariableField(SerializedProperty property, GUIContent label, FungusScript fungusScript, Func filter = null) + static public void VariableField(SerializedProperty property, + GUIContent label, + FungusScript fungusScript, + Func filter, + Func drawer = null) { List variableKeys = new List(); List variableObjects = new List(); @@ -90,12 +94,49 @@ namespace Fungus } } - selectedIndex = EditorGUILayout.Popup(label.text, selectedIndex, variableKeys.ToArray()); - + if (drawer == null) + { + selectedIndex = EditorGUILayout.Popup(label.text, selectedIndex, variableKeys.ToArray()); + } + else + { + selectedIndex = drawer(label.text, selectedIndex, variableKeys.ToArray()); + } + property.objectReferenceValue = variableObjects[selectedIndex]; } } + [CustomPropertyDrawer(typeof(VariablePropertyAttribute))] + public class VariableDrawer : PropertyDrawer + { + + public override void OnGUI (Rect position, SerializedProperty property, GUIContent label) + { + VariablePropertyAttribute variableProperty = attribute as VariablePropertyAttribute; + + EditorGUI.BeginProperty(position, label, property); + + // Filter the variables by the types listed in the VariableProperty attribute + Func compare = v => + { + if (variableProperty.VariableTypes.Length == 0) + { + return true; + } + return variableProperty.VariableTypes.Contains(v.GetType()); + }; + + VariableEditor.VariableField(property, + label, + FungusScriptWindow.GetFungusScript(), + compare, + (s,t,u) => (EditorGUI.Popup(position, s, t, u))); + + EditorGUI.EndProperty(); + } + } + public class VariableDataDrawer : PropertyDrawer where T : Variable { diff --git a/Assets/Fungus/FungusScript/Scripts/Commands/DeleteSaveKey.cs b/Assets/Fungus/FungusScript/Scripts/Commands/DeleteSaveKey.cs new file mode 100644 index 00000000..f4f037c1 --- /dev/null +++ b/Assets/Fungus/FungusScript/Scripts/Commands/DeleteSaveKey.cs @@ -0,0 +1,50 @@ +using UnityEngine; +using System; +using System.Collections; + +namespace Fungus +{ + [CommandInfo("Scripting", + "Delete Save Key", + "Deletes a saved value from permanent storage.")] + [AddComponentMenu("")] + public class DeleteSaveKey : Command + { + [Tooltip("Name of the saved value. Supports variable substition e.g. \"player_{$PlayerNumber}")] + public string key = ""; + + public override void OnEnter() + { + if (key == "") + { + Continue(); + return; + } + + FungusScript fungusScript = GetFungusScript(); + + // Prepend the current save profile (if any) + string prefsKey = SetSaveProfile.saveProfile + "_" + fungusScript.SubstituteVariables(key); + + PlayerPrefs.DeleteKey(prefsKey); + + Continue(); + } + + public override string GetSummary() + { + if (key.Length == 0) + { + return "Error: No stored value key selected"; + } + + return key; + } + + public override Color GetButtonColor() + { + return new Color32(235, 191, 217, 255); + } + } + +} \ No newline at end of file diff --git a/Assets/Fungus/FungusScript/Editor/RandomFloatEditor.cs.meta b/Assets/Fungus/FungusScript/Scripts/Commands/DeleteSaveKey.cs.meta similarity index 78% rename from Assets/Fungus/FungusScript/Editor/RandomFloatEditor.cs.meta rename to Assets/Fungus/FungusScript/Scripts/Commands/DeleteSaveKey.cs.meta index 9302a7c4..5cc3ac73 100644 --- a/Assets/Fungus/FungusScript/Editor/RandomFloatEditor.cs.meta +++ b/Assets/Fungus/FungusScript/Scripts/Commands/DeleteSaveKey.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: e1674366d369d428eac4568d9f0dae19 +guid: e1205d6641f2146b19d496037f937ba0 MonoImporter: serializedVersion: 2 defaultReferences: [] diff --git a/Assets/Fungus/FungusScript/Scripts/Commands/If.cs b/Assets/Fungus/FungusScript/Scripts/Commands/If.cs index 99441ee1..b01d7a51 100644 --- a/Assets/Fungus/FungusScript/Scripts/Commands/If.cs +++ b/Assets/Fungus/FungusScript/Scripts/Commands/If.cs @@ -20,7 +20,12 @@ namespace Fungus [AddComponentMenu("")] public class If : Command { - [Tooltip("The variable whos value will be checked")] + + [Tooltip("Variable to use in expression")] + [VariableProperty(typeof(BooleanVariable), + typeof(IntegerVariable), + typeof(FloatVariable), + typeof(StringVariable))] public Variable variable; [Tooltip("The type of comparison to be performed")] diff --git a/Assets/Fungus/FungusScript/Scripts/Commands/LoadGlobals.cs b/Assets/Fungus/FungusScript/Scripts/Commands/LoadGlobals.cs deleted file mode 100644 index 566d46e9..00000000 --- a/Assets/Fungus/FungusScript/Scripts/Commands/LoadGlobals.cs +++ /dev/null @@ -1,33 +0,0 @@ -using UnityEngine; -using System; -using System.Collections; - -namespace Fungus -{ - [CommandInfo("Scripting", - "Load Globals", - "Loads a set of global variables previously saved using the Save Globals command.")] - [AddComponentMenu("")] - public class LoadGlobals : Command - { - [Tooltip("Save Name of saved global variable values")] - public string saveName = ""; - - public override void OnEnter() - { - //GlobalVariables.Load(saveName); - Continue(); - } - - public override string GetSummary() - { - return saveName; - } - - public override Color GetButtonColor() - { - return new Color32(235, 191, 217, 255); - } - } - -} \ No newline at end of file diff --git a/Assets/Fungus/FungusScript/Scripts/Commands/LoadVariable.cs b/Assets/Fungus/FungusScript/Scripts/Commands/LoadVariable.cs new file mode 100644 index 00000000..10283ede --- /dev/null +++ b/Assets/Fungus/FungusScript/Scripts/Commands/LoadVariable.cs @@ -0,0 +1,97 @@ +using UnityEngine; +using System; +using System.Collections; + +namespace Fungus +{ + [CommandInfo("Scripting", + "Load Variable", + "Loads a saved value and stores it in a Boolean, Integer, Float or String variable. If the key is not found then the variable is not modified.")] + [AddComponentMenu("")] + public class LoadVariable : Command + { + [Tooltip("Name of the saved value. Supports variable substition e.g. \"player_{$PlayerNumber}\"")] + public string key = ""; + + [Tooltip("Variable to store the value in.")] + [VariableProperty(typeof(BooleanVariable), + typeof(IntegerVariable), + typeof(FloatVariable), + typeof(StringVariable))] + public Variable variable; + + public override void OnEnter() + { + if (key == "" || + variable == null) + { + Continue(); + return; + } + + FungusScript fungusScript = GetFungusScript(); + + // Prepend the current save profile (if any) + string prefsKey = SetSaveProfile.saveProfile + "_" + fungusScript.SubstituteVariables(key); + + System.Type variableType = variable.GetType(); + + if (variableType == typeof(BooleanVariable)) + { + BooleanVariable booleanVariable = variable as BooleanVariable; + if (booleanVariable != null) + { + // PlayerPrefs does not have bool accessors, so just use int + booleanVariable.value = (PlayerPrefs.GetInt(prefsKey) == 1); + } + } + else if (variableType == typeof(IntegerVariable)) + { + IntegerVariable integerVariable = variable as IntegerVariable; + if (integerVariable != null) + { + integerVariable.value = PlayerPrefs.GetInt(prefsKey); + } + } + else if (variableType == typeof(FloatVariable)) + { + FloatVariable floatVariable = variable as FloatVariable; + if (floatVariable != null) + { + floatVariable.value = PlayerPrefs.GetFloat(prefsKey); + } + } + else if (variableType == typeof(StringVariable)) + { + StringVariable stringVariable = variable as StringVariable; + if (stringVariable != null) + { + stringVariable.value = PlayerPrefs.GetString(prefsKey); + } + } + + Continue(); + } + + public override string GetSummary() + { + if (key.Length == 0) + { + return "Error: No stored value key selected"; + } + + if (variable == null) + { + return "Error: No variable selected"; + } + + return "'" + key + "' into " + variable.key; + } + + public override Color GetButtonColor() + { + return new Color32(235, 191, 217, 255); + } + } + +} \ No newline at end of file diff --git a/Assets/Fungus/FungusScript/Scripts/Commands/LoadGlobals.cs.meta b/Assets/Fungus/FungusScript/Scripts/Commands/LoadVariable.cs.meta similarity index 100% rename from Assets/Fungus/FungusScript/Scripts/Commands/LoadGlobals.cs.meta rename to Assets/Fungus/FungusScript/Scripts/Commands/LoadVariable.cs.meta diff --git a/Assets/Fungus/FungusScript/Scripts/Commands/RandomFloat.cs b/Assets/Fungus/FungusScript/Scripts/Commands/RandomFloat.cs index 69459088..a8b5a524 100644 --- a/Assets/Fungus/FungusScript/Scripts/Commands/RandomFloat.cs +++ b/Assets/Fungus/FungusScript/Scripts/Commands/RandomFloat.cs @@ -10,6 +10,7 @@ namespace Fungus public class RandomFloat : Command { [Tooltip("The variable whos value will be set")] + [VariableProperty(typeof(FloatVariable))] public FloatVariable variable; [Tooltip("Minimum value for random range")] diff --git a/Assets/Fungus/FungusScript/Scripts/Commands/RandomInteger.cs b/Assets/Fungus/FungusScript/Scripts/Commands/RandomInteger.cs index 10d57f17..69d6b437 100644 --- a/Assets/Fungus/FungusScript/Scripts/Commands/RandomInteger.cs +++ b/Assets/Fungus/FungusScript/Scripts/Commands/RandomInteger.cs @@ -10,6 +10,7 @@ namespace Fungus public class RandomInteger : Command { [Tooltip("The variable whos value will be set")] + [VariableProperty(typeof(IntegerVariable))] public IntegerVariable variable; [Tooltip("Minimum value for random range")] diff --git a/Assets/Fungus/FungusScript/Scripts/Commands/SaveGlobals.cs b/Assets/Fungus/FungusScript/Scripts/Commands/SaveGlobals.cs deleted file mode 100644 index 803121ee..00000000 --- a/Assets/Fungus/FungusScript/Scripts/Commands/SaveGlobals.cs +++ /dev/null @@ -1,33 +0,0 @@ -using UnityEngine; -using System; -using System.Collections; - -namespace Fungus -{ - [CommandInfo("Scripting", - "Save Globals", - "Saves all current global variables to persistent storage. These can be loaded back in again in future using the LoadGlobals command. This provides a basic save game system.")] - [AddComponentMenu("")] - public class SaveGlobals : Command - { - [Tooltip("Save Name of saved global variable values")] - public string saveName = ""; - - public override void OnEnter() - { - //GlobalVariables.Save(saveName); - Continue(); - } - - public override string GetSummary() - { - return saveName; - } - - public override Color GetButtonColor() - { - return new Color32(235, 191, 217, 255); - } - } - -} \ No newline at end of file diff --git a/Assets/Fungus/FungusScript/Scripts/Commands/SaveVariable.cs b/Assets/Fungus/FungusScript/Scripts/Commands/SaveVariable.cs new file mode 100644 index 00000000..d120d59d --- /dev/null +++ b/Assets/Fungus/FungusScript/Scripts/Commands/SaveVariable.cs @@ -0,0 +1,99 @@ +using UnityEngine; +using System; +using System.Collections; + +namespace Fungus +{ + [CommandInfo("Scripting", + "Save Variable", + "Save an Boolean, Integer, Float or String variable to persistent storage using a string key. " + + "The value can be loaded again later using the Load Variable command. You can also " + + "use the Set Save Profile command to manage separate save profiles for multiple players.")] + [AddComponentMenu("")] + public class SaveVariable : Command + { + [Tooltip("Name of the saved value. Supports variable substition e.g. \"player_{$PlayerNumber}")] + public string key = ""; + + [Tooltip("Variable to read the value from. Only Boolean, Integer, Float and String are supported.")] + [VariableProperty(typeof(BooleanVariable), + typeof(IntegerVariable), + typeof(FloatVariable), + typeof(StringVariable))] + public Variable variable; + + public override void OnEnter() + { + if (key == "" || + variable == null) + { + Continue(); + return; + } + + FungusScript fungusScript = GetFungusScript(); + + // Prepend the current save profile (if any) + string prefsKey = SetSaveProfile.saveProfile + "_" + fungusScript.SubstituteVariables(key); + + System.Type variableType = variable.GetType(); + + if (variableType == typeof(BooleanVariable)) + { + BooleanVariable booleanVariable = variable as BooleanVariable; + if (booleanVariable != null) + { + // PlayerPrefs does not have bool accessors, so just use int + PlayerPrefs.SetInt(prefsKey, booleanVariable.value ? 1 : 0); + } + } + else if (variableType == typeof(IntegerVariable)) + { + IntegerVariable integerVariable = variable as IntegerVariable; + if (integerVariable != null) + { + PlayerPrefs.SetInt(prefsKey, integerVariable.value); + } + } + else if (variableType == typeof(FloatVariable)) + { + FloatVariable floatVariable = variable as FloatVariable; + if (floatVariable != null) + { + PlayerPrefs.SetFloat(prefsKey, floatVariable.value); + } + } + else if (variableType == typeof(StringVariable)) + { + StringVariable stringVariable = variable as StringVariable; + if (stringVariable != null) + { + PlayerPrefs.SetString(prefsKey, stringVariable.value); + } + } + + Continue(); + } + + public override string GetSummary() + { + if (key.Length == 0) + { + return "Error: No stored value key selected"; + } + + if (variable == null) + { + return "Error: No variable selected"; + } + + return variable.key + " into '" + key + "'"; + } + + public override Color GetButtonColor() + { + return new Color32(235, 191, 217, 255); + } + } + +} \ No newline at end of file diff --git a/Assets/Fungus/FungusScript/Scripts/Commands/SaveGlobals.cs.meta b/Assets/Fungus/FungusScript/Scripts/Commands/SaveVariable.cs.meta similarity index 100% rename from Assets/Fungus/FungusScript/Scripts/Commands/SaveGlobals.cs.meta rename to Assets/Fungus/FungusScript/Scripts/Commands/SaveVariable.cs.meta diff --git a/Assets/Fungus/FungusScript/Scripts/Commands/SetSaveProfile.cs b/Assets/Fungus/FungusScript/Scripts/Commands/SetSaveProfile.cs new file mode 100644 index 00000000..3ac59254 --- /dev/null +++ b/Assets/Fungus/FungusScript/Scripts/Commands/SetSaveProfile.cs @@ -0,0 +1,39 @@ +using UnityEngine; +using System; +using System.Collections; + +namespace Fungus +{ + [CommandInfo("Scripting", + "Set Save Profile", + "Sets the active profile that the Save Variable and Load Variable commands will use. This is useful to crete multiple player save games. Once set, the profile applies across all Fungus Scripts and will also persist across scene loads.")] + [AddComponentMenu("")] + public class SetSaveProfile : Command + { + /** + * Shared save profile name used by SaveVariable and LoadVariable. + */ + public static string saveProfile = ""; + + [Tooltip("Name of save profile to make active.")] + public string saveProfileName = ""; + + public override void OnEnter() + { + saveProfile = saveProfileName; + + Continue(); + } + + public override string GetSummary() + { + return saveProfileName; + } + + public override Color GetButtonColor() + { + return new Color32(235, 191, 217, 255); + } + } + +} \ No newline at end of file diff --git a/Assets/Fungus/FungusScript/Editor/RandomIntegerEditor.cs.meta b/Assets/Fungus/FungusScript/Scripts/Commands/SetSaveProfile.cs.meta similarity index 78% rename from Assets/Fungus/FungusScript/Editor/RandomIntegerEditor.cs.meta rename to Assets/Fungus/FungusScript/Scripts/Commands/SetSaveProfile.cs.meta index 3f9c6c91..29e82ed4 100644 --- a/Assets/Fungus/FungusScript/Editor/RandomIntegerEditor.cs.meta +++ b/Assets/Fungus/FungusScript/Scripts/Commands/SetSaveProfile.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 61c5d800d9a7e4e18864b9c00b0b2fe9 +guid: 9a240aa44597844f89e6d1ba15a96b04 MonoImporter: serializedVersion: 2 defaultReferences: [] diff --git a/Assets/Fungus/FungusScript/Scripts/Commands/SetVariable.cs b/Assets/Fungus/FungusScript/Scripts/Commands/SetVariable.cs index 101e720e..9a6235ba 100644 --- a/Assets/Fungus/FungusScript/Scripts/Commands/SetVariable.cs +++ b/Assets/Fungus/FungusScript/Scripts/Commands/SetVariable.cs @@ -20,6 +20,10 @@ namespace Fungus } [Tooltip("The variable whos value will be set")] + [VariableProperty(typeof(BooleanVariable), + typeof(IntegerVariable), + typeof(FloatVariable), + typeof(StringVariable))] public Variable variable; [Tooltip("The type of math operation to be performed")] diff --git a/Assets/Fungus/FungusScript/Scripts/Variable.cs b/Assets/Fungus/FungusScript/Scripts/Variable.cs index 88a1675e..7531fda2 100644 --- a/Assets/Fungus/FungusScript/Scripts/Variable.cs +++ b/Assets/Fungus/FungusScript/Scripts/Variable.cs @@ -25,6 +25,16 @@ namespace Fungus public int Order { get; set; } } + public class VariablePropertyAttribute : PropertyAttribute + { + public VariablePropertyAttribute (params System.Type[] variableTypes) + { + this.VariableTypes = variableTypes; + } + + public System.Type[] VariableTypes { get; set; } + } + [RequireComponent(typeof(FungusScript))] public abstract class Variable : MonoBehaviour {