From 14d7e7eb413cc85a9f40c1debd9bd78524410aa8 Mon Sep 17 00:00:00 2001 From: max Date: Tue, 20 Apr 2021 20:23:13 +0200 Subject: [PATCH] Added ScrollViewScope. --- Editor/SceneDebugViewerWindow.cs | 70 +++++++++++++++++--------------- 1 file changed, 38 insertions(+), 32 deletions(-) diff --git a/Editor/SceneDebugViewerWindow.cs b/Editor/SceneDebugViewerWindow.cs index 6bc828b..91a5aee 100644 --- a/Editor/SceneDebugViewerWindow.cs +++ b/Editor/SceneDebugViewerWindow.cs @@ -10,6 +10,7 @@ namespace TAO.SceneDebugViewer.Editor public static List options = new List(); private GUIStyle optionsButtonStyle = null; + private Vector2 scrollPos; [MenuItem("Window/Analysis/SceneDebugViewer")] static void Init() @@ -37,49 +38,54 @@ namespace TAO.SceneDebugViewer.Editor Load(); } - if (window.position.width <= 101) + using (var scope = new GUILayout.ScrollViewScope(scrollPos, false, false)) { - // Compact grid. - optionsButtonStyle = new GUIStyle(GUI.skin.button) + scrollPos = scope.scrollPosition; + + if (window.position.width <= 101) { - alignment = TextAnchor.MiddleCenter, - fixedHeight = 44 - }; - - for (int i = 0; i < options.Count; i += 2) - { - GUILayout.BeginHorizontal(); - - if (GUILayout.Button(options[i].Content.compact, optionsButtonStyle)) + // Compact grid. + optionsButtonStyle = new GUIStyle(GUI.skin.button) { - options[i].Replace(); - } + alignment = TextAnchor.MiddleCenter, + fixedHeight = 44 + }; - if (i + 1 < options.Count) + for (int i = 0; i < options.Count; i += 2) { - if (GUILayout.Button(options[i + 1].Content.compact, optionsButtonStyle)) + GUILayout.BeginHorizontal(); + + if (GUILayout.Button(options[i].Content.compact, optionsButtonStyle)) { - options[i + 1].Replace(); + options[i].Replace(); } + + if (i + 1 < options.Count) + { + if (GUILayout.Button(options[i + 1].Content.compact, optionsButtonStyle)) + { + options[i + 1].Replace(); + } + } + + GUILayout.EndHorizontal(); } - - GUILayout.EndHorizontal(); } - } - else - { - // Normal list. - optionsButtonStyle = new GUIStyle(GUI.skin.button) + else { - alignment = TextAnchor.MiddleLeft, - fixedHeight = 44 - }; - - for (int i = 0; i < options.Count; i ++) - { - if (GUILayout.Button(options[i].Content.normal, optionsButtonStyle)) + // Normal list. + optionsButtonStyle = new GUIStyle(GUI.skin.button) { - options[i].Replace(); + alignment = TextAnchor.MiddleLeft, + fixedHeight = 44 + }; + + for (int i = 0; i < options.Count; i ++) + { + if (GUILayout.Button(options[i].Content.normal, optionsButtonStyle)) + { + options[i].Replace(); + } } } }