Browse Source

Merge pull request #482 from snozbot/live-edit-lua

Live edit lua
master
Chris Gregan 9 years ago
parent
commit
a2675b73a2
  1. 51
      Assets/Fungus/Thirdparty/FungusLua/Scripts/Editor/LuaScriptEditor.cs
  2. 12
      Assets/Fungus/Thirdparty/FungusLua/Scripts/Editor/LuaScriptEditor.cs.meta
  3. 11
      Assets/Fungus/Thirdparty/FungusLua/Scripts/LuaScript.cs

51
Assets/Fungus/Thirdparty/FungusLua/Scripts/Editor/LuaScriptEditor.cs vendored

@ -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();
}
}
}

12
Assets/Fungus/Thirdparty/FungusLua/Scripts/Editor/LuaScriptEditor.cs.meta vendored

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: db0946039407442029cadd010a2a7a80
timeCreated: 1463763860
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

11
Assets/Fungus/Thirdparty/FungusLua/Scripts/LuaScript.cs vendored

@ -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;
@ -94,12 +96,7 @@ namespace Fungus
string s = GetLuaString();
luaFunction = luaEnvironment.LoadLuaString(s, friendlyName);
// Always initialise when playing in the editor.
// Allows the user to edit the Lua script while the game is playing.
if ( !(Application.isPlaying && Application.isEditor) )
{
initialised = true;
}
initialised = true;
}
/// <summary>

Loading…
Cancel
Save