Skip to content
This repository was archived by the owner on May 9, 2023. It is now read-only.

Commit 2285a49

Browse files
committed
Add support for Unity Editor release
1 parent efdf244 commit 2285a49

File tree

7 files changed

+124
-39
lines changed

7 files changed

+124
-39
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ The standalone release can be used with any injector or loader of your choice, b
5151
3. Create an instance of Unity Explorer with `UnityExplorer.ExplorerStandalone.CreateInstance();`
5252
4. Optionally subscribe to the `ExplorerStandalone.OnLog` event to handle logging if you wish
5353

54+
## Unity Editor
55+
56+
1. Download the [`UnityExplorer.Editor`](https://github.com/sinai-dev/UnityExplorer/releases/latest/download/UnityExplorer.Editor.zip) release.
57+
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.
58+
3. Drag the `Runtime/UnityExplorer` prefab into your scene, or create a GameObject and add the `Explorer Editor Behaviour` script to it.
59+
5460
# Common issues and solutions
5561

5662
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.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#if STANDALONE
2+
using System;
3+
using System.Collections.Generic;
4+
using System.IO;
5+
using System.Linq;
6+
using System.Reflection;
7+
using System.Text;
8+
using UnityEngine;
9+
10+
namespace UnityExplorer.Loader.Standalone
11+
{
12+
public class ExplorerEditorBehaviour : MonoBehaviour
13+
{
14+
internal void Awake()
15+
{
16+
ExplorerEditorLoader.Initialize();
17+
DontDestroyOnLoad(this);
18+
this.gameObject.hideFlags = HideFlags.HideAndDontSave;
19+
}
20+
21+
internal void OnDestroy()
22+
{
23+
OnApplicationQuit();
24+
}
25+
26+
internal void OnApplicationQuit()
27+
{
28+
if (UI.UIManager.UIRoot)
29+
Destroy(UI.UIManager.UIRoot.transform.root.gameObject);
30+
}
31+
}
32+
}
33+
#endif
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#if STANDALONE
2+
using System;
3+
using System.Collections.Generic;
4+
using System.IO;
5+
using System.Linq;
6+
using System.Text;
7+
using UnityEngine;
8+
9+
namespace UnityExplorer.Loader.Standalone
10+
{
11+
public class ExplorerEditorLoader : ExplorerStandalone
12+
{
13+
public static void Initialize()
14+
{
15+
Instance = new ExplorerEditorLoader();
16+
OnLog += LogHandler;
17+
Instance.configHandler = new StandaloneConfigHandler();
18+
19+
ExplorerCore.Init(Instance);
20+
}
21+
22+
static void LogHandler(string message, LogType logType)
23+
{
24+
switch (logType)
25+
{
26+
case LogType.Assert: Debug.LogError(message); break;
27+
case LogType.Error: Debug.LogError(message); break;
28+
case LogType.Exception: Debug.LogError(message); break;
29+
case LogType.Log: Debug.Log(message); break;
30+
case LogType.Warning: Debug.LogWarning(message); break;
31+
}
32+
}
33+
34+
protected override void CheckExplorerFolder()
35+
{
36+
if (explorerFolder == null)
37+
explorerFolder = Path.Combine(Application.dataPath, "UnityExplorer~");
38+
}
39+
}
40+
}
41+
#endif

src/Loader/Standalone/ExplorerStandalone.cs

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
using System.Reflection;
66
using UnityEngine;
77
using UnityExplorer.Config;
8-
using UnityExplorer.Loader.STANDALONE;
98
using UnityEngine.EventSystems;
109
using UniverseLib.Input;
10+
using UnityExplorer.Loader.Standalone;
1111
#if CPP
1212
using UnhollowerRuntimeLib;
1313
#endif
@@ -16,6 +16,33 @@ namespace UnityExplorer
1616
{
1717
public class ExplorerStandalone : IExplorerLoader
1818
{
19+
public static ExplorerStandalone Instance { get; protected set; }
20+
21+
/// <summary>
22+
/// Invoked whenever Explorer logs something. Subscribe to this to handle logging.
23+
/// </summary>
24+
public static event Action<string, LogType> OnLog;
25+
26+
public string UnhollowedModulesFolder => unhollowedPath;
27+
private string unhollowedPath;
28+
29+
public ConfigHandler ConfigHandler => configHandler;
30+
internal StandaloneConfigHandler configHandler;
31+
32+
public string ExplorerFolder
33+
{
34+
get
35+
{
36+
CheckExplorerFolder();
37+
return explorerFolder;
38+
}
39+
}
40+
protected static string explorerFolder;
41+
42+
Action<object> IExplorerLoader.OnLogMessage => (object log) => { OnLog?.Invoke(log?.ToString() ?? "", LogType.Log); };
43+
Action<object> IExplorerLoader.OnLogWarning => (object log) => { OnLog?.Invoke(log?.ToString() ?? "", LogType.Warning); };
44+
Action<object> IExplorerLoader.OnLogError => (object log) => { OnLog?.Invoke(log?.ToString() ?? "", LogType.Error); };
45+
1946
/// <summary>
2047
/// Call this to initialize UnityExplorer without adding a log listener or Unhollowed modules path.
2148
/// The default Unhollowed path "UnityExplorer\Modules\" will be used.
@@ -50,60 +77,33 @@ public static ExplorerStandalone CreateInstance(Action<string, LogType> logListe
5077
OnLog += logListener;
5178

5279
if (string.IsNullOrEmpty(unhollowedModulesPath) || !Directory.Exists(unhollowedModulesPath))
53-
instance._unhollowedPath = Path.Combine(instance.ExplorerFolder, "Modules");
80+
instance.unhollowedPath = Path.Combine(instance.ExplorerFolder, "Modules");
5481
else
55-
instance._unhollowedPath = unhollowedModulesPath;
82+
instance.unhollowedPath = unhollowedModulesPath;
5683

5784
return instance;
5885
}
5986

60-
public static ExplorerStandalone Instance { get; private set; }
61-
62-
/// <summary>
63-
/// Invoked whenever Explorer logs something. Subscribe to this to handle logging.
64-
/// </summary>
65-
public static event Action<string, LogType> OnLog;
66-
67-
public string UnhollowedModulesFolder => _unhollowedPath;
68-
private string _unhollowedPath;
69-
70-
public ConfigHandler ConfigHandler => _configHandler;
71-
private StandaloneConfigHandler _configHandler;
72-
73-
public string ExplorerFolder
74-
{
75-
get
76-
{
77-
CheckExplorerFolder();
78-
return s_explorerFolder;
79-
}
80-
}
81-
private static string s_explorerFolder;
82-
83-
Action<object> IExplorerLoader.OnLogMessage => (object log) => { OnLog?.Invoke(log?.ToString() ?? "", LogType.Log); };
84-
Action<object> IExplorerLoader.OnLogWarning => (object log) => { OnLog?.Invoke(log?.ToString() ?? "", LogType.Warning); };
85-
Action<object> IExplorerLoader.OnLogError => (object log) => { OnLog?.Invoke(log?.ToString() ?? "", LogType.Error); };
86-
87-
private void Init()
87+
internal void Init()
8888
{
8989
Instance = this;
90-
_configHandler = new StandaloneConfigHandler();
90+
configHandler = new StandaloneConfigHandler();
9191

9292
ExplorerCore.Init(this);
9393
}
9494

95-
private void CheckExplorerFolder()
95+
protected virtual void CheckExplorerFolder()
9696
{
97-
if (s_explorerFolder == null)
97+
if (explorerFolder == null)
9898
{
99-
s_explorerFolder =
99+
explorerFolder =
100100
Path.Combine(
101101
Path.GetDirectoryName(
102102
Uri.UnescapeDataString(new Uri(Assembly.GetExecutingAssembly().CodeBase).AbsolutePath)),
103103
"UnityExplorer");
104104

105-
if (!Directory.Exists(s_explorerFolder))
106-
Directory.CreateDirectory(s_explorerFolder);
105+
if (!Directory.Exists(explorerFolder))
106+
Directory.CreateDirectory(explorerFolder);
107107
}
108108
}
109109
}

src/Loader/Standalone/StandaloneConfigHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
using Tomlet;
1010
using Tomlet.Models;
1111

12-
namespace UnityExplorer.Loader.STANDALONE
12+
namespace UnityExplorer.Loader.Standalone
1313
{
1414
public class StandaloneConfigHandler : ConfigHandler
1515
{

src/UI/DisplayManager.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ public static class DisplayManager
1818
public static int Width => ActiveDisplay.renderingWidth;
1919
public static int Height => ActiveDisplay.renderingHeight;
2020

21-
public static Vector3 MousePosition => Display.RelativeMouseAt(InputManager.MousePosition);
21+
public static Vector3 MousePosition => Application.isEditor
22+
? InputManager.MousePosition
23+
: Display.RelativeMouseAt(InputManager.MousePosition);
24+
2225
public static bool MouseInTargetDisplay => MousePosition.z == ActiveDisplayIndex;
2326

2427
private static Camera canvasCamera;

src/UnityExplorer.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,8 @@
265265
<Compile Include="CacheObject\Views\CacheListEntryCell.cs" />
266266
<Compile Include="CacheObject\Views\CacheMemberCell.cs" />
267267
<Compile Include="CacheObject\Views\CacheObjectCell.cs" />
268+
<Compile Include="Loader\Standalone\Editor\ExplorerEditorBehaviour.cs" />
269+
<Compile Include="Loader\Standalone\Editor\ExplorerEditorLoader.cs" />
268270
<Compile Include="Runtime\UnityCrashPrevention.cs" />
269271
<Compile Include="UI\DisplayManager.cs" />
270272
<Compile Include="UI\Notification.cs" />

0 commit comments

Comments
 (0)