mirror of
https://github.com/sinai-dev/UnityExplorer.git
synced 2025-01-06 01:23:31 +08:00
starting work on a cleanup/rewrite
This commit is contained in:
parent
9665753dc8
commit
9e996816ef
@ -25,7 +25,7 @@ namespace UnityExplorer.Config
|
||||
public KeyCode Main_Menu_Toggle = KeyCode.F7;
|
||||
public bool Force_Unlock_Mouse = true;
|
||||
public int Default_Page_Limit = 25;
|
||||
public string Default_Output_Path = Path.Combine(ExplorerCore.ExplorerFolder, "Output");
|
||||
public string Default_Output_Path = Path.Combine(ExplorerCore.EXPLORER_FOLDER, "Output");
|
||||
public bool Log_Unity_Debug = false;
|
||||
public bool Hide_On_Startup = false;
|
||||
public string Window_Anchors = DEFAULT_WINDOW_ANCHORS;
|
||||
|
@ -7,6 +7,7 @@ using UnityExplorer.Config;
|
||||
using UnityExplorer.Helpers;
|
||||
using UnityExplorer.Input;
|
||||
using UnityExplorer.Inspectors;
|
||||
using UnityExplorer.Runtime;
|
||||
using UnityExplorer.UI;
|
||||
using UnityExplorer.UI.Modules;
|
||||
|
||||
@ -21,17 +22,16 @@ namespace UnityExplorer
|
||||
|
||||
public static ExplorerCore Instance { get; private set; }
|
||||
|
||||
private static IExplorerLoader s_loader;
|
||||
public static IExplorerLoader Loader => s_loader
|
||||
public static IExplorerLoader Loader =>
|
||||
#if ML
|
||||
?? (s_loader = ExplorerMelonMod.Instance);
|
||||
ExplorerMelonMod.Instance;
|
||||
#elif BIE
|
||||
?? (s_loader = ExplorerBepInPlugin.Instance);
|
||||
ExplorerBepInPlugin.Instance;
|
||||
#elif STANDALONE
|
||||
?? (s_loader = ExplorerStandalone.Instance);
|
||||
ExplorerStandalone.Instance;
|
||||
#endif
|
||||
|
||||
public static string ExplorerFolder => Loader.ExplorerFolder;
|
||||
public static string EXPLORER_FOLDER => Loader.ExplorerFolder;
|
||||
|
||||
public ExplorerCore()
|
||||
{
|
||||
@ -43,19 +43,16 @@ namespace UnityExplorer
|
||||
|
||||
Instance = this;
|
||||
|
||||
#if CPP
|
||||
ReflectionHelpers.TryLoadGameModules();
|
||||
#endif
|
||||
RuntimeProvider.Init();
|
||||
|
||||
if (!Directory.Exists(ExplorerFolder))
|
||||
Directory.CreateDirectory(ExplorerFolder);
|
||||
if (!Directory.Exists(EXPLORER_FOLDER))
|
||||
Directory.CreateDirectory(EXPLORER_FOLDER);
|
||||
|
||||
ExplorerConfig.OnLoad();
|
||||
|
||||
InputManager.Init();
|
||||
ForceUnlockCursor.Init();
|
||||
|
||||
SetupEvents();
|
||||
ForceUnlockCursor.Init();
|
||||
|
||||
UIManager.ShowMenu = true;
|
||||
|
||||
@ -72,33 +69,7 @@ namespace UnityExplorer
|
||||
UIManager.Update();
|
||||
}
|
||||
|
||||
private void SetupEvents()
|
||||
{
|
||||
#if CPP
|
||||
try
|
||||
{
|
||||
Application.add_logMessageReceived(new Action<string, string, LogType>(OnUnityLog));
|
||||
|
||||
SceneManager.add_sceneLoaded(new Action<Scene, LoadSceneMode>((Scene a, LoadSceneMode b) => { OnSceneLoaded(); }));
|
||||
SceneManager.add_activeSceneChanged(new Action<Scene, Scene>((Scene a, Scene b) => { OnSceneLoaded(); }));
|
||||
}
|
||||
catch
|
||||
{
|
||||
// exceptions here are non-fatal, just ignore.
|
||||
}
|
||||
#else
|
||||
Application.logMessageReceived += OnUnityLog;
|
||||
SceneManager.sceneLoaded += (Scene a, LoadSceneMode b) => { OnSceneLoaded(); };
|
||||
SceneManager.activeSceneChanged += (Scene a, Scene b) => { OnSceneLoaded(); };
|
||||
#endif
|
||||
}
|
||||
|
||||
internal void OnSceneLoaded()
|
||||
{
|
||||
UIManager.OnSceneChange();
|
||||
}
|
||||
|
||||
private void OnUnityLog(string message, string stackTrace, LogType type)
|
||||
public void OnUnityLog(string message, string stackTrace, LogType type)
|
||||
{
|
||||
if (!DebugConsole.LogUnity)
|
||||
return;
|
||||
|
@ -1,33 +0,0 @@
|
||||
#if CPP
|
||||
using System;
|
||||
using UnityEngine.Events;
|
||||
|
||||
namespace UnityExplorer.Helpers
|
||||
{
|
||||
// Possibly temporary, just so Il2Cpp can do the same style "AddListener" as Mono.
|
||||
// Just saves me having a preprocessor directive for every single AddListener.
|
||||
|
||||
public static class EventHelper
|
||||
{
|
||||
public static void AddListener(this UnityEvent action, Action listener)
|
||||
{
|
||||
action.AddListener(listener);
|
||||
}
|
||||
|
||||
public static void AddListener<T>(this UnityEvent<T> action, Action<T> listener)
|
||||
{
|
||||
action.AddListener(listener);
|
||||
}
|
||||
|
||||
public static void AddListener<T0, T1>(this UnityEvent<T0, T1> action, Action<T0, T1> listener)
|
||||
{
|
||||
action.AddListener(listener);
|
||||
}
|
||||
|
||||
public static void AddListener<T0, T1, T2>(this UnityEvent<T0, T1, T2> action, Action<T0, T1, T2> listener)
|
||||
{
|
||||
action.AddListener(listener);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
@ -35,7 +35,7 @@ namespace UnityExplorer.Inspectors.Reflection
|
||||
else if (typeof(Enum).IsAssignableFrom(type))
|
||||
{
|
||||
// NET 3.5 doesn't have "GetCustomAttribute", gotta use the multiple version.
|
||||
if (type.GetCustomAttributes(typeof(FlagsAttribute), true) is object[] fa && fa.Length > 0)
|
||||
if (type.GetCustomAttributes(typeof(FlagsAttribute), true) is object[] fa && fa.Any())
|
||||
return typeof(InteractiveFlags);
|
||||
else
|
||||
return typeof(InteractiveEnum);
|
||||
|
@ -96,11 +96,11 @@ namespace UnityExplorer.Inspectors
|
||||
}
|
||||
}
|
||||
|
||||
internal void OnSceneChange()
|
||||
{
|
||||
m_sceneDropdown.OnCancel(null);
|
||||
RefreshSceneSelector();
|
||||
}
|
||||
//internal void OnSceneChange()
|
||||
//{
|
||||
// m_sceneDropdown.OnCancel(null);
|
||||
// RefreshSceneSelector();
|
||||
//}
|
||||
|
||||
private void RefreshSceneSelector()
|
||||
{
|
||||
@ -138,8 +138,11 @@ namespace UnityExplorer.Inspectors
|
||||
|
||||
if (anyChange)
|
||||
{
|
||||
m_sceneDropdown.OnCancel(null);
|
||||
m_sceneDropdownText.text = newNames[0];
|
||||
SetTargetScene(newScenes[0]);
|
||||
|
||||
SearchPage.Instance.OnSceneChange();
|
||||
}
|
||||
|
||||
m_currentScenes = newScenes.ToArray();
|
||||
|
@ -30,10 +30,10 @@ namespace UnityExplorer
|
||||
ExplorerCore.Update();
|
||||
}
|
||||
|
||||
public override void OnSceneWasLoaded(int buildIndex, string sceneName)
|
||||
{
|
||||
ExplorerCore.Instance.OnSceneLoaded();
|
||||
}
|
||||
//public override void OnSceneWasLoaded(int buildIndex, string sceneName)
|
||||
//{
|
||||
// ExplorerCore.Instance.OnSceneLoaded();
|
||||
//}
|
||||
}
|
||||
}
|
||||
#endif
|
47
src/Runtime/Il2Cpp/Il2CppProvider.cs
Normal file
47
src/Runtime/Il2Cpp/Il2CppProvider.cs
Normal file
@ -0,0 +1,47 @@
|
||||
#if CPP
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityExplorer.Helpers;
|
||||
|
||||
namespace UnityExplorer.Runtime.Il2Cpp
|
||||
{
|
||||
public class Il2CppProvider : RuntimeProvider
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
ReflectionHelpers.TryLoadGameModules();
|
||||
}
|
||||
|
||||
public override void SetupEvents()
|
||||
{
|
||||
Application.add_logMessageReceived(
|
||||
new Action<string, string, LogType>(ExplorerCore.Instance.OnUnityLog));
|
||||
|
||||
//SceneManager.add_sceneLoaded(
|
||||
// new Action<Scene, LoadSceneMode>(ExplorerCore.Instance.OnSceneLoaded1));
|
||||
|
||||
//SceneManager.add_activeSceneChanged(
|
||||
// new Action<Scene, Scene>(ExplorerCore.Instance.OnSceneLoaded2));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class UnityEventExtensions
|
||||
{
|
||||
public static void AddListener(this UnityEvent action, Action listener)
|
||||
{
|
||||
action.AddListener(listener);
|
||||
}
|
||||
|
||||
public static void AddListener<T>(this UnityEvent<T> action, Action<T> listener)
|
||||
{
|
||||
action.AddListener(listener);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
26
src/Runtime/Mono/MonoProvider.cs
Normal file
26
src/Runtime/Mono/MonoProvider.cs
Normal file
@ -0,0 +1,26 @@
|
||||
#if MONO
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
namespace UnityExplorer.Runtime.Mono
|
||||
{
|
||||
public class MonoProvider : RuntimeProvider
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
}
|
||||
|
||||
public override void SetupEvents()
|
||||
{
|
||||
Application.logMessageReceived += ExplorerCore.Instance.OnUnityLog;
|
||||
//SceneManager.sceneLoaded += ExplorerCore.Instance.OnSceneLoaded1;
|
||||
//SceneManager.activeSceneChanged += ExplorerCore.Instance.OnSceneLoaded2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
35
src/Runtime/RuntimeProvider.cs
Normal file
35
src/Runtime/RuntimeProvider.cs
Normal file
@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace UnityExplorer.Runtime
|
||||
{
|
||||
// Work in progress, this will be used to replace all the "if CPP / if MONO"
|
||||
// pre-processor directives all over the codebase.
|
||||
|
||||
public abstract class RuntimeProvider
|
||||
{
|
||||
public static RuntimeProvider Instance;
|
||||
|
||||
public RuntimeProvider()
|
||||
{
|
||||
Initialize();
|
||||
|
||||
SetupEvents();
|
||||
}
|
||||
|
||||
public static void Init() =>
|
||||
#if CPP
|
||||
Instance = new Il2Cpp.Il2CppProvider();
|
||||
#else
|
||||
Instance = new Mono.MonoProvider();
|
||||
#endif
|
||||
|
||||
|
||||
public abstract void Initialize();
|
||||
|
||||
public abstract void SetupEvents();
|
||||
|
||||
}
|
||||
}
|
@ -198,12 +198,12 @@ namespace UnityExplorer.Tests
|
||||
}
|
||||
}
|
||||
|
||||
public static string TestRefInOutGeneric<T>(ref string arg0, in int arg1, out string arg2) where T : Component
|
||||
{
|
||||
arg2 = "this is arg2";
|
||||
//public static string TestRefInOutGeneric<T>(ref string arg0, in int arg1, out string arg2) where T : Component
|
||||
//{
|
||||
// arg2 = "this is arg2";
|
||||
|
||||
return $"T: '{typeof(T).FullName}', ref arg0: '{arg0}', in arg1: '{arg1}', out arg2: '{arg2}'";
|
||||
}
|
||||
// return $"T: '{typeof(T).FullName}', ref arg0: '{arg0}', in arg1: '{arg1}', out arg2: '{arg2}'";
|
||||
//}
|
||||
|
||||
// test a non-generic dictionary
|
||||
|
||||
|
@ -52,7 +52,7 @@ namespace UnityExplorer.UI.Modules
|
||||
//if (!SaveToDisk)
|
||||
// return;
|
||||
|
||||
var path = ExplorerCore.ExplorerFolder + @"\Logs";
|
||||
var path = ExplorerCore.EXPLORER_FOLDER + @"\Logs";
|
||||
|
||||
if (!Directory.Exists(path))
|
||||
Directory.CreateDirectory(path);
|
||||
|
@ -109,6 +109,9 @@ namespace UnityExplorer.UI.Modules
|
||||
|
||||
private void RefreshResultList()
|
||||
{
|
||||
if (m_resultListPageHandler == null || m_results == null)
|
||||
return;
|
||||
|
||||
m_resultListPageHandler.ListCount = m_results.Length;
|
||||
|
||||
int newCount = 0;
|
||||
|
@ -99,11 +99,11 @@ namespace UnityExplorer.UI
|
||||
ForceUnlockCursor.UpdateCursorControl();
|
||||
}
|
||||
|
||||
public static void OnSceneChange()
|
||||
{
|
||||
SceneExplorer.Instance?.OnSceneChange();
|
||||
SearchPage.Instance?.OnSceneChange();
|
||||
}
|
||||
//public static void OnSceneChange()
|
||||
//{
|
||||
// SceneExplorer.Instance?.OnSceneChange();
|
||||
// SearchPage.Instance?.OnSceneChange();
|
||||
//}
|
||||
|
||||
public static void Update()
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user