mirror of
https://github.com/sinai-dev/UnityExplorer.git
synced 2025-06-23 00:52:31 +08:00
Compare commits
9 Commits
Author | SHA1 | Date | |
---|---|---|---|
c2d9b9b59e | |||
c748be7bcc | |||
09dae6f1d3 | |||
6ca117b070 | |||
113f2fd922 | |||
7443f6500e | |||
92566c2729 | |||
713f87f455 | |||
4241e7e207 |
10
README.md
10
README.md
@ -6,7 +6,7 @@
|
||||
An in-game explorer and a suite of debugging tools for <a href="https://docs.unity3d.com/Manual/IL2CPP.html">IL2CPP</a> and <b>Mono</b> Unity games, to aid with modding development.
|
||||
</p>
|
||||
|
||||
## Releases [](../../releases/latest) []() []()
|
||||
## Releases [](../../releases/latest) [](../../releases) [](../../releases/latest)
|
||||
|
||||
| Mod Loader | IL2CPP | Mono |
|
||||
| ----------- | ------ | ---- |
|
||||
@ -135,10 +135,10 @@ Building the project should be straight-forward, the references are all inside t
|
||||
|
||||
## Acknowledgments
|
||||
|
||||
* [ManlyMarco](https://github.com/ManlyMarco) for [Runtime Unity Editor](https://github.com/ManlyMarco/RuntimeUnityEditor), snippets from the REPL Console were used for UnityExplorer's C# Console.
|
||||
* [denikson](https://github.com/denikson) (aka Horse) for [mcs-unity](https://github.com/denikson/mcs-unity), used as the `Mono.CSharp` reference for the C# Console.
|
||||
* [HerpDerpenstine](https://github.com/HerpDerpinstine) for [MelonCoroutines](https://github.com/LavaGang/MelonLoader/blob/master/MelonLoader.Support.Il2Cpp/MelonCoroutines.cs), they were included for standalone IL2CPP coroutine support.
|
||||
* [InGameCodeEditor](https://assetstore.unity.com/packages/tools/gui/ingame-code-editor-144254) was used as the base for the syntax highlighting for UnityExplorer's C# console (`UnityExplorer.UI.Main.CSConsole.Lexer`).
|
||||
* [ManlyMarco](https://github.com/ManlyMarco) for [Runtime Unity Editor](https://github.com/ManlyMarco/RuntimeUnityEditor) \[[license](THIRDPARTY_LICENSES.md#runtimeunityeditor-license)\], snippets from the REPL Console were used for UnityExplorer's C# Console.
|
||||
* [denikson](https://github.com/denikson) (aka Horse) for [mcs-unity](https://github.com/denikson/mcs-unity) \[no license\], used as the `Mono.CSharp` reference for the C# Console.
|
||||
* [HerpDerpenstine](https://github.com/HerpDerpinstine) for [MelonCoroutines](https://github.com/LavaGang/MelonLoader/blob/6cc958ec23b5e2e8453a73bc2e0d5aa353d4f0d1/MelonLoader.Support.Il2Cpp/MelonCoroutines.cs) \[[license](THIRDPARTY_LICENSES.md#melonloader-license)\], they were included for standalone IL2CPP coroutine support.
|
||||
* [InGameCodeEditor](https://assetstore.unity.com/packages/tools/gui/ingame-code-editor-144254) \[[license](THIRDPARTY_LICENSES.md#ingamecodeeditor-license)\] was used as the base for the syntax highlighting for UnityExplorer's C# console (`UnityExplorer.UI.Main.CSConsole.Lexer`).
|
||||
|
||||
### Disclaimer
|
||||
|
||||
|
1067
THIRDPARTY_LICENSES.md
Normal file
1067
THIRDPARTY_LICENSES.md
Normal file
File diff suppressed because it is too large
Load Diff
@ -7,6 +7,7 @@ using System.Linq;
|
||||
using UnityExplorer.Core.Runtime;
|
||||
using UnityExplorer.UI.Main.CSConsole;
|
||||
using UnityExplorer.UI.Main.Home;
|
||||
using UnityExplorer.UI.Inspectors;
|
||||
|
||||
namespace UnityExplorer.Core.CSharp
|
||||
{
|
||||
|
@ -89,7 +89,7 @@ namespace UnityExplorer.Core.Input
|
||||
|
||||
public static void SetEventSystem()
|
||||
{
|
||||
// temp disabled for new InputSystem
|
||||
// not overriding EventSystem for new InputSystem, dont seem to need to.
|
||||
if (InputManager.CurrentType == InputType.InputSystem)
|
||||
return;
|
||||
|
||||
@ -112,6 +112,7 @@ namespace UnityExplorer.Core.Input
|
||||
|
||||
public static void ReleaseEventSystem()
|
||||
{
|
||||
// not overriding EventSystem for new InputSystem, dont seem to need to.
|
||||
if (InputManager.CurrentType == InputType.InputSystem)
|
||||
return;
|
||||
|
||||
|
@ -15,8 +15,6 @@ namespace UnityExplorer.Core.Input
|
||||
|
||||
BaseInputModule UIModule { get; }
|
||||
|
||||
PointerEventData InputPointerEvent { get; }
|
||||
|
||||
void AddUIInputModule();
|
||||
void ActivateModule();
|
||||
}
|
||||
|
@ -27,7 +27,6 @@ namespace UnityExplorer.Core.Input
|
||||
public static bool GetMouseButton(int btn) => m_inputModule.GetMouseButton(btn);
|
||||
|
||||
public static BaseInputModule UIInput => m_inputModule.UIModule;
|
||||
public static PointerEventData InputPointerEvent => m_inputModule.InputPointerEvent;
|
||||
|
||||
public static void ActivateUIModule() => m_inputModule.ActivateModule();
|
||||
|
||||
@ -52,7 +51,7 @@ namespace UnityExplorer.Core.Input
|
||||
|
||||
if (m_inputModule == null)
|
||||
{
|
||||
ExplorerCore.LogWarning("Could not find any Input module!");
|
||||
ExplorerCore.LogWarning("Could not find any Input Module Type!");
|
||||
m_inputModule = new NoInput();
|
||||
CurrentType = InputType.None;
|
||||
}
|
||||
|
@ -5,6 +5,10 @@ using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityExplorer.UI;
|
||||
using System.Collections.Generic;
|
||||
using UnityExplorer.UI.Inspectors;
|
||||
#if CPP
|
||||
using UnhollowerRuntimeLib;
|
||||
#endif
|
||||
|
||||
namespace UnityExplorer.Core.Input
|
||||
{
|
||||
@ -131,41 +135,74 @@ namespace UnityExplorer.Core.Input
|
||||
|
||||
// UI Input
|
||||
|
||||
//public Type TInputSystemUIInputModule
|
||||
// => m_tUIInputModule
|
||||
// ?? (m_tUIInputModule = ReflectionHelpers.GetTypeByName("UnityEngine.InputSystem.UI.InputSystemUIInputModule"));
|
||||
//internal Type m_tUIInputModule;
|
||||
public Type TInputSystemUIInputModule
|
||||
=> m_tUIInputModule
|
||||
?? (m_tUIInputModule = ReflectionUtility.GetTypeByName("UnityEngine.InputSystem.UI.InputSystemUIInputModule"));
|
||||
internal Type m_tUIInputModule;
|
||||
|
||||
public BaseInputModule UIModule => null; // m_newInputModule;
|
||||
//internal BaseInputModule m_newInputModule;
|
||||
|
||||
public PointerEventData InputPointerEvent => null;
|
||||
public BaseInputModule UIModule => m_newInputModule;
|
||||
internal BaseInputModule m_newInputModule;
|
||||
|
||||
public void AddUIInputModule()
|
||||
{
|
||||
// if (TInputSystemUIInputModule != null)
|
||||
// {
|
||||
//#if CPP
|
||||
// // m_newInputModule = UIManager.CanvasRoot.AddComponent(Il2CppType.From(TInputSystemUIInputModule)).TryCast<BaseInputModule>();
|
||||
//#else
|
||||
// m_newInputModule = (BaseInputModule)UIManager.CanvasRoot.AddComponent(TInputSystemUIInputModule);
|
||||
//#endif
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// ExplorerCore.LogWarning("New input system: Could not find type by name 'UnityEngine.InputSystem.UI.InputSystemUIInputModule'");
|
||||
// }
|
||||
if (TInputSystemUIInputModule == null)
|
||||
{
|
||||
ExplorerCore.LogWarning("Unable to find UI Input Module Type, Input will not work!");
|
||||
return;
|
||||
}
|
||||
|
||||
var assetType = ReflectionUtility.GetTypeByName("UnityEngine.InputSystem.InputActionAsset");
|
||||
#if CPP
|
||||
m_newInputModule = UIManager.CanvasRoot.AddComponent(Il2CppType.From(TInputSystemUIInputModule)).TryCast<BaseInputModule>();
|
||||
var asset = ScriptableObject.CreateInstance(Il2CppType.From(assetType));
|
||||
#else
|
||||
m_newInputModule = (BaseInputModule)UIManager.CanvasRoot.AddComponent(TInputSystemUIInputModule);
|
||||
var asset = ScriptableObject.CreateInstance(assetType);
|
||||
#endif
|
||||
inputExtensions = ReflectionUtility.GetTypeByName("UnityEngine.InputSystem.InputActionSetupExtensions");
|
||||
|
||||
var addMap = inputExtensions.GetMethod("AddActionMap", new Type[] { assetType, typeof(string) });
|
||||
var map = addMap.Invoke(null, new object[] { asset, "UI" });
|
||||
|
||||
CreateAction(map, "point", new[] { "<Mouse>/position" }, "point");
|
||||
CreateAction(map, "click", new[] { "<Mouse>/leftButton" }, "leftClick");
|
||||
CreateAction(map, "rightClick", new[] { "<Mouse>/rightButton" }, "rightClick");
|
||||
CreateAction(map, "scrollWheel", new[] { "<Mouse>/scroll" }, "scrollWheel");
|
||||
|
||||
UI_Enable = map.GetType().GetMethod("Enable");
|
||||
UI_Enable.Invoke(map, new object[0]);
|
||||
UI_ActionMap = map;
|
||||
}
|
||||
|
||||
private Type inputExtensions;
|
||||
private object UI_ActionMap;
|
||||
private MethodInfo UI_Enable;
|
||||
|
||||
private void CreateAction(object map, string actionName, string[] bindings, string propertyName)
|
||||
{
|
||||
var addAction = inputExtensions.GetMethod("AddAction");
|
||||
var pointAction = addAction.Invoke(null, new object[] { map, actionName, default, null, null, null, null, null });
|
||||
|
||||
var inputActionType = pointAction.GetType();
|
||||
var addBinding = inputExtensions.GetMethod("AddBinding",
|
||||
new Type[] { inputActionType, typeof(string), typeof(string), typeof(string), typeof(string) });
|
||||
|
||||
foreach (string binding in bindings)
|
||||
addBinding.Invoke(null, new object[] { pointAction, binding, null, null, null });
|
||||
|
||||
var inputRef = ReflectionUtility.GetTypeByName("UnityEngine.InputSystem.InputActionReference")
|
||||
.GetMethod("Create")
|
||||
.Invoke(null, new object[] { pointAction });
|
||||
|
||||
TInputSystemUIInputModule
|
||||
.GetProperty(propertyName)
|
||||
.SetValue(m_newInputModule, inputRef, null);
|
||||
}
|
||||
|
||||
public void ActivateModule()
|
||||
{
|
||||
//#if CPP
|
||||
// // m_newInputModule.ActivateModule();
|
||||
//#else
|
||||
// m_newInputModule.ActivateModule();
|
||||
//#endif
|
||||
|
||||
|
||||
m_newInputModule.ActivateModule();
|
||||
UI_Enable.Invoke(UI_ActionMap, new object[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -44,13 +44,6 @@ namespace UnityExplorer.Core.Input
|
||||
public BaseInputModule UIModule => m_inputModule;
|
||||
internal StandaloneInputModule m_inputModule;
|
||||
|
||||
public PointerEventData InputPointerEvent =>
|
||||
#if CPP
|
||||
m_inputModule.m_InputPointerEvent;
|
||||
#else
|
||||
null;
|
||||
#endif
|
||||
|
||||
public void AddUIInputModule()
|
||||
{
|
||||
m_inputModule = UIManager.CanvasRoot.gameObject.AddComponent<StandaloneInputModule>();
|
||||
|
@ -16,7 +16,6 @@ namespace UnityExplorer.Core.Input
|
||||
public bool GetMouseButtonDown(int btn) => false;
|
||||
|
||||
public BaseInputModule UIModule => null;
|
||||
public PointerEventData InputPointerEvent => null;
|
||||
public void ActivateModule() { }
|
||||
public void AddUIInputModule() { }
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ using System.Reflection;
|
||||
using BF = System.Reflection.BindingFlags;
|
||||
using UnityExplorer.Core.Runtime;
|
||||
|
||||
namespace UnityExplorer.Core
|
||||
namespace UnityExplorer
|
||||
{
|
||||
public static class ReflectionUtility
|
||||
{
|
||||
@ -18,7 +18,7 @@ namespace UnityExplorer.Core
|
||||
/// </summary>
|
||||
/// <param name="obj">The object to get the true Type for.</param>
|
||||
/// <returns>The most accurate Type of the object which could be identified.</returns>
|
||||
public static Type GetType(this object obj)
|
||||
public static Type GetActualType(this object obj)
|
||||
{
|
||||
if (obj == null)
|
||||
return null;
|
||||
@ -32,7 +32,7 @@ namespace UnityExplorer.Core
|
||||
/// <param name="obj">The object to cast</param>
|
||||
/// <returns>The object, cast to the underlying Type if possible, otherwise the original object.</returns>
|
||||
public static object Cast(this object obj)
|
||||
=> ReflectionProvider.Instance.Cast(obj, GetType(obj));
|
||||
=> ReflectionProvider.Instance.Cast(obj, GetActualType(obj));
|
||||
|
||||
/// <summary>
|
||||
/// Cast an object to a Type, if possible.
|
||||
@ -105,7 +105,7 @@ namespace UnityExplorer.Core
|
||||
/// <summary>
|
||||
/// Get all base types of the provided Type, including itself.
|
||||
/// </summary>
|
||||
public static Type[] GetAllBaseTypes(this object obj) => GetAllBaseTypes(GetType(obj));
|
||||
public static Type[] GetAllBaseTypes(this object obj) => GetAllBaseTypes(GetActualType(obj));
|
||||
|
||||
/// <summary>
|
||||
/// Get all base types of the provided Type, including itself.
|
||||
|
@ -154,21 +154,24 @@ namespace UnityExplorer.Core.Runtime.Il2Cpp
|
||||
/// <returns>The object, as the type (or a normal C# object) if successful or the input value if not.</returns>
|
||||
public static object Il2CppCast(object obj, Type castTo)
|
||||
{
|
||||
if (!(obj is Il2CppSystem.Object ilObj))
|
||||
if (!(obj is Il2CppSystem.Object cppObj))
|
||||
return obj;
|
||||
|
||||
if (!Il2CppTypeNotNull(castTo, out IntPtr castToPtr))
|
||||
return obj;
|
||||
|
||||
IntPtr castFromPtr = il2cpp_object_get_class(ilObj.Pointer);
|
||||
IntPtr castFromPtr = il2cpp_object_get_class(cppObj.Pointer);
|
||||
|
||||
if (!il2cpp_class_is_assignable_from(castToPtr, castFromPtr))
|
||||
return obj;
|
||||
return null;
|
||||
|
||||
if (RuntimeSpecificsStore.IsInjected(castToPtr))
|
||||
return UnhollowerBaseLib.Runtime.ClassInjectorBase.GetMonoObjectFromIl2CppPointer(ilObj.Pointer);
|
||||
return UnhollowerBaseLib.Runtime.ClassInjectorBase.GetMonoObjectFromIl2CppPointer(cppObj.Pointer);
|
||||
|
||||
return Activator.CreateInstance(castTo, ilObj.Pointer);
|
||||
if (castTo == typeof(string))
|
||||
return cppObj.ToString();
|
||||
|
||||
return Activator.CreateInstance(castTo, cppObj.Pointer);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -319,6 +322,14 @@ namespace UnityExplorer.Core.Runtime.Il2Cpp
|
||||
return false;
|
||||
}
|
||||
|
||||
public override void BoxStringToType(ref object value, Type castTo)
|
||||
{
|
||||
if (castTo == typeof(Il2CppSystem.String))
|
||||
value = (Il2CppSystem.String)(value as string);
|
||||
else
|
||||
value = (Il2CppSystem.Object)(value as string);
|
||||
}
|
||||
|
||||
// ~~~~~~~~~~ not used ~~~~~~~~~~~~
|
||||
|
||||
// cached il2cpp unbox methods
|
||||
|
@ -27,6 +27,9 @@ namespace UnityExplorer.Core.Runtime.Mono
|
||||
|
||||
public override string ProcessTypeNameInString(Type type, string theString, ref string typeName)
|
||||
=> theString;
|
||||
|
||||
// not necessary
|
||||
public override void BoxStringToType(ref object _string, Type castTo) { }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -25,5 +25,7 @@ namespace UnityExplorer.Core.Runtime
|
||||
public abstract string ProcessTypeNameInString(Type type, string theString, ref string typeName);
|
||||
|
||||
public abstract bool LoadModule(string module);
|
||||
|
||||
public abstract void BoxStringToType(ref object _string, Type castTo);
|
||||
}
|
||||
}
|
||||
|
29
src/Core/TestClass.cs
Normal file
29
src/Core/TestClass.cs
Normal file
@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace UnityExplorer
|
||||
{
|
||||
public static class TestClass
|
||||
{
|
||||
public static UI.Main.PanelDragger.ResizeTypes flags = UI.Main.PanelDragger.ResizeTypes.NONE;
|
||||
|
||||
#if CPP
|
||||
public static string testStringOne = "Test";
|
||||
public static Il2CppSystem.Object testStringTwo = "string boxed as cpp object";
|
||||
public static Il2CppSystem.String testStringThree = "string boxed as cpp string";
|
||||
public static string nullString = null;
|
||||
|
||||
public static Il2CppSystem.Collections.Hashtable testHashset;
|
||||
|
||||
static TestClass()
|
||||
{
|
||||
testHashset = new Il2CppSystem.Collections.Hashtable();
|
||||
testHashset.Add("key1", "itemOne");
|
||||
testHashset.Add("key2", "itemTwo");
|
||||
testHashset.Add("key3", "itemThree");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
@ -5,6 +5,7 @@ using UnityExplorer.Core.Config;
|
||||
using UnityExplorer.Core.Input;
|
||||
using UnityExplorer.Core.Runtime;
|
||||
using UnityExplorer.UI;
|
||||
using UnityExplorer.UI.Inspectors;
|
||||
using UnityExplorer.UI.Main;
|
||||
|
||||
namespace UnityExplorer
|
||||
@ -12,7 +13,7 @@ namespace UnityExplorer
|
||||
public class ExplorerCore
|
||||
{
|
||||
public const string NAME = "UnityExplorer";
|
||||
public const string VERSION = "3.3.4";
|
||||
public const string VERSION = "3.3.8";
|
||||
public const string AUTHOR = "Sinai";
|
||||
public const string GUID = "com.sinai.unityexplorer";
|
||||
|
||||
@ -46,6 +47,8 @@ namespace UnityExplorer
|
||||
UIManager.Init();
|
||||
|
||||
Log($"{NAME} {VERSION} initialized.");
|
||||
|
||||
//InspectorManager.Instance.Inspect(typeof(TestClass));
|
||||
}
|
||||
|
||||
public static void Update()
|
||||
|
@ -21,8 +21,12 @@ namespace UnityExplorer.Loader.ML
|
||||
{
|
||||
prefCategory = MelonPreferences.CreateCategory(CTG_NAME, $"{CTG_NAME} Settings");
|
||||
|
||||
try
|
||||
{
|
||||
MelonPreferences.Mapper.RegisterMapper(KeycodeReader, KeycodeWriter);
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
public override void LoadConfig()
|
||||
{
|
||||
|
@ -10,7 +10,7 @@ using UnityExplorer.Core.Runtime;
|
||||
using UnityExplorer.Core;
|
||||
using UnityExplorer.UI.Utility;
|
||||
using UnityExplorer.UI.InteractiveValues;
|
||||
using UnityExplorer.UI.Main.Home.Inspectors.Reflection;
|
||||
using UnityExplorer.UI.Inspectors.Reflection;
|
||||
|
||||
namespace UnityExplorer.UI.CacheObject
|
||||
{
|
||||
@ -86,7 +86,7 @@ namespace UnityExplorer.UI.CacheObject
|
||||
{
|
||||
try
|
||||
{
|
||||
Type baseType = ReflectionUtility.GetType(IValue.Value) ?? FallbackType;
|
||||
Type baseType = ReflectionUtility.GetActualType(IValue.Value) ?? FallbackType;
|
||||
|
||||
if (!ReflectionProvider.Instance.IsReflectionSupported(baseType))
|
||||
throw new Exception("Type not supported with reflection");
|
||||
@ -94,7 +94,7 @@ namespace UnityExplorer.UI.CacheObject
|
||||
UpdateReflection();
|
||||
|
||||
if (IValue.Value != null)
|
||||
IValue.Value = IValue.Value.Cast(ReflectionUtility.GetType(IValue.Value));
|
||||
IValue.Value = IValue.Value.Cast(ReflectionUtility.GetActualType(IValue.Value));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
@ -55,7 +55,7 @@ namespace UnityExplorer.UI.CacheObject
|
||||
// if the type has changed fundamentally, make a new interactivevalue for it
|
||||
var type = value == null
|
||||
? FallbackType
|
||||
: ReflectionUtility.GetType(value);
|
||||
: ReflectionUtility.GetActualType(value);
|
||||
|
||||
var ivalueType = InteractiveValue.GetIValueForType(type);
|
||||
|
||||
|
@ -7,7 +7,7 @@ using UnityEngine.UI;
|
||||
using UnityExplorer.Core.Runtime;
|
||||
using UnityExplorer.UI.Utility;
|
||||
|
||||
namespace UnityExplorer.UI.Main.Home.Inspectors.GameObjects
|
||||
namespace UnityExplorer.UI.Inspectors.GameObjects
|
||||
{
|
||||
public class ChildList
|
||||
{
|
@ -8,7 +8,7 @@ using UnityExplorer.Core;
|
||||
using UnityExplorer.Core.Runtime;
|
||||
using UnityExplorer.UI.Utility;
|
||||
|
||||
namespace UnityExplorer.UI.Main.Home.Inspectors.GameObjects
|
||||
namespace UnityExplorer.UI.Inspectors.GameObjects
|
||||
{
|
||||
public class ComponentList
|
||||
{
|
||||
@ -75,7 +75,7 @@ namespace UnityExplorer.UI.Main.Home.Inspectors.GameObjects
|
||||
|
||||
var text = s_compListTexts[i];
|
||||
|
||||
text.text = SignatureHighlighter.ParseFullSyntax(ReflectionUtility.GetType(comp), true);
|
||||
text.text = SignatureHighlighter.ParseFullSyntax(ReflectionUtility.GetActualType(comp), true);
|
||||
|
||||
var toggle = s_compToggles[i];
|
||||
#if CPP
|
@ -8,7 +8,7 @@ using UnityExplorer.Core.Input;
|
||||
using UnityExplorer.Core.Runtime;
|
||||
using UnityExplorer.Core.Unity;
|
||||
|
||||
namespace UnityExplorer.UI.Main.Home.Inspectors.GameObjects
|
||||
namespace UnityExplorer.UI.Inspectors.GameObjects
|
||||
{
|
||||
public class GameObjectControls
|
||||
{
|
@ -7,7 +7,7 @@ using UnityEngine.UI;
|
||||
using UnityExplorer.Core.Runtime;
|
||||
using UnityExplorer.Core.Unity;
|
||||
|
||||
namespace UnityExplorer.UI.Main.Home.Inspectors.GameObjects
|
||||
namespace UnityExplorer.UI.Inspectors.GameObjects
|
||||
{
|
||||
public class GameObjectInspector : InspectorBase
|
||||
{
|
@ -11,6 +11,7 @@ using UnityExplorer.Core.Input;
|
||||
using UnityExplorer.Core.Runtime;
|
||||
using UnityExplorer.UI;
|
||||
using UnityExplorer.UI.Main;
|
||||
using UnityExplorer.UI.Inspectors;
|
||||
|
||||
namespace UnityExplorer.UI.Main.Home
|
||||
{
|
@ -3,7 +3,7 @@ using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityExplorer.Core.Unity;
|
||||
|
||||
namespace UnityExplorer.UI.Main.Home.Inspectors
|
||||
namespace UnityExplorer.UI.Inspectors
|
||||
{
|
||||
public abstract class InspectorBase
|
||||
{
|
@ -9,12 +9,11 @@ using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UI;
|
||||
using UnityExplorer.Core.Runtime;
|
||||
using UnityExplorer.UI.Main.Home;
|
||||
using UnityExplorer.UI.Main.Home.Inspectors;
|
||||
using UnityExplorer.UI.CacheObject;
|
||||
using UnityExplorer.UI.Main.Home.Inspectors.GameObjects;
|
||||
using UnityExplorer.UI.Main.Home.Inspectors.Reflection;
|
||||
using UnityExplorer.UI.Inspectors.GameObjects;
|
||||
using UnityExplorer.UI.Inspectors.Reflection;
|
||||
|
||||
namespace UnityExplorer.UI.Main.Home
|
||||
namespace UnityExplorer.UI.Inspectors
|
||||
{
|
||||
public class InspectorManager
|
||||
{
|
@ -9,7 +9,7 @@ using UnityExplorer.Core;
|
||||
using UnityExplorer.Core.Config;
|
||||
using UnityExplorer.Core.Runtime;
|
||||
|
||||
namespace UnityExplorer.UI.Main.Home.Inspectors.Reflection
|
||||
namespace UnityExplorer.UI.Inspectors.Reflection
|
||||
{
|
||||
public enum MemberScopes
|
||||
{
|
@ -9,9 +9,11 @@ using UnityExplorer.Core;
|
||||
using UnityExplorer.Core.Config;
|
||||
using UnityExplorer.Core.Runtime;
|
||||
using UnityExplorer.UI.CacheObject;
|
||||
using UnityExplorer.UI.Main;
|
||||
using UnityExplorer.UI.Main.Home;
|
||||
using UnityExplorer.UI.Utility;
|
||||
|
||||
namespace UnityExplorer.UI.Main.Home.Inspectors.Reflection
|
||||
namespace UnityExplorer.UI.Inspectors.Reflection
|
||||
{
|
||||
public class ReflectionInspector : InspectorBase
|
||||
{
|
||||
@ -78,7 +80,7 @@ namespace UnityExplorer.UI.Main.Home.Inspectors.Reflection
|
||||
if (this is StaticInspector)
|
||||
m_targetType = target as Type;
|
||||
else
|
||||
m_targetType = ReflectionUtility.GetType(target);
|
||||
m_targetType = ReflectionUtility.GetActualType(target);
|
||||
|
||||
m_targetTypeShortName = SignatureHighlighter.ParseFullSyntax(m_targetType, false);
|
||||
|
@ -3,7 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace UnityExplorer.UI.Main.Home.Inspectors.Reflection
|
||||
namespace UnityExplorer.UI.Inspectors.Reflection
|
||||
{
|
||||
public class StaticInspector : ReflectionInspector
|
||||
{
|
@ -218,32 +218,37 @@ namespace UnityExplorer.UI.InteractiveValues
|
||||
|
||||
private IDictionary EnumerateWithReflection()
|
||||
{
|
||||
var valueType = ReflectionUtility.GetType(Value);
|
||||
var valueType = ReflectionUtility.GetActualType(Value);
|
||||
|
||||
// get keys and values
|
||||
var keys = valueType.GetProperty("Keys").GetValue(Value, null);
|
||||
var values = valueType.GetProperty("Values").GetValue(Value, null);
|
||||
|
||||
// create lists to hold them
|
||||
var keyList = new List<object>();
|
||||
var valueList = new List<object>();
|
||||
|
||||
// store entries with reflection
|
||||
EnumerateCollection(keys, keyList);
|
||||
EnumerateCollection(values, valueList);
|
||||
var hashtable = Value.Cast(typeof(Il2CppSystem.Collections.Hashtable)) as Il2CppSystem.Collections.Hashtable;
|
||||
|
||||
// make actual mono dictionary
|
||||
var dict = (IDictionary)Activator.CreateInstance(typeof(Dictionary<,>)
|
||||
.MakeGenericType(m_typeOfKeys, m_typeofValues));
|
||||
if (hashtable != null)
|
||||
{
|
||||
EnumerateCppHashtable(hashtable, keyList, valueList);
|
||||
}
|
||||
else
|
||||
{
|
||||
var keys = valueType.GetProperty("Keys").GetValue(Value, null);
|
||||
var values = valueType.GetProperty("Values").GetValue(Value, null);
|
||||
|
||||
EnumerateCppIDictionary(keys, keyList);
|
||||
EnumerateCppIDictionary(values, valueList);
|
||||
}
|
||||
|
||||
var dict = Activator.CreateInstance(typeof(Dictionary<,>)
|
||||
.MakeGenericType(m_typeOfKeys, m_typeofValues))
|
||||
as IDictionary;
|
||||
|
||||
// finally iterate into mono dictionary
|
||||
for (int i = 0; i < keyList.Count; i++)
|
||||
dict.Add(keyList[i], valueList[i]);
|
||||
|
||||
return dict;
|
||||
}
|
||||
|
||||
private void EnumerateCollection(object collection, List<object> list)
|
||||
private void EnumerateCppIDictionary(object collection, List<object> list)
|
||||
{
|
||||
// invoke GetEnumerator
|
||||
var enumerator = collection.GetType().GetMethod("GetEnumerator").Invoke(collection, null);
|
||||
@ -258,6 +263,18 @@ namespace UnityExplorer.UI.InteractiveValues
|
||||
list.Add(current.GetValue(enumerator, null));
|
||||
}
|
||||
}
|
||||
|
||||
private void EnumerateCppHashtable(Il2CppSystem.Collections.Hashtable hashtable, List<object> keys, List<object> values)
|
||||
{
|
||||
for (int i = 0; i < hashtable.buckets.Count; i++)
|
||||
{
|
||||
var bucket = hashtable.buckets[i];
|
||||
if (bucket == null || bucket.key == null)
|
||||
continue;
|
||||
keys.Add(bucket.key);
|
||||
values.Add(bucket.val);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#endregion
|
||||
|
@ -94,7 +94,7 @@ namespace UnityExplorer.UI.InteractiveValues
|
||||
{
|
||||
base.RefreshUIForValue();
|
||||
|
||||
if (m_subContentConstructed)
|
||||
if (m_subContentConstructed && !(this is InteractiveFlags))
|
||||
{
|
||||
m_dropdownText.text = Value?.ToString() ?? "<no value set>";
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ using System.Reflection;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityExplorer.Core;
|
||||
using UnityExplorer.Core.Config;
|
||||
using UnityExplorer.Core.Unity;
|
||||
using UnityExplorer.UI;
|
||||
@ -38,11 +39,11 @@ namespace UnityExplorer.UI.InteractiveValues
|
||||
|
||||
internal IEnumerable RefIEnumerable;
|
||||
internal IList RefIList;
|
||||
#if CPP
|
||||
internal Il2CppSystem.Collections.ICollection CppICollection;
|
||||
#else
|
||||
internal ICollection CppICollection = null;
|
||||
#endif
|
||||
//#if CPP
|
||||
// internal object CppICollection;
|
||||
//#else
|
||||
// internal object CppICollection = null;
|
||||
//#endif
|
||||
|
||||
internal readonly Type m_baseEntryType;
|
||||
|
||||
@ -55,13 +56,17 @@ namespace UnityExplorer.UI.InteractiveValues
|
||||
RefIEnumerable = Value as IEnumerable;
|
||||
RefIList = Value as IList;
|
||||
|
||||
#if CPP
|
||||
if (Value != null && RefIList == null)
|
||||
{
|
||||
try { CppICollection = (Value as Il2CppSystem.Object).TryCast<Il2CppSystem.Collections.ICollection>(); }
|
||||
catch { }
|
||||
}
|
||||
#endif
|
||||
//#if CPP
|
||||
// if (Value != null && RefIList == null)
|
||||
// {
|
||||
// try
|
||||
// {
|
||||
// var type = typeof(Il2CppSystem.Collections.ICollection).MakeGenericType(this.m_baseEntryType);
|
||||
// CppICollection = (Value as Il2CppSystem.Object).Cast(type);
|
||||
// }
|
||||
// catch { }
|
||||
// }
|
||||
//#endif
|
||||
|
||||
if (m_subContentParent.activeSelf)
|
||||
{
|
||||
@ -91,8 +96,8 @@ namespace UnityExplorer.UI.InteractiveValues
|
||||
if (Value != null)
|
||||
{
|
||||
string count = "?";
|
||||
if (m_recacheWanted && (RefIList != null || CppICollection != null))
|
||||
count = RefIList?.Count.ToString() ?? CppICollection.Count.ToString();
|
||||
if (m_recacheWanted && RefIList != null)// || CppICollection != null))
|
||||
count = RefIList.Count.ToString();// ?? CppICollection.Count.ToString();
|
||||
else if (!m_recacheWanted)
|
||||
count = m_entries.Count.ToString();
|
||||
|
||||
|
@ -26,8 +26,6 @@ namespace UnityExplorer.UI.InteractiveValues
|
||||
|
||||
public override void OnValueUpdated()
|
||||
{
|
||||
base.OnValueUpdated();
|
||||
|
||||
if (Owner.CanWrite)
|
||||
{
|
||||
var enabledNames = new List<string>();
|
||||
@ -37,10 +35,10 @@ namespace UnityExplorer.UI.InteractiveValues
|
||||
enabledNames.AddRange(enabled);
|
||||
|
||||
for (int i = 0; i < m_values.Length; i++)
|
||||
{
|
||||
m_enabledFlags[i] = enabledNames.Contains(m_values[i].Value);
|
||||
}
|
||||
}
|
||||
|
||||
base.OnValueUpdated();
|
||||
}
|
||||
|
||||
public override void RefreshUIForValue()
|
||||
@ -48,6 +46,8 @@ namespace UnityExplorer.UI.InteractiveValues
|
||||
GetDefaultLabel();
|
||||
m_baseLabel.text = DefaultLabel;
|
||||
|
||||
base.RefreshUIForValue();
|
||||
|
||||
if (m_subContentConstructed)
|
||||
{
|
||||
for (int i = 0; i < m_values.Length; i++)
|
||||
|
198
src/UI/InteractiveValues/InteractiveFloatStruct.cs
Normal file
198
src/UI/InteractiveValues/InteractiveFloatStruct.cs
Normal file
@ -0,0 +1,198 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using System.Reflection;
|
||||
|
||||
namespace UnityExplorer.UI.InteractiveValues
|
||||
{
|
||||
// Class for supporting any "float struct" (ie Vector, Rect, etc).
|
||||
// Supports any struct where all the public instance fields are floats (or types assignable to float)
|
||||
|
||||
public class StructInfo
|
||||
{
|
||||
public string[] FieldNames { get; }
|
||||
private readonly FieldInfo[] m_fields;
|
||||
|
||||
public StructInfo(Type type)
|
||||
{
|
||||
m_fields = type.GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public)
|
||||
.Where(it => !it.IsLiteral)
|
||||
.ToArray();
|
||||
|
||||
FieldNames = m_fields.Select(it => it.Name)
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
public object SetValue(ref object instance, int fieldIndex, float val)
|
||||
{
|
||||
m_fields[fieldIndex].SetValue(instance, val);
|
||||
return instance;
|
||||
}
|
||||
|
||||
public float GetValue(object instance, int fieldIndex)
|
||||
=> (float)m_fields[fieldIndex].GetValue(instance);
|
||||
|
||||
public void RefreshUI(InputField[] inputs, object instance)
|
||||
{
|
||||
try
|
||||
{
|
||||
for (int i = 0; i < m_fields.Length; i++)
|
||||
{
|
||||
var field = m_fields[i];
|
||||
float val = (float)field.GetValue(instance);
|
||||
inputs[i].text = val.ToString();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ExplorerCore.Log(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class InteractiveFloatStruct : InteractiveValue
|
||||
{
|
||||
private static readonly Dictionary<string, bool> _typeSupportCache = new Dictionary<string, bool>();
|
||||
public static bool IsTypeSupported(Type type)
|
||||
{
|
||||
if (!type.IsValueType)
|
||||
return false;
|
||||
|
||||
if (_typeSupportCache.TryGetValue(type.AssemblyQualifiedName, out bool ret))
|
||||
return ret;
|
||||
|
||||
ret = true;
|
||||
var fields = type.GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
|
||||
foreach (var field in fields)
|
||||
{
|
||||
if (field.IsLiteral)
|
||||
continue;
|
||||
|
||||
if (!typeof(float).IsAssignableFrom(field.FieldType))
|
||||
{
|
||||
ret = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
_typeSupportCache.Add(type.AssemblyQualifiedName, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
//~~~~~~~~~ Instance ~~~~~~~~~~
|
||||
|
||||
public InteractiveFloatStruct(object value, Type valueType) : base(value, valueType) { }
|
||||
|
||||
public override bool HasSubContent => true;
|
||||
public override bool SubContentWanted => true;
|
||||
|
||||
public StructInfo StructInfo;
|
||||
|
||||
public override void RefreshUIForValue()
|
||||
{
|
||||
InitializeStructInfo();
|
||||
|
||||
base.RefreshUIForValue();
|
||||
|
||||
if (m_subContentConstructed)
|
||||
StructInfo.RefreshUI(m_inputs, this.Value);
|
||||
}
|
||||
|
||||
internal override void OnToggleSubcontent(bool toggle)
|
||||
{
|
||||
InitializeStructInfo();
|
||||
|
||||
base.OnToggleSubcontent(toggle);
|
||||
|
||||
StructInfo.RefreshUI(m_inputs, this.Value);
|
||||
}
|
||||
|
||||
internal Type m_lastStructType;
|
||||
|
||||
internal void InitializeStructInfo()
|
||||
{
|
||||
var type = Value?.GetType() ?? FallbackType;
|
||||
|
||||
if (StructInfo != null && type == m_lastStructType)
|
||||
return;
|
||||
|
||||
if (StructInfo != null && m_subContentConstructed)
|
||||
DestroySubContent();
|
||||
|
||||
m_lastStructType = type;
|
||||
|
||||
StructInfo = new StructInfo(type);
|
||||
|
||||
if (m_subContentParent.activeSelf)
|
||||
ConstructSubcontent();
|
||||
}
|
||||
|
||||
#region UI CONSTRUCTION
|
||||
|
||||
internal InputField[] m_inputs;
|
||||
|
||||
public override void ConstructUI(GameObject parent, GameObject subGroup)
|
||||
{
|
||||
base.ConstructUI(parent, subGroup);
|
||||
}
|
||||
|
||||
public override void ConstructSubcontent()
|
||||
{
|
||||
base.ConstructSubcontent();
|
||||
|
||||
if (StructInfo == null)
|
||||
{
|
||||
ExplorerCore.LogWarning("Setting up subcontent but structinfo is null");
|
||||
return;
|
||||
}
|
||||
|
||||
var editorContainer = UIFactory.CreateVerticalGroup(m_subContentParent, "EditorContent", false, true, true, true, 2, new Vector4(4, 4, 4, 4),
|
||||
new Color(0.08f, 0.08f, 0.08f));
|
||||
|
||||
m_inputs = new InputField[StructInfo.FieldNames.Length];
|
||||
|
||||
for (int i = 0; i < StructInfo.FieldNames.Length; i++)
|
||||
AddEditorRow(i, editorContainer);
|
||||
|
||||
RefreshUIForValue();
|
||||
}
|
||||
|
||||
internal void AddEditorRow(int index, GameObject groupObj)
|
||||
{
|
||||
try
|
||||
{
|
||||
var row = UIFactory.CreateHorizontalGroup(groupObj, "EditorRow", false, true, true, true, 5, default, new Color(1, 1, 1, 0));
|
||||
|
||||
string name = StructInfo.FieldNames[index];
|
||||
|
||||
var label = UIFactory.CreateLabel(row, "RowLabel", $"{name}:", TextAnchor.MiddleRight, Color.cyan);
|
||||
UIFactory.SetLayoutElement(label.gameObject, minWidth: 30, flexibleWidth: 0, minHeight: 25);
|
||||
|
||||
var inputFieldObj = UIFactory.CreateInputField(row, "InputField", "...", 14, 3, 1);
|
||||
UIFactory.SetLayoutElement(inputFieldObj, minWidth: 120, minHeight: 25, flexibleWidth: 0);
|
||||
|
||||
var inputField = inputFieldObj.GetComponent<InputField>();
|
||||
m_inputs[index] = inputField;
|
||||
|
||||
inputField.onValueChanged.AddListener((string val) =>
|
||||
{
|
||||
try
|
||||
{
|
||||
float f = float.Parse(val);
|
||||
Value = StructInfo.SetValue(ref this.Value, index, f);
|
||||
Owner.SetValue();
|
||||
}
|
||||
catch { }
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ExplorerCore.Log(ex);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -9,6 +9,7 @@ using UnityExplorer.Core.Unity;
|
||||
using UnityExplorer.UI;
|
||||
using UnityExplorer.UI.Utility;
|
||||
using UnityExplorer.UI.CacheObject;
|
||||
using UnityExplorer.Core.Runtime;
|
||||
|
||||
namespace UnityExplorer.UI.InteractiveValues
|
||||
{
|
||||
@ -23,6 +24,14 @@ namespace UnityExplorer.UI.InteractiveValues
|
||||
|
||||
public override void OnValueUpdated()
|
||||
{
|
||||
#if CPP
|
||||
// strings boxed as Il2CppSystem.Objects can behave weirdly.
|
||||
// GetActualType will find they are a string, but if its boxed
|
||||
// then we need to unbox it like this...
|
||||
if (!(Value is string) && Value is Il2CppSystem.Object cppobj)
|
||||
Value = cppobj.ToString();
|
||||
#endif
|
||||
|
||||
base.OnValueUpdated();
|
||||
}
|
||||
|
||||
@ -88,10 +97,18 @@ namespace UnityExplorer.UI.InteractiveValues
|
||||
m_labelLayout.flexibleWidth = 0;
|
||||
}
|
||||
|
||||
internal void OnApplyClicked()
|
||||
internal void SetValueFromInput()
|
||||
{
|
||||
Value = m_valueInput.text;
|
||||
|
||||
if (!typeof(string).IsAssignableFrom(Owner.FallbackType))
|
||||
ReflectionProvider.Instance.BoxStringToType(ref Value, Owner.FallbackType);
|
||||
|
||||
Owner.SetValue();
|
||||
|
||||
// revert back to string now
|
||||
OnValueUpdated();
|
||||
|
||||
RefreshUIForValue();
|
||||
}
|
||||
|
||||
@ -162,7 +179,7 @@ namespace UnityExplorer.UI.InteractiveValues
|
||||
|
||||
if (Owner.CanWrite)
|
||||
{
|
||||
var apply = UIFactory.CreateButton(groupObj, "ApplyButton", "Apply", OnApplyClicked, new Color(0.2f, 0.2f, 0.2f));
|
||||
var apply = UIFactory.CreateButton(groupObj, "ApplyButton", "Apply", SetValueFromInput, new Color(0.2f, 0.2f, 0.2f));
|
||||
UIFactory.SetLayoutElement(apply.gameObject, minWidth: 50, minHeight: 25, flexibleWidth: 0);
|
||||
}
|
||||
else
|
||||
|
@ -1,298 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityExplorer.Core.Unity;
|
||||
using UnityExplorer.UI;
|
||||
|
||||
namespace UnityExplorer.UI.InteractiveValues
|
||||
{
|
||||
#region IStructInfo helper
|
||||
|
||||
public interface IStructInfo
|
||||
{
|
||||
string[] FieldNames { get; }
|
||||
object SetValue(ref object value, int fieldIndex, float val);
|
||||
void RefreshUI(InputField[] inputs, object value);
|
||||
}
|
||||
|
||||
public class StructInfo<T> : IStructInfo where T : struct
|
||||
{
|
||||
public string[] FieldNames { get; set; }
|
||||
|
||||
public delegate void SetMethod(ref T value, int fieldIndex, float val);
|
||||
public SetMethod SetValueMethod;
|
||||
|
||||
public delegate void UpdateMethod(InputField[] inputs, object value);
|
||||
public UpdateMethod UpdateUIMethod;
|
||||
|
||||
public object SetValue(ref object value, int fieldIndex, float val)
|
||||
{
|
||||
var box = (T)value;
|
||||
SetValueMethod.Invoke(ref box, fieldIndex, val);
|
||||
return box;
|
||||
}
|
||||
|
||||
public void RefreshUI(InputField[] inputs, object value)
|
||||
{
|
||||
UpdateUIMethod.Invoke(inputs, value);
|
||||
}
|
||||
}
|
||||
|
||||
// This part is a bit ugly, but everything else is generalized above.
|
||||
// I could generalize it more with reflection, but it would be different for
|
||||
// mono/il2cpp and also slower.
|
||||
public static class StructInfoFactory
|
||||
{
|
||||
public static IStructInfo Create(Type type)
|
||||
{
|
||||
if (type == typeof(Vector2))
|
||||
{
|
||||
return new StructInfo<Vector2>()
|
||||
{
|
||||
FieldNames = new[] { "x", "y", },
|
||||
SetValueMethod = (ref Vector2 vec, int fieldIndex, float val) =>
|
||||
{
|
||||
switch (fieldIndex)
|
||||
{
|
||||
case 0: vec.x = val; break;
|
||||
case 1: vec.y = val; break;
|
||||
}
|
||||
},
|
||||
UpdateUIMethod = (InputField[] inputs, object value) =>
|
||||
{
|
||||
Vector2 vec = (Vector2)value;
|
||||
inputs[0].text = vec.x.ToString();
|
||||
inputs[1].text = vec.y.ToString();
|
||||
}
|
||||
};
|
||||
}
|
||||
else if (type == typeof(Vector3))
|
||||
{
|
||||
return new StructInfo<Vector3>()
|
||||
{
|
||||
FieldNames = new[] { "x", "y", "z" },
|
||||
SetValueMethod = (ref Vector3 vec, int fieldIndex, float val) =>
|
||||
{
|
||||
switch (fieldIndex)
|
||||
{
|
||||
case 0: vec.x = val; break;
|
||||
case 1: vec.y = val; break;
|
||||
case 2: vec.z = val; break;
|
||||
}
|
||||
},
|
||||
UpdateUIMethod = (InputField[] inputs, object value) =>
|
||||
{
|
||||
Vector3 vec = (Vector3)value;
|
||||
inputs[0].text = vec.x.ToString();
|
||||
inputs[1].text = vec.y.ToString();
|
||||
inputs[2].text = vec.z.ToString();
|
||||
}
|
||||
};
|
||||
}
|
||||
else if (type == typeof(Vector4))
|
||||
{
|
||||
return new StructInfo<Vector4>()
|
||||
{
|
||||
FieldNames = new[] { "x", "y", "z", "w" },
|
||||
SetValueMethod = (ref Vector4 vec, int fieldIndex, float val) =>
|
||||
{
|
||||
switch (fieldIndex)
|
||||
{
|
||||
case 0: vec.x = val; break;
|
||||
case 1: vec.y = val; break;
|
||||
case 2: vec.z = val; break;
|
||||
case 3: vec.w = val; break;
|
||||
}
|
||||
},
|
||||
UpdateUIMethod = (InputField[] inputs, object value) =>
|
||||
{
|
||||
Vector4 vec = (Vector4)value;
|
||||
inputs[0].text = vec.x.ToString();
|
||||
inputs[1].text = vec.y.ToString();
|
||||
inputs[2].text = vec.z.ToString();
|
||||
inputs[3].text = vec.w.ToString();
|
||||
}
|
||||
};
|
||||
}
|
||||
else if (type == typeof(Rect))
|
||||
{
|
||||
return new StructInfo<Rect>()
|
||||
{
|
||||
FieldNames = new[] { "x", "y", "width", "height" },
|
||||
SetValueMethod = (ref Rect vec, int fieldIndex, float val) =>
|
||||
{
|
||||
switch (fieldIndex)
|
||||
{
|
||||
case 0: vec.x = val; break;
|
||||
case 1: vec.y = val; break;
|
||||
case 2: vec.width = val; break;
|
||||
case 3: vec.height = val; break;
|
||||
}
|
||||
},
|
||||
UpdateUIMethod = (InputField[] inputs, object value) =>
|
||||
{
|
||||
Rect vec = (Rect)value;
|
||||
inputs[0].text = vec.x.ToString();
|
||||
inputs[1].text = vec.y.ToString();
|
||||
inputs[2].text = vec.width.ToString();
|
||||
inputs[3].text = vec.height.ToString();
|
||||
}
|
||||
};
|
||||
}
|
||||
else if (type == typeof(Color))
|
||||
{
|
||||
return new StructInfo<Color>()
|
||||
{
|
||||
FieldNames = new[] { "r", "g", "b", "a" },
|
||||
SetValueMethod = (ref Color vec, int fieldIndex, float val) =>
|
||||
{
|
||||
switch (fieldIndex)
|
||||
{
|
||||
case 0: vec.r = val; break;
|
||||
case 1: vec.g = val; break;
|
||||
case 2: vec.b = val; break;
|
||||
case 3: vec.a = val; break;
|
||||
}
|
||||
},
|
||||
UpdateUIMethod = (InputField[] inputs, object value) =>
|
||||
{
|
||||
Color vec = (Color)value;
|
||||
inputs[0].text = vec.r.ToString();
|
||||
inputs[1].text = vec.g.ToString();
|
||||
inputs[2].text = vec.b.ToString();
|
||||
inputs[3].text = vec.a.ToString();
|
||||
}
|
||||
};
|
||||
}
|
||||
else
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public class InteractiveUnityStruct : InteractiveValue
|
||||
{
|
||||
public static bool SupportsType(Type type) => s_supportedTypes.Contains(type);
|
||||
private static readonly HashSet<Type> s_supportedTypes = new HashSet<Type>
|
||||
{
|
||||
typeof(Vector2),
|
||||
typeof(Vector3),
|
||||
typeof(Vector4),
|
||||
typeof(Rect),
|
||||
//typeof(Color) // todo might make a special editor for colors
|
||||
};
|
||||
|
||||
//~~~~~~~~~ Instance ~~~~~~~~~~
|
||||
|
||||
public InteractiveUnityStruct(object value, Type valueType) : base(value, valueType) { }
|
||||
|
||||
public override bool HasSubContent => true;
|
||||
public override bool SubContentWanted => true;
|
||||
public override bool WantInspectBtn => true;
|
||||
|
||||
public IStructInfo StructInfo;
|
||||
|
||||
public override void RefreshUIForValue()
|
||||
{
|
||||
InitializeStructInfo();
|
||||
|
||||
base.RefreshUIForValue();
|
||||
|
||||
if (m_subContentConstructed)
|
||||
StructInfo.RefreshUI(m_inputs, this.Value);
|
||||
}
|
||||
|
||||
internal override void OnToggleSubcontent(bool toggle)
|
||||
{
|
||||
InitializeStructInfo();
|
||||
|
||||
base.OnToggleSubcontent(toggle);
|
||||
|
||||
StructInfo.RefreshUI(m_inputs, this.Value);
|
||||
}
|
||||
|
||||
internal Type m_lastStructType;
|
||||
|
||||
internal void InitializeStructInfo()
|
||||
{
|
||||
var type = Value?.GetType() ?? FallbackType;
|
||||
|
||||
if (StructInfo != null && type == m_lastStructType)
|
||||
return;
|
||||
|
||||
if (StructInfo != null)
|
||||
DestroySubContent();
|
||||
|
||||
m_lastStructType = type;
|
||||
|
||||
StructInfo = StructInfoFactory.Create(type);
|
||||
|
||||
if (m_subContentParent.activeSelf)
|
||||
{
|
||||
ConstructSubcontent();
|
||||
}
|
||||
}
|
||||
|
||||
#region UI CONSTRUCTION
|
||||
|
||||
internal InputField[] m_inputs;
|
||||
|
||||
public override void ConstructUI(GameObject parent, GameObject subGroup)
|
||||
{
|
||||
base.ConstructUI(parent, subGroup);
|
||||
}
|
||||
|
||||
public override void ConstructSubcontent()
|
||||
{
|
||||
base.ConstructSubcontent();
|
||||
|
||||
if (StructInfo == null)
|
||||
{
|
||||
ExplorerCore.LogWarning("Setting up subcontent but structinfo is null");
|
||||
return;
|
||||
}
|
||||
|
||||
var editorContainer = UIFactory.CreateVerticalGroup(m_subContentParent, "EditorContent", false, true, true, true, 2, new Vector4(4,4,4,4),
|
||||
new Color(0.08f, 0.08f, 0.08f));
|
||||
|
||||
m_inputs = new InputField[StructInfo.FieldNames.Length];
|
||||
|
||||
for (int i = 0; i < StructInfo.FieldNames.Length; i++)
|
||||
AddEditorRow(i, editorContainer);
|
||||
|
||||
if (Owner.CanWrite)
|
||||
{
|
||||
var applyBtn = UIFactory.CreateButton(editorContainer, "ApplyButton", "Apply", OnSetValue, new Color(0.2f, 0.2f, 0.2f));
|
||||
UIFactory.SetLayoutElement(applyBtn.gameObject, minWidth: 175, minHeight: 25, flexibleWidth: 0);
|
||||
|
||||
void OnSetValue()
|
||||
{
|
||||
Owner.SetValue();
|
||||
RefreshUIForValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal void AddEditorRow(int index, GameObject groupObj)
|
||||
{
|
||||
var rowObj = UIFactory.CreateHorizontalGroup(groupObj, "EditorRow", false, true, true, true, 5, default, new Color(1, 1, 1, 0));
|
||||
|
||||
var label = UIFactory.CreateLabel(rowObj, "RowLabel", $"{StructInfo.FieldNames[index]}:", TextAnchor.MiddleRight, Color.cyan);
|
||||
UIFactory.SetLayoutElement(label.gameObject, minWidth: 50, flexibleWidth: 0, minHeight: 25);
|
||||
|
||||
var inputFieldObj = UIFactory.CreateInputField(rowObj, "InputField", "...", 14, 3, 1);
|
||||
UIFactory.SetLayoutElement(inputFieldObj, minWidth: 120, minHeight: 25, flexibleWidth: 0);
|
||||
|
||||
var inputField = inputFieldObj.GetComponent<InputField>();
|
||||
m_inputs[index] = inputField;
|
||||
|
||||
inputField.onValueChanged.AddListener((string val) => { Value = StructInfo.SetValue(ref this.Value, index, float.Parse(val)); });
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -12,6 +12,7 @@ using UnityExplorer.UI;
|
||||
using UnityExplorer.UI.Utility;
|
||||
using UnityExplorer.UI.CacheObject;
|
||||
using UnityExplorer.UI.Main.Home;
|
||||
using UnityExplorer.UI.Inspectors;
|
||||
|
||||
namespace UnityExplorer.UI.InteractiveValues
|
||||
{
|
||||
@ -30,8 +31,8 @@ namespace UnityExplorer.UI.InteractiveValues
|
||||
// arbitrarily check some types, fastest methods first.
|
||||
if (type == typeof(bool))
|
||||
return typeof(InteractiveBool);
|
||||
// if type is primitive then it must be a number if its not a bool
|
||||
else if (type.IsPrimitive)
|
||||
// if type is primitive then it must be a number if its not a bool. Also check for decimal.
|
||||
else if (type.IsPrimitive || type == typeof(decimal))
|
||||
return typeof(InteractiveNumber);
|
||||
// check for strings
|
||||
else if (type == typeof(string))
|
||||
@ -48,8 +49,8 @@ namespace UnityExplorer.UI.InteractiveValues
|
||||
// check for unity struct types
|
||||
else if (typeof(Color).IsAssignableFrom(type))
|
||||
return typeof(InteractiveColor);
|
||||
else if (InteractiveUnityStruct.SupportsType(type))
|
||||
return typeof(InteractiveUnityStruct);
|
||||
else if (InteractiveFloatStruct.IsTypeSupported(type))
|
||||
return typeof(InteractiveFloatStruct);
|
||||
// check Transform, force InteractiveValue so they dont become InteractiveEnumerables.
|
||||
else if (typeof(Transform).IsAssignableFrom(type))
|
||||
return typeof(InteractiveValue);
|
||||
@ -66,7 +67,7 @@ namespace UnityExplorer.UI.InteractiveValues
|
||||
|
||||
public static InteractiveValue Create(object value, Type fallbackType)
|
||||
{
|
||||
var type = ReflectionUtility.GetType(value) ?? fallbackType;
|
||||
var type = ReflectionUtility.GetActualType(value) ?? fallbackType;
|
||||
var iType = GetIValueForType(type);
|
||||
|
||||
return (InteractiveValue)Activator.CreateInstance(iType, new object[] { value, type });
|
||||
|
@ -59,7 +59,7 @@ namespace UnityExplorer.UI.Main.CSConsole
|
||||
|
||||
ResetConsole(false);
|
||||
// Make sure compiler is supported on this platform
|
||||
Evaluator.Compile("");
|
||||
Evaluator.Compile("new object();");
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -73,6 +73,8 @@ namespace UnityExplorer.UI.Main.CSConsole
|
||||
|
||||
ExplorerCore.LogWarning(info);
|
||||
|
||||
this.RefNavbarButton.GetComponentInChildren<Text>().text += " (disabled)";
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -217,7 +217,6 @@ namespace UnityExplorer.UI.Main
|
||||
{
|
||||
LogUnity = val;
|
||||
ConfigManager.Log_Unity_Debug.Value = val;
|
||||
ConfigManager.Handler.SaveConfig();
|
||||
});
|
||||
|
||||
ConfigManager.Log_Unity_Debug.OnValueChanged += (bool val) => { unityToggle.isOn = val; };
|
||||
|
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityExplorer.UI.Inspectors;
|
||||
|
||||
namespace UnityExplorer.UI.Main.Home
|
||||
{
|
||||
|
@ -13,6 +13,7 @@ using UnityExplorer.UI.Utility;
|
||||
using UnityExplorer.UI.Main.Search;
|
||||
using System.IO;
|
||||
using UnityExplorer.Core;
|
||||
using UnityExplorer.UI.Inspectors;
|
||||
|
||||
namespace UnityExplorer.UI.Main.Home
|
||||
{
|
||||
|
@ -10,6 +10,7 @@ using UnityExplorer.Core;
|
||||
using UnityExplorer.UI.Utility;
|
||||
using UnityExplorer.Core.Search;
|
||||
using UnityExplorer.UI.Main.Home;
|
||||
using UnityExplorer.UI.Inspectors;
|
||||
|
||||
namespace UnityExplorer.UI.Main.Search
|
||||
{
|
||||
@ -129,7 +130,7 @@ namespace UnityExplorer.UI.Main.Search
|
||||
|
||||
if (m_context != SearchContext.StaticClass)
|
||||
{
|
||||
var name = SignatureHighlighter.ParseFullSyntax(ReflectionUtility.GetType(obj), true);
|
||||
var name = SignatureHighlighter.ParseFullSyntax(ReflectionUtility.GetActualType(obj), true);
|
||||
|
||||
if (unityObj && m_context != SearchContext.Singleton)
|
||||
{
|
||||
|
@ -140,6 +140,8 @@ namespace UnityExplorer.UI
|
||||
ExplorerCore.Log("This game does not ship with the 'UI/Default' shader, using manual Default Shader...");
|
||||
Graphic.defaultGraphicMaterial.shader = BackupShader;
|
||||
}
|
||||
else
|
||||
BackupShader = Graphic.defaultGraphicMaterial.shader;
|
||||
|
||||
ConsoleFont = bundle.LoadAsset<Font>("CONSOLA");
|
||||
|
||||
@ -148,9 +150,11 @@ namespace UnityExplorer.UI
|
||||
|
||||
private static AssetBundle LoadExplorerUi(string id)
|
||||
{
|
||||
var data = ReadFully(typeof(ExplorerCore)
|
||||
var stream = typeof(ExplorerCore)
|
||||
.Assembly
|
||||
.GetManifestResourceStream($"UnityExplorer.Resources.explorerui.{id}.bundle"));
|
||||
.GetManifestResourceStream($"UnityExplorer.Resources.explorerui.{id}.bundle");
|
||||
|
||||
var data = ReadFully(stream);
|
||||
|
||||
return AssetBundle.LoadFromMemory(data);
|
||||
}
|
||||
|
@ -246,6 +246,7 @@
|
||||
<Compile Include="Core\Search\SceneFilter.cs" />
|
||||
<Compile Include="Core\Search\SearchContext.cs" />
|
||||
<Compile Include="Core\Search\SearchProvider.cs" />
|
||||
<Compile Include="Core\TestClass.cs" />
|
||||
<Compile Include="Core\Unity\UnityHelpers.cs" />
|
||||
<Compile Include="Loader\BIE\BepInExConfigHandler.cs" />
|
||||
<Compile Include="Loader\BIE\ExplorerBepInPlugin.cs" />
|
||||
@ -272,7 +273,7 @@
|
||||
<Compile Include="UI\InteractiveValues\InteractiveFlags.cs" />
|
||||
<Compile Include="UI\InteractiveValues\InteractiveNumber.cs" />
|
||||
<Compile Include="UI\InteractiveValues\InteractiveString.cs" />
|
||||
<Compile Include="UI\InteractiveValues\InteractiveUnityStruct.cs" />
|
||||
<Compile Include="UI\InteractiveValues\InteractiveFloatStruct.cs" />
|
||||
<Compile Include="UI\InteractiveValues\InteractiveValue.cs" />
|
||||
<Compile Include="UI\Main\BaseMenuPage.cs" />
|
||||
<Compile Include="UI\Main\CSConsole\AutoCompleter.cs" />
|
||||
@ -286,16 +287,16 @@
|
||||
<Compile Include="UI\Main\CSConsole\Lexer\SymbolMatch.cs" />
|
||||
<Compile Include="UI\Main\DebugConsole.cs" />
|
||||
<Compile Include="UI\Main\Home\HomePage.cs" />
|
||||
<Compile Include="UI\Main\Home\InspectorManager.cs" />
|
||||
<Compile Include="UI\Main\Home\Inspectors\GameObjects\ChildList.cs" />
|
||||
<Compile Include="UI\Main\Home\Inspectors\GameObjects\ComponentList.cs" />
|
||||
<Compile Include="UI\Main\Home\Inspectors\GameObjects\GameObjectControls.cs" />
|
||||
<Compile Include="UI\Main\Home\Inspectors\GameObjects\GameObjectInspector.cs" />
|
||||
<Compile Include="UI\Main\Home\Inspectors\InspectorBase.cs" />
|
||||
<Compile Include="UI\Main\Home\Inspectors\Reflection\InstanceInspector.cs" />
|
||||
<Compile Include="UI\Main\Home\Inspectors\Reflection\ReflectionInspector.cs" />
|
||||
<Compile Include="UI\Main\Home\Inspectors\Reflection\StaticInspector.cs" />
|
||||
<Compile Include="UI\Main\Home\InspectUnderMouse.cs" />
|
||||
<Compile Include="UI\Inspectors\InspectorManager.cs" />
|
||||
<Compile Include="UI\Inspectors\GameObjects\ChildList.cs" />
|
||||
<Compile Include="UI\Inspectors\GameObjects\ComponentList.cs" />
|
||||
<Compile Include="UI\Inspectors\GameObjects\GameObjectControls.cs" />
|
||||
<Compile Include="UI\Inspectors\GameObjects\GameObjectInspector.cs" />
|
||||
<Compile Include="UI\Inspectors\InspectorBase.cs" />
|
||||
<Compile Include="UI\Inspectors\Reflection\InstanceInspector.cs" />
|
||||
<Compile Include="UI\Inspectors\Reflection\ReflectionInspector.cs" />
|
||||
<Compile Include="UI\Inspectors\Reflection\StaticInspector.cs" />
|
||||
<Compile Include="UI\Inspectors\InspectUnderMouse.cs" />
|
||||
<Compile Include="UI\Main\Home\SceneExplorer.cs" />
|
||||
<Compile Include="UI\Main\MainMenu.cs" />
|
||||
<Compile Include="UI\Main\Options\OptionsPage.cs" />
|
||||
|
Reference in New Issue
Block a user