diff --git a/Assets/Fungus/Thirdparty/FungusLua/Scripts/Editor/LuaScriptEditor.cs b/Assets/Fungus/Thirdparty/FungusLua/Scripts/Editor/LuaScriptEditor.cs new file mode 100644 index 00000000..3f19feaa --- /dev/null +++ b/Assets/Fungus/Thirdparty/FungusLua/Scripts/Editor/LuaScriptEditor.cs @@ -0,0 +1,51 @@ +using UnityEditor; +using UnityEditorInternal; +using UnityEngine; +using System.Collections; +using System.Collections.Generic; + +namespace Fungus +{ + + [CustomEditor (typeof(LuaScript))] + public class LuaScriptEditor : Editor + { + protected SerializedProperty luaEnvironmentProp; + protected SerializedProperty luaFileProp; + protected SerializedProperty luaScriptProp; + protected SerializedProperty runAsCoroutineProp; + + protected virtual void OnEnable() + { + luaEnvironmentProp = serializedObject.FindProperty("luaEnvironment"); + luaFileProp = serializedObject.FindProperty("luaFile"); + luaScriptProp = serializedObject.FindProperty("luaScript"); + runAsCoroutineProp = serializedObject.FindProperty("runAsCoroutine"); + } + + public override void OnInspectorGUI() + { + serializedObject.Update(); + + EditorGUILayout.PropertyField(luaEnvironmentProp); + EditorGUILayout.PropertyField(luaFileProp); + + EditorGUI.BeginChangeCheck(); + + EditorGUILayout.PropertyField(luaScriptProp); + + if (EditorGUI.EndChangeCheck() && + EditorApplication.isPlaying) + { + // Reinitialise if the Lua script is changed while running in editor + LuaScript luaScript = target as LuaScript; + luaScript.initialised = false; + } + + EditorGUILayout.PropertyField(runAsCoroutineProp); + + serializedObject.ApplyModifiedProperties(); + } + } + +} \ No newline at end of file diff --git a/Assets/Fungus/Thirdparty/FungusLua/Scripts/Editor/LuaScriptEditor.cs.meta b/Assets/Fungus/Thirdparty/FungusLua/Scripts/Editor/LuaScriptEditor.cs.meta new file mode 100644 index 00000000..0b6f3e30 --- /dev/null +++ b/Assets/Fungus/Thirdparty/FungusLua/Scripts/Editor/LuaScriptEditor.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: db0946039407442029cadd010a2a7a80 +timeCreated: 1463763860 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Fungus/Thirdparty/FungusLua/Scripts/LuaScript.cs b/Assets/Fungus/Thirdparty/FungusLua/Scripts/LuaScript.cs index 5c6f2267..5c6e8627 100644 --- a/Assets/Fungus/Thirdparty/FungusLua/Scripts/LuaScript.cs +++ b/Assets/Fungus/Thirdparty/FungusLua/Scripts/LuaScript.cs @@ -43,7 +43,9 @@ namespace Fungus protected string friendlyName = ""; - protected bool initialised; + // This is public so the editor code can force the component to reinitialise + [NonSerialized] + public bool initialised; // Stores the compiled Lua code for fast execution later. protected Closure luaFunction;