diff --git a/Assets/Fungus/Thirdparty/FungusLua/Scripts/Components/LuaEnvironment.cs b/Assets/Fungus/Thirdparty/FungusLua/Scripts/Components/LuaEnvironment.cs index 39c9a648..353babe8 100644 --- a/Assets/Fungus/Thirdparty/FungusLua/Scripts/Components/LuaEnvironment.cs +++ b/Assets/Fungus/Thirdparty/FungusLua/Scripts/Components/LuaEnvironment.cs @@ -3,37 +3,24 @@ using UnityEngine; using System.Collections; -using System.Collections.Generic; using System; -using System.Diagnostics; using System.Linq; using MoonSharp.Interpreter; -using MoonSharp.Interpreter.Loaders; using MoonSharp.VsCodeDebugger; namespace Fungus { /// /// Wrapper for a MoonSharp Lua Script instance. + /// A debug server is started automatically when running in the Unity Editor. Use VS Code to debug Lua scripts. /// public class LuaEnvironment : MonoBehaviour { - /// - /// Launches the remote Lua debugger in your browser and breaks execution at the first executed Lua command. - /// - [Tooltip("Launches the remote Lua debugger in your browser and breaks execution at the first executed Lua command. Standalone platform only.")] - [SerializeField] protected bool remoteDebugger = false; - /// /// The MoonSharp interpreter instance. /// protected Script interpreter; - /// - /// Instance of VS Code debug server when debugging option is enabled. - /// - protected MoonSharpVsCodeDebugServer debugServer; - /// /// Flag used to avoid startup dependency issues. /// @@ -45,13 +32,13 @@ namespace Fungus } /// - /// This function is called when the MonoBehaviour will be destroyed. + /// Detach the MoonSharp script from the debugger. /// protected virtual void OnDestroy() { - if (debugServer != null) + if (DebugServer != null) { - debugServer.Detach(interpreter); + DebugServer.Detach(interpreter); } } @@ -125,16 +112,16 @@ namespace Fungus yield return StartCoroutine(coroutine); } - protected virtual void ActivateVSCodeDebugger(Script script) + protected virtual void StartVSCodeDebugger() { - // Create the debugger server - debugServer = new MoonSharpVsCodeDebugServer(); - - // Start the debugger server - debugServer.Start(); + if (DebugServer == null) + { + // Create the debugger server + DebugServer = new MoonSharpVsCodeDebugServer(); - // Attach the script to the debugger - debugServer.AttachToScript(script, gameObject.name); + // Start the debugger server + DebugServer.Start(); + } } /// @@ -162,6 +149,11 @@ namespace Fungus #region Public members + /// + /// Instance of VS Code debug server when debugging option is enabled. + /// + public static MoonSharpVsCodeDebugServer DebugServer { get; private set; } + /// /// Returns the first Lua Environment found in the scene, or creates one if none exists. /// This is a slow operation, call it once at startup and cache the returned value. @@ -261,11 +253,15 @@ namespace Fungus initializer.Initialize(); } - #if UNITY_STANDALONE - if (remoteDebugger) - { - ActivateVSCodeDebugger(interpreter); - } + // + // Change this to #if UNITY_STANDALONE if you want to debug a standalone build. + // + + #if UNITY_EDITOR + StartVSCodeDebugger(); + + // Attach the MoonSharp script to the debugger + DebugServer.AttachToScript(interpreter, gameObject.name); #endif initialised = true; diff --git a/Assets/Fungus/Thirdparty/VSCode.meta b/Assets/Fungus/Thirdparty/VSCode.meta deleted file mode 100644 index 8ab072d3..00000000 --- a/Assets/Fungus/Thirdparty/VSCode.meta +++ /dev/null @@ -1,9 +0,0 @@ -fileFormatVersion: 2 -guid: f550ad0c0d1094942a72476811c503d6 -folderAsset: yes -timeCreated: 1476781536 -licenseType: Free -DefaultImporter: - userData: - assetBundleName: - assetBundleVariant: