From 3c964cfef9a9db94c3a0c16b7a7fb3deb7a662dc Mon Sep 17 00:00:00 2001 From: sinaioutlander <49360850+sinaioutlander@users.noreply.github.com> Date: Sun, 18 Oct 2020 21:41:04 +1100 Subject: [PATCH] 2.0.7 * More unstripping fixes. Explorer now works 100% on a blank Unity project (so should therefore work on any Unity game, regardless of stripping). * Some cleanups --- src/CacheObject/CacheMember.cs | 4 +- src/CacheObject/CacheMethod.cs | 4 +- src/Explorer.csproj | 17 +- src/ExplorerCore.cs | 2 +- src/Helpers/ICallHelper.cs | 8 +- src/Helpers/ReflectionHelpers.cs | 21 +- src/Input/InputManager.cs | 5 +- src/Input/InputSystem.cs | 86 +- src/Input/LegacyInput.cs | 34 +- src/Tests/TestClass.cs | 5 + src/UI/Inspectors/GameObjectInspector.cs | 84 +- .../Reflection/InstanceInspector.cs | 2 +- src/UI/Inspectors/ReflectionInspector.cs | 30 +- src/UI/InteractiveValue/InteractiveValue.cs | 14 +- .../Object/InteractiveDictionary.cs | 10 +- .../Object/InteractiveEnumerable.cs | 12 +- .../Object/InteractiveTexture2D.cs | 10 +- .../Struct/InteractiveColor.cs | 30 +- .../Struct/InteractiveFlags.cs | 10 +- .../Struct/InteractivePrimitive.cs | 16 +- .../Struct/InteractiveQuaternion.cs | 24 +- .../Struct/InteractiveRect.cs | 30 +- .../Struct/InteractiveVector.cs | 30 +- src/UI/Main/ConsolePage.cs | 27 +- src/UI/Main/OptionsPage.cs | 18 +- src/UI/Main/ScenePage.cs | 17 +- src/UI/Main/SearchPage.cs | 29 +- src/UI/MainMenu.cs | 20 +- src/UI/Shared/Buttons.cs | 2 +- src/UI/Shared/PageHelper.cs | 2 +- src/UI/Shared/ResizeDrag.cs | 16 +- src/UI/TabViewWindow.cs | 12 +- src/UI/WindowManager.cs | 2 +- src/Unstrip/IMGUI/GUIHelper.cs | 175 ++++ src/Unstrip/IMGUI/GUIUnstrip.cs | 832 +++++++++++++++--- ...nal_GUIUtility.cs => GUIUtilityUnstrip.cs} | 2 +- src/Unstrip/IMGUI/Internal.cs | 762 ---------------- ...youtUtility.cs => LayoutUtilityUnstrip.cs} | 2 +- ...ViewState.cs => ScrollViewStateUnstrip.cs} | 2 +- ...iderHandler.cs => SliderHandlerUnstrip.cs} | 14 +- ...l_SliderState.cs => SliderStateUnstrip.cs} | 2 +- ...nal_TextEditor.cs => TextEditorUnstrip.cs} | 4 +- .../ImageConversion/ImageConversionUnstrip.cs | 17 +- src/Unstrip/Resources/ResourcesUnstrip.cs | 39 + 44 files changed, 1281 insertions(+), 1203 deletions(-) create mode 100644 src/Unstrip/IMGUI/GUIHelper.cs rename src/Unstrip/IMGUI/{Internal_GUIUtility.cs => GUIUtilityUnstrip.cs} (98%) delete mode 100644 src/Unstrip/IMGUI/Internal.cs rename src/Unstrip/IMGUI/{Internal_LayoutUtility.cs => LayoutUtilityUnstrip.cs} (98%) rename src/Unstrip/IMGUI/{Internal_ScrollViewState.cs => ScrollViewStateUnstrip.cs} (97%) rename src/Unstrip/IMGUI/{Internal_SliderHandler.cs => SliderHandlerUnstrip.cs} (95%) rename src/Unstrip/IMGUI/{Internal_SliderState.cs => SliderStateUnstrip.cs} (86%) rename src/Unstrip/IMGUI/{Internal_TextEditor.cs => TextEditorUnstrip.cs} (99%) create mode 100644 src/Unstrip/Resources/ResourcesUnstrip.cs diff --git a/src/CacheObject/CacheMember.cs b/src/CacheObject/CacheMember.cs index 1675b2a..e2cbeed 100644 --- a/src/CacheObject/CacheMember.cs +++ b/src/CacheObject/CacheMember.cs @@ -123,13 +123,13 @@ namespace Explorer.CacheObject label = $"[{label} = {this.m_arguments[i].DefaultValue ?? "null"}]"; } - GUIUnstrip.BeginHorizontal(new GUILayoutOption[0]); + GUIHelper.BeginHorizontal(new GUILayoutOption[0]); GUI.skin.label.alignment = TextAnchor.MiddleCenter; GUILayout.Label(i.ToString(), new GUILayoutOption[] { GUILayout.Width(15) }); GUILayout.Label(label, new GUILayoutOption[] { GUILayout.ExpandWidth(false) }); - this.m_argumentInput[i] = GUIUnstrip.TextField(input, new GUILayoutOption[] { GUILayout.ExpandWidth(true) }); + this.m_argumentInput[i] = GUIHelper.TextField(input, new GUILayoutOption[] { GUILayout.ExpandWidth(true) }); GUI.skin.label.alignment = TextAnchor.MiddleLeft; diff --git a/src/CacheObject/CacheMethod.cs b/src/CacheObject/CacheMethod.cs index f115c22..36ecc17 100644 --- a/src/CacheObject/CacheMethod.cs +++ b/src/CacheObject/CacheMethod.cs @@ -182,14 +182,14 @@ namespace Explorer.CacheObject } var input = this.GenericArgInput[i]; - GUIUnstrip.BeginHorizontal(new GUILayoutOption[0]); + GUIHelper.BeginHorizontal(new GUILayoutOption[0]); GUI.skin.label.alignment = TextAnchor.MiddleCenter; GUILayout.Label( $"{this.GenericArgs[i].Name}", new GUILayoutOption[] { GUILayout.Width(15) } ); - this.GenericArgInput[i] = GUIUnstrip.TextField(input, new GUILayoutOption[] { GUILayout.Width(150) }); + this.GenericArgInput[i] = GUIHelper.TextField(input, new GUILayoutOption[] { GUILayout.Width(150) }); GUI.skin.label.alignment = TextAnchor.MiddleLeft; GUILayout.Label(types, new GUILayoutOption[0]); diff --git a/src/Explorer.csproj b/src/Explorer.csproj index b945f13..42d0b4e 100644 --- a/src/Explorer.csproj +++ b/src/Explorer.csproj @@ -262,18 +262,19 @@ - - + + + - - - - + + + + - - + + diff --git a/src/ExplorerCore.cs b/src/ExplorerCore.cs index a702835..7e80d10 100644 --- a/src/ExplorerCore.cs +++ b/src/ExplorerCore.cs @@ -12,7 +12,7 @@ namespace Explorer public class ExplorerCore { public const string NAME = "Explorer " + VERSION + " (" + PLATFORM + ", " + MODLOADER + ")"; - public const string VERSION = "2.0.6"; + public const string VERSION = "2.0.7"; public const string AUTHOR = "Sinai"; public const string GUID = "com.sinai.explorer"; diff --git a/src/Helpers/ICallHelper.cs b/src/Helpers/ICallHelper.cs index a2de5bd..bc89879 100644 --- a/src/Helpers/ICallHelper.cs +++ b/src/Helpers/ICallHelper.cs @@ -5,9 +5,11 @@ using System.Linq; using System.Runtime.InteropServices; using System.Text; using System.Reflection; +using System.Diagnostics.CodeAnalysis; namespace Explorer.Helpers { + [SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "External methods")] public static class ICallHelper { private static readonly Dictionary iCallCache = new Dictionary(); @@ -32,14 +34,8 @@ namespace Explorer.Helpers return (T)iCall; } - #region External - #pragma warning disable IDE1006 // Naming Styles - [DllImport("GameAssembly", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] public static extern IntPtr il2cpp_resolve_icall([MarshalAs(UnmanagedType.LPStr)] string name); - - #pragma warning restore IDE1006 - #endregion } } #endif \ No newline at end of file diff --git a/src/Helpers/ReflectionHelpers.cs b/src/Helpers/ReflectionHelpers.cs index 3d756c9..d1aca8f 100644 --- a/src/Helpers/ReflectionHelpers.cs +++ b/src/Helpers/ReflectionHelpers.cs @@ -5,6 +5,7 @@ using System.IO; using System.Reflection; using UnityEngine; using BF = System.Reflection.BindingFlags; +using System.Diagnostics.CodeAnalysis; #if CPP using ILType = Il2CppSystem.Type; using UnhollowerBaseLib; @@ -14,6 +15,7 @@ using System.Runtime.InteropServices; namespace Explorer.Helpers { + [SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "External methods")] public class ReflectionHelpers { public static BF CommonFlags = BF.Public | BF.Instance | BF.NonPublic | BF.Static; @@ -51,12 +53,6 @@ namespace Explorer.Helpers .GetField("NativeClassPtr", BF.Public | BF.Static) .GetValue(null); - if (castToPtr == IntPtr.Zero) - { - ExplorerCore.LogWarning($"[Il2CppCast] Could not get an IntPtr for castTo '{castTo.FullName}'!"); - //return obj; - } - ClassPointers.Add(castTo, castToPtr); } else @@ -64,16 +60,18 @@ namespace Explorer.Helpers castToPtr = ClassPointers[castTo]; } - IntPtr objPtr = ilObj.Pointer; - var classPtr = il2cpp_object_get_class(objPtr); + if (castToPtr == IntPtr.Zero) + return obj; + + var classPtr = il2cpp_object_get_class(ilObj.Pointer); if (!il2cpp_class_is_assignable_from(castToPtr, classPtr)) return obj; - if (RuntimeSpecificsStore.IsInjected(classPtr)) - return UnhollowerBaseLib.Runtime.ClassInjectorBase.GetMonoObjectFromIl2CppPointer(objPtr); + if (RuntimeSpecificsStore.IsInjected(castToPtr)) + return UnhollowerBaseLib.Runtime.ClassInjectorBase.GetMonoObjectFromIl2CppPointer(ilObj.Pointer); - return Activator.CreateInstance(castTo, objPtr); + return Activator.CreateInstance(castTo, ilObj.Pointer); } [DllImport("GameAssembly", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] @@ -81,6 +79,7 @@ namespace Explorer.Helpers [DllImport("GameAssembly", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] public static extern IntPtr il2cpp_object_get_class(IntPtr obj); + #endif public static Type GetTypeByName(string fullName) diff --git a/src/Input/InputManager.cs b/src/Input/InputManager.cs index e2ed087..291a281 100644 --- a/src/Input/InputManager.cs +++ b/src/Input/InputManager.cs @@ -3,12 +3,14 @@ using System.Reflection; using UnityEngine; using Explorer.Input; using Explorer.Helpers; +using System.Diagnostics.CodeAnalysis; #if CPP using UnhollowerBaseLib; #endif namespace Explorer { + [SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "Unity style")] public static class InputManager { private static IAbstractInput m_inputModule; @@ -49,7 +51,6 @@ namespace Explorer #endif #if CPP -#pragma warning disable IDE1006 // public extern static string compositionString { get; } internal delegate IntPtr d_get_compositionString(); @@ -82,8 +83,6 @@ namespace Explorer iCall.Invoke(ref value); } } - -#pragma warning restore IDE1006 #endif } } \ No newline at end of file diff --git a/src/Input/InputSystem.cs b/src/Input/InputSystem.cs index c0004fc..d653004 100644 --- a/src/Input/InputSystem.cs +++ b/src/Input/InputSystem.cs @@ -10,64 +10,64 @@ namespace Explorer.Input { public class InputSystem : IAbstractInput { - public static Type TKeyboard => _keyboard ?? (_keyboard = ReflectionHelpers.GetTypeByName("UnityEngine.InputSystem.Keyboard")); - private static Type _keyboard; + public static Type TKeyboard => m_tKeyboard ?? (m_tKeyboard = ReflectionHelpers.GetTypeByName("UnityEngine.InputSystem.Keyboard")); + private static Type m_tKeyboard; - public static Type TMouse => _mouse ?? (_mouse = ReflectionHelpers.GetTypeByName("UnityEngine.InputSystem.Mouse")); - private static Type _mouse; + public static Type TMouse => m_tMouse ?? (m_tMouse = ReflectionHelpers.GetTypeByName("UnityEngine.InputSystem.Mouse")); + private static Type m_tMouse; - public static Type TKey => _key ?? (_key = ReflectionHelpers.GetTypeByName("UnityEngine.InputSystem.Key")); - private static Type _key; + public static Type TKey => m_tKey ?? (m_tKey = ReflectionHelpers.GetTypeByName("UnityEngine.InputSystem.Key")); + private static Type m_tKey; - private static PropertyInfo _btnIsPressedProp; - private static PropertyInfo _btnWasPressedProp; + private static PropertyInfo m_btnIsPressedProp; + private static PropertyInfo m_btnWasPressedProp; - private static object CurrentKeyboard => _currentKeyboard ?? (_currentKeyboard = _kbCurrentProp.GetValue(null, null)); - private static object _currentKeyboard; - private static PropertyInfo _kbCurrentProp; - private static PropertyInfo _kbIndexer; + private static object CurrentKeyboard => m_currentKeyboard ?? (m_currentKeyboard = m_kbCurrentProp.GetValue(null, null)); + private static object m_currentKeyboard; + private static PropertyInfo m_kbCurrentProp; + private static PropertyInfo m_kbIndexer; - private static object CurrentMouse => _currentMouse ?? (_currentMouse = _mouseCurrentProp.GetValue(null, null)); - private static object _currentMouse; - private static PropertyInfo _mouseCurrentProp; + private static object CurrentMouse => m_currentMouse ?? (m_currentMouse = m_mouseCurrentProp.GetValue(null, null)); + private static object m_currentMouse; + private static PropertyInfo m_mouseCurrentProp; - private static object LeftMouseButton => _lmb ?? (_lmb = _leftButtonProp.GetValue(CurrentMouse, null)); - private static object _lmb; - private static PropertyInfo _leftButtonProp; + private static object LeftMouseButton => m_lmb ?? (m_lmb = m_leftButtonProp.GetValue(CurrentMouse, null)); + private static object m_lmb; + private static PropertyInfo m_leftButtonProp; - private static object RightMouseButton => _rmb ?? (_rmb = _rightButtonProp.GetValue(CurrentMouse, null)); - private static object _rmb; - private static PropertyInfo _rightButtonProp; + private static object RightMouseButton => m_rmb ?? (m_rmb = m_rightButtonProp.GetValue(CurrentMouse, null)); + private static object m_rmb; + private static PropertyInfo m_rightButtonProp; - private static object MousePositionInfo => _pos ?? (_pos = _positionProp.GetValue(CurrentMouse, null)); - private static object _pos; - private static PropertyInfo _positionProp; - private static MethodInfo _readVector2InputMethod; + private static object MousePositionInfo => m_pos ?? (m_pos = m_positionProp.GetValue(CurrentMouse, null)); + private static object m_pos; + private static PropertyInfo m_positionProp; + private static MethodInfo m_readVector2InputMethod; - public Vector2 MousePosition => (Vector2)_readVector2InputMethod.Invoke(MousePositionInfo, new object[0]); + public Vector2 MousePosition => (Vector2)m_readVector2InputMethod.Invoke(MousePositionInfo, new object[0]); public bool GetKeyDown(KeyCode key) { var parsedKey = Enum.Parse(TKey, key.ToString()); - var actualKey = _kbIndexer.GetValue(CurrentKeyboard, new object[] { parsedKey }); + var actualKey = m_kbIndexer.GetValue(CurrentKeyboard, new object[] { parsedKey }); - return (bool)_btnWasPressedProp.GetValue(actualKey, null); + return (bool)m_btnWasPressedProp.GetValue(actualKey, null); } public bool GetKey(KeyCode key) { var parsed = Enum.Parse(TKey, key.ToString()); - var actualKey = _kbIndexer.GetValue(CurrentKeyboard, new object[] { parsed }); + var actualKey = m_kbIndexer.GetValue(CurrentKeyboard, new object[] { parsed }); - return (bool)_btnIsPressedProp.GetValue(actualKey, null); + return (bool)m_btnIsPressedProp.GetValue(actualKey, null); } public bool GetMouseButtonDown(int btn) { switch (btn) { - case 0: return (bool)_btnWasPressedProp.GetValue(LeftMouseButton, null); - case 1: return (bool)_btnWasPressedProp.GetValue(RightMouseButton, null); + case 0: return (bool)m_btnWasPressedProp.GetValue(LeftMouseButton, null); + case 1: return (bool)m_btnWasPressedProp.GetValue(RightMouseButton, null); // case 2: return (bool)_btnWasPressedProp.GetValue(MiddleMouseButton, null); default: throw new NotImplementedException(); } @@ -77,8 +77,8 @@ namespace Explorer.Input { switch (btn) { - case 0: return (bool)_btnIsPressedProp.GetValue(LeftMouseButton, null); - case 1: return (bool)_btnIsPressedProp.GetValue(RightMouseButton, null); + case 0: return (bool)m_btnIsPressedProp.GetValue(LeftMouseButton, null); + case 1: return (bool)m_btnIsPressedProp.GetValue(RightMouseButton, null); // case 2: return (bool)_btnIsPressedProp.GetValue(MiddleMouseButton, null); default: throw new NotImplementedException(); } @@ -88,21 +88,21 @@ namespace Explorer.Input { ExplorerCore.Log("Initializing new InputSystem support..."); - _kbCurrentProp = TKeyboard.GetProperty("current"); - _kbIndexer = TKeyboard.GetProperty("Item", new Type[] { TKey }); + m_kbCurrentProp = TKeyboard.GetProperty("current"); + m_kbIndexer = TKeyboard.GetProperty("Item", new Type[] { TKey }); var btnControl = ReflectionHelpers.GetTypeByName("UnityEngine.InputSystem.Controls.ButtonControl"); - _btnIsPressedProp = btnControl.GetProperty("isPressed"); - _btnWasPressedProp = btnControl.GetProperty("wasPressedThisFrame"); + m_btnIsPressedProp = btnControl.GetProperty("isPressed"); + m_btnWasPressedProp = btnControl.GetProperty("wasPressedThisFrame"); - _mouseCurrentProp = TMouse.GetProperty("current"); - _leftButtonProp = TMouse.GetProperty("leftButton"); - _rightButtonProp = TMouse.GetProperty("rightButton"); + m_mouseCurrentProp = TMouse.GetProperty("current"); + m_leftButtonProp = TMouse.GetProperty("leftButton"); + m_rightButtonProp = TMouse.GetProperty("rightButton"); - _positionProp = ReflectionHelpers.GetTypeByName("UnityEngine.InputSystem.Pointer") + m_positionProp = ReflectionHelpers.GetTypeByName("UnityEngine.InputSystem.Pointer") .GetProperty("position"); - _readVector2InputMethod = ReflectionHelpers.GetTypeByName("UnityEngine.InputSystem.InputControl`1") + m_readVector2InputMethod = ReflectionHelpers.GetTypeByName("UnityEngine.InputSystem.InputControl`1") .MakeGenericType(typeof(Vector2)) .GetMethod("ReadValue"); } diff --git a/src/Input/LegacyInput.cs b/src/Input/LegacyInput.cs index 8b3e996..4188316 100644 --- a/src/Input/LegacyInput.cs +++ b/src/Input/LegacyInput.cs @@ -10,34 +10,34 @@ namespace Explorer.Input { public class LegacyInput : IAbstractInput { - public static Type TInput => _input ?? (_input = ReflectionHelpers.GetTypeByName("UnityEngine.Input")); - private static Type _input; + public static Type TInput => m_tInput ?? (m_tInput = ReflectionHelpers.GetTypeByName("UnityEngine.Input")); + private static Type m_tInput; - private static PropertyInfo _mousePositionProp; - private static MethodInfo _getKeyMethod; - private static MethodInfo _getKeyDownMethod; - private static MethodInfo _getMouseButtonMethod; - private static MethodInfo _getMouseButtonDownMethod; + private static PropertyInfo m_mousePositionProp; + private static MethodInfo m_getKeyMethod; + private static MethodInfo m_getKeyDownMethod; + private static MethodInfo m_getMouseButtonMethod; + private static MethodInfo m_getMouseButtonDownMethod; - public Vector2 MousePosition => (Vector3)_mousePositionProp.GetValue(null, null); + public Vector2 MousePosition => (Vector3)m_mousePositionProp.GetValue(null, null); - public bool GetKey(KeyCode key) => (bool)_getKeyMethod.Invoke(null, new object[] { key }); + public bool GetKey(KeyCode key) => (bool)m_getKeyMethod.Invoke(null, new object[] { key }); - public bool GetKeyDown(KeyCode key) => (bool)_getKeyDownMethod.Invoke(null, new object[] { key }); + public bool GetKeyDown(KeyCode key) => (bool)m_getKeyDownMethod.Invoke(null, new object[] { key }); - public bool GetMouseButton(int btn) => (bool)_getMouseButtonMethod.Invoke(null, new object[] { btn }); + public bool GetMouseButton(int btn) => (bool)m_getMouseButtonMethod.Invoke(null, new object[] { btn }); - public bool GetMouseButtonDown(int btn) => (bool)_getMouseButtonDownMethod.Invoke(null, new object[] { btn }); + public bool GetMouseButtonDown(int btn) => (bool)m_getMouseButtonDownMethod.Invoke(null, new object[] { btn }); public void Init() { ExplorerCore.Log("Initializing Legacy Input support..."); - _mousePositionProp = TInput.GetProperty("mousePosition"); - _getKeyMethod = TInput.GetMethod("GetKey", new Type[] { typeof(KeyCode) }); - _getKeyDownMethod = TInput.GetMethod("GetKeyDown", new Type[] { typeof(KeyCode) }); - _getMouseButtonMethod = TInput.GetMethod("GetMouseButton", new Type[] { typeof(int) }); - _getMouseButtonDownMethod = TInput.GetMethod("GetMouseButtonDown", new Type[] { typeof(int) }); + m_mousePositionProp = TInput.GetProperty("mousePosition"); + m_getKeyMethod = TInput.GetMethod("GetKey", new Type[] { typeof(KeyCode) }); + m_getKeyDownMethod = TInput.GetMethod("GetKeyDown", new Type[] { typeof(KeyCode) }); + m_getMouseButtonMethod = TInput.GetMethod("GetMouseButton", new Type[] { typeof(int) }); + m_getMouseButtonDownMethod = TInput.GetMethod("GetMouseButtonDown", new Type[] { typeof(int) }); } } } diff --git a/src/Tests/TestClass.cs b/src/Tests/TestClass.cs index e5644b4..94f9212 100644 --- a/src/Tests/TestClass.cs +++ b/src/Tests/TestClass.cs @@ -8,6 +8,7 @@ using Explorer.UI.Shared; #if CPP using UnhollowerBaseLib; using UnityEngine.SceneManagement; +using Explorer.Unstrip.ImageConversion; #endif namespace Explorer.Tests @@ -63,6 +64,10 @@ namespace Explorer.Tests GameObject.DontDestroyOnLoad(TestTexture); GameObject.DontDestroyOnLoad(TestSprite); + //// test loading a tex from file + //var dataToLoad = System.IO.File.ReadAllBytes(@"Mods\Explorer\Tex_Nemundis_Nebula.png"); + //ExplorerCore.Log($"Tex load success: {TestTexture.LoadImage(dataToLoad, false)}"); + ILHashSetTest = new Il2CppSystem.Collections.Generic.HashSet(); ILHashSetTest.Add("1"); ILHashSetTest.Add("2"); diff --git a/src/UI/Inspectors/GameObjectInspector.cs b/src/UI/Inspectors/GameObjectInspector.cs index 35f766b..26ddb39 100644 --- a/src/UI/Inspectors/GameObjectInspector.cs +++ b/src/UI/Inspectors/GameObjectInspector.cs @@ -224,12 +224,12 @@ namespace Explorer.UI.Inspectors if (!WindowManager.TabView) { Header(); - GUIUnstrip.BeginArea(new Rect(5, 25, rect.width - 10, rect.height - 35), GUI.skin.box); + GUIHelper.BeginArea(new Rect(5, 25, rect.width - 10, rect.height - 35), GUI.skin.box); } - scroll = GUIUnstrip.BeginScrollView(scroll); + scroll = GUIHelper.BeginScrollView(scroll); - GUIUnstrip.BeginHorizontal(new GUILayoutOption[0]); + GUIHelper.BeginHorizontal(new GUILayoutOption[0]); GUILayout.Label("Scene: " + (m_scene == "" ? "n/a" : m_scene) + "", new GUILayoutOption[0]); if (m_scene == UnityHelpers.ActiveSceneName) { @@ -245,7 +245,7 @@ namespace Explorer.UI.Inspectors } GUILayout.EndHorizontal(); - GUIUnstrip.BeginHorizontal(new GUILayoutOption[0]); + GUIHelper.BeginHorizontal(new GUILayoutOption[0]); GUILayout.Label("Path:", new GUILayoutOption[] { GUILayout.Width(50) }); string pathlabel = TargetGO.transform.GetGameObjectPath(); if (TargetGO.transform.parent != null) @@ -255,24 +255,24 @@ namespace Explorer.UI.Inspectors InspectGameObject(TargetGO.transform.parent); } } - GUIUnstrip.TextArea(pathlabel, new GUILayoutOption[0]); + GUIHelper.TextArea(pathlabel, new GUILayoutOption[0]); GUILayout.EndHorizontal(); - GUIUnstrip.BeginHorizontal(new GUILayoutOption[0]); + GUIHelper.BeginHorizontal(new GUILayoutOption[0]); GUILayout.Label("Name:", new GUILayoutOption[] { GUILayout.Width(50) }); - GUIUnstrip.TextArea(m_name, new GUILayoutOption[0]); + GUIHelper.TextArea(m_name, new GUILayoutOption[0]); GUILayout.EndHorizontal(); LayerControls(); // --- Horizontal Columns section --- - GUIUnstrip.BeginHorizontal(new GUILayoutOption[0]); + GUIHelper.BeginHorizontal(new GUILayoutOption[0]); - GUIUnstrip.BeginVertical(new GUILayoutOption[] { GUILayout.Width(rect.width / 2 - 17) }); + GUIHelper.BeginVertical(new GUILayoutOption[] { GUILayout.Width(rect.width / 2 - 17) }); TransformList(rect); GUILayout.EndVertical(); - GUIUnstrip.BeginVertical(new GUILayoutOption[] { GUILayout.Width(rect.width / 2 - 17) }); + GUIHelper.BeginVertical(new GUILayoutOption[] { GUILayout.Width(rect.width / 2 - 17) }); ComponentList(rect); GUILayout.EndVertical(); @@ -280,13 +280,13 @@ namespace Explorer.UI.Inspectors GameObjectControls(); - GUIUnstrip.EndScrollView(); + GUIHelper.EndScrollView(); if (!WindowManager.TabView) { m_rect = ResizeDrag.ResizeWindow(rect, windowID); - GUIUnstrip.EndArea(); + GUIHelper.EndArea(); } } catch (Exception e) @@ -297,7 +297,7 @@ namespace Explorer.UI.Inspectors private void LayerControls() { - GUIUnstrip.BeginHorizontal(); + GUIHelper.BeginHorizontal(); GUILayout.Label("Layer:", new GUILayoutOption[] { GUILayout.Width(50) }); if (GUILayout.Button("<", new GUILayoutOption[] { GUILayout.Width(30) })) @@ -325,12 +325,12 @@ namespace Explorer.UI.Inspectors private void TransformList(Rect m_rect) { - GUIUnstrip.BeginVertical(GUIContent.none, GUI.skin.box, null); - m_transformScroll = GUIUnstrip.BeginScrollView(m_transformScroll); + GUIHelper.BeginVertical(GUIContent.none, GUI.skin.box, null); + m_transformScroll = GUIHelper.BeginScrollView(m_transformScroll); GUILayout.Label("Children", new GUILayoutOption[0]); - GUIUnstrip.BeginHorizontal(new GUILayoutOption[0]); + GUIHelper.BeginHorizontal(new GUILayoutOption[0]); ChildPages.DrawLimitInputArea(); if (ChildPages.ItemCount > ChildPages.ItemsPerPage) @@ -338,7 +338,7 @@ namespace Explorer.UI.Inspectors ChildPages.CurrentPageLabel(); GUILayout.EndHorizontal(); - GUIUnstrip.BeginHorizontal(new GUILayoutOption[0]); + GUIHelper.BeginHorizontal(new GUILayoutOption[0]); if (GUILayout.Button("< Prev", new GUILayoutOption[] { GUILayout.Width(80) })) { @@ -373,17 +373,17 @@ namespace Explorer.UI.Inspectors GUILayout.Label("None", new GUILayoutOption[0]); } - GUIUnstrip.EndScrollView(); + GUIHelper.EndScrollView(); GUILayout.EndVertical(); } private void ComponentList(Rect m_rect) { - GUIUnstrip.BeginVertical(GUIContent.none, GUI.skin.box, null); - m_compScroll = GUIUnstrip.BeginScrollView(m_compScroll); + GUIHelper.BeginVertical(GUIContent.none, GUI.skin.box, null); + m_compScroll = GUIHelper.BeginScrollView(m_compScroll); GUILayout.Label("Components", new GUILayoutOption[0]); - GUIUnstrip.BeginHorizontal(new GUILayoutOption[0]); + GUIHelper.BeginHorizontal(new GUILayoutOption[0]); CompPages.DrawLimitInputArea(); if (CompPages.ItemCount > CompPages.ItemsPerPage) @@ -391,7 +391,7 @@ namespace Explorer.UI.Inspectors CompPages.CurrentPageLabel(); GUILayout.EndHorizontal(); - GUIUnstrip.BeginHorizontal(new GUILayoutOption[0]); + GUIHelper.BeginHorizontal(new GUILayoutOption[0]); if (GUILayout.Button("< Prev", new GUILayoutOption[] { GUILayout.Width(80) })) { @@ -404,9 +404,9 @@ namespace Explorer.UI.Inspectors } GUILayout.EndHorizontal(); - GUIUnstrip.BeginHorizontal(new GUILayoutOption[0]); + GUIHelper.BeginHorizontal(new GUILayoutOption[0]); var width = m_rect.width / 2 - 135f; - m_addComponentInput = GUIUnstrip.TextField(m_addComponentInput, new GUILayoutOption[] { GUILayout.Width(width) }); + m_addComponentInput = GUIHelper.TextField(m_addComponentInput, new GUILayoutOption[] { GUILayout.Width(width) }); if (GUILayout.Button("Add Comp", new GUILayoutOption[0])) { if (ReflectionHelpers.GetTypeByName(m_addComponentInput) is Type compType) @@ -453,7 +453,7 @@ namespace Explorer.UI.Inspectors #else component.GetType(); #endif - GUIUnstrip.BeginHorizontal(new GUILayoutOption[0]); + GUIHelper.BeginHorizontal(new GUILayoutOption[0]); if (ReflectionHelpers.BehaviourType.IsAssignableFrom(type)) { #if CPP @@ -464,7 +464,7 @@ namespace Explorer.UI.Inspectors } else { - GUIUnstrip.Space(26); + GUIHelper.Space(26); } if (GUILayout.Button("" + type.Name + "", new GUILayoutOption[] { GUILayout.Width(m_rect.width / 2 - 100) })) { @@ -488,7 +488,7 @@ namespace Explorer.UI.Inspectors } } - GUIUnstrip.EndScrollView(); + GUIHelper.EndScrollView(); GUILayout.EndVertical(); } @@ -520,7 +520,7 @@ namespace Explorer.UI.Inspectors { if (m_hideControls) { - GUIUnstrip.BeginHorizontal(new GUILayoutOption[0]); + GUIHelper.BeginHorizontal(new GUILayoutOption[0]); GUILayout.Label("GameObject Controls", new GUILayoutOption[] { GUILayout.Width(200) }); if (GUILayout.Button("^ Show ^", new GUILayoutOption[] { GUILayout.Width(75) })) { @@ -531,9 +531,9 @@ namespace Explorer.UI.Inspectors return; } - GUIUnstrip.BeginVertical(GUIContent.none, GUI.skin.box, new GUILayoutOption[] { GUILayout.Width(520) }); + GUIHelper.BeginVertical(GUIContent.none, GUI.skin.box, new GUILayoutOption[] { GUILayout.Width(520) }); - GUIUnstrip.BeginHorizontal(new GUILayoutOption[0]); + GUIHelper.BeginHorizontal(new GUILayoutOption[0]); GUILayout.Label("GameObject Controls", new GUILayoutOption[] { GUILayout.Width(200) }); if (GUILayout.Button("v Hide v", new GUILayoutOption[] { GUILayout.Width(75) })) { @@ -541,7 +541,7 @@ namespace Explorer.UI.Inspectors } GUILayout.EndHorizontal(); - GUIUnstrip.BeginHorizontal(new GUILayoutOption[0]); + GUIHelper.BeginHorizontal(new GUILayoutOption[0]); bool m_active = TargetGO.activeSelf; m_active = GUILayout.Toggle(m_active, (m_active ? "Enabled " : "Disabled") + "", new GUILayoutOption[] { GUILayout.Width(80) }); @@ -566,9 +566,9 @@ namespace Explorer.UI.Inspectors } GUILayout.EndHorizontal(); - GUIUnstrip.BeginHorizontal(new GUILayoutOption[0]); + GUIHelper.BeginHorizontal(new GUILayoutOption[0]); - m_setParentInput = GUIUnstrip.TextField(m_setParentInput, new GUILayoutOption[0]); + m_setParentInput = GUIHelper.TextField(m_setParentInput, new GUILayoutOption[0]); if (GUILayout.Button("Set Parent", new GUILayoutOption[] { GUILayout.Width(80) })) { if (GameObject.Find(m_setParentInput) is GameObject newparent) @@ -587,13 +587,13 @@ namespace Explorer.UI.Inspectors } GUILayout.EndHorizontal(); - GUIUnstrip.BeginVertical(GUIContent.none, GUI.skin.box, null); + GUIHelper.BeginVertical(GUIContent.none, GUI.skin.box, null); m_cachedInput[0] = TranslateControl(TranslateType.Position, ref m_translateAmount, false); m_cachedInput[1] = TranslateControl(TranslateType.Rotation, ref m_rotateAmount, true); m_cachedInput[2] = TranslateControl(TranslateType.Scale, ref m_scaleAmount, false); - GUIUnstrip.BeginHorizontal(new GUILayoutOption[0]); + GUIHelper.BeginHorizontal(new GUILayoutOption[0]); if (GUILayout.Button("Apply to Transform", new GUILayoutOption[0]) || m_autoApplyTransform) { if (m_localContext) @@ -619,7 +619,7 @@ namespace Explorer.UI.Inspectors } GUILayout.EndHorizontal(); - GUIUnstrip.BeginHorizontal(new GUILayoutOption[0]); + GUIHelper.BeginHorizontal(new GUILayoutOption[0]); BoolToggle(ref m_autoApplyTransform, "Auto-apply to Transform?"); BoolToggle(ref m_autoUpdateTransform, "Auto-update from transform?"); GUILayout.EndHorizontal(); @@ -681,7 +681,7 @@ namespace Explorer.UI.Inspectors private Vector3 TranslateControl(TranslateType mode, ref float amount, bool multByTime) { - GUIUnstrip.BeginHorizontal(new GUILayoutOption[0]); + GUIHelper.BeginHorizontal(new GUILayoutOption[0]); GUILayout.Label($"{(m_localContext ? "Local " : "")}{mode}:", new GUILayoutOption[] { GUILayout.Width(m_localContext ? 110 : 65) }); @@ -704,7 +704,7 @@ namespace Explorer.UI.Inspectors Vector3 input = m_cachedInput[(int)mode]; - GUIUnstrip.BeginHorizontal(new GUILayoutOption[0]); + GUIHelper.BeginHorizontal(new GUILayoutOption[0]); GUI.skin.label.alignment = TextAnchor.MiddleRight; GUILayout.Label("X:", new GUILayoutOption[] { GUILayout.Width(20) }); @@ -718,7 +718,7 @@ namespace Explorer.UI.Inspectors GUILayout.Label("+/-:", new GUILayoutOption[] { GUILayout.Width(30) }); var amountInput = amount.ToString("F3"); - amountInput = GUIUnstrip.TextField(amountInput, new GUILayoutOption[] { GUILayout.Width(60) }); + amountInput = GUIHelper.TextField(amountInput, new GUILayoutOption[] { GUILayout.Width(60) }); if (float.TryParse(amountInput, out float f)) { amount = f; @@ -733,16 +733,16 @@ namespace Explorer.UI.Inspectors private void PlusMinusFloat(ref float f, float amount, bool multByTime) { string s = f.ToString("F3"); - s = GUIUnstrip.TextField(s, new GUILayoutOption[] { GUILayout.Width(60) }); + s = GUIHelper.TextField(s, new GUILayoutOption[] { GUILayout.Width(60) }); if (float.TryParse(s, out float f2)) { f = f2; } - if (GUIUnstrip.RepeatButton("-", new GUILayoutOption[] { GUILayout.Width(20) })) + if (GUIHelper.RepeatButton("-", new GUILayoutOption[] { GUILayout.Width(20) })) { f -= multByTime ? amount * Time.deltaTime : amount; } - if (GUIUnstrip.RepeatButton("+", new GUILayoutOption[] { GUILayout.Width(20) })) + if (GUIHelper.RepeatButton("+", new GUILayoutOption[] { GUILayout.Width(20) })) { f += multByTime ? amount * Time.deltaTime : amount; } diff --git a/src/UI/Inspectors/Reflection/InstanceInspector.cs b/src/UI/Inspectors/Reflection/InstanceInspector.cs index 013f823..281974e 100644 --- a/src/UI/Inspectors/Reflection/InstanceInspector.cs +++ b/src/UI/Inspectors/Reflection/InstanceInspector.cs @@ -80,7 +80,7 @@ namespace Explorer.UI.Inspectors if (m_uObj) { - GUIUnstrip.BeginHorizontal(new GUILayoutOption[0]); + GUIHelper.BeginHorizontal(new GUILayoutOption[0]); GUILayout.Label("Tools:", new GUILayoutOption[] { GUILayout.Width(80) }); Buttons.InstantiateButton(m_uObj); if (m_component && m_component.gameObject is GameObject obj) diff --git a/src/UI/Inspectors/ReflectionInspector.cs b/src/UI/Inspectors/ReflectionInspector.cs index bcebc65..ff094ea 100644 --- a/src/UI/Inspectors/ReflectionInspector.cs +++ b/src/UI/Inspectors/ReflectionInspector.cs @@ -254,12 +254,12 @@ namespace Explorer.UI.Inspectors if (!WindowManager.TabView) { Header(); - GUIUnstrip.BeginArea(new Rect(5, 25, rect.width - 10, rect.height - 35), GUI.skin.box); + GUIHelper.BeginArea(new Rect(5, 25, rect.width - 10, rect.height - 35), GUI.skin.box); } var asInstance = this as InstanceInspector; - GUIUnstrip.BeginHorizontal(new GUILayoutOption[0]); + GUIHelper.BeginHorizontal(new GUILayoutOption[0]); var labelWidth = (asInstance != null && asInstance.m_uObj) ? new GUILayoutOption[] { GUILayout.Width(245f) } : new GUILayoutOption[0]; @@ -273,12 +273,12 @@ namespace Explorer.UI.Inspectors UIStyles.HorizontalLine(Color.grey); - GUIUnstrip.BeginHorizontal(new GUILayoutOption[0]); + GUIHelper.BeginHorizontal(new GUILayoutOption[0]); GUILayout.Label("Search:", new GUILayoutOption[] { GUILayout.Width(75) }); - m_search = GUIUnstrip.TextField(m_search, new GUILayoutOption[0]); + m_search = GUIHelper.TextField(m_search, new GUILayoutOption[0]); GUILayout.EndHorizontal(); - GUIUnstrip.BeginHorizontal(new GUILayoutOption[0]); + GUIHelper.BeginHorizontal(new GUILayoutOption[0]); GUILayout.Label("Filter:", new GUILayoutOption[] { GUILayout.Width(75) }); FilterTypeToggle(MemberTypes.All, "All"); FilterTypeToggle(MemberTypes.Property, "Properties"); @@ -288,7 +288,7 @@ namespace Explorer.UI.Inspectors if (this is InstanceInspector) { - GUIUnstrip.BeginHorizontal(new GUILayoutOption[0]); + GUIHelper.BeginHorizontal(new GUILayoutOption[0]); GUILayout.Label("Scope:", new GUILayoutOption[] { GUILayout.Width(75) }); FilterScopeToggle(MemberScopes.Both, "Both"); FilterScopeToggle(MemberScopes.Instance, "Instance"); @@ -296,7 +296,7 @@ namespace Explorer.UI.Inspectors GUILayout.EndHorizontal(); } - GUIUnstrip.BeginHorizontal(new GUILayoutOption[0]); + GUIHelper.BeginHorizontal(new GUILayoutOption[0]); GUILayout.Label("Values:", new GUILayoutOption[] { GUILayout.Width(75) }); if (GUILayout.Button("Update", new GUILayoutOption[] { GUILayout.Width(100) })) { @@ -309,12 +309,12 @@ namespace Explorer.UI.Inspectors GUI.color = Color.white; GUILayout.EndHorizontal(); - GUIUnstrip.Space(10); + GUIHelper.Space(10); Pages.ItemCount = m_cachedMembersFiltered.Length; // prev/next page buttons - GUIUnstrip.BeginHorizontal(new GUILayoutOption[0]); + GUIHelper.BeginHorizontal(new GUILayoutOption[0]); Pages.DrawLimitInputArea(); @@ -336,13 +336,13 @@ namespace Explorer.UI.Inspectors // ====== BODY ====== - scroll = GUIUnstrip.BeginScrollView(scroll); + scroll = GUIHelper.BeginScrollView(scroll); - GUIUnstrip.Space(10); + GUIHelper.Space(10); UIStyles.HorizontalLine(Color.grey); - GUIUnstrip.BeginVertical(GUIContent.none, GUI.skin.box, null); + GUIHelper.BeginVertical(GUIContent.none, GUI.skin.box, null); var members = this.m_cachedMembersFiltered; int start = Pages.CalculateOffsetIndex(); @@ -351,7 +351,7 @@ namespace Explorer.UI.Inspectors { var holder = members[j]; - GUIUnstrip.BeginHorizontal(new GUILayoutOption[] { GUILayout.Height(25) }); + GUIHelper.BeginHorizontal(new GUILayoutOption[] { GUILayout.Height(25) }); try { holder.Draw(rect, 180f); @@ -369,13 +369,13 @@ namespace Explorer.UI.Inspectors } GUILayout.EndVertical(); - GUIUnstrip.EndScrollView(); + GUIHelper.EndScrollView(); if (!WindowManager.TabView) { m_rect = ResizeDrag.ResizeWindow(rect, windowID); - GUIUnstrip.EndArea(); + GUIHelper.EndArea(); } } catch (Exception e) when (e.Message.Contains("in a group with only")) diff --git a/src/UI/InteractiveValue/InteractiveValue.cs b/src/UI/InteractiveValue/InteractiveValue.cs index 8247150..ec358dd 100644 --- a/src/UI/InteractiveValue/InteractiveValue.cs +++ b/src/UI/InteractiveValue/InteractiveValue.cs @@ -71,14 +71,14 @@ namespace Explorer.UI } else { - GUIUnstrip.Space(labelWidth); + GUIHelper.Space(labelWidth); } var cacheMethod = OwnerCacheObject as CacheMethod; if (cacheMember != null && cacheMember.HasParameters) { - GUIUnstrip.BeginVertical(new GUILayoutOption[] { GUILayout.ExpandHeight(true) } ); + GUIHelper.BeginVertical(new GUILayoutOption[] { GUILayout.ExpandHeight(true) } ); if (cacheMember.m_isEvaluating) { @@ -92,7 +92,7 @@ namespace Explorer.UI cacheMember.DrawArgsInput(); } - GUIUnstrip.BeginHorizontal(new GUILayoutOption[0]); + GUIHelper.BeginHorizontal(new GUILayoutOption[0]); if (GUILayout.Button(EVALUATE_LABEL, new GUILayoutOption[] { GUILayout.Width(70) })) { if (cacheMethod != null) @@ -122,8 +122,8 @@ namespace Explorer.UI GUILayout.EndVertical(); GUILayout.EndHorizontal(); - GUIUnstrip.BeginHorizontal(new GUILayoutOption[0]); - GUIUnstrip.Space(labelWidth); + GUIHelper.BeginHorizontal(new GUILayoutOption[0]); + GUIHelper.Space(labelWidth); } else if (cacheMethod != null) { @@ -133,8 +133,8 @@ namespace Explorer.UI } GUILayout.EndHorizontal(); - GUIUnstrip.BeginHorizontal(new GUILayoutOption[0]); - GUIUnstrip.Space(labelWidth); + GUIHelper.BeginHorizontal(new GUILayoutOption[0]); + GUIHelper.Space(labelWidth); } string typeName = $"{ValueType.FullName}"; diff --git a/src/UI/InteractiveValue/Object/InteractiveDictionary.cs b/src/UI/InteractiveValue/Object/InteractiveDictionary.cs index 233df5d..5a9b68b 100644 --- a/src/UI/InteractiveValue/Object/InteractiveDictionary.cs +++ b/src/UI/InteractiveValue/Object/InteractiveDictionary.cs @@ -237,7 +237,7 @@ namespace Explorer.UI } GUI.skin.button.alignment = TextAnchor.MiddleCenter; - GUIUnstrip.Space(5); + GUIHelper.Space(5); if (IsExpanded) { @@ -246,9 +246,9 @@ namespace Explorer.UI if (count > Pages.ItemsPerPage) { GUILayout.EndHorizontal(); - GUIUnstrip.BeginHorizontal(new GUILayoutOption[0]); + GUIHelper.BeginHorizontal(new GUILayoutOption[0]); - GUIUnstrip.Space(whitespace); + GUIHelper.Space(whitespace); Pages.CurrentPageLabel(); @@ -264,7 +264,7 @@ namespace Explorer.UI Pages.DrawLimitInputArea(); - GUIUnstrip.Space(5); + GUIHelper.Space(5); } int offset = Pages.CalculateOffsetIndex(); @@ -276,7 +276,7 @@ namespace Explorer.UI //collapsing the BeginHorizontal called from ReflectionWindow.WindowFunction or previous array entry GUILayout.EndHorizontal(); - GUIUnstrip.BeginHorizontal(new GUILayoutOption[0]); + GUIHelper.BeginHorizontal(new GUILayoutOption[0]); //GUIUnstrip.Space(whitespace); diff --git a/src/UI/InteractiveValue/Object/InteractiveEnumerable.cs b/src/UI/InteractiveValue/Object/InteractiveEnumerable.cs index a1d97c4..ef51379 100644 --- a/src/UI/InteractiveValue/Object/InteractiveEnumerable.cs +++ b/src/UI/InteractiveValue/Object/InteractiveEnumerable.cs @@ -298,7 +298,7 @@ namespace Explorer.UI } GUI.skin.button.alignment = TextAnchor.MiddleCenter; - GUIUnstrip.Space(5); + GUIHelper.Space(5); if (IsExpanded) { @@ -307,9 +307,9 @@ namespace Explorer.UI if (count > Pages.ItemsPerPage) { GUILayout.EndHorizontal(); - GUIUnstrip.BeginHorizontal(new GUILayoutOption[0]); + GUIHelper.BeginHorizontal(new GUILayoutOption[0]); - GUIUnstrip.Space(whitespace); + GUIHelper.Space(whitespace); Pages.CurrentPageLabel(); @@ -325,7 +325,7 @@ namespace Explorer.UI Pages.DrawLimitInputArea(); - GUIUnstrip.Space(5); + GUIHelper.Space(5); } int offset = Pages.CalculateOffsetIndex(); @@ -336,9 +336,9 @@ namespace Explorer.UI //collapsing the BeginHorizontal called from ReflectionWindow.WindowFunction or previous array entry GUILayout.EndHorizontal(); - GUIUnstrip.BeginHorizontal(new GUILayoutOption[0]); + GUIHelper.BeginHorizontal(new GUILayoutOption[0]); - GUIUnstrip.Space(whitespace); + GUIHelper.Space(whitespace); if (entry == null || entry.IValue == null) { diff --git a/src/UI/InteractiveValue/Object/InteractiveTexture2D.cs b/src/UI/InteractiveValue/Object/InteractiveTexture2D.cs index 60e83e0..b6e0eb3 100644 --- a/src/UI/InteractiveValue/Object/InteractiveTexture2D.cs +++ b/src/UI/InteractiveValue/Object/InteractiveTexture2D.cs @@ -57,9 +57,9 @@ namespace Explorer.UI public override void DrawValue(Rect window, float width) { - GUIUnstrip.BeginVertical(); + GUIHelper.BeginVertical(); - GUIUnstrip.BeginHorizontal(); + GUIHelper.BeginHorizontal(); if (currentTex && !IsExpanded) { @@ -105,11 +105,11 @@ namespace Explorer.UI private void DrawTextureControls() { - GUIUnstrip.BeginHorizontal(); + GUIHelper.BeginHorizontal(); GUILayout.Label("Save folder:", new GUILayoutOption[] { GUILayout.Width(80f) }); - saveFolder = GUIUnstrip.TextField(saveFolder, new GUILayoutOption[0]); - GUIUnstrip.Space(10f); + saveFolder = GUIHelper.TextField(saveFolder, new GUILayoutOption[0]); + GUIHelper.Space(10f); GUILayout.EndHorizontal(); diff --git a/src/UI/InteractiveValue/Struct/InteractiveColor.cs b/src/UI/InteractiveValue/Struct/InteractiveColor.cs index 5de25b1..1c21a5c 100644 --- a/src/UI/InteractiveValue/Struct/InteractiveColor.cs +++ b/src/UI/InteractiveValue/Struct/InteractiveColor.cs @@ -63,40 +63,40 @@ namespace Explorer.UI var whitespace = CalcWhitespace(window); - GUIUnstrip.BeginHorizontal(new GUILayoutOption[0]); - GUIUnstrip.Space(whitespace); + GUIHelper.BeginHorizontal(new GUILayoutOption[0]); + GUIHelper.Space(whitespace); GUILayout.Label("R:", new GUILayoutOption[] { GUILayout.Width(30) }); - r = GUIUnstrip.TextField(r, new GUILayoutOption[] { GUILayout.Width(120) }); + r = GUIHelper.TextField(r, new GUILayoutOption[] { GUILayout.Width(120) }); GUILayout.EndHorizontal(); - GUIUnstrip.BeginHorizontal(new GUILayoutOption[0]); - GUIUnstrip.Space(whitespace); + GUIHelper.BeginHorizontal(new GUILayoutOption[0]); + GUIHelper.Space(whitespace); GUILayout.Label("G:", new GUILayoutOption[] { GUILayout.Width(30) }); - g = GUIUnstrip.TextField(g, new GUILayoutOption[] { GUILayout.Width(120) }); + g = GUIHelper.TextField(g, new GUILayoutOption[] { GUILayout.Width(120) }); GUILayout.EndHorizontal(); - GUIUnstrip.BeginHorizontal(new GUILayoutOption[0]); - GUIUnstrip.Space(whitespace); + GUIHelper.BeginHorizontal(new GUILayoutOption[0]); + GUIHelper.Space(whitespace); GUILayout.Label("B:", new GUILayoutOption[] { GUILayout.Width(30) }); - b = GUIUnstrip.TextField(b, new GUILayoutOption[] { GUILayout.Width(120) }); + b = GUIHelper.TextField(b, new GUILayoutOption[] { GUILayout.Width(120) }); GUILayout.EndHorizontal(); - GUIUnstrip.BeginHorizontal(new GUILayoutOption[0]); - GUIUnstrip.Space(whitespace); + GUIHelper.BeginHorizontal(new GUILayoutOption[0]); + GUIHelper.Space(whitespace); GUILayout.Label("A:", new GUILayoutOption[] { GUILayout.Width(30) }); - a = GUIUnstrip.TextField(a, new GUILayoutOption[] { GUILayout.Width(120) }); + a = GUIHelper.TextField(a, new GUILayoutOption[] { GUILayout.Width(120) }); GUILayout.EndHorizontal(); // draw set value button - GUIUnstrip.BeginHorizontal(new GUILayoutOption[0]); - GUIUnstrip.Space(whitespace); + GUIHelper.BeginHorizontal(new GUILayoutOption[0]); + GUIHelper.Space(whitespace); if (GUILayout.Button("Apply", new GUILayoutOption[] { GUILayout.Width(155) })) { SetValueFromInput(); } GUILayout.EndHorizontal(); - GUIUnstrip.BeginHorizontal(new GUILayoutOption[0]); + GUIHelper.BeginHorizontal(new GUILayoutOption[0]); } } diff --git a/src/UI/InteractiveValue/Struct/InteractiveFlags.cs b/src/UI/InteractiveValue/Struct/InteractiveFlags.cs index e6a1141..00d76b8 100644 --- a/src/UI/InteractiveValue/Struct/InteractiveFlags.cs +++ b/src/UI/InteractiveValue/Struct/InteractiveFlags.cs @@ -75,23 +75,23 @@ namespace Explorer.UI for (int i = 0; i < EnumNames.Length; i++) { - GUIUnstrip.BeginHorizontal(new GUILayoutOption[0]); - GUIUnstrip.Space(whitespace); + GUIHelper.BeginHorizontal(new GUILayoutOption[0]); + GUIHelper.Space(whitespace); m_enabledFlags[i] = GUILayout.Toggle(m_enabledFlags[i], EnumNames[i], new GUILayoutOption[0]); GUILayout.EndHorizontal(); } - GUIUnstrip.BeginHorizontal(new GUILayoutOption[0]); - GUIUnstrip.Space(whitespace); + GUIHelper.BeginHorizontal(new GUILayoutOption[0]); + GUIHelper.Space(whitespace); if (GUILayout.Button("Apply", new GUILayoutOption[] { GUILayout.Width(155) })) { SetFlagsFromInput(); } GUILayout.EndHorizontal(); - GUIUnstrip.BeginHorizontal(new GUILayoutOption[0]); + GUIHelper.BeginHorizontal(new GUILayoutOption[0]); } } diff --git a/src/UI/InteractiveValue/Struct/InteractivePrimitive.cs b/src/UI/InteractiveValue/Struct/InteractivePrimitive.cs index c21bceb..9503a58 100644 --- a/src/UI/InteractiveValue/Struct/InteractivePrimitive.cs +++ b/src/UI/InteractiveValue/Struct/InteractivePrimitive.cs @@ -98,13 +98,13 @@ namespace Explorer.UI // all other non-bool values use TextField - GUIUnstrip.BeginVertical(new GUILayoutOption[0]); + GUIHelper.BeginVertical(new GUILayoutOption[0]); - GUIUnstrip.BeginHorizontal(new GUILayoutOption[0]); + GUIHelper.BeginHorizontal(new GUILayoutOption[0]); GUILayout.Label("" + ValueType.Name + "", new GUILayoutOption[] { GUILayout.Width(50) }); - m_valueToString = GUIUnstrip.TextArea(m_valueToString, new GUILayoutOption[] { GUILayout.ExpandWidth(true) }); + m_valueToString = GUIHelper.TextArea(m_valueToString, new GUILayoutOption[] { GUILayout.ExpandWidth(true) }); DrawApplyButton(); @@ -113,7 +113,7 @@ namespace Explorer.UI m_inBitwiseMode = GUILayout.Toggle(m_inBitwiseMode, "Bitwise?", new GUILayoutOption[0]); } - GUIUnstrip.Space(10); + GUIHelper.Space(10); GUILayout.EndHorizontal(); @@ -147,7 +147,7 @@ namespace Explorer.UI { if (OwnerCacheObject.CanWrite) { - GUIUnstrip.BeginHorizontal(new GUILayoutOption[0]); + GUIHelper.BeginHorizontal(new GUILayoutOption[0]); GUI.skin.label.alignment = TextAnchor.MiddleRight; GUILayout.Label("RHS:", new GUILayoutOption[] { GUILayout.Width(35) }); @@ -203,14 +203,14 @@ namespace Explorer.UI } } - m_bitwiseOperatorInput = GUIUnstrip.TextField(m_bitwiseOperatorInput, new GUILayoutOption[] { GUILayout.Width(55) }); + m_bitwiseOperatorInput = GUIHelper.TextField(m_bitwiseOperatorInput, new GUILayoutOption[] { GUILayout.Width(55) }); GUILayout.EndHorizontal(); } - GUIUnstrip.BeginHorizontal(new GUILayoutOption[0]); + GUIHelper.BeginHorizontal(new GUILayoutOption[0]); GUILayout.Label($"Binary:", new GUILayoutOption[] { GUILayout.Width(60) }); - m_binaryInput = GUIUnstrip.TextField(m_binaryInput, new GUILayoutOption[0]); + m_binaryInput = GUIHelper.TextField(m_binaryInput, new GUILayoutOption[0]); if (OwnerCacheObject.CanWrite) { if (GUILayout.Button("Apply", new GUILayoutOption[0])) diff --git a/src/UI/InteractiveValue/Struct/InteractiveQuaternion.cs b/src/UI/InteractiveValue/Struct/InteractiveQuaternion.cs index cd00cc0..10a5a96 100644 --- a/src/UI/InteractiveValue/Struct/InteractiveQuaternion.cs +++ b/src/UI/InteractiveValue/Struct/InteractiveQuaternion.cs @@ -58,34 +58,34 @@ namespace Explorer.UI var whitespace = CalcWhitespace(window); - GUIUnstrip.BeginHorizontal(new GUILayoutOption[0]); - GUIUnstrip.Space(whitespace); + GUIHelper.BeginHorizontal(new GUILayoutOption[0]); + GUIHelper.Space(whitespace); GUILayout.Label("X:", new GUILayoutOption[] { GUILayout.Width(30) }); - x = GUIUnstrip.TextField(x, new GUILayoutOption[] { GUILayout.Width(120) }); + x = GUIHelper.TextField(x, new GUILayoutOption[] { GUILayout.Width(120) }); GUILayout.EndHorizontal(); - GUIUnstrip.BeginHorizontal(new GUILayoutOption[0]); - GUIUnstrip.Space(whitespace); + GUIHelper.BeginHorizontal(new GUILayoutOption[0]); + GUIHelper.Space(whitespace); GUILayout.Label("Y:", new GUILayoutOption[] { GUILayout.Width(30) }); - y = GUIUnstrip.TextField(y, new GUILayoutOption[] { GUILayout.Width(120) }); + y = GUIHelper.TextField(y, new GUILayoutOption[] { GUILayout.Width(120) }); GUILayout.EndHorizontal(); - GUIUnstrip.BeginHorizontal(new GUILayoutOption[0]); - GUIUnstrip.Space(whitespace); + GUIHelper.BeginHorizontal(new GUILayoutOption[0]); + GUIHelper.Space(whitespace); GUILayout.Label("Z:", new GUILayoutOption[] { GUILayout.Width(30) }); - z = GUIUnstrip.TextField(z, new GUILayoutOption[] { GUILayout.Width(120) }); + z = GUIHelper.TextField(z, new GUILayoutOption[] { GUILayout.Width(120) }); GUILayout.EndHorizontal(); // draw set value button - GUIUnstrip.BeginHorizontal(new GUILayoutOption[0]); - GUIUnstrip.Space(whitespace); + GUIHelper.BeginHorizontal(new GUILayoutOption[0]); + GUIHelper.Space(whitespace); if (GUILayout.Button("Apply", new GUILayoutOption[] { GUILayout.Width(155) })) { SetValueFromInput(); } GUILayout.EndHorizontal(); - GUIUnstrip.BeginHorizontal(new GUILayoutOption[0]); + GUIHelper.BeginHorizontal(new GUILayoutOption[0]); } } diff --git a/src/UI/InteractiveValue/Struct/InteractiveRect.cs b/src/UI/InteractiveValue/Struct/InteractiveRect.cs index 5814f52..ba5e65f 100644 --- a/src/UI/InteractiveValue/Struct/InteractiveRect.cs +++ b/src/UI/InteractiveValue/Struct/InteractiveRect.cs @@ -60,40 +60,40 @@ namespace Explorer.UI var whitespace = CalcWhitespace(window); - GUIUnstrip.BeginHorizontal(new GUILayoutOption[0]); - GUIUnstrip.Space(whitespace); + GUIHelper.BeginHorizontal(new GUILayoutOption[0]); + GUIHelper.Space(whitespace); GUILayout.Label("X:", new GUILayoutOption[] { GUILayout.Width(30) }); - x = GUIUnstrip.TextField(x, new GUILayoutOption[] { GUILayout.Width(120) }); + x = GUIHelper.TextField(x, new GUILayoutOption[] { GUILayout.Width(120) }); GUILayout.EndHorizontal(); - GUIUnstrip.BeginHorizontal(new GUILayoutOption[0]); - GUIUnstrip.Space(whitespace); + GUIHelper.BeginHorizontal(new GUILayoutOption[0]); + GUIHelper.Space(whitespace); GUILayout.Label("Y:", new GUILayoutOption[] { GUILayout.Width(30) }); - y = GUIUnstrip.TextField(y, new GUILayoutOption[] { GUILayout.Width(120) }); + y = GUIHelper.TextField(y, new GUILayoutOption[] { GUILayout.Width(120) }); GUILayout.EndHorizontal(); - GUIUnstrip.BeginHorizontal(new GUILayoutOption[0]); - GUIUnstrip.Space(whitespace); + GUIHelper.BeginHorizontal(new GUILayoutOption[0]); + GUIHelper.Space(whitespace); GUILayout.Label("W:", new GUILayoutOption[] { GUILayout.Width(30) }); - w = GUIUnstrip.TextField(w, new GUILayoutOption[] { GUILayout.Width(120) }); + w = GUIHelper.TextField(w, new GUILayoutOption[] { GUILayout.Width(120) }); GUILayout.EndHorizontal(); - GUIUnstrip.BeginHorizontal(new GUILayoutOption[0]); - GUIUnstrip.Space(whitespace); + GUIHelper.BeginHorizontal(new GUILayoutOption[0]); + GUIHelper.Space(whitespace); GUILayout.Label("H:", new GUILayoutOption[] { GUILayout.Width(30) }); - h = GUIUnstrip.TextField(h, new GUILayoutOption[] { GUILayout.Width(120) }); + h = GUIHelper.TextField(h, new GUILayoutOption[] { GUILayout.Width(120) }); GUILayout.EndHorizontal(); // draw set value button - GUIUnstrip.BeginHorizontal(new GUILayoutOption[0]); - GUIUnstrip.Space(whitespace); + GUIHelper.BeginHorizontal(new GUILayoutOption[0]); + GUIHelper.Space(whitespace); if (GUILayout.Button("Apply", new GUILayoutOption[] { GUILayout.Width(155) })) { SetValueFromInput(); } GUILayout.EndHorizontal(); - GUIUnstrip.BeginHorizontal(new GUILayoutOption[0]); + GUIHelper.BeginHorizontal(new GUILayoutOption[0]); } } diff --git a/src/UI/InteractiveValue/Struct/InteractiveVector.cs b/src/UI/InteractiveValue/Struct/InteractiveVector.cs index 5306610..872f12e 100644 --- a/src/UI/InteractiveValue/Struct/InteractiveVector.cs +++ b/src/UI/InteractiveValue/Struct/InteractiveVector.cs @@ -100,47 +100,47 @@ namespace Explorer.UI var whitespace = CalcWhitespace(window); // always draw x and y - GUIUnstrip.BeginHorizontal(new GUILayoutOption[0]); - GUIUnstrip.Space(whitespace); + GUIHelper.BeginHorizontal(new GUILayoutOption[0]); + GUIHelper.Space(whitespace); GUILayout.Label("X:", new GUILayoutOption[] { GUILayout.Width(30) }); - x = GUIUnstrip.TextField(x, new GUILayoutOption[] { GUILayout.Width(120) }); + x = GUIHelper.TextField(x, new GUILayoutOption[] { GUILayout.Width(120) }); GUILayout.EndHorizontal(); - GUIUnstrip.BeginHorizontal(new GUILayoutOption[0]); - GUIUnstrip.Space(whitespace); + GUIHelper.BeginHorizontal(new GUILayoutOption[0]); + GUIHelper.Space(whitespace); GUILayout.Label("Y:", new GUILayoutOption[] { GUILayout.Width(30) }); - y = GUIUnstrip.TextField(y, new GUILayoutOption[] { GUILayout.Width(120) }); + y = GUIHelper.TextField(y, new GUILayoutOption[] { GUILayout.Width(120) }); GUILayout.EndHorizontal(); if (VectorSize > 2) { // draw z - GUIUnstrip.BeginHorizontal(new GUILayoutOption[0]); - GUIUnstrip.Space(whitespace); + GUIHelper.BeginHorizontal(new GUILayoutOption[0]); + GUIHelper.Space(whitespace); GUILayout.Label("Z:", new GUILayoutOption[] { GUILayout.Width(30) }); - z = GUIUnstrip.TextField(z, new GUILayoutOption[] { GUILayout.Width(120) }); + z = GUIHelper.TextField(z, new GUILayoutOption[] { GUILayout.Width(120) }); GUILayout.EndHorizontal(); } if (VectorSize > 3) { // draw w - GUIUnstrip.BeginHorizontal(new GUILayoutOption[0]); - GUIUnstrip.Space(whitespace); + GUIHelper.BeginHorizontal(new GUILayoutOption[0]); + GUIHelper.Space(whitespace); GUILayout.Label("W:", new GUILayoutOption[] { GUILayout.Width(30) }); - w = GUIUnstrip.TextField(w, new GUILayoutOption[] { GUILayout.Width(120) }); + w = GUIHelper.TextField(w, new GUILayoutOption[] { GUILayout.Width(120) }); GUILayout.EndHorizontal(); } // draw set value button - GUIUnstrip.BeginHorizontal(new GUILayoutOption[0]); - GUIUnstrip.Space(whitespace); + GUIHelper.BeginHorizontal(new GUILayoutOption[0]); + GUIHelper.Space(whitespace); if (GUILayout.Button("Apply", new GUILayoutOption[] { GUILayout.Width(155) })) { SetValueFromInput(); } GUILayout.EndHorizontal(); - GUIUnstrip.BeginHorizontal(new GUILayoutOption[0]); + GUIHelper.BeginHorizontal(new GUILayoutOption[0]); } } diff --git a/src/UI/Main/ConsolePage.cs b/src/UI/Main/ConsolePage.cs index 3777c05..445b566 100644 --- a/src/UI/Main/ConsolePage.cs +++ b/src/UI/Main/ConsolePage.cs @@ -8,6 +8,8 @@ using System.Reflection; using System.IO; #if CPP using UnhollowerRuntimeLib; +using TextEditor = Explorer.Unstrip.IMGUI.TextEditorUnstrip; +using Explorer.Unstrip.IMGUI; #endif namespace Explorer.UI.Main @@ -140,15 +142,15 @@ Help();"; GUILayout.Label("Enter code here as though it is a method body:", new GUILayoutOption[0]); - inputAreaScroll = GUIUnstrip.BeginScrollView( + inputAreaScroll = GUIHelper.BeginScrollView( inputAreaScroll, - new GUILayoutOption[] { GUILayout.Height(250), GUILayout.ExpandHeight(true) } + new GUILayoutOption[] { GUILayout.Height(250), GUIHelper.ExpandHeight(true) } ); GUI.SetNextControlName(INPUT_CONTROL_NAME); - m_input = GUIUnstrip.TextArea(m_input, new GUILayoutOption[] { GUILayout.ExpandHeight(true) }); + m_input = GUIHelper.TextArea(m_input, new GUILayoutOption[] { GUIHelper.ExpandHeight(true) }); - GUIUnstrip.EndScrollView(); + GUIHelper.EndScrollView(); // EXECUTE BUTTON @@ -179,7 +181,7 @@ Help();"; // SUGGESTIONS if (AutoCompletes.Count > 0) { - autocompleteScroll = GUIUnstrip.BeginScrollView(autocompleteScroll, new GUILayoutOption[] { GUILayout.Height(150) }); + autocompleteScroll = GUIHelper.BeginScrollView(autocompleteScroll, new GUILayoutOption[] { GUILayout.Height(150) }); var origSkin = GUI.skin.button; GUI.skin.button = AutocompleteStyle; @@ -196,7 +198,7 @@ Help();"; GUI.skin.button = origSkin; - GUIUnstrip.EndScrollView(); + GUIHelper.EndScrollView(); } if (shouldRefocus) @@ -209,9 +211,9 @@ Help();"; GUILayout.Label("Using directives:", new GUILayoutOption[0]); - GUIUnstrip.BeginHorizontal(new GUILayoutOption[0]); + GUIHelper.BeginHorizontal(new GUILayoutOption[0]); GUILayout.Label("Add namespace:", new GUILayoutOption[] { GUILayout.Width(105) }); - m_usingInput = GUIUnstrip.TextField(m_usingInput, new GUILayoutOption[] { GUILayout.Width(150) }); + m_usingInput = GUIHelper.TextField(m_usingInput, new GUILayoutOption[] { GUILayout.Width(150) }); if (GUILayout.Button("Add", new GUILayoutOption[] { GUILayout.Width(120) })) { AddUsing(m_usingInput); @@ -245,7 +247,8 @@ Help();"; #endif #if CPP - textEditor = GUIUtility.GetStateObject(Il2CppType.Of(), GUIUtility.keyboardControl).TryCast(); + //textEditor = GUIUtility.GetStateObject(Il2CppType.Of(), GUIUtility.keyboardControl).TryCast(); + textEditor = (TextEditor)GUIUtilityUnstrip.GetMonoStateObject(typeof(TextEditor), GUIUtility.keyboardControl); #else textEditor = (TextEditor)GUIUtility.GetStateObject(typeof(TextEditor), GUIUtility.keyboardControl); #endif @@ -346,9 +349,9 @@ Help();"; { var style = new GUIStyle { - border = new RectOffset(0, 0, 0, 0), - margin = new RectOffset(0, 0, 0, 0), - padding = new RectOffset(0, 0, 0, 0), + border = new RectOffset(), + margin = new RectOffset(), + padding = new RectOffset(), hover = { background = Texture2D.whiteTexture, textColor = Color.black }, normal = { background = null }, focused = { background = Texture2D.whiteTexture, textColor = Color.black }, diff --git a/src/UI/Main/OptionsPage.cs b/src/UI/Main/OptionsPage.cs index 5453eee..d3c2572 100644 --- a/src/UI/Main/OptionsPage.cs +++ b/src/UI/Main/OptionsPage.cs @@ -56,44 +56,44 @@ namespace Explorer.UI.Main GUILayout.Label("Options", new GUILayoutOption[0]); GUI.skin.label.alignment = TextAnchor.MiddleLeft; - GUIUnstrip.BeginVertical(GUIContent.none, GUI.skin.box, new GUILayoutOption[0]); + GUIHelper.BeginVertical(GUIContent.none, GUI.skin.box, new GUILayoutOption[0]); - GUIUnstrip.BeginHorizontal(new GUILayoutOption[0]); + GUIHelper.BeginHorizontal(new GUILayoutOption[0]); GUILayout.Label($"Menu Toggle Key:", new GUILayoutOption[] { GUILayout.Width(215f) }); toggleKeyInput.IValue.DrawValue(MainMenu.MainRect, MainMenu.MainRect.width - 215f); GUILayout.EndHorizontal(); UIStyles.HorizontalLine(Color.black, true); - GUIUnstrip.BeginHorizontal(new GUILayoutOption[0]); + GUIHelper.BeginHorizontal(new GUILayoutOption[0]); GUILayout.Label($"Default Window Size:", new GUILayoutOption[] { GUILayout.Width(215f) }); defaultSizeInput.IValue.DrawValue(MainMenu.MainRect, MainMenu.MainRect.width - 215f); GUILayout.EndHorizontal(); UIStyles.HorizontalLine(Color.black, true); - GUIUnstrip.BeginHorizontal(new GUILayoutOption[0]); + GUIHelper.BeginHorizontal(new GUILayoutOption[0]); GUILayout.Label($"Default Items per Page:", new GUILayoutOption[] { GUILayout.Width(215f) }); defaultPageLimitInput.IValue.DrawValue(MainMenu.MainRect, MainMenu.MainRect.width - 215f); GUILayout.EndHorizontal(); UIStyles.HorizontalLine(Color.black, true); - GUIUnstrip.BeginHorizontal(new GUILayoutOption[0]); + GUIHelper.BeginHorizontal(new GUILayoutOption[0]); GUILayout.Label($"Enable Bitwise Editing:", new GUILayoutOption[] { GUILayout.Width(215f) }); bitwiseSupportInput.IValue.DrawValue(MainMenu.MainRect, MainMenu.MainRect.width - 215f); GUILayout.EndHorizontal(); UIStyles.HorizontalLine(Color.black, true); - GUIUnstrip.BeginHorizontal(new GUILayoutOption[0]); + GUIHelper.BeginHorizontal(new GUILayoutOption[0]); GUILayout.Label($"Enable Tab View:", new GUILayoutOption[] { GUILayout.Width(215f) }); tabViewInput.IValue.DrawValue(MainMenu.MainRect, MainMenu.MainRect.width - 215f); GUILayout.EndHorizontal(); UIStyles.HorizontalLine(Color.black, true); - GUIUnstrip.BeginHorizontal(new GUILayoutOption[0]); + GUIHelper.BeginHorizontal(new GUILayoutOption[0]); GUILayout.Label($"Default Output Path:", new GUILayoutOption[] { GUILayout.Width(215f) }); defaultOutputPathInput.IValue.DrawValue(MainMenu.MainRect, MainMenu.MainRect.width - 215f); GUILayout.EndHorizontal(); @@ -105,13 +105,13 @@ namespace Explorer.UI.Main GUILayout.EndVertical(); - GUIUnstrip.Space(10f); + GUIHelper.Space(10f); GUI.skin.label.alignment = TextAnchor.MiddleCenter; GUILayout.Label("Other", new GUILayoutOption[0]); GUI.skin.label.alignment = TextAnchor.MiddleLeft; - GUIUnstrip.BeginVertical(GUIContent.none, GUI.skin.box, new GUILayoutOption[0]); + GUIHelper.BeginVertical(GUIContent.none, GUI.skin.box, new GUILayoutOption[0]); if (GUILayout.Button("Inspect Test Class", new GUILayoutOption[0])) { diff --git a/src/UI/Main/ScenePage.cs b/src/UI/Main/ScenePage.cs index 52e0efc..870387d 100644 --- a/src/UI/Main/ScenePage.cs +++ b/src/UI/Main/ScenePage.cs @@ -6,6 +6,7 @@ using UnityEngine.SceneManagement; using Explorer.UI.Shared; using Explorer.CacheObject; using Explorer.Helpers; +using Explorer.Unstrip.Resources; namespace Explorer.UI.Main { @@ -80,7 +81,7 @@ namespace Explorer.UI.Main { var matches = new List(); - foreach (var obj in Resources.FindObjectsOfTypeAll(ReflectionHelpers.GameObjectType)) + foreach (var obj in ResourcesUnstrip.FindObjectsOfTypeAll(ReflectionHelpers.GameObjectType)) { #if CPP var go = obj.TryCast(); @@ -164,7 +165,7 @@ namespace Explorer.UI.Main { DrawHeaderArea(); - GUIUnstrip.BeginVertical(GUIContent.none, GUI.skin.box, null); + GUIHelper.BeginVertical(GUIContent.none, GUI.skin.box, null); DrawPageButtons(); @@ -190,7 +191,7 @@ namespace Explorer.UI.Main private void DrawHeaderArea() { - GUIUnstrip.BeginHorizontal(new GUILayoutOption[0]); + GUIHelper.BeginHorizontal(new GUILayoutOption[0]); // Current Scene label GUILayout.Label("Current Scene:", new GUILayoutOption[] { GUILayout.Width(120) }); @@ -200,10 +201,10 @@ namespace Explorer.UI.Main GUILayout.EndHorizontal(); // ----- GameObject Search ----- - GUIUnstrip.BeginHorizontal(GUIContent.none, GUI.skin.box, null); + GUIHelper.BeginHorizontal(GUIContent.none, GUI.skin.box, null); GUILayout.Label("Search Scene:", new GUILayoutOption[] { GUILayout.Width(100) }); - m_searchInput = GUIUnstrip.TextField(m_searchInput, new GUILayoutOption[0]); + m_searchInput = GUIHelper.TextField(m_searchInput, new GUILayoutOption[0]); if (GUILayout.Button("Search", new GUILayoutOption[] { GUILayout.Width(80) })) { @@ -211,7 +212,7 @@ namespace Explorer.UI.Main } GUILayout.EndHorizontal(); - GUIUnstrip.Space(5); + GUIHelper.Space(5); } private void SceneChangeButtons() @@ -252,7 +253,7 @@ namespace Explorer.UI.Main private void DrawPageButtons() { - GUIUnstrip.BeginHorizontal(new GUILayoutOption[0]); + GUIHelper.BeginHorizontal(new GUILayoutOption[0]); Pages.DrawLimitInputArea(); @@ -283,7 +284,7 @@ namespace Explorer.UI.Main { if (m_currentTransform != null) { - GUIUnstrip.BeginHorizontal(new GUILayoutOption[0]); + GUIHelper.BeginHorizontal(new GUILayoutOption[0]); if (GUILayout.Button("<-", new GUILayoutOption[] { GUILayout.Width(35) })) { TraverseUp(); diff --git a/src/UI/Main/SearchPage.cs b/src/UI/Main/SearchPage.cs index bfa91bd..61bf967 100644 --- a/src/UI/Main/SearchPage.cs +++ b/src/UI/Main/SearchPage.cs @@ -7,6 +7,7 @@ using UnityEngine; using Explorer.UI.Shared; using Explorer.CacheObject; using Explorer.Helpers; +using Explorer.Unstrip.Resources; namespace Explorer.UI.Main { @@ -163,7 +164,7 @@ namespace Explorer.UI.Main var matches = new List(); - var allObjectsOfType = Resources.FindObjectsOfTypeAll(searchType); + var allObjectsOfType = ResourcesUnstrip.FindObjectsOfTypeAll(searchType); //ExplorerCore.Log("Found count: " + allObjectsOfType.Length); @@ -350,7 +351,7 @@ namespace Explorer.UI.Main try { // helpers - GUIUnstrip.BeginHorizontal(GUIContent.none, GUI.skin.box, null); + GUIHelper.BeginHorizontal(GUIContent.none, GUI.skin.box, null); GUILayout.Label("Helpers", new GUILayoutOption[] { GUILayout.Width(70) }); if (GUILayout.Button("Find Static Instances", new GUILayoutOption[] { GUILayout.Width(180) })) { @@ -366,7 +367,7 @@ namespace Explorer.UI.Main SearchBox(); // results - GUIUnstrip.BeginVertical(GUIContent.none, GUI.skin.box, null); + GUIHelper.BeginVertical(GUIContent.none, GUI.skin.box, null); GUI.skin.label.alignment = TextAnchor.MiddleCenter; GUILayout.Label("Results " + " (" + m_searchResults.Count + ")", new GUILayoutOption[0]); @@ -374,7 +375,7 @@ namespace Explorer.UI.Main int count = m_searchResults.Count; - GUIUnstrip.BeginHorizontal(new GUILayoutOption[0]); + GUIHelper.BeginHorizontal(new GUILayoutOption[0]); Pages.DrawLimitInputArea(); @@ -400,7 +401,7 @@ namespace Explorer.UI.Main GUILayout.EndHorizontal(); - resultsScroll = GUIUnstrip.BeginScrollView(resultsScroll); + resultsScroll = GUIHelper.BeginScrollView(resultsScroll); var _temprect = new Rect(MainMenu.MainRect.x, MainMenu.MainRect.y, MainMenu.MainRect.width + 160, MainMenu.MainRect.height); @@ -420,7 +421,7 @@ namespace Explorer.UI.Main GUILayout.Label("No results found!", new GUILayoutOption[0]); } - GUIUnstrip.EndScrollView(); + GUIHelper.EndScrollView(); GUILayout.EndVertical(); } catch (Exception e) @@ -440,28 +441,28 @@ namespace Explorer.UI.Main private void SearchBox() { - GUIUnstrip.BeginVertical(GUIContent.none, GUI.skin.box, null); + GUIHelper.BeginVertical(GUIContent.none, GUI.skin.box, null); // ----- GameObject Search ----- GUI.skin.label.alignment = TextAnchor.MiddleCenter; GUILayout.Label("Search", new GUILayoutOption[0]); GUI.skin.label.alignment = TextAnchor.UpperLeft; - GUIUnstrip.BeginHorizontal(new GUILayoutOption[0]); + GUIHelper.BeginHorizontal(new GUILayoutOption[0]); GUILayout.Label("Name Contains:", new GUILayoutOption[] { GUILayout.Width(100) }); - m_searchInput = GUIUnstrip.TextField(m_searchInput, new GUILayoutOption[] { GUILayout.Width(200) }); + m_searchInput = GUIHelper.TextField(m_searchInput, new GUILayoutOption[] { GUILayout.Width(200) }); GUILayout.Label("Max Results:", new GUILayoutOption[] { GUILayout.Width(100) }); var s = MaxSearchResults.ToString(); - s = GUIUnstrip.TextField(s, new GUILayoutOption[] { GUILayout.Width(80) }); + s = GUIHelper.TextField(s, new GUILayoutOption[] { GUILayout.Width(80) }); if (int.TryParse(s, out int i)) { MaxSearchResults = i; } GUILayout.EndHorizontal(); - GUIUnstrip.BeginHorizontal(new GUILayoutOption[0]); + GUIHelper.BeginHorizontal(new GUILayoutOption[0]); GUILayout.Label("Class Filter:", new GUILayoutOption[] { GUILayout.Width(100) }); ClassFilterToggle(TypeFilter.Object, "Object"); @@ -471,15 +472,15 @@ namespace Explorer.UI.Main GUILayout.EndHorizontal(); if (TypeMode == TypeFilter.Custom) { - GUIUnstrip.BeginHorizontal(new GUILayoutOption[0]); + GUIHelper.BeginHorizontal(new GUILayoutOption[0]); GUI.skin.label.alignment = TextAnchor.MiddleRight; GUILayout.Label("Custom Class:", new GUILayoutOption[] { GUILayout.Width(250) }); GUI.skin.label.alignment = TextAnchor.UpperLeft; - m_typeInput = GUIUnstrip.TextField(m_typeInput, new GUILayoutOption[] { GUILayout.Width(250) }); + m_typeInput = GUIHelper.TextField(m_typeInput, new GUILayoutOption[] { GUILayout.Width(250) }); GUILayout.EndHorizontal(); } - GUIUnstrip.BeginHorizontal(new GUILayoutOption[0]); + GUIHelper.BeginHorizontal(new GUILayoutOption[0]); GUILayout.Label("Scene Filter:", new GUILayoutOption[] { GUILayout.Width(100) }); SceneFilterToggle(SceneFilter.Any, "Any", 60); SceneFilterToggle(SceneFilter.This, "This Scene", 100); diff --git a/src/UI/MainMenu.cs b/src/UI/MainMenu.cs index 25ffd32..4c23a03 100644 --- a/src/UI/MainMenu.cs +++ b/src/UI/MainMenu.cs @@ -47,7 +47,7 @@ namespace Explorer.UI return; } m_currentPage = index; - GUIUnstrip.BringWindowToFront(MainWindowID); + GUIHelper.BringWindowToFront(MainWindowID); GUI.FocusWindow(MainWindowID); } @@ -58,39 +58,39 @@ namespace Explorer.UI public void OnGUI() { - MainRect = GUIUnstrip.Window(MainWindowID, MainRect, (GUI.WindowFunction)MainWindow, ExplorerCore.NAME); + MainRect = GUIHelper.Window(MainWindowID, MainRect, (GUI.WindowFunction)MainWindow, ExplorerCore.NAME); } private void MainWindow(int id) { GUI.DragWindow(new Rect(0, 0, MainRect.width - 90, 20)); - if (GUIUnstrip.Button(new Rect(MainRect.width - 90, 2, 80, 20), $"Hide ({ModConfig.Instance.Main_Menu_Toggle})")) + if (GUIHelper.Button(new Rect(MainRect.width - 90, 2, 80, 20), $"Hide ({ModConfig.Instance.Main_Menu_Toggle})")) { ExplorerCore.ShowMenu = false; return; } - GUIUnstrip.BeginArea(new Rect(5, 25, MainRect.width - 10, MainRect.height - 35), GUI.skin.box); + GUIHelper.BeginArea(new Rect(5, 25, MainRect.width - 10, MainRect.height - 35), GUI.skin.box); MainHeader(); var page = Pages[m_currentPage]; - page.scroll = GUIUnstrip.BeginScrollView(page.scroll); + page.scroll = GUIHelper.BeginScrollView(page.scroll); page.DrawWindow(); - GUIUnstrip.EndScrollView(); + GUIHelper.EndScrollView(); MainRect = ResizeDrag.ResizeWindow(MainRect, MainWindowID); - GUIUnstrip.EndArea(); + GUIHelper.EndArea(); } private void MainHeader() { - GUIUnstrip.BeginHorizontal(new GUILayoutOption[0]); + GUIHelper.BeginHorizontal(new GUILayoutOption[0]); for (int i = 0; i < Pages.Count; i++) { if (m_currentPage == i) @@ -105,7 +105,7 @@ namespace Explorer.UI } GUILayout.EndHorizontal(); - GUIUnstrip.BeginHorizontal(new GUILayoutOption[0]); + GUIHelper.BeginHorizontal(new GUILayoutOption[0]); GUI.color = Color.white; InspectUnderMouse.EnableInspect = GUILayout.Toggle(InspectUnderMouse.EnableInspect, "Inspect Under Mouse (Shift + RMB)", new GUILayoutOption[0]); @@ -117,7 +117,7 @@ namespace Explorer.UI GUILayout.EndHorizontal(); //GUIUnstrip.Space(10); - GUIUnstrip.Space(10); + GUIHelper.Space(10); GUI.color = Color.white; } diff --git a/src/UI/Shared/Buttons.cs b/src/UI/Shared/Buttons.cs index 8d7007d..8229d9f 100644 --- a/src/UI/Shared/Buttons.cs +++ b/src/UI/Shared/Buttons.cs @@ -59,7 +59,7 @@ namespace Explorer.UI.Shared // ------ toggle active button ------ - GUIUnstrip.BeginHorizontal(new GUILayoutOption[0]); + GUIHelper.BeginHorizontal(new GUILayoutOption[0]); GUI.skin.button.alignment = TextAnchor.UpperLeft; GUI.color = color; diff --git a/src/UI/Shared/PageHelper.cs b/src/UI/Shared/PageHelper.cs index 989cf50..e809264 100644 --- a/src/UI/Shared/PageHelper.cs +++ b/src/UI/Shared/PageHelper.cs @@ -94,7 +94,7 @@ namespace Explorer.UI.Shared { GUILayout.Label("Limit: ", new GUILayoutOption[] { GUILayout.Width(50) }); var limit = this.ItemsPerPage.ToString(); - limit = GUIUnstrip.TextField(limit, new GUILayoutOption[] { GUILayout.Width(50) }); + limit = GUIHelper.TextField(limit, new GUILayoutOption[] { GUILayout.Width(50) }); if (limit != ItemsPerPage.ToString() && int.TryParse(limit, out int i)) { ItemsPerPage = i; diff --git a/src/UI/Shared/ResizeDrag.cs b/src/UI/Shared/ResizeDrag.cs index fe73ee3..0ef4d59 100644 --- a/src/UI/Shared/ResizeDrag.cs +++ b/src/UI/Shared/ResizeDrag.cs @@ -25,7 +25,7 @@ namespace Explorer.UI.Shared try { - GUIUnstrip.BeginHorizontal(GUIContent.none, GUI.skin.box, null); + GUIHelper.BeginHorizontal(GUIContent.none, GUI.skin.box, null); GUI.skin.label.alignment = TextAnchor.MiddleCenter; #if BIE @@ -38,12 +38,12 @@ namespace Explorer.UI.Shared GUILayout.Button(gcDrag, GUI.skin.label, new GUILayoutOption[] { GUILayout.Height(15) }); #endif - var resizeDragArea = GUIUnstrip.GetLastRect(); + var resizeDragArea = GUIHelper.GetLastRect(); var mousePos = InputManager.MousePosition; try { - var mouse = GUIUnstrip.ScreenToGUIPoint(new Vector2(mousePos.x, Screen.height - mousePos.y)); + var mouse = GUIHelper.ScreenToGUIPoint(new Vector2(mousePos.x, Screen.height - mousePos.y)); if (resizeDragArea.Contains(mouse)) { IsMouseInResizeArea = true; @@ -92,26 +92,26 @@ namespace Explorer.UI.Shared } else { - GUIUnstrip.BeginHorizontal(new GUILayoutOption[0]); + GUIHelper.BeginHorizontal(new GUILayoutOption[0]); GUILayout.Label("Resize window:", new GUILayoutOption[] { GUILayout.Width(100) }); GUI.skin.label.alignment = TextAnchor.MiddleRight; GUILayout.Label("Width:", new GUILayoutOption[] { GUILayout.Width(60) }); - if (GUIUnstrip.RepeatButton("-", new GUILayoutOption[] { GUILayout.Width(20) })) + if (GUIHelper.RepeatButton("-", new GUILayoutOption[] { GUILayout.Width(20) })) { _rect.width -= 5f; } - if (GUIUnstrip.RepeatButton("+", new GUILayoutOption[] { GUILayout.Width(20) })) + if (GUIHelper.RepeatButton("+", new GUILayoutOption[] { GUILayout.Width(20) })) { _rect.width += 5f; } GUILayout.Label("Height:", new GUILayoutOption[] { GUILayout.Width(60) }); - if (GUIUnstrip.RepeatButton("-", new GUILayoutOption[] { GUILayout.Width(20) })) + if (GUIHelper.RepeatButton("-", new GUILayoutOption[] { GUILayout.Width(20) })) { _rect.height -= 5f; } - if (GUIUnstrip.RepeatButton("+", new GUILayoutOption[] { GUILayout.Width(20) })) + if (GUIHelper.RepeatButton("+", new GUILayoutOption[] { GUILayout.Width(20) })) { _rect.height += 5f; } diff --git a/src/UI/TabViewWindow.cs b/src/UI/TabViewWindow.cs index de5d3ce..13e356d 100644 --- a/src/UI/TabViewWindow.cs +++ b/src/UI/TabViewWindow.cs @@ -52,7 +52,7 @@ namespace Explorer.UI try { GUI.DragWindow(new Rect(0, 0, m_rect.width - 90, 20)); - if (GUIUnstrip.Button(new Rect(m_rect.width - 90, 2, 80, 20), "Close All")) + if (GUIHelper.Button(new Rect(m_rect.width - 90, 2, 80, 20), "Close All")) { foreach (var window in WindowManager.Windows) { @@ -61,10 +61,10 @@ namespace Explorer.UI return; } - GUIUnstrip.BeginArea(new Rect(5, 25, m_rect.width - 10, m_rect.height - 35), GUI.skin.box); + GUIHelper.BeginArea(new Rect(5, 25, m_rect.width - 10, m_rect.height - 35), GUI.skin.box); - GUIUnstrip.BeginVertical(GUIContent.none, GUI.skin.box, null); - GUIUnstrip.BeginHorizontal(new GUILayoutOption[0]); + GUIHelper.BeginVertical(GUIContent.none, GUI.skin.box, null); + GUIHelper.BeginHorizontal(new GUILayoutOption[0]); GUI.skin.button.alignment = TextAnchor.MiddleLeft; int tabPerRow = (int)Math.Floor(m_rect.width / 238); int rowCount = 0; @@ -83,7 +83,7 @@ namespace Explorer.UI { rowCount = 0; GUILayout.EndHorizontal(); - GUIUnstrip.BeginHorizontal(new GUILayoutOption[0]); + GUIHelper.BeginHorizontal(new GUILayoutOption[0]); } rowCount++; @@ -109,7 +109,7 @@ namespace Explorer.UI m_rect = ResizeDrag.ResizeWindow(m_rect, windowID); - GUIUnstrip.EndArea(); + GUIHelper.EndArea(); } catch (Exception e) { diff --git a/src/UI/WindowManager.cs b/src/UI/WindowManager.cs index fbb07ab..82dda49 100644 --- a/src/UI/WindowManager.cs +++ b/src/UI/WindowManager.cs @@ -110,7 +110,7 @@ namespace Explorer.UI { if (!TabView) { - GUIUnstrip.BringWindowToFront(window.windowID); + GUIHelper.BringWindowToFront(window.windowID); GUI.FocusWindow(window.windowID); } else diff --git a/src/Unstrip/IMGUI/GUIHelper.cs b/src/Unstrip/IMGUI/GUIHelper.cs new file mode 100644 index 0000000..e5d7102 --- /dev/null +++ b/src/Unstrip/IMGUI/GUIHelper.cs @@ -0,0 +1,175 @@ +using System; +using System.Collections.Generic; +using System.Reflection; +using UnityEngine; +#if CPP +using Explorer.Unstrip.IMGUI; +#endif + +namespace Explorer +{ + // All the pre-processor directive stuff is in this class to keep it separate. + // This is so Mono build can use this class and not have to worry. + + public class GUIHelper + { + + internal static GUILayoutOption ExpandHeight(bool expand) + { +#if CPP + return GUIUnstrip.ExpandHeight(expand); +#else + return GUILayout.ExpandHeight(expand); +#endif + } + + public static void BeginHorizontal(params GUILayoutOption[] options) + => BeginHorizontal(GUIContent.none, GUIStyle.none, options); + + public static void BeginHorizontal(GUIStyle style, params GUILayoutOption[] options) + => BeginHorizontal(GUIContent.none, style, options); + + public static void BeginHorizontal(GUIContent content, GUIStyle style, params GUILayoutOption[] options) + { +#if CPP + GUIUnstrip.BeginLayoutDirection(false, content, style, options); +#else + GUILayout.BeginHorizontal(content, style, options); +#endif + } + + public static void BeginVertical(params GUILayoutOption[] options) + => BeginVertical(GUIContent.none, GUIStyle.none, options); + + public static void BeginVertical(GUIStyle style, params GUILayoutOption[] options) + => BeginVertical(GUIContent.none, style, options); + + public static void BeginVertical(GUIContent content, GUIStyle style, params GUILayoutOption[] options) + { +#if CPP + GUIUnstrip.BeginLayoutDirection(true, content, style, options); +#else + GUILayout.BeginVertical(content, style, options); +#endif + } + + + public static Rect GetLastRect() + { +#if CPP + return LayoutUtilityUnstrip.GetLastRect(); +#else + return GUILayoutUtility.GetLastRect(); +#endif + } + + public static string TextField(string text, GUILayoutOption[] options) + { +#if CPP + return GUIUnstrip.TextField(text, options, false); +#else + return GUILayout.TextField(text, options); +#endif + } + + public static string TextArea(string text, params GUILayoutOption[] options) + { +#if CPP + return GUIUnstrip.TextField(text, options, true); +#else + return GUILayout.TextArea(text, options); +#endif + } + + public static Rect Window(int id, Rect rect, GUI.WindowFunction windowFunc, string title) + { +#if CPP + return GUI.Window(id, rect, windowFunc, GUIContent.Temp(title), GUI.skin.window); +#else + return GUI.Window(id, rect, windowFunc, title); +#endif + } + + public static bool Button(Rect rect, string title) + { +#if CPP + return GUI.Button(rect, GUIContent.Temp(title), GUI.skin.button); +#else + return GUI.Button(rect, title); +#endif + } + + public static void BringWindowToFront(int id) + { +#if CPP + GUIUnstrip.BringWindowToFront(id); +#else + GUI.BringWindowToFront(id); +#endif + } + + public static Vector2 ScreenToGUIPoint(Vector2 screenPoint) + { +#if CPP + return GUIUnstrip.ScreenToGUIPoint(screenPoint); +#else + return GUIUtility.ScreenToGUIPoint(screenPoint); +#endif + } + + public static void Space(float pixels) + { +#if CPP + GUIUnstrip.Space(pixels); +#else + GUILayout.Space(pixels); +#endif + } + + public static bool RepeatButton(string text, params GUILayoutOption[] options) + { +#if CPP + return GUIUnstrip.DoRepeatButton(GUIContent.Temp(text), GUI.skin.button, options); +#else + return GUILayout.RepeatButton(text, options); +#endif + } + + public static void BeginArea(Rect screenRect, GUIStyle style) + { +#if CPP + GUIUnstrip.BeginArea(screenRect, GUIContent.none, style); +#else + GUILayout.BeginArea(screenRect, style); +#endif + } + + static public void EndArea() + { +#if CPP + GUIUnstrip.EndArea(); +#else + GUILayout.EndArea(); +#endif + } + + + public static Vector2 BeginScrollView(Vector2 scroll, params GUILayoutOption[] options) + { +#if CPP + return GUIUnstrip.BeginScrollView(scroll, options); +#else + return GUILayout.BeginScrollView(scroll, options); +#endif + } + + public static void EndScrollView(bool handleScrollWheel = true) + { +#if CPP + GUIUnstrip.EndScrollView(handleScrollWheel); +#else + GUILayout.EndScrollView(); +#endif + } + } +} \ No newline at end of file diff --git a/src/Unstrip/IMGUI/GUIUnstrip.cs b/src/Unstrip/IMGUI/GUIUnstrip.cs index 3b4f8e8..88b98aa 100644 --- a/src/Unstrip/IMGUI/GUIUnstrip.cs +++ b/src/Unstrip/IMGUI/GUIUnstrip.cs @@ -1,162 +1,786 @@ -using System; +#if CPP +using System; using System.Collections.Generic; using System.Reflection; using UnityEngine; -#if CPP -using Explorer.Unstrip.IMGUI; -#endif +using UnityEngineInternal; +using UnhollowerRuntimeLib; -namespace Explorer +namespace Explorer.Unstrip.IMGUI { + // Also contains some stuff from GUI. + // This class was meant to be temporary but who knows. + public class GUIUnstrip { - public static void BeginHorizontal(params GUILayoutOption[] options) - => BeginHorizontal(GUIContent.none, GUIStyle.none, options); + #region Properties + public static int s_ScrollControlId; - public static void BeginHorizontal(GUIStyle style, params GUILayoutOption[] options) - => BeginHorizontal(GUIContent.none, style, options); + public static bool ScrollFailed = false; + public static bool ManualUnstripFailed = false; - public static void BeginHorizontal(GUIContent content, GUIStyle style, params GUILayoutOption[] options) + public static Stack ScrollStack => m_scrollStack ?? GetScrollStack(); + public static Stack m_scrollStack; + //public static PropertyInfo m_scrollViewStatesInfo; + + public static GUIStyle SpaceStyle => m_spaceStyle ?? GetSpaceStyle(); + public static GUIStyle m_spaceStyle; + + public static DateTime nextScrollStepTime; + + public static MethodInfo ScreenToGuiPointMethod; + public static bool m_screenToGuiAttemped; + + public static MethodInfo m_bringWindowToFrontMethod; + public static bool m_bringWindowFrontAttempted; + + private static Stack GetScrollStack() { -#if CPP - Internal.BeginLayoutDirection(false, content, style, options); -#else - GUILayout.BeginHorizontal(content, style, options); -#endif + m_scrollStack = new Stack(); + + return m_scrollStack; } - public static void BeginVertical(params GUILayoutOption[] options) - => BeginVertical(GUIContent.none, GUIStyle.none, options); - - public static void BeginVertical(GUIStyle style, params GUILayoutOption[] options) - => BeginVertical(GUIContent.none, style, options); - - public static void BeginVertical(GUIContent content, GUIStyle style, params GUILayoutOption[] options) + private static GUIStyle GetSpaceStyle() { -#if CPP - Internal.BeginLayoutDirection(true, content, style, options); -#else - GUILayout.BeginVertical(content, style, options); -#endif + try + { + m_spaceStyle = typeof(GUILayoutUtility) + .GetProperty("s_SpaceStyle") + .GetValue(null, null) + .Il2CppCast(typeof(GUIStyle)) + as GUIStyle; + + if (m_spaceStyle == null) throw new Exception(); + } + catch { } + + if (m_spaceStyle == null) + { + m_spaceStyle = new GUIStyle(); + } + m_spaceStyle.stretchWidth = false; + return m_spaceStyle; } + #endregion - public static Rect GetLastRect() + #region GUILayout Methods + + public static GUILayoutOption ExpandWidth(bool expand) { -#if CPP - return Internal_LayoutUtility.GetLastRect(); -#else - return GUILayoutUtility.GetLastRect(); -#endif + var ilValue = new Il2CppSystem.Int32 + { + m_value = (!expand) ? 0 : 1 + }; + + var option = new GUILayoutOption(GUILayoutOption.Type.stretchWidth, ilValue.BoxIl2CppObject()); + + return option; } - public static string TextField(string text, GUILayoutOption[] options) + public static GUILayoutOption ExpandHeight(bool expand) { -#if CPP - return Internal.TextField(text, options, false); -#else - return GUILayout.TextField(text, options); -#endif + var ilValue = new Il2CppSystem.Int32 + { + m_value = (!expand) ? 0 : 1 + }; + + var option = new GUILayoutOption(GUILayoutOption.Type.stretchHeight, ilValue.BoxIl2CppObject()); + + return option; } - public static string TextArea(string text, params GUILayoutOption[] options) + public static void BeginLayoutDirection(bool vertical, GUIContent content, GUIStyle style, GUILayoutOption[] options) { -#if CPP - return Internal.TextField(text, options, true); -#else - return GUILayout.TextArea(text, options); -#endif + var g = GUILayoutUtility.BeginLayoutGroup(style, options, Il2CppType.Of()); + g.isVertical = vertical; + if (style != GUIStyle.none || content != GUIContent.none) + GUI.Box(g.rect, content, style); } - public static Rect Window(int id, Rect rect, GUI.WindowFunction windowFunc, string title) + public static string TextField(string text, GUILayoutOption[] options, bool multiLine) { -#if CPP - return GUI.Window(id, rect, windowFunc, GUIContent.Temp(title), GUI.skin.window); -#else - return GUI.Window(id, rect, windowFunc, title); -#endif + text = text ?? string.Empty; + + var skin = multiLine ? GUI.skin.textArea : GUI.skin.textField; + + int controlID = GUIUtility.GetControlID(FocusType.Keyboard); + GUIContent guicontent = GUIContent.Temp(text); + bool flag = GUIUtility.keyboardControl != controlID; + if (flag) + { + guicontent = GUIContent.Temp(text); + } + else + { + guicontent = GUIContent.Temp(text); + // guicontent = GUIContent.Temp(text + GUIUtility.compositionString); + } + Rect rect = LayoutUtilityUnstrip.GetRect(guicontent, skin, options); + bool flag2 = GUIUtility.keyboardControl == controlID; + if (flag2) + { + guicontent = GUIContent.Temp(text); + } + DoTextField(rect, controlID, guicontent, multiLine, -1, skin); + return guicontent.text; } - public static bool Button(Rect rect, string title) + internal static void DoTextField(Rect position, int id, GUIContent content, bool multiline, int maxLength, GUIStyle style) { -#if CPP - return GUI.Button(rect, GUIContent.Temp(title), GUI.skin.button); -#else - return GUI.Button(rect, title); -#endif + if (GUIUtilityUnstrip.GetMonoStateObject(typeof(TextEditorUnstrip), id) is TextEditorUnstrip textEditor) + { + if (maxLength >= 0 && content.text.Length > maxLength) + { + content.text = content.text.Substring(0, maxLength); + } + textEditor.m_Content.text = content.text; + textEditor.SaveBackup(); + textEditor.position = position; + textEditor.style = style; + textEditor.multiline = multiline; + textEditor.controlID = id; + textEditor.DetectFocusChange(); + HandleTextFieldEventForDesktop(position, id, content, multiline, maxLength, style, textEditor); + textEditor.UpdateScrollOffsetIfNeeded(Event.current); + } } - public static void BringWindowToFront(int id) + private static void HandleTextFieldEventForDesktop(Rect position, int id, GUIContent content, bool multiline, int maxLength, + GUIStyle style, TextEditorUnstrip editor) { -#if CPP - Internal.BringWindowToFront(id); -#else - GUI.BringWindowToFront(id); -#endif + var evt = Event.current; + + bool change = false; + switch (evt.type) + { + case EventType.MouseDown: + if (position.Contains(evt.mousePosition)) + { + GUIUtility.hotControl = id; + GUIUtility.keyboardControl = id; + editor.m_HasFocus = true; + editor.MoveCursorToPosition(Event.current.mousePosition); + if (Event.current.clickCount == 2 && GUI.skin.settings.doubleClickSelectsWord) + { + editor.SelectCurrentWord(); + editor.DblClickSnap(TextEditorUnstrip.DblClickSnapping.WORDS); + editor.MouseDragSelectsWholeWords(true); + } + if (Event.current.clickCount == 3 && GUI.skin.settings.tripleClickSelectsLine) + { + editor.SelectCurrentParagraph(); + editor.MouseDragSelectsWholeWords(true); + editor.DblClickSnap(TextEditorUnstrip.DblClickSnapping.PARAGRAPHS); + } + evt.Use(); + } + break; + case EventType.MouseDrag: + if (GUIUtility.hotControl == id) + { + if (evt.shift) + editor.MoveCursorToPosition(Event.current.mousePosition); + else + editor.SelectToPosition(Event.current.mousePosition); + evt.Use(); + } + break; + case EventType.MouseUp: + if (GUIUtility.hotControl == id) + { + editor.MouseDragSelectsWholeWords(false); + GUIUtility.hotControl = 0; + evt.Use(); + } + break; + case EventType.KeyDown: + if (GUIUtility.keyboardControl != id) + return; + + if (editor.HandleKeyEvent(evt)) + { + evt.Use(); + change = true; + content.text = editor.text; + break; + } + + // Ignore tab & shift-tab in textfields + if (evt.keyCode == KeyCode.Tab || evt.character == '\t') + return; + + char c = evt.character; + + if (c == '\n' && !multiline && !evt.alt) + return; + + + // Simplest test: only allow the character if the display font supports it. + Font font = style.font; + if (!font) + font = GUI.skin.font; + + if (font.HasCharacter(c) || c == '\n') + { + editor.Insert(c); + change = true; + break; + } + + // On windows, keypresses also send events with keycode but no character. Eat them up here. + if (c == 0) + { + // if we have a composition string, make sure we clear the previous selection. + if (InputManager.compositionString.Length > 0) + { + editor.ReplaceSelection(""); + change = true; + } + + evt.Use(); + } + // else { + // REALLY USEFUL: + // Debug.Log ("unhandled " +evt); + // evt.Use (); + // } + break; + case EventType.Repaint: + // If we have keyboard focus, draw the cursor + // TODO: check if this OpenGL view has keyboard focus + if (GUIUtility.keyboardControl != id) + { + style.Draw(position, content, id, false); + } + else + { + editor.DrawCursor(content.text); + } + break; + } + + if (GUIUtility.keyboardControl == id) + GUIUtility.textFieldInput = true; + + if (change) + { + GUI.changed = true; + content.text = editor.text; + if (maxLength >= 0 && content.text.Length > maxLength) + content.text = content.text.Substring(0, maxLength); + evt.Use(); + } } - public static Vector2 ScreenToGUIPoint(Vector2 screenPoint) + public static bool DoRepeatButton(GUIContent content, GUIStyle style, GUILayoutOption[] options) { -#if CPP - return Internal.ScreenToGUIPoint(screenPoint); -#else - return GUIUtility.ScreenToGUIPoint(screenPoint); -#endif + return GUI.DoRepeatButton(LayoutUtilityUnstrip.GetRect(content, style, options), content, style, FocusType.Passive); } public static void Space(float pixels) { -#if CPP - Internal.Space(pixels); -#else - GUILayout.Space(pixels); -#endif + if (GUILayoutUtility.current.topLevel.isVertical) + LayoutUtilityUnstrip.GetRect(0, pixels, SpaceStyle, new GUILayoutOption[] { GUILayout.Height(pixels) }); + else + LayoutUtilityUnstrip.GetRect(pixels, 0, SpaceStyle, new GUILayoutOption[] { GUILayout.Width(pixels) }); + + if (Event.current.type == EventType.Layout) + { + GUILayoutUtility.current.topLevel.entries[GUILayoutUtility.current.topLevel.entries.Count - 1].consideredForMargin = false; + } } - public static bool RepeatButton(string text, params GUILayoutOption[] options) + public static Vector2 ScreenToGUIPoint(Vector2 screenPoint) { -#if CPP - return Internal.DoRepeatButton(GUIContent.Temp(text), GUI.skin.button, options); -#else - return GUILayout.RepeatButton(text, options); -#endif + if (!m_screenToGuiAttemped) + { + m_screenToGuiAttemped = true; + ScreenToGuiPointMethod = typeof(GUIUtility).GetMethod("ScreenToGUIPoint"); + } + if (ScreenToGuiPointMethod == null) + { + throw new Exception("Couldn't get method 'GUIUtility.ScreenToGUIPoint'!"); + } + return (Vector2)ScreenToGuiPointMethod.Invoke(null, new object[] { screenPoint }); } - public static void BeginArea(Rect screenRect, GUIStyle style) + public static void BringWindowToFront(int id) { -#if CPP - Internal.BeginArea(screenRect, GUIContent.none, style); -#else - GUILayout.BeginArea(screenRect, style); -#endif + if (!m_bringWindowFrontAttempted) + { + m_bringWindowFrontAttempted = true; + m_bringWindowToFrontMethod = typeof(GUI).GetMethod("BringWindowToFront"); + } + if (m_bringWindowToFrontMethod == null) + { + throw new Exception("Couldn't get method 'GUIUtility.BringWindowToFront'!"); + } + m_bringWindowToFrontMethod.Invoke(null, new object[] { id }); } - static public void EndArea() + public static void BeginArea(Rect screenRect, GUIContent content, GUIStyle style) { -#if CPP - Internal.EndArea(); -#else - GUILayout.EndArea(); -#endif + var g = BeginLayoutArea(style, typeof(GUILayoutGroup)); + if (Event.current.type == EventType.Layout) + { + g.resetCoords = true; + g.minWidth = g.maxWidth = screenRect.width; + g.minHeight = g.maxHeight = screenRect.height; + g.rect = Rect.MinMaxRect(screenRect.xMin, screenRect.yMin, g.rect.xMax, g.rect.yMax); + } + + BeginGroup(g.rect, content, style); } + internal static GUILayoutGroup BeginLayoutArea(GUIStyle style, Type layoutType) + { + EventType type = Event.current.type; + GUILayoutGroup guilayoutGroup; + if (type != EventType.Used && type != EventType.Layout) + { + guilayoutGroup = GUILayoutUtility.current.windows.GetNext().TryCast(); + guilayoutGroup.ResetCursor(); + } + else + { + guilayoutGroup = (GUILayoutGroup)Activator.CreateInstance(layoutType); + guilayoutGroup.style = style; + GUILayoutUtility.current.windows.Add(guilayoutGroup); + } + GUILayoutUtility.current.layoutGroups.Push(guilayoutGroup); + GUILayoutUtility.current.topLevel = guilayoutGroup; + return guilayoutGroup; + } + + public static void BeginGroup(Rect position, GUIContent content, GUIStyle style) + { + BeginGroup(position, content, style, Vector2.zero); + } + + internal static void BeginGroup(Rect position, GUIContent content, GUIStyle style, Vector2 scrollOffset) + { + int id = GUIUtility.GetControlID(GUI.s_BeginGroupHash, FocusType.Passive); + + if (content != GUIContent.none || style != GUIStyle.none) + { + switch (Event.current.type) + { + case EventType.Repaint: + style.Draw(position, content, id); + break; + default: + if (position.Contains(Event.current.mousePosition)) + GUIUtility.mouseUsed = true; + break; + } + } + GUIClip.Push(position, scrollOffset, Vector2.zero, false); + } + + public static void EndArea() + { + if (Event.current.type == EventType.Used) + return; + GUILayoutUtility.current.layoutGroups.Pop(); + GUILayoutUtility.current.topLevel = GUILayoutUtility.current.layoutGroups.Peek().TryCast(); + GUI.EndGroup(); + } + + #endregion + + #region Scrolling public static Vector2 BeginScrollView(Vector2 scroll, params GUILayoutOption[] options) { -#if CPP - return Internal.BeginScrollView(scroll, options); -#else - return GUILayout.BeginScrollView(scroll, options); -#endif + // First, just try normal way, may not have been stripped or was unstripped successfully. + if (!ScrollFailed) + { + try + { + return GUILayout.BeginScrollView(scroll, options); + } + catch + { + ScrollFailed = true; + } + } + + // Try manual implementation. + if (!ManualUnstripFailed) + { + try + { + return BeginScrollView_ImplLayout(scroll, + false, + false, + GUI.skin.horizontalScrollbar, + GUI.skin.verticalScrollbar, + GUI.skin.scrollView, + options); + } + catch (Exception e) + { + ExplorerCore.Log("Exception on manual BeginScrollView: " + e.GetType() + ", " + e.Message + "\r\n" + e.StackTrace); + ManualUnstripFailed = true; + } + } + + // Sorry! No scrolling for you. + return scroll; } - public static void EndScrollView(bool handleScrollWheel = true) + internal static void EndScrollView(bool handleScrollWheel) { -#if CPP - Internal.EndScrollView(handleScrollWheel); -#else - GUILayout.EndScrollView(); -#endif + // Only end the scroll view for the relevant BeginScrollView option, if any. + + if (!ScrollFailed) + { + GUILayout.EndScrollView(); + } + else if (!ManualUnstripFailed) + { + GUILayoutUtility.EndLayoutGroup(); + + if (ScrollStack.Count <= 0) return; + + var scrollExt = ScrollStack.Peek() as ScrollViewStateUnstrip; + + //var state = ScrollStack.Peek().TryCast(); + //var scrollExt = Internal_ScrollViewState.FromPointer(state.Pointer); + + //if (scrollExt == null) throw new Exception("Could not get scrollExt!"); + + GUIClip.Pop(); + + ScrollStack.Pop(); + + var position = scrollExt.position; + + if (handleScrollWheel && Event.current.type == EventType.ScrollWheel && position.Contains(Event.current.mousePosition)) + { + var pos = scrollExt.scrollPosition; + pos.x = Mathf.Clamp(scrollExt.scrollPosition.x + Event.current.delta.x * 20f, 0f, scrollExt.viewRect.width - scrollExt.visibleRect.width); + pos.y = Mathf.Clamp(scrollExt.scrollPosition.y + Event.current.delta.y * 20f, 0f, scrollExt.viewRect.height - scrollExt.visibleRect.height); + + if (scrollExt.scrollPosition.x < 0f) + { + pos.x = 0f; + } + if (pos.y < 0f) + { + pos.y = 0f; + } + + scrollExt.apply = true; + + Event.current.Use(); + } + } + } + + private static Vector2 BeginScrollView_ImplLayout(Vector2 scrollPosition, bool alwaysShowHorizontal, bool alwaysShowVertical, + GUIStyle horizontalScrollbar, GUIStyle verticalScrollbar, GUIStyle background, params GUILayoutOption[] options) + { + var guiscrollGroup = GUILayoutUtility.BeginLayoutGroup(background, null, Il2CppType.Of()) + .TryCast(); + + EventType type = Event.current.type; + if (type == EventType.Layout) + { + guiscrollGroup.resetCoords = true; + guiscrollGroup.isVertical = true; + guiscrollGroup.stretchWidth = 1; + guiscrollGroup.stretchHeight = 1; + guiscrollGroup.verticalScrollbar = verticalScrollbar; + guiscrollGroup.horizontalScrollbar = horizontalScrollbar; + guiscrollGroup.needsVerticalScrollbar = alwaysShowVertical; + guiscrollGroup.needsHorizontalScrollbar = alwaysShowHorizontal; + guiscrollGroup.ApplyOptions(options); + } + + return BeginScrollView_Impl(guiscrollGroup.rect, + scrollPosition, + new Rect(0f, 0f, guiscrollGroup.clientWidth, guiscrollGroup.clientHeight), + alwaysShowHorizontal, + alwaysShowVertical, + horizontalScrollbar, + verticalScrollbar, + background + ); + } + + private static Vector2 BeginScrollView_Impl(Rect position, Vector2 scrollPosition, Rect viewRect, bool alwaysShowHorizontal, + bool alwaysShowVertical, GUIStyle horizontalScrollbar, GUIStyle verticalScrollbar, GUIStyle background) + { + // GUIUtility.CheckOnGUI(); + + int controlID = GUIUtility.GetControlID(GUI.s_ScrollviewHash, FocusType.Passive); + + ScrollViewStateUnstrip scrollExt; + try + { + scrollExt = (ScrollViewStateUnstrip)GUIUtilityUnstrip.GetMonoStateObject(typeof(ScrollViewStateUnstrip), controlID); + } + catch + { + return Vector2.zero; + } + + bool apply = scrollExt.apply; + if (apply) + { + scrollPosition = scrollExt.scrollPosition; + scrollExt.apply = false; + } + + scrollExt.position = position; + + scrollExt.scrollPosition = scrollPosition; + scrollExt.visibleRect = scrollExt.viewRect = viewRect; + + var rect = scrollExt.visibleRect; + rect.width = position.width; + rect.height = position.height; + + ScrollStack.Push(scrollExt); + + Rect screenRect = new Rect(position.x, position.y, position.width, position.height); + EventType type = Event.current.type; + if (type != EventType.Layout) + { + if (type != EventType.Used) + { + bool flag = alwaysShowVertical; + bool flag2 = alwaysShowHorizontal; + if (flag2 || viewRect.width > screenRect.width) + { + rect.height = position.height - horizontalScrollbar.fixedHeight + (float)horizontalScrollbar.margin.top; + + screenRect.height -= horizontalScrollbar.fixedHeight + (float)horizontalScrollbar.margin.top; + flag2 = true; + } + if (flag || viewRect.height > screenRect.height) + { + rect.width = position.width - verticalScrollbar.fixedWidth + (float)verticalScrollbar.margin.left; + + screenRect.width -= verticalScrollbar.fixedWidth + (float)verticalScrollbar.margin.left; + flag = true; + if (!flag2 && viewRect.width > screenRect.width) + { + rect.height = position.height - horizontalScrollbar.fixedHeight + (float)horizontalScrollbar.margin.top; + screenRect.height -= horizontalScrollbar.fixedHeight + (float)horizontalScrollbar.margin.top; + flag2 = true; + } + } + if (Event.current.type == EventType.Repaint && background != GUIStyle.none) + { + background.Draw(position, position.Contains(Event.current.mousePosition), false, flag2 && flag, false); + } + if (flag2 && horizontalScrollbar != GUIStyle.none) + { + scrollPosition.x = HorizontalScroll( + new Rect( + position.x, + position.yMax - horizontalScrollbar.fixedHeight, + screenRect.width, + horizontalScrollbar.fixedHeight), + scrollPosition.x, + Mathf.Min(screenRect.width, viewRect.width), + 0f, + viewRect.width, + horizontalScrollbar + ); + } + else + { + GUIUtility.GetControlID(GUI.s_SliderHash, FocusType.Passive); + GUIUtility.GetControlID(GUI.s_RepeatButtonHash, FocusType.Passive); + GUIUtility.GetControlID(GUI.s_RepeatButtonHash, FocusType.Passive); + scrollPosition.x = ((horizontalScrollbar == GUIStyle.none) + ? Mathf.Clamp(scrollPosition.x, 0f, Mathf.Max(viewRect.width - position.width, 0f)) + : 0f); + } + if (flag && verticalScrollbar != GUIStyle.none) + { + scrollPosition.y = VerticalScroll( + new Rect( + screenRect.xMax + (float)verticalScrollbar.margin.left, + screenRect.y, + verticalScrollbar.fixedWidth, + screenRect.height), + scrollPosition.y, + Mathf.Min(screenRect.height, viewRect.height), + 0f, + viewRect.height, + verticalScrollbar + ); + } + else + { + GUIUtility.GetControlID(GUI.s_SliderHash, FocusType.Passive); + GUIUtility.GetControlID(GUI.s_RepeatButtonHash, FocusType.Passive); + GUIUtility.GetControlID(GUI.s_RepeatButtonHash, FocusType.Passive); + scrollPosition.y = ((verticalScrollbar == GUIStyle.none) + ? Mathf.Clamp(scrollPosition.y, 0f, Mathf.Max(viewRect.height - position.height, 0f)) + : 0f); + } + } + } + else + { + GUIUtility.GetControlID(GUI.s_SliderHash, FocusType.Passive); + GUIUtility.GetControlID(GUI.s_RepeatButtonHash, FocusType.Passive); + GUIUtility.GetControlID(GUI.s_RepeatButtonHash, FocusType.Passive); + GUIUtility.GetControlID(GUI.s_SliderHash, FocusType.Passive); + GUIUtility.GetControlID(GUI.s_RepeatButtonHash, FocusType.Passive); + GUIUtility.GetControlID(GUI.s_RepeatButtonHash, FocusType.Passive); + } + GUIClip.Push(screenRect, + new Vector2( + Mathf.Round(-scrollPosition.x - viewRect.x), + Mathf.Round(-scrollPosition.y - viewRect.y)), + Vector2.zero, + false + ); + + return scrollPosition; + } + + public static float HorizontalScroll(Rect position, float value, float size, float leftValue, float rightValue, GUIStyle style) + { + return Scroller(position, value, size, leftValue, rightValue, style, + GUI.skin.GetStyle(style.name + "thumb"), + GUI.skin.GetStyle(style.name + "leftbutton"), + GUI.skin.GetStyle(style.name + "rightbutton"), + true); + } + + public static float VerticalScroll(Rect position, float value, float size, float topValue, float bottomValue, GUIStyle style) + { + return Scroller(position, value, size, topValue, bottomValue, style, + GUI.skin.GetStyle(style.name + "thumb"), + GUI.skin.GetStyle(style.name + "upbutton"), + GUI.skin.GetStyle(style.name + "downbutton"), + false); + } + + private static float Scroller(Rect position, float value, float size, float leftValue, float rightValue, GUIStyle slider, + GUIStyle thumb, GUIStyle leftButton, GUIStyle rightButton, bool horiz) + { + GUIUtility.CheckOnGUI(); + int controlID = GUIUtility.GetControlID(GUI.s_SliderHash, FocusType.Passive, position); + Rect position2; + Rect rect; + Rect rect2; + if (horiz) + { + position2 = new Rect(position.x + leftButton.fixedWidth, + position.y, + position.width - leftButton.fixedWidth - rightButton.fixedWidth, + position.height); + + rect = new Rect(position.x, position.y, leftButton.fixedWidth, position.height); + rect2 = new Rect(position.xMax - rightButton.fixedWidth, position.y, rightButton.fixedWidth, position.height); + } + else + { + position2 = new Rect(position.x, + position.y + leftButton.fixedHeight, + position.width, + position.height - leftButton.fixedHeight - rightButton.fixedHeight); + + rect = new Rect(position.x, position.y, position.width, leftButton.fixedHeight); + rect2 = new Rect(position.x, position.yMax - rightButton.fixedHeight, position.width, rightButton.fixedHeight); + } + + value = Slider(position2, value, size, leftValue, rightValue, slider, thumb, horiz, controlID); + + bool flag = Event.current.type == EventType.MouseUp; + if (ScrollerRepeatButton(controlID, rect, leftButton)) + { + value -= 10f * ((leftValue >= rightValue) ? -1f : 1f); + } + if (ScrollerRepeatButton(controlID, rect2, rightButton)) + { + value += 10f * ((leftValue >= rightValue) ? -1f : 1f); + } + if (flag && Event.current.type == EventType.Used) + { + s_ScrollControlId = 0; + } + if (leftValue < rightValue) + { + value = Mathf.Clamp(value, leftValue, rightValue - size); + } + else + { + value = Mathf.Clamp(value, rightValue, leftValue - size); + } + return value; + } + + public static float Slider(Rect position, float value, float size, float start, float end, GUIStyle slider, + GUIStyle thumb, bool horiz, int id) + { + if (id == 0) + { + id = GUIUtility.GetControlID(GUI.s_SliderHash, FocusType.Passive, position); + } + var sliderHandler = new SliderHandlerUnstrip(position, value, size, start, end, slider, thumb, horiz, id); + return sliderHandler.Handle(); + } + + private static bool ScrollerRepeatButton(int scrollerID, Rect rect, GUIStyle style) + { + bool result = false; + if (GUI.DoRepeatButton(rect, GUIContent.none, style, FocusType.Passive)) + { + bool flag = s_ScrollControlId != scrollerID; + s_ScrollControlId = scrollerID; + + if (flag) + { + result = true; + nextScrollStepTime = DateTime.Now.AddMilliseconds(250.0); + } + else if (DateTime.Now >= nextScrollStepTime) + { + result = true; + nextScrollStepTime = DateTime.Now.AddMilliseconds(30.0); + } + if (Event.current.type == EventType.Repaint) + { + GUI.InternalRepaintEditorWindow(); + } + } + return result; + } + + #endregion + } + + #region Extensions + + public static class Extensions + { + public static Rect Unstripped_GetLast(this GUILayoutGroup group) + { + Rect result; + if (group.m_Cursor > 0 && group.m_Cursor <= group.entries.Count) + { + GUILayoutEntry guilayoutEntry = group.entries[group.m_Cursor - 1]; + result = guilayoutEntry.rect; + } + else + { + result = GUILayoutEntry.kDummyRect; + } + return result; } } -} \ No newline at end of file + + #endregion +} +#endif diff --git a/src/Unstrip/IMGUI/Internal_GUIUtility.cs b/src/Unstrip/IMGUI/GUIUtilityUnstrip.cs similarity index 98% rename from src/Unstrip/IMGUI/Internal_GUIUtility.cs rename to src/Unstrip/IMGUI/GUIUtilityUnstrip.cs index 53ec2c3..ab54a0f 100644 --- a/src/Unstrip/IMGUI/Internal_GUIUtility.cs +++ b/src/Unstrip/IMGUI/GUIUtilityUnstrip.cs @@ -8,7 +8,7 @@ using Explorer.Helpers; namespace Explorer.Unstrip.IMGUI { - public class Internal_GUIUtility + public class GUIUtilityUnstrip { public static Dictionary MonoStateCache = new Dictionary(); diff --git a/src/Unstrip/IMGUI/Internal.cs b/src/Unstrip/IMGUI/Internal.cs deleted file mode 100644 index c8d827c..0000000 --- a/src/Unstrip/IMGUI/Internal.cs +++ /dev/null @@ -1,762 +0,0 @@ -#if CPP -using System; -using System.Collections.Generic; -using System.Reflection; -using UnityEngine; -using UnityEngineInternal; -using UnhollowerRuntimeLib; - -namespace Explorer.Unstrip.IMGUI -{ - public class Internal - { - #region Properties - public static int s_ScrollControlId; - - public static bool ScrollFailed = false; - public static bool ManualUnstripFailed = false; - - public static Stack ScrollStack => m_scrollStack ?? GetScrollStack(); - public static Stack m_scrollStack; - //public static PropertyInfo m_scrollViewStatesInfo; - - public static GUIStyle SpaceStyle => m_spaceStyle ?? GetSpaceStyle(); - public static GUIStyle m_spaceStyle; - - public static DateTime nextScrollStepTime; - - public static MethodInfo ScreenToGuiPointMethod; - public static bool m_screenToGuiAttemped; - - public static MethodInfo m_bringWindowToFrontMethod; - public static bool m_bringWindowFrontAttempted; - - private static Stack GetScrollStack() - { - m_scrollStack = new Stack(); - - return m_scrollStack; - } - - private static GUIStyle GetSpaceStyle() - { - try - { - m_spaceStyle = typeof(GUILayoutUtility) - .GetProperty("s_SpaceStyle") - .GetValue(null, null) - .Il2CppCast(typeof(GUIStyle)) - as GUIStyle; - - if (m_spaceStyle == null) throw new Exception(); - } - catch { } - - if (m_spaceStyle == null) - { - m_spaceStyle = new GUIStyle(); - } - m_spaceStyle.stretchWidth = false; - return m_spaceStyle; - } - - #endregion - - #region GUILayout Methods - - public static void BeginLayoutDirection(bool vertical, GUIContent content, GUIStyle style, GUILayoutOption[] options) - { - var g = GUILayoutUtility.BeginLayoutGroup(style, options, Il2CppType.Of()); - g.isVertical = vertical; - if (style != GUIStyle.none || content != GUIContent.none) - GUI.Box(g.rect, content, style); - } - - public static string TextField(string text, GUILayoutOption[] options, bool multiLine) - { - text = text ?? string.Empty; - - var skin = multiLine ? GUI.skin.textArea : GUI.skin.textField; - - int controlID = GUIUtility.GetControlID(FocusType.Keyboard); - GUIContent guicontent = GUIContent.Temp(text); - bool flag = GUIUtility.keyboardControl != controlID; - if (flag) - { - guicontent = GUIContent.Temp(text); - } - else - { - guicontent = GUIContent.Temp(text); - // guicontent = GUIContent.Temp(text + GUIUtility.compositionString); - } - Rect rect = Internal_LayoutUtility.GetRect(guicontent, skin, options); - bool flag2 = GUIUtility.keyboardControl == controlID; - if (flag2) - { - guicontent = GUIContent.Temp(text); - } - DoTextField(rect, controlID, guicontent, multiLine, -1, skin); - return guicontent.text; - } - - internal static void DoTextField(Rect position, int id, GUIContent content, bool multiline, int maxLength, GUIStyle style) - { - if (Internal_GUIUtility.GetMonoStateObject(typeof(Internal_TextEditor), id) is Internal_TextEditor textEditor) - { - if (maxLength >= 0 && content.text.Length > maxLength) - { - content.text = content.text.Substring(0, maxLength); - } - textEditor.m_Content.text = content.text; - textEditor.SaveBackup(); - textEditor.position = position; - textEditor.style = style; - textEditor.multiline = multiline; - textEditor.controlID = id; - textEditor.DetectFocusChange(); - HandleTextFieldEventForDesktop(position, id, content, multiline, maxLength, style, textEditor); - textEditor.UpdateScrollOffsetIfNeeded(Event.current); - } - } - - private static void HandleTextFieldEventForDesktop(Rect position, int id, GUIContent content, bool multiline, int maxLength, - GUIStyle style, Internal_TextEditor editor) - { - var evt = Event.current; - - bool change = false; - switch (evt.type) - { - case EventType.MouseDown: - if (position.Contains(evt.mousePosition)) - { - GUIUtility.hotControl = id; - GUIUtility.keyboardControl = id; - editor.m_HasFocus = true; - editor.MoveCursorToPosition(Event.current.mousePosition); - if (Event.current.clickCount == 2 && GUI.skin.settings.doubleClickSelectsWord) - { - editor.SelectCurrentWord(); - editor.DblClickSnap(Internal_TextEditor.DblClickSnapping.WORDS); - editor.MouseDragSelectsWholeWords(true); - } - if (Event.current.clickCount == 3 && GUI.skin.settings.tripleClickSelectsLine) - { - editor.SelectCurrentParagraph(); - editor.MouseDragSelectsWholeWords(true); - editor.DblClickSnap(Internal_TextEditor.DblClickSnapping.PARAGRAPHS); - } - evt.Use(); - } - break; - case EventType.MouseDrag: - if (GUIUtility.hotControl == id) - { - if (evt.shift) - editor.MoveCursorToPosition(Event.current.mousePosition); - else - editor.SelectToPosition(Event.current.mousePosition); - evt.Use(); - } - break; - case EventType.MouseUp: - if (GUIUtility.hotControl == id) - { - editor.MouseDragSelectsWholeWords(false); - GUIUtility.hotControl = 0; - evt.Use(); - } - break; - case EventType.KeyDown: - if (GUIUtility.keyboardControl != id) - return; - - if (editor.HandleKeyEvent(evt)) - { - evt.Use(); - change = true; - content.text = editor.text; - break; - } - - // Ignore tab & shift-tab in textfields - if (evt.keyCode == KeyCode.Tab || evt.character == '\t') - return; - - char c = evt.character; - - if (c == '\n' && !multiline && !evt.alt) - return; - - - // Simplest test: only allow the character if the display font supports it. - Font font = style.font; - if (!font) - font = GUI.skin.font; - - if (font.HasCharacter(c) || c == '\n') - { - editor.Insert(c); - change = true; - break; - } - - // On windows, keypresses also send events with keycode but no character. Eat them up here. - if (c == 0) - { - // if we have a composition string, make sure we clear the previous selection. - if (InputManager.compositionString.Length > 0) - { - editor.ReplaceSelection(""); - change = true; - } - - evt.Use(); - } - // else { - // REALLY USEFUL: - // Debug.Log ("unhandled " +evt); - // evt.Use (); - // } - break; - case EventType.Repaint: - // If we have keyboard focus, draw the cursor - // TODO: check if this OpenGL view has keyboard focus - if (GUIUtility.keyboardControl != id) - { - style.Draw(position, content, id, false); - } - else - { - editor.DrawCursor(content.text); - } - break; - } - - if (GUIUtility.keyboardControl == id) - GUIUtility.textFieldInput = true; - - if (change) - { - GUI.changed = true; - content.text = editor.text; - if (maxLength >= 0 && content.text.Length > maxLength) - content.text = content.text.Substring(0, maxLength); - evt.Use(); - } - } - - public static bool DoRepeatButton(GUIContent content, GUIStyle style, GUILayoutOption[] options) - { - return GUI.DoRepeatButton(Internal_LayoutUtility.GetRect(content, style, options), content, style, FocusType.Passive); - } - - public static void Space(float pixels) - { - if (GUILayoutUtility.current.topLevel.isVertical) - Internal_LayoutUtility.GetRect(0, pixels, SpaceStyle, new GUILayoutOption[] { GUILayout.Height(pixels) }); - else - Internal_LayoutUtility.GetRect(pixels, 0, SpaceStyle, new GUILayoutOption[] { GUILayout.Width(pixels) }); - - if (Event.current.type == EventType.Layout) - { - GUILayoutUtility.current.topLevel.entries[GUILayoutUtility.current.topLevel.entries.Count - 1].consideredForMargin = false; - } - } - - public static Vector2 ScreenToGUIPoint(Vector2 screenPoint) - { - if (!m_screenToGuiAttemped) - { - m_screenToGuiAttemped = true; - ScreenToGuiPointMethod = typeof(GUIUtility).GetMethod("ScreenToGUIPoint"); - } - if (ScreenToGuiPointMethod == null) - { - throw new Exception("Couldn't get method 'GUIUtility.ScreenToGUIPoint'!"); - } - return (Vector2)ScreenToGuiPointMethod.Invoke(null, new object[] { screenPoint }); - } - - public static void BringWindowToFront(int id) - { - if (!m_bringWindowFrontAttempted) - { - m_bringWindowFrontAttempted = true; - m_bringWindowToFrontMethod = typeof(GUI).GetMethod("BringWindowToFront"); - } - if (m_bringWindowToFrontMethod == null) - { - throw new Exception("Couldn't get method 'GUIUtility.BringWindowToFront'!"); - } - m_bringWindowToFrontMethod.Invoke(null, new object[] { id }); - } - - public static void BeginArea(Rect screenRect, GUIContent content, GUIStyle style) - { - var g = BeginLayoutArea(style, typeof(GUILayoutGroup)); - if (Event.current.type == EventType.Layout) - { - g.resetCoords = true; - g.minWidth = g.maxWidth = screenRect.width; - g.minHeight = g.maxHeight = screenRect.height; - g.rect = Rect.MinMaxRect(screenRect.xMin, screenRect.yMin, g.rect.xMax, g.rect.yMax); - } - - BeginGroup(g.rect, content, style); - } - - internal static GUILayoutGroup BeginLayoutArea(GUIStyle style, Type layoutType) - { - EventType type = Event.current.type; - GUILayoutGroup guilayoutGroup; - if (type != EventType.Used && type != EventType.Layout) - { - guilayoutGroup = GUILayoutUtility.current.windows.GetNext().TryCast(); - guilayoutGroup.ResetCursor(); - } - else - { - guilayoutGroup = (GUILayoutGroup)Activator.CreateInstance(layoutType); - guilayoutGroup.style = style; - GUILayoutUtility.current.windows.Add(guilayoutGroup); - } - GUILayoutUtility.current.layoutGroups.Push(guilayoutGroup); - GUILayoutUtility.current.topLevel = guilayoutGroup; - return guilayoutGroup; - } - - public static void BeginGroup(Rect position, GUIContent content, GUIStyle style) - { - BeginGroup(position, content, style, Vector2.zero); - } - - internal static void BeginGroup(Rect position, GUIContent content, GUIStyle style, Vector2 scrollOffset) - { - int id = GUIUtility.GetControlID(GUI.s_BeginGroupHash, FocusType.Passive); - - if (content != GUIContent.none || style != GUIStyle.none) - { - switch (Event.current.type) - { - case EventType.Repaint: - style.Draw(position, content, id); - break; - default: - if (position.Contains(Event.current.mousePosition)) - GUIUtility.mouseUsed = true; - break; - } - } - GUIClip.Push(position, scrollOffset, Vector2.zero, false); - } - - public static void EndArea() - { - if (Event.current.type == EventType.Used) - return; - GUILayoutUtility.current.layoutGroups.Pop(); - GUILayoutUtility.current.topLevel = GUILayoutUtility.current.layoutGroups.Peek().TryCast(); - GUI.EndGroup(); - } - - #endregion - - #region Scrolling - - public static Vector2 BeginScrollView(Vector2 scroll, params GUILayoutOption[] options) - { - // First, just try normal way, may not have been stripped or was unstripped successfully. - if (!ScrollFailed) - { - try - { - return GUILayout.BeginScrollView(scroll, options); - } - catch - { - ScrollFailed = true; - } - } - - // Try manual implementation. - if (!ManualUnstripFailed) - { - try - { - return BeginScrollView_ImplLayout(scroll, - false, - false, - GUI.skin.horizontalScrollbar, - GUI.skin.verticalScrollbar, - GUI.skin.scrollView, - options); - } - catch (Exception e) - { - ExplorerCore.Log("Exception on manual BeginScrollView: " + e.GetType() + ", " + e.Message + "\r\n" + e.StackTrace); - ManualUnstripFailed = true; - } - } - - // Sorry! No scrolling for you. - return scroll; - } - - internal static void EndScrollView(bool handleScrollWheel) - { - // Only end the scroll view for the relevant BeginScrollView option, if any. - - if (!ScrollFailed) - { - GUILayout.EndScrollView(); - } - else if (!ManualUnstripFailed) - { - GUILayoutUtility.EndLayoutGroup(); - - if (ScrollStack.Count <= 0) return; - - var scrollExt = ScrollStack.Peek() as Internal_ScrollViewState; - - //var state = ScrollStack.Peek().TryCast(); - //var scrollExt = Internal_ScrollViewState.FromPointer(state.Pointer); - - //if (scrollExt == null) throw new Exception("Could not get scrollExt!"); - - GUIClip.Pop(); - - ScrollStack.Pop(); - - var position = scrollExt.position; - - if (handleScrollWheel && Event.current.type == EventType.ScrollWheel && position.Contains(Event.current.mousePosition)) - { - var pos = scrollExt.scrollPosition; - pos.x = Mathf.Clamp(scrollExt.scrollPosition.x + Event.current.delta.x * 20f, 0f, scrollExt.viewRect.width - scrollExt.visibleRect.width); - pos.y = Mathf.Clamp(scrollExt.scrollPosition.y + Event.current.delta.y * 20f, 0f, scrollExt.viewRect.height - scrollExt.visibleRect.height); - - if (scrollExt.scrollPosition.x < 0f) - { - pos.x = 0f; - } - if (pos.y < 0f) - { - pos.y = 0f; - } - - scrollExt.apply = true; - - Event.current.Use(); - } - } - } - - private static Vector2 BeginScrollView_ImplLayout(Vector2 scrollPosition, bool alwaysShowHorizontal, bool alwaysShowVertical, - GUIStyle horizontalScrollbar, GUIStyle verticalScrollbar, GUIStyle background, params GUILayoutOption[] options) - { - var guiscrollGroup = GUILayoutUtility.BeginLayoutGroup(background, null, Il2CppType.Of()) - .TryCast(); - - EventType type = Event.current.type; - if (type == EventType.Layout) - { - guiscrollGroup.resetCoords = true; - guiscrollGroup.isVertical = true; - guiscrollGroup.stretchWidth = 1; - guiscrollGroup.stretchHeight = 1; - guiscrollGroup.verticalScrollbar = verticalScrollbar; - guiscrollGroup.horizontalScrollbar = horizontalScrollbar; - guiscrollGroup.needsVerticalScrollbar = alwaysShowVertical; - guiscrollGroup.needsHorizontalScrollbar = alwaysShowHorizontal; - guiscrollGroup.ApplyOptions(options); - } - - return BeginScrollView_Impl(guiscrollGroup.rect, - scrollPosition, - new Rect(0f, 0f, guiscrollGroup.clientWidth, guiscrollGroup.clientHeight), - alwaysShowHorizontal, - alwaysShowVertical, - horizontalScrollbar, - verticalScrollbar, - background - ); - } - - private static Vector2 BeginScrollView_Impl(Rect position, Vector2 scrollPosition, Rect viewRect, bool alwaysShowHorizontal, - bool alwaysShowVertical, GUIStyle horizontalScrollbar, GUIStyle verticalScrollbar, GUIStyle background) - { - // GUIUtility.CheckOnGUI(); - - int controlID = GUIUtility.GetControlID(GUI.s_ScrollviewHash, FocusType.Passive); - - var scrollExt = (Internal_ScrollViewState)Internal_GUIUtility.GetMonoStateObject(typeof(Internal_ScrollViewState), controlID); - - //var scrollViewState = Internal_GUIUtility.GetStateObject(Il2CppType.Of(), controlID) - // .TryCast(); - - //if (scrollViewState == null) - // return scrollPosition; - - //var scrollExt = Internal_ScrollViewState.FromPointer(scrollViewState.Pointer); - - //if (scrollExt == null) - // return scrollPosition; - - bool apply = scrollExt.apply; - if (apply) - { - scrollPosition = scrollExt.scrollPosition; - scrollExt.apply = false; - } - - scrollExt.position = position; - - scrollExt.scrollPosition = scrollPosition; - scrollExt.visibleRect = scrollExt.viewRect = viewRect; - - var rect = scrollExt.visibleRect; - rect.width = position.width; - rect.height = position.height; - - ScrollStack.Push(scrollExt); - - Rect screenRect = new Rect(position.x, position.y, position.width, position.height); - EventType type = Event.current.type; - if (type != EventType.Layout) - { - if (type != EventType.Used) - { - bool flag = alwaysShowVertical; - bool flag2 = alwaysShowHorizontal; - if (flag2 || viewRect.width > screenRect.width) - { - rect.height = position.height - horizontalScrollbar.fixedHeight + (float)horizontalScrollbar.margin.top; - - screenRect.height -= horizontalScrollbar.fixedHeight + (float)horizontalScrollbar.margin.top; - flag2 = true; - } - if (flag || viewRect.height > screenRect.height) - { - rect.width = position.width - verticalScrollbar.fixedWidth + (float)verticalScrollbar.margin.left; - - screenRect.width -= verticalScrollbar.fixedWidth + (float)verticalScrollbar.margin.left; - flag = true; - if (!flag2 && viewRect.width > screenRect.width) - { - rect.height = position.height - horizontalScrollbar.fixedHeight + (float)horizontalScrollbar.margin.top; - screenRect.height -= horizontalScrollbar.fixedHeight + (float)horizontalScrollbar.margin.top; - flag2 = true; - } - } - if (Event.current.type == EventType.Repaint && background != GUIStyle.none) - { - background.Draw(position, position.Contains(Event.current.mousePosition), false, flag2 && flag, false); - } - if (flag2 && horizontalScrollbar != GUIStyle.none) - { - scrollPosition.x = HorizontalScroll( - new Rect( - position.x, - position.yMax - horizontalScrollbar.fixedHeight, - screenRect.width, - horizontalScrollbar.fixedHeight), - scrollPosition.x, - Mathf.Min(screenRect.width, viewRect.width), - 0f, - viewRect.width, - horizontalScrollbar - ); - } - else - { - GUIUtility.GetControlID(GUI.s_SliderHash, FocusType.Passive); - GUIUtility.GetControlID(GUI.s_RepeatButtonHash, FocusType.Passive); - GUIUtility.GetControlID(GUI.s_RepeatButtonHash, FocusType.Passive); - scrollPosition.x = ((horizontalScrollbar == GUIStyle.none) - ? Mathf.Clamp(scrollPosition.x, 0f, Mathf.Max(viewRect.width - position.width, 0f)) - : 0f); - } - if (flag && verticalScrollbar != GUIStyle.none) - { - scrollPosition.y = VerticalScroll( - new Rect( - screenRect.xMax + (float)verticalScrollbar.margin.left, - screenRect.y, - verticalScrollbar.fixedWidth, - screenRect.height), - scrollPosition.y, - Mathf.Min(screenRect.height, viewRect.height), - 0f, - viewRect.height, - verticalScrollbar - ); - } - else - { - GUIUtility.GetControlID(GUI.s_SliderHash, FocusType.Passive); - GUIUtility.GetControlID(GUI.s_RepeatButtonHash, FocusType.Passive); - GUIUtility.GetControlID(GUI.s_RepeatButtonHash, FocusType.Passive); - scrollPosition.y = ((verticalScrollbar == GUIStyle.none) - ? Mathf.Clamp(scrollPosition.y, 0f, Mathf.Max(viewRect.height - position.height, 0f)) - : 0f); - } - } - } - else - { - GUIUtility.GetControlID(GUI.s_SliderHash, FocusType.Passive); - GUIUtility.GetControlID(GUI.s_RepeatButtonHash, FocusType.Passive); - GUIUtility.GetControlID(GUI.s_RepeatButtonHash, FocusType.Passive); - GUIUtility.GetControlID(GUI.s_SliderHash, FocusType.Passive); - GUIUtility.GetControlID(GUI.s_RepeatButtonHash, FocusType.Passive); - GUIUtility.GetControlID(GUI.s_RepeatButtonHash, FocusType.Passive); - } - GUIClip.Push(screenRect, - new Vector2( - Mathf.Round(-scrollPosition.x - viewRect.x), - Mathf.Round(-scrollPosition.y - viewRect.y)), - Vector2.zero, - false - ); - - return scrollPosition; - } - - public static float HorizontalScroll(Rect position, float value, float size, float leftValue, float rightValue, GUIStyle style) - { - return Scroller(position, value, size, leftValue, rightValue, style, - GUI.skin.GetStyle(style.name + "thumb"), - GUI.skin.GetStyle(style.name + "leftbutton"), - GUI.skin.GetStyle(style.name + "rightbutton"), - true); - } - - public static float VerticalScroll(Rect position, float value, float size, float topValue, float bottomValue, GUIStyle style) - { - return Scroller(position, value, size, topValue, bottomValue, style, - GUI.skin.GetStyle(style.name + "thumb"), - GUI.skin.GetStyle(style.name + "upbutton"), - GUI.skin.GetStyle(style.name + "downbutton"), - false); - } - - private static float Scroller(Rect position, float value, float size, float leftValue, float rightValue, GUIStyle slider, - GUIStyle thumb, GUIStyle leftButton, GUIStyle rightButton, bool horiz) - { - GUIUtility.CheckOnGUI(); - int controlID = GUIUtility.GetControlID(GUI.s_SliderHash, FocusType.Passive, position); - Rect position2; - Rect rect; - Rect rect2; - if (horiz) - { - position2 = new Rect(position.x + leftButton.fixedWidth, - position.y, - position.width - leftButton.fixedWidth - rightButton.fixedWidth, - position.height); - - rect = new Rect(position.x, position.y, leftButton.fixedWidth, position.height); - rect2 = new Rect(position.xMax - rightButton.fixedWidth, position.y, rightButton.fixedWidth, position.height); - } - else - { - position2 = new Rect(position.x, - position.y + leftButton.fixedHeight, - position.width, - position.height - leftButton.fixedHeight - rightButton.fixedHeight); - - rect = new Rect(position.x, position.y, position.width, leftButton.fixedHeight); - rect2 = new Rect(position.x, position.yMax - rightButton.fixedHeight, position.width, rightButton.fixedHeight); - } - - value = Slider(position2, value, size, leftValue, rightValue, slider, thumb, horiz, controlID); - - bool flag = Event.current.type == EventType.MouseUp; - if (ScrollerRepeatButton(controlID, rect, leftButton)) - { - value -= 10f * ((leftValue >= rightValue) ? -1f : 1f); - } - if (ScrollerRepeatButton(controlID, rect2, rightButton)) - { - value += 10f * ((leftValue >= rightValue) ? -1f : 1f); - } - if (flag && Event.current.type == EventType.Used) - { - s_ScrollControlId = 0; - } - if (leftValue < rightValue) - { - value = Mathf.Clamp(value, leftValue, rightValue - size); - } - else - { - value = Mathf.Clamp(value, rightValue, leftValue - size); - } - return value; - } - - public static float Slider(Rect position, float value, float size, float start, float end, GUIStyle slider, - GUIStyle thumb, bool horiz, int id) - { - if (id == 0) - { - id = GUIUtility.GetControlID(GUI.s_SliderHash, FocusType.Passive, position); - } - var sliderHandler = new Internal_SliderHandler(position, value, size, start, end, slider, thumb, horiz, id); - return sliderHandler.Handle(); - } - - private static bool ScrollerRepeatButton(int scrollerID, Rect rect, GUIStyle style) - { - bool result = false; - if (GUI.DoRepeatButton(rect, GUIContent.none, style, FocusType.Passive)) - { - bool flag = s_ScrollControlId != scrollerID; - s_ScrollControlId = scrollerID; - - if (flag) - { - result = true; - nextScrollStepTime = DateTime.Now.AddMilliseconds(250.0); - } - else if (DateTime.Now >= nextScrollStepTime) - { - result = true; - nextScrollStepTime = DateTime.Now.AddMilliseconds(30.0); - } - if (Event.current.type == EventType.Repaint) - { - GUI.InternalRepaintEditorWindow(); - } - } - return result; - } - - #endregion - } - - #region Extensions - - public static class Extensions - { - public static Rect Unstripped_GetLast(this GUILayoutGroup group) - { - Rect result; - if (group.m_Cursor > 0 && group.m_Cursor <= group.entries.Count) - { - GUILayoutEntry guilayoutEntry = group.entries[group.m_Cursor - 1]; - result = guilayoutEntry.rect; - } - else - { - result = GUILayoutEntry.kDummyRect; - } - return result; - } - } - - #endregion -} -#endif diff --git a/src/Unstrip/IMGUI/Internal_LayoutUtility.cs b/src/Unstrip/IMGUI/LayoutUtilityUnstrip.cs similarity index 98% rename from src/Unstrip/IMGUI/Internal_LayoutUtility.cs rename to src/Unstrip/IMGUI/LayoutUtilityUnstrip.cs index 5300430..0d3273c 100644 --- a/src/Unstrip/IMGUI/Internal_LayoutUtility.cs +++ b/src/Unstrip/IMGUI/LayoutUtilityUnstrip.cs @@ -3,7 +3,7 @@ using UnityEngine; namespace Explorer.Unstrip.IMGUI { - public class Internal_LayoutUtility + public class LayoutUtilityUnstrip { public static Rect GetRect(float width, float height, GUIStyle style, params GUILayoutOption[] options) { diff --git a/src/Unstrip/IMGUI/Internal_ScrollViewState.cs b/src/Unstrip/IMGUI/ScrollViewStateUnstrip.cs similarity index 97% rename from src/Unstrip/IMGUI/Internal_ScrollViewState.cs rename to src/Unstrip/IMGUI/ScrollViewStateUnstrip.cs index c19f0e0..9fca083 100644 --- a/src/Unstrip/IMGUI/Internal_ScrollViewState.cs +++ b/src/Unstrip/IMGUI/ScrollViewStateUnstrip.cs @@ -5,7 +5,7 @@ using UnityEngine; namespace Explorer.Unstrip.IMGUI { - public class Internal_ScrollViewState + public class ScrollViewStateUnstrip { public Rect position; public Rect visibleRect; diff --git a/src/Unstrip/IMGUI/Internal_SliderHandler.cs b/src/Unstrip/IMGUI/SliderHandlerUnstrip.cs similarity index 95% rename from src/Unstrip/IMGUI/Internal_SliderHandler.cs rename to src/Unstrip/IMGUI/SliderHandlerUnstrip.cs index e6d16f9..12a1533 100644 --- a/src/Unstrip/IMGUI/Internal_SliderHandler.cs +++ b/src/Unstrip/IMGUI/SliderHandlerUnstrip.cs @@ -5,7 +5,7 @@ using UnityEngine; namespace Explorer.Unstrip.IMGUI { - public struct Internal_SliderHandler + public struct SliderHandlerUnstrip { public static int ScrollTroughSide { @@ -57,7 +57,7 @@ namespace Explorer.Unstrip.IMGUI private readonly bool horiz; private readonly int id; - public Internal_SliderHandler(Rect position, float currentValue, float size, float start, + public SliderHandlerUnstrip(Rect position, float currentValue, float size, float start, float end, GUIStyle slider, GUIStyle thumb, bool horiz, int id) { this.position = position; @@ -120,7 +120,7 @@ namespace Explorer.Unstrip.IMGUI { var state = GetSliderState(); state.isDragging = false; - Internal.nextScrollStepTime = DateTime.Now.AddMilliseconds(250.0); + GUIUnstrip.nextScrollStepTime = DateTime.Now.AddMilliseconds(250.0); ScrollTroughSide = this.CurrentScrollTroughSide(); result = this.PageMovementValue(); } @@ -194,7 +194,7 @@ namespace Explorer.Unstrip.IMGUI else { GUI.InternalRepaintEditorWindow(); - if (DateTime.Now < Internal.nextScrollStepTime) + if (DateTime.Now < GUIUnstrip.nextScrollStepTime) { result = this.currentValue; } @@ -204,7 +204,7 @@ namespace Explorer.Unstrip.IMGUI } else { - Internal.nextScrollStepTime = DateTime.Now.AddMilliseconds(30.0); + GUIUnstrip.nextScrollStepTime = DateTime.Now.AddMilliseconds(30.0); if (this.SupportsPageMovements()) { GetSliderState().isDragging = false; @@ -309,9 +309,9 @@ namespace Explorer.Unstrip.IMGUI state.isDragging = true; } - private Internal_SliderState GetSliderState() + private SliderStateUnstrip GetSliderState() { - return (Internal_SliderState)Internal_GUIUtility.GetMonoStateObject(typeof(Internal_SliderState), this.id); + return (SliderStateUnstrip)GUIUtilityUnstrip.GetMonoStateObject(typeof(SliderStateUnstrip), this.id); } private Rect ThumbRect() diff --git a/src/Unstrip/IMGUI/Internal_SliderState.cs b/src/Unstrip/IMGUI/SliderStateUnstrip.cs similarity index 86% rename from src/Unstrip/IMGUI/Internal_SliderState.cs rename to src/Unstrip/IMGUI/SliderStateUnstrip.cs index 437ed4b..7de37ad 100644 --- a/src/Unstrip/IMGUI/Internal_SliderState.cs +++ b/src/Unstrip/IMGUI/SliderStateUnstrip.cs @@ -5,7 +5,7 @@ using System.Text; namespace Explorer.Unstrip.IMGUI { - public class Internal_SliderState + public class SliderStateUnstrip { public float dragStartPos; public float dragStartValue; diff --git a/src/Unstrip/IMGUI/Internal_TextEditor.cs b/src/Unstrip/IMGUI/TextEditorUnstrip.cs similarity index 99% rename from src/Unstrip/IMGUI/Internal_TextEditor.cs rename to src/Unstrip/IMGUI/TextEditorUnstrip.cs index 0efdc45..8c24e05 100644 --- a/src/Unstrip/IMGUI/Internal_TextEditor.cs +++ b/src/Unstrip/IMGUI/TextEditorUnstrip.cs @@ -9,9 +9,9 @@ using UnityEngine; namespace Explorer.Unstrip.IMGUI { - public class Internal_TextEditor + public class TextEditorUnstrip { - public Internal_TextEditor() { } + public TextEditorUnstrip() { } // public Internal_TextEditor(IntPtr ptr) : base(ptr) { } public TouchScreenKeyboard keyboardOnScreen = null; diff --git a/src/Unstrip/ImageConversion/ImageConversionUnstrip.cs b/src/Unstrip/ImageConversion/ImageConversionUnstrip.cs index bac3c0b..0f6617f 100644 --- a/src/Unstrip/ImageConversion/ImageConversionUnstrip.cs +++ b/src/Unstrip/ImageConversion/ImageConversionUnstrip.cs @@ -31,29 +31,26 @@ namespace Explorer.Unstrip.ImageConversion byte[] safeData = new byte[data.Length]; for (int i = 0; i < data.Length; i++) { - safeData[i] = (byte)data[i]; // not sure if cast is needed + safeData[i] = (byte)data[i]; } return safeData; } - // ******** LoadImage not yet working. ******** - // bool ImageConversion.LoadImage(this Texture2D tex, byte[] data, bool markNonReadable); internal delegate bool d_LoadImage(IntPtr tex, IntPtr data, bool markNonReadable); public static bool LoadImage(this Texture2D tex, byte[] data, bool markNonReadable) { - IntPtr unmanagedArray = Marshal.AllocHGlobal(data.Length); - Marshal.Copy(data, 0, unmanagedArray, data.Length); + var il2cppArray = new Il2CppStructArray(data.Length); + for (int i = 0; i < data.Length; i++) + { + il2cppArray[i] = data[i]; + } var ret = ICallHelper.GetICall("UnityEngine.ImageConversion::LoadImage") - .Invoke(tex.Pointer, unmanagedArray, markNonReadable); - - // var ret = tex.LoadRawTextureDataImpl(unmanagedArray, data.Length); - - Marshal.FreeHGlobal(unmanagedArray); + .Invoke(tex.Pointer, il2cppArray.Pointer, markNonReadable); return ret; } diff --git a/src/Unstrip/Resources/ResourcesUnstrip.cs b/src/Unstrip/Resources/ResourcesUnstrip.cs new file mode 100644 index 0000000..fa52091 --- /dev/null +++ b/src/Unstrip/Resources/ResourcesUnstrip.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Explorer.Helpers; +using UnityEngine; +#if CPP +using UnhollowerBaseLib; +#endif + +namespace Explorer.Unstrip.Resources +{ + public class ResourcesUnstrip + { +#if CPP + internal delegate IntPtr d_FindObjectsOfTypeAll(IntPtr type); + + public static UnityEngine.Object[] FindObjectsOfTypeAll(Il2CppSystem.Type type) + { + var arrayPtr = ICallHelper.GetICall("UnityEngine.Resources::FindObjectsOfTypeAll") + .Invoke(type.Pointer); + + var array = new Il2CppReferenceArray(arrayPtr); + + var ret = new UnityEngine.Object[array.Length]; + + for (int i = 0; i < array.Length; i++) + { + ret[i] = array[i]; + } + + return ret; + } +#else + public static UnityEngine.Object[] FindObjectsOfTypeAll(Type type) => UnityEngine.Resources.FindObjectsOfTypeAll(type); +#endif + + } +}