diff --git a/src/CachedObjects/CacheObjectBase.cs b/src/CachedObjects/CacheObjectBase.cs index 3f6d199a..8c148d5e 100644 --- a/src/CachedObjects/CacheObjectBase.cs +++ b/src/CachedObjects/CacheObjectBase.cs @@ -384,7 +384,7 @@ public void Draw(Rect window, float labelWidth = 215f) } else { - GUILayout.Space(labelWidth); + GUIUnstrip.Space(labelWidth); } var cm = this as CacheMethod; @@ -451,7 +451,7 @@ public void Draw(Rect window, float labelWidth = 215f) // new line and space GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(null); - GUILayout.Space(labelWidth); + GUIUnstrip.Space(labelWidth); } else if (cm != null) { @@ -465,7 +465,7 @@ public void Draw(Rect window, float labelWidth = 215f) // new line and space GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(null); - GUILayout.Space(labelWidth); + GUIUnstrip.Space(labelWidth); } if (!string.IsNullOrEmpty(ReflectionException)) diff --git a/src/CachedObjects/Object/CacheDictionary.cs b/src/CachedObjects/Object/CacheDictionary.cs index 056eff11..5fdedcf9 100644 --- a/src/CachedObjects/Object/CacheDictionary.cs +++ b/src/CachedObjects/Object/CacheDictionary.cs @@ -235,7 +235,7 @@ public override void DrawValue(Rect window, float width) } GUI.skin.button.alignment = TextAnchor.MiddleCenter; - GUILayout.Space(5); + GUIUnstrip.Space(5); if (IsExpanded) { @@ -246,7 +246,7 @@ public override void DrawValue(Rect window, float width) GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(null); - GUILayout.Space(whitespace); + GUIUnstrip.Space(whitespace); Pages.CurrentPageLabel(); @@ -262,7 +262,7 @@ public override void DrawValue(Rect window, float width) Pages.DrawLimitInputArea(); - GUILayout.Space(5); + GUIUnstrip.Space(5); } int offset = Pages.CalculateOffsetIndex(); @@ -276,7 +276,7 @@ public override void DrawValue(Rect window, float width) GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(null); - //GUILayout.Space(whitespace); + //GUIUnstrip.Space(whitespace); if (key == null || val == null) { diff --git a/src/CachedObjects/Object/CacheList.cs b/src/CachedObjects/Object/CacheList.cs index 28c29716..d1a94b37 100644 --- a/src/CachedObjects/Object/CacheList.cs +++ b/src/CachedObjects/Object/CacheList.cs @@ -297,7 +297,7 @@ public override void DrawValue(Rect window, float width) } GUI.skin.button.alignment = TextAnchor.MiddleCenter; - GUILayout.Space(5); + GUIUnstrip.Space(5); if (IsExpanded) { @@ -308,7 +308,7 @@ public override void DrawValue(Rect window, float width) GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(null); - GUILayout.Space(whitespace); + GUIUnstrip.Space(whitespace); Pages.CurrentPageLabel(); @@ -324,7 +324,7 @@ public override void DrawValue(Rect window, float width) Pages.DrawLimitInputArea(); - GUILayout.Space(5); + GUIUnstrip.Space(5); } int offset = Pages.CalculateOffsetIndex(); @@ -337,7 +337,7 @@ public override void DrawValue(Rect window, float width) GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(null); - GUILayout.Space(whitespace); + GUIUnstrip.Space(whitespace); if (entry == null || entry.Value == null) { diff --git a/src/CachedObjects/Struct/CacheColor.cs b/src/CachedObjects/Struct/CacheColor.cs index b9e42176..26b2d0f6 100644 --- a/src/CachedObjects/Struct/CacheColor.cs +++ b/src/CachedObjects/Struct/CacheColor.cs @@ -61,32 +61,32 @@ public override void DrawValue(Rect window, float width) var whitespace = CalcWhitespace(window); GUILayout.BeginHorizontal(null); - GUILayout.Space(whitespace); + GUIUnstrip.Space(whitespace); GUILayout.Label("R:", new GUILayoutOption[] { GUILayout.Width(30) }); r = GUILayout.TextField(r, new GUILayoutOption[] { GUILayout.Width(120) }); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(null); - GUILayout.Space(whitespace); + GUIUnstrip.Space(whitespace); GUILayout.Label("G:", new GUILayoutOption[] { GUILayout.Width(30) }); g = GUILayout.TextField(g, new GUILayoutOption[] { GUILayout.Width(120) }); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(null); - GUILayout.Space(whitespace); + GUIUnstrip.Space(whitespace); GUILayout.Label("B:", new GUILayoutOption[] { GUILayout.Width(30) }); b = GUILayout.TextField(b, new GUILayoutOption[] { GUILayout.Width(120) }); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(null); - GUILayout.Space(whitespace); + GUIUnstrip.Space(whitespace); GUILayout.Label("A:", new GUILayoutOption[] { GUILayout.Width(30) }); a = GUILayout.TextField(a, new GUILayoutOption[] { GUILayout.Width(120) }); GUILayout.EndHorizontal(); // draw set value button GUILayout.BeginHorizontal(null); - GUILayout.Space(whitespace); + GUIUnstrip.Space(whitespace); if (GUILayout.Button("Apply", new GUILayoutOption[] { GUILayout.Width(155) })) { SetValueFromInput(); diff --git a/src/CachedObjects/Struct/CachePrimitive.cs b/src/CachedObjects/Struct/CachePrimitive.cs index 3130c799..6c55a194 100644 --- a/src/CachedObjects/Struct/CachePrimitive.cs +++ b/src/CachedObjects/Struct/CachePrimitive.cs @@ -92,7 +92,7 @@ public override void DrawValue(Rect window, float width) } } - GUILayout.Space(10); + GUIUnstrip.Space(10); } } diff --git a/src/CachedObjects/Struct/CacheQuaternion.cs b/src/CachedObjects/Struct/CacheQuaternion.cs index b15e1789..373d56b1 100644 --- a/src/CachedObjects/Struct/CacheQuaternion.cs +++ b/src/CachedObjects/Struct/CacheQuaternion.cs @@ -56,26 +56,26 @@ public override void DrawValue(Rect window, float width) var whitespace = CalcWhitespace(window); GUILayout.BeginHorizontal(null); - GUILayout.Space(whitespace); + GUIUnstrip.Space(whitespace); GUILayout.Label("X:", new GUILayoutOption[] { GUILayout.Width(30) }); x = GUILayout.TextField(x, new GUILayoutOption[] { GUILayout.Width(120) }); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(null); - GUILayout.Space(whitespace); + GUIUnstrip.Space(whitespace); GUILayout.Label("Y:", new GUILayoutOption[] { GUILayout.Width(30) }); y = GUILayout.TextField(y, new GUILayoutOption[] { GUILayout.Width(120) }); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(null); - GUILayout.Space(whitespace); + GUIUnstrip.Space(whitespace); GUILayout.Label("Z:", new GUILayoutOption[] { GUILayout.Width(30) }); z = GUILayout.TextField(z, new GUILayoutOption[] { GUILayout.Width(120) }); GUILayout.EndHorizontal(); // draw set value button GUILayout.BeginHorizontal(null); - GUILayout.Space(whitespace); + GUIUnstrip.Space(whitespace); if (GUILayout.Button("Apply", new GUILayoutOption[] { GUILayout.Width(155) })) { SetValueFromInput(); diff --git a/src/CachedObjects/Struct/CacheRect.cs b/src/CachedObjects/Struct/CacheRect.cs index 038c23fa..5d3ed229 100644 --- a/src/CachedObjects/Struct/CacheRect.cs +++ b/src/CachedObjects/Struct/CacheRect.cs @@ -58,32 +58,32 @@ public override void DrawValue(Rect window, float width) var whitespace = CalcWhitespace(window); GUILayout.BeginHorizontal(null); - GUILayout.Space(whitespace); + GUIUnstrip.Space(whitespace); GUILayout.Label("X:", new GUILayoutOption[] { GUILayout.Width(30) }); x = GUILayout.TextField(x, new GUILayoutOption[] { GUILayout.Width(120) }); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(null); - GUILayout.Space(whitespace); + GUIUnstrip.Space(whitespace); GUILayout.Label("Y:", new GUILayoutOption[] { GUILayout.Width(30) }); y = GUILayout.TextField(y, new GUILayoutOption[] { GUILayout.Width(120) }); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(null); - GUILayout.Space(whitespace); + GUIUnstrip.Space(whitespace); GUILayout.Label("W:", new GUILayoutOption[] { GUILayout.Width(30) }); w = GUILayout.TextField(w, new GUILayoutOption[] { GUILayout.Width(120) }); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(null); - GUILayout.Space(whitespace); + GUIUnstrip.Space(whitespace); GUILayout.Label("H:", new GUILayoutOption[] { GUILayout.Width(30) }); h = GUILayout.TextField(h, new GUILayoutOption[] { GUILayout.Width(120) }); GUILayout.EndHorizontal(); // draw set value button GUILayout.BeginHorizontal(null); - GUILayout.Space(whitespace); + GUIUnstrip.Space(whitespace); if (GUILayout.Button("Apply", new GUILayoutOption[] { GUILayout.Width(155) })) { SetValueFromInput(); diff --git a/src/CachedObjects/Struct/CacheVector.cs b/src/CachedObjects/Struct/CacheVector.cs index 1a6da124..8b0087af 100644 --- a/src/CachedObjects/Struct/CacheVector.cs +++ b/src/CachedObjects/Struct/CacheVector.cs @@ -94,13 +94,13 @@ public override void DrawValue(Rect window, float width) // always draw x and y GUILayout.BeginHorizontal(null); - GUILayout.Space(whitespace); + GUIUnstrip.Space(whitespace); GUILayout.Label("X:", new GUILayoutOption[] { GUILayout.Width(30) }); x = GUILayout.TextField(x, new GUILayoutOption[] { GUILayout.Width(120) }); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(null); - GUILayout.Space(whitespace); + GUIUnstrip.Space(whitespace); GUILayout.Label("Y:", new GUILayoutOption[] { GUILayout.Width(30) }); y = GUILayout.TextField(y, new GUILayoutOption[] { GUILayout.Width(120) }); GUILayout.EndHorizontal(); @@ -109,7 +109,7 @@ public override void DrawValue(Rect window, float width) { // draw z GUILayout.BeginHorizontal(null); - GUILayout.Space(whitespace); + GUIUnstrip.Space(whitespace); GUILayout.Label("Z:", new GUILayoutOption[] { GUILayout.Width(30) }); z = GUILayout.TextField(z, new GUILayoutOption[] { GUILayout.Width(120) }); GUILayout.EndHorizontal(); @@ -118,7 +118,7 @@ public override void DrawValue(Rect window, float width) { // draw w GUILayout.BeginHorizontal(null); - GUILayout.Space(whitespace); + GUIUnstrip.Space(whitespace); GUILayout.Label("W:", new GUILayoutOption[] { GUILayout.Width(30) }); w = GUILayout.TextField(w, new GUILayoutOption[] { GUILayout.Width(120) }); GUILayout.EndHorizontal(); @@ -126,7 +126,7 @@ public override void DrawValue(Rect window, float width) // draw set value button GUILayout.BeginHorizontal(null); - GUILayout.Space(whitespace); + GUIUnstrip.Space(whitespace); if (GUILayout.Button("Apply", new GUILayoutOption[] { GUILayout.Width(155) })) { SetValueFromInput(); diff --git a/src/CppExplorer.cs b/src/CppExplorer.cs index a6694adf..a335cfc4 100644 --- a/src/CppExplorer.cs +++ b/src/CppExplorer.cs @@ -13,7 +13,7 @@ namespace Explorer public class CppExplorer : MelonMod { public const string NAME = "CppExplorer"; - public const string VERSION = "1.6.9"; + public const string VERSION = "1.7.0"; public const string AUTHOR = "Sinai"; public const string GUID = "com.sinai.cppexplorer"; diff --git a/src/CppExplorer.csproj b/src/CppExplorer.csproj index 467c78ec..4284edae 100644 --- a/src/CppExplorer.csproj +++ b/src/CppExplorer.csproj @@ -96,13 +96,14 @@ + - + diff --git a/src/Menu/CursorControl.cs b/src/Menu/CursorControl.cs index 9f255aa0..9f377bd8 100644 --- a/src/Menu/CursorControl.cs +++ b/src/Menu/CursorControl.cs @@ -24,16 +24,19 @@ public static bool ForceUnlockMouse public static bool ShouldForceMouse => CppExplorer.ShowMenu && ForceUnlockMouse; + private static Type CursorType => m_cursorType ?? (m_cursorType = ReflectionHelpers.GetTypeByName("UnityEngine.Cursor")); + private static Type m_cursorType; + public static void Init() { try { // Check if Cursor class is loaded - if (ReflectionHelpers.GetTypeByName("UnityEngine.Cursor") == null) + if (CursorType == null) { MelonLogger.Log("Trying to manually load Cursor module..."); - if (ReflectionHelpers.LoadModule("UnityEngine.CoreModule")) + if (ReflectionHelpers.LoadModule("UnityEngine.CoreModule") && CursorType != null) { MelonLogger.Log("Ok!"); } @@ -47,11 +50,12 @@ public static void Init() m_lastLockMode = Cursor.lockState; m_lastVisibleState = Cursor.visible; - TryPatch("lockState", new HarmonyMethod(typeof(CursorControl).GetMethod(nameof(Prefix_set_lockState))), false, false); - TryPatch("visible", new HarmonyMethod(typeof(CursorControl).GetMethod(nameof(Prefix_set_visible))), false, false); + // Setup Harmony Patches + TryPatch("lockState", new HarmonyMethod(typeof(CursorControl).GetMethod(nameof(Prefix_set_lockState))), true); + TryPatch("lockState", new HarmonyMethod(typeof(CursorControl).GetMethod(nameof(Postfix_get_lockState))), false); - TryPatch("lockState", new HarmonyMethod(typeof(CursorControl).GetMethod(nameof(Postfix_get_lockState))), true, true); - TryPatch("visible", new HarmonyMethod(typeof(CursorControl).GetMethod(nameof(Postfix_get_visible))), true, true); + TryPatch("visible", new HarmonyMethod(typeof(CursorControl).GetMethod(nameof(Prefix_set_visible))), true); + TryPatch("visible", new HarmonyMethod(typeof(CursorControl).GetMethod(nameof(Postfix_get_visible))), false); } catch (Exception e) { @@ -64,18 +68,23 @@ public static void Init() ForceUnlockMouse = true; } - private static void TryPatch(string property, HarmonyMethod patch, bool getter = true, bool postfix = false) + private static void TryPatch(string property, HarmonyMethod patch, bool setter) { - // Setup Harmony Patches try { var harmony = CppExplorer.Instance.harmonyInstance; - var prop = typeof(Cursor).GetProperty(property); - harmony.Patch(getter ? prop.GetGetMethod() : prop.GetSetMethod(), - postfix ? null : patch, - postfix ? patch : null); + if (setter) + { + // setter is prefix + harmony.Patch(prop.GetSetMethod(), patch); + } + else + { + // getter is postfix + harmony.Patch(prop.GetGetMethod(), null, patch); + } } catch (Exception e) { @@ -170,69 +179,5 @@ public static void Postfix_get_visible(ref bool __result) __result = m_lastVisibleState; } } - - //[HarmonyPatch(typeof(Cursor), nameof(Cursor.lockState), MethodType.Setter)] - //public class Cursor_set_lockState - //{ - // [HarmonyPrefix] - // public static void Prefix(ref CursorLockMode value) - // { - // if (!m_currentlySettingCursor) - // { - // m_lastLockMode = value; - - // if (ShouldForceMouse) - // { - // value = CursorLockMode.None; - // } - // } - // } - //} - - //[HarmonyPatch(typeof(Cursor), nameof(Cursor.visible), MethodType.Setter)] - //public class Cursor_set_visible - //{ - // [HarmonyPrefix] - // public static void Prefix(ref bool value) - // { - // if (!m_currentlySettingCursor) - // { - // m_lastVisibleState = value; - - // if (ShouldForceMouse) - // { - // value = true; - // } - // } - // } - //} - - //// Make it appear as though UnlockMouse is disabled to the rest of the application. - - //[HarmonyPatch(typeof(Cursor), nameof(Cursor.lockState), MethodType.Getter)] - //public class Cursor_get_lockState - //{ - // [HarmonyPostfix] - // public static void Postfix(ref CursorLockMode __result) - // { - // if (ShouldForceMouse) - // { - // __result = m_lastLockMode; - // } - // } - //} - - //[HarmonyPatch(typeof(Cursor), nameof(Cursor.visible), MethodType.Getter)] - //public class Cursor_get_visible - //{ - // [HarmonyPostfix] - // public static void Postfix(ref bool __result) - // { - // if (ShouldForceMouse) - // { - // __result = m_lastVisibleState; - // } - // } - //} } } diff --git a/src/Menu/MainMenu/InspectUnderMouse.cs b/src/Menu/InspectUnderMouse.cs similarity index 100% rename from src/Menu/MainMenu/InspectUnderMouse.cs rename to src/Menu/InspectUnderMouse.cs diff --git a/src/Menu/MainMenu/MainMenu.cs b/src/Menu/MainMenu/MainMenu.cs index 447f4366..370f9b3c 100644 --- a/src/Menu/MainMenu/MainMenu.cs +++ b/src/Menu/MainMenu/MainMenu.cs @@ -110,7 +110,9 @@ private void MainHeader() WindowManager.TabView = GUILayout.Toggle(WindowManager.TabView, "Tab View", null); GUILayout.EndHorizontal(); - GUILayout.Space(10); + //GUIUnstrip.Space(10); + GUIUnstrip.Space(10); + GUI.color = Color.white; } } diff --git a/src/Menu/MainMenu/Pages/ScenePage.cs b/src/Menu/MainMenu/Pages/ScenePage.cs index 34727893..bcdd7c34 100644 --- a/src/Menu/MainMenu/Pages/ScenePage.cs +++ b/src/Menu/MainMenu/Pages/ScenePage.cs @@ -244,7 +244,7 @@ private void DrawHeaderArea() } GUILayout.EndHorizontal(); - GUILayout.Space(5); + GUIUnstrip.Space(5); } private void SceneChangeButtons() diff --git a/src/Menu/Windows/GameObjectWindow.cs b/src/Menu/Windows/GameObjectWindow.cs index ec7c2a60..034ba77c 100644 --- a/src/Menu/Windows/GameObjectWindow.cs +++ b/src/Menu/Windows/GameObjectWindow.cs @@ -385,7 +385,7 @@ private void ComponentList(Rect m_rect) } else { - GUILayout.Space(26); + GUIUnstrip.Space(26); } if (GUILayout.Button("" + ilType.Name + "", new GUILayoutOption[] { GUILayout.Width(m_rect.width / 2 - 100) })) { diff --git a/src/Menu/Windows/ReflectionWindow.cs b/src/Menu/Windows/ReflectionWindow.cs index 1db6ed89..810e0d5f 100644 --- a/src/Menu/Windows/ReflectionWindow.cs +++ b/src/Menu/Windows/ReflectionWindow.cs @@ -288,7 +288,7 @@ public override void WindowFunction(int windowID) GUI.color = Color.white; GUILayout.EndHorizontal(); - GUILayout.Space(10); + GUIUnstrip.Space(10); Pages.ItemCount = m_cachedMembersFiltered.Length; @@ -317,7 +317,7 @@ public override void WindowFunction(int windowID) scroll = GUIUnstrip.BeginScrollView(scroll); - GUILayout.Space(10); + GUIUnstrip.Space(10); UIStyles.HorizontalLine(Color.grey); diff --git a/src/Menu/Windows/ResizeDrag.cs b/src/Menu/Windows/ResizeDrag.cs index 1ca0b383..d263be0b 100644 --- a/src/Menu/Windows/ResizeDrag.cs +++ b/src/Menu/Windows/ResizeDrag.cs @@ -32,7 +32,7 @@ public static Rect ResizeWindow(Rect _rect, int ID) GUILayout.Button(gcDrag, GUI.skin.label, new GUILayoutOption[] { GUILayout.Height(15) }); //var r = GUILayoutUtility.GetLastRect(); - var r = GUIUnstrip.GetLastRect(); + var r = LayoutUtilityUnstrip.GetLastRect(); var mousePos = InputHelper.mousePosition; diff --git a/src/UnstripFixes/GUIUnstrip.cs b/src/UnstripFixes/GUIUnstrip.cs index 84fac682..068e97f5 100644 --- a/src/UnstripFixes/GUIUnstrip.cs +++ b/src/UnstripFixes/GUIUnstrip.cs @@ -42,20 +42,20 @@ private static GenericStack ScrollStack } private static PropertyInfo m_scrollViewStatesInfo; - - public static Rect GetLastRect() + public static void Space(float pixels) { - EventType type = Event.current.type; - Rect last; - if (type != EventType.Layout && type != EventType.Used) - { - last = GUILayoutUtility.current.topLevel.GetLastUnstripped(); - } + GUIUtility.CheckOnGUI(); + + if (GUILayoutUtility.current.topLevel.isVertical) + + LayoutUtilityUnstrip.GetRect(0, pixels, GUILayoutUtility.spaceStyle, new GUILayoutOption[] { GUILayout.Height(pixels) }); else + LayoutUtilityUnstrip.GetRect(pixels, 0, GUILayoutUtility.spaceStyle, new GUILayoutOption[] { GUILayout.Width(pixels) }); + + if (Event.current.type == EventType.Layout) { - last = GUILayoutUtility.kDummyRect; + GUILayoutUtility.current.topLevel.entries[GUILayoutUtility.current.topLevel.entries.Count - 1].consideredForMargin = false; } - return last; } // Fix for BeginScrollView. diff --git a/src/UnstripFixes/LayoutUtilityUnstrip.cs b/src/UnstripFixes/LayoutUtilityUnstrip.cs new file mode 100644 index 00000000..13ade380 --- /dev/null +++ b/src/UnstripFixes/LayoutUtilityUnstrip.cs @@ -0,0 +1,112 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UnityEngine; + +namespace Explorer +{ + public class LayoutUtilityUnstrip + { + public static Rect GetRect(float width, float height) { return DoGetRect(width, width, height, height, GUIStyle.none, null); } + public static Rect GetRect(float width, float height, GUIStyle style) { return DoGetRect(width, width, height, height, style, null); } + public static Rect GetRect(float width, float height, params GUILayoutOption[] options) { return DoGetRect(width, width, height, height, GUIStyle.none, options); } + // Reserve layout space for a rectangle with a fixed content area. + public static Rect GetRect(float width, float height, GUIStyle style, params GUILayoutOption[] options) + { return DoGetRect(width, width, height, height, style, options); } + + public static Rect GetRect(float minWidth, float maxWidth, float minHeight, float maxHeight) + { return DoGetRect(minWidth, maxWidth, minHeight, maxHeight, GUIStyle.none, null); } + + public static Rect GetRect(float minWidth, float maxWidth, float minHeight, float maxHeight, GUIStyle style) + { return DoGetRect(minWidth, maxWidth, minHeight, maxHeight, style, null); } + + public static Rect GetRect(float minWidth, float maxWidth, float minHeight, float maxHeight, params GUILayoutOption[] options) + { return DoGetRect(minWidth, maxWidth, minHeight, maxHeight, GUIStyle.none, options); } + // Reserve layout space for a flexible rect. + public static Rect GetRect(float minWidth, float maxWidth, float minHeight, float maxHeight, GUIStyle style, params GUILayoutOption[] options) + { return DoGetRect(minWidth, maxWidth, minHeight, maxHeight, style, options); } + static Rect DoGetRect(float minWidth, float maxWidth, float minHeight, float maxHeight, GUIStyle style, GUILayoutOption[] options) + { + switch (Event.current.type) + { + case EventType.Layout: + GUILayoutUtility.current.topLevel.Add(new GUILayoutEntry(minWidth, maxWidth, minHeight, maxHeight, style, options)); + return GUILayoutUtility.kDummyRect; + case EventType.Used: + return GUILayoutUtility.kDummyRect; + default: + return GUILayoutUtility.current.topLevel.GetNext().rect; + } + } + public static Rect GetRect(GUIContent content, GUIStyle style) { return DoGetRect(content, style, null); } + // Reserve layout space for a rectangle for displaying some contents with a specific style. + public static Rect GetRect(GUIContent content, GUIStyle style, params GUILayoutOption[] options) { return DoGetRect(content, style, options); } + + static Rect DoGetRect(GUIContent content, GUIStyle style, GUILayoutOption[] options) + { + GUIUtility.CheckOnGUI(); + + switch (Event.current.type) + { + case EventType.Layout: + if (style.isHeightDependantOnWidth) + { + GUILayoutUtility.current.topLevel.Add(new GUIWordWrapSizer(style, content, options)); + } + else + { + Vector2 sizeConstraints = new Vector2(0, 0); + if (options != null) + { + foreach (var option in options) + { + if (float.TryParse(option.value.ToString(), out float f)) + { + switch (option.type) + { + case GUILayoutOption.Type.maxHeight: + sizeConstraints.y = f; + break; + case GUILayoutOption.Type.maxWidth: + sizeConstraints.x = f; + break; + } + } + } + } + + Vector2 size = style.CalcSizeWithConstraints(content, sizeConstraints); + // This is needed on non-integer scale ratios to avoid errors to accumulate in further layout calculations + size.x = Mathf.Ceil(size.x); + size.y = Mathf.Ceil(size.y); + GUILayoutUtility.current.topLevel.Add(new GUILayoutEntry(size.x, size.x, size.y, size.y, style, options)); + } + return GUILayoutUtility.kDummyRect; + + case EventType.Used: + return GUILayoutUtility.kDummyRect; + default: + var entry = GUILayoutUtility.current.topLevel.GetNext(); + //GUIDebugger.LogLayoutEntry(entry.rect, entry.marginLeft, entry.marginRight, entry.marginTop, entry.marginBottom, entry.style); + return entry.rect; + } + } + + public static Rect GetLastRect() + { + EventType type = Event.current.type; + Rect last; + if (type != EventType.Layout && type != EventType.Used) + { + last = GUILayoutUtility.current.topLevel.GetLastUnstripped(); + } + else + { + last = GUILayoutUtility.kDummyRect; + } + return last; + } + } +}