diff --git a/README.md b/README.md index 217c794..f510303 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,12 @@ The standalone release can be used with any injector or loader of your choice, b 3. Create an instance of Unity Explorer with `UnityExplorer.ExplorerStandalone.CreateInstance();` 4. Optionally subscribe to the `ExplorerStandalone.OnLog` event to handle logging if you wish +## Unity Editor + +1. Download the [`UnityExplorer.Editor`](https://github.com/sinai-dev/UnityExplorer/releases/latest/download/UnityExplorer.Editor.zip) release. +2. Install the package, either by using the Package Manager and importing the `package.json` file, or by manually dragging the folder into your `Assets` folder. +3. Drag the `Runtime/UnityExplorer` prefab into your scene, or create a GameObject and add the `Explorer Editor Behaviour` script to it. + # Common issues and solutions Although UnityExplorer should work out of the box for most Unity games, in some cases you may need to tweak the settings for it to work properly. diff --git a/src/Loader/Standalone/Editor/ExplorerEditorBehaviour.cs b/src/Loader/Standalone/Editor/ExplorerEditorBehaviour.cs new file mode 100644 index 0000000..fd94b52 --- /dev/null +++ b/src/Loader/Standalone/Editor/ExplorerEditorBehaviour.cs @@ -0,0 +1,33 @@ +#if STANDALONE +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Reflection; +using System.Text; +using UnityEngine; + +namespace UnityExplorer.Loader.Standalone +{ + public class ExplorerEditorBehaviour : MonoBehaviour + { + internal void Awake() + { + ExplorerEditorLoader.Initialize(); + DontDestroyOnLoad(this); + this.gameObject.hideFlags = HideFlags.HideAndDontSave; + } + + internal void OnDestroy() + { + OnApplicationQuit(); + } + + internal void OnApplicationQuit() + { + if (UI.UIManager.UIRoot) + Destroy(UI.UIManager.UIRoot.transform.root.gameObject); + } + } +} +#endif \ No newline at end of file diff --git a/src/Loader/Standalone/Editor/ExplorerEditorLoader.cs b/src/Loader/Standalone/Editor/ExplorerEditorLoader.cs new file mode 100644 index 0000000..6ffe190 --- /dev/null +++ b/src/Loader/Standalone/Editor/ExplorerEditorLoader.cs @@ -0,0 +1,41 @@ +#if STANDALONE +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using UnityEngine; + +namespace UnityExplorer.Loader.Standalone +{ + public class ExplorerEditorLoader : ExplorerStandalone + { + public static void Initialize() + { + Instance = new ExplorerEditorLoader(); + OnLog += LogHandler; + Instance.configHandler = new StandaloneConfigHandler(); + + ExplorerCore.Init(Instance); + } + + static void LogHandler(string message, LogType logType) + { + switch (logType) + { + case LogType.Assert: Debug.LogError(message); break; + case LogType.Error: Debug.LogError(message); break; + case LogType.Exception: Debug.LogError(message); break; + case LogType.Log: Debug.Log(message); break; + case LogType.Warning: Debug.LogWarning(message); break; + } + } + + protected override void CheckExplorerFolder() + { + if (explorerFolder == null) + explorerFolder = Path.Combine(Application.dataPath, "UnityExplorer~"); + } + } +} +#endif \ No newline at end of file diff --git a/src/Loader/Standalone/ExplorerStandalone.cs b/src/Loader/Standalone/ExplorerStandalone.cs index 5ba7a83..cbe2951 100644 --- a/src/Loader/Standalone/ExplorerStandalone.cs +++ b/src/Loader/Standalone/ExplorerStandalone.cs @@ -5,9 +5,9 @@ using System.IO; using System.Reflection; using UnityEngine; using UnityExplorer.Config; -using UnityExplorer.Loader.STANDALONE; using UnityEngine.EventSystems; using UniverseLib.Input; +using UnityExplorer.Loader.Standalone; #if CPP using UnhollowerRuntimeLib; #endif @@ -16,6 +16,33 @@ namespace UnityExplorer { public class ExplorerStandalone : IExplorerLoader { + public static ExplorerStandalone Instance { get; protected set; } + + /// + /// Invoked whenever Explorer logs something. Subscribe to this to handle logging. + /// + public static event Action OnLog; + + public string UnhollowedModulesFolder => unhollowedPath; + private string unhollowedPath; + + public ConfigHandler ConfigHandler => configHandler; + internal StandaloneConfigHandler configHandler; + + public string ExplorerFolder + { + get + { + CheckExplorerFolder(); + return explorerFolder; + } + } + protected static string explorerFolder; + + Action IExplorerLoader.OnLogMessage => (object log) => { OnLog?.Invoke(log?.ToString() ?? "", LogType.Log); }; + Action IExplorerLoader.OnLogWarning => (object log) => { OnLog?.Invoke(log?.ToString() ?? "", LogType.Warning); }; + Action IExplorerLoader.OnLogError => (object log) => { OnLog?.Invoke(log?.ToString() ?? "", LogType.Error); }; + /// /// Call this to initialize UnityExplorer without adding a log listener or Unhollowed modules path. /// The default Unhollowed path "UnityExplorer\Modules\" will be used. @@ -50,60 +77,33 @@ namespace UnityExplorer OnLog += logListener; if (string.IsNullOrEmpty(unhollowedModulesPath) || !Directory.Exists(unhollowedModulesPath)) - instance._unhollowedPath = Path.Combine(instance.ExplorerFolder, "Modules"); + instance.unhollowedPath = Path.Combine(instance.ExplorerFolder, "Modules"); else - instance._unhollowedPath = unhollowedModulesPath; + instance.unhollowedPath = unhollowedModulesPath; return instance; } - public static ExplorerStandalone Instance { get; private set; } - - /// - /// Invoked whenever Explorer logs something. Subscribe to this to handle logging. - /// - public static event Action OnLog; - - public string UnhollowedModulesFolder => _unhollowedPath; - private string _unhollowedPath; - - public ConfigHandler ConfigHandler => _configHandler; - private StandaloneConfigHandler _configHandler; - - public string ExplorerFolder - { - get - { - CheckExplorerFolder(); - return s_explorerFolder; - } - } - private static string s_explorerFolder; - - Action IExplorerLoader.OnLogMessage => (object log) => { OnLog?.Invoke(log?.ToString() ?? "", LogType.Log); }; - Action IExplorerLoader.OnLogWarning => (object log) => { OnLog?.Invoke(log?.ToString() ?? "", LogType.Warning); }; - Action IExplorerLoader.OnLogError => (object log) => { OnLog?.Invoke(log?.ToString() ?? "", LogType.Error); }; - - private void Init() + internal void Init() { Instance = this; - _configHandler = new StandaloneConfigHandler(); + configHandler = new StandaloneConfigHandler(); ExplorerCore.Init(this); } - private void CheckExplorerFolder() + protected virtual void CheckExplorerFolder() { - if (s_explorerFolder == null) + if (explorerFolder == null) { - s_explorerFolder = + explorerFolder = Path.Combine( Path.GetDirectoryName( Uri.UnescapeDataString(new Uri(Assembly.GetExecutingAssembly().CodeBase).AbsolutePath)), "UnityExplorer"); - if (!Directory.Exists(s_explorerFolder)) - Directory.CreateDirectory(s_explorerFolder); + if (!Directory.Exists(explorerFolder)) + Directory.CreateDirectory(explorerFolder); } } } diff --git a/src/Loader/Standalone/StandaloneConfigHandler.cs b/src/Loader/Standalone/StandaloneConfigHandler.cs index c533e03..47dce6a 100644 --- a/src/Loader/Standalone/StandaloneConfigHandler.cs +++ b/src/Loader/Standalone/StandaloneConfigHandler.cs @@ -9,7 +9,7 @@ using UnityEngine; using Tomlet; using Tomlet.Models; -namespace UnityExplorer.Loader.STANDALONE +namespace UnityExplorer.Loader.Standalone { public class StandaloneConfigHandler : ConfigHandler { diff --git a/src/UI/DisplayManager.cs b/src/UI/DisplayManager.cs index 9a8ac01..a3795da 100644 --- a/src/UI/DisplayManager.cs +++ b/src/UI/DisplayManager.cs @@ -18,7 +18,10 @@ namespace UnityExplorer.UI public static int Width => ActiveDisplay.renderingWidth; public static int Height => ActiveDisplay.renderingHeight; - public static Vector3 MousePosition => Display.RelativeMouseAt(InputManager.MousePosition); + public static Vector3 MousePosition => Application.isEditor + ? InputManager.MousePosition + : Display.RelativeMouseAt(InputManager.MousePosition); + public static bool MouseInTargetDisplay => MousePosition.z == ActiveDisplayIndex; private static Camera canvasCamera; diff --git a/src/UnityExplorer.csproj b/src/UnityExplorer.csproj index 4c73b3b..18811ae 100644 --- a/src/UnityExplorer.csproj +++ b/src/UnityExplorer.csproj @@ -265,6 +265,8 @@ + +