diff --git a/Editor/ProfileEditor.cs b/Editor/ProfileEditor.cs index 739e8fc..faa423b 100644 --- a/Editor/ProfileEditor.cs +++ b/Editor/ProfileEditor.cs @@ -113,19 +113,21 @@ public static bool Foldout(bool foldout, string content, GUIStyle style = null) if (style == null) style = EditorStyles.foldout; // Wrap foldout into a layout region to get the foldout's rect - var rect = EditorGUILayout.BeginHorizontal(GUIStyle.none); - var clicked = false; - - // Determine if it is being clicked on the foldout before - // calling it to avoid it eating the event - if (Event.current.type == EventType.MouseUp - && rect.Contains(Event.current.mousePosition)) { - clicked = true; - } + bool newFoldout = false; + bool clicked = false; + using (var rectScope = new EditorGUILayout.HorizontalScope(GUIStyle.none)) + { + var rect = rectScope.rect; - var newFoldout = EditorGUILayout.Foldout(foldout, content, style); + // Determine if it is being clicked on the foldout before + // calling it to avoid it eating the event + if (Event.current.type == EventType.MouseUp + && rect.Contains(Event.current.mousePosition)) { + clicked = true; + } - EditorGUILayout.EndHorizontal(); + newFoldout = EditorGUILayout.Foldout(foldout, content, style); + } // Act in case we saw a click but the foldout didn't toggle if (newFoldout == foldout && clicked) { @@ -142,7 +144,7 @@ public static bool Foldout(bool foldout, string content, GUIStyle style = null) /// public static bool Foldout(string path, bool def, string content, GUIStyle style = null) { - EditorGUI.BeginChangeCheck(); + using var _ = new EditorGUI.ChangeCheckScope(); var wasExpanded = EditorProfile.Instance.IsExpanded(path); if (def) wasExpanded = !wasExpanded; @@ -474,7 +476,7 @@ void InitializeGUI() void SourceProfileGUI() { if (editorProfile != null) { - EditorGUILayout.BeginHorizontal(); + using (new EditorGUILayout.HorizontalScope()) { if (sourceProfiles == null) { sourceProfiles = BuildProfile.AllBuildProfiles.Prepend(null).ToArray(); @@ -501,7 +503,6 @@ void SourceProfileGUI() } GUI.enabled = true; } - EditorGUILayout.EndHorizontal(); } } @@ -525,7 +526,7 @@ protected void BuildGUI() EditorGUILayout.Space(); var usesActive = buildProfile.UsesActiveBuildTarget(); - EditorGUILayout.BeginHorizontal(); + using (new EditorGUILayout.HorizontalScope()) { GUILayout.Label("Build Targets", boldLabel); if (GUILayout.Button(GUIContent.none, plusStyle)) { @@ -544,11 +545,10 @@ protected void BuildGUI() } GUILayout.FlexibleSpace(); } - EditorGUILayout.EndHorizontal(); foreach (var target in buildProfile.BuildTargets) { - EditorGUILayout.BeginHorizontal(); - EditorGUI.BeginDisabledGroup(usesActive); + using var _ = new EditorGUILayout.HorizontalScope(); + using (new EditorGUI.DisabledGroupScope(usesActive)) { if (GUILayout.Button(GUIContent.none, minusStyle)) { delayedRemovals.Add(() => { @@ -557,7 +557,6 @@ protected void BuildGUI() } EditorGUILayout.LabelField(target.ToString()); } - EditorGUI.EndDisabledGroup(); var path = buildProfile.GetLastBuildPath(target); if (!string.IsNullOrEmpty(path) @@ -565,27 +564,23 @@ protected void BuildGUI() && GUILayout.Button("Show", EditorStyles.miniButton, GUILayout.ExpandWidth(false))) { EditorUtility.RevealInFinder(path); } - EditorGUI.BeginDisabledGroup(BuildRunner.Current != null); + using (new EditorGUI.DisabledGroupScope(BuildRunner.Current != null)) { if (GUILayout.Button("Build", EditorStyles.miniButton, GUILayout.ExpandWidth(false))) { BuildManager.Build(buildProfile, target); } } - EditorGUI.EndDisabledGroup(); - - EditorGUILayout.EndHorizontal(); } EditorGUILayout.Space(); - EditorGUI.BeginDisabledGroup(BuildRunner.Current != null); + using (new EditorGUI.DisabledGroupScope(BuildRunner.Current != null)) { var count = buildProfile.BuildTargets.Count(); if (GUILayout.Button("Build " + count + " Target" + (count > 1 ? "s" : ""), EditorStyles.miniButton)) { BuildManager.Build(buildProfile); } } - EditorGUI.EndDisabledGroup(); } protected void AddBuildTarget(object userData) @@ -673,12 +668,11 @@ protected bool OptionGUI(Option option, int depth, bool showDefaultVariant = fal } if (category != lastCategory) { - EditorGUILayout.BeginHorizontal(categoryBackground); + using (new EditorGUILayout.HorizontalScope(categoryBackground)) { var path = pathBase + "_" + category; categoryExpanded = Foldout(path, true, category, categoryFoldout); } - EditorGUILayout.EndHorizontal(); lastCategory = category; } else if (categoryExpanded) { GUILayout.Label(GUIContent.none, separator); @@ -691,8 +685,10 @@ protected bool OptionGUI(Option option, int depth, bool showDefaultVariant = fal // Option GUI var lineHeight = EditorGUIUtility.singleLineHeight + linePadding; - var rect = EditorGUILayout.BeginHorizontal(GUILayout.Height(lineHeight)); + Rect rect; + using (var rectScope = new EditorGUILayout.HorizontalScope(GUILayout.Height(lineHeight))) { + rect = rectScope.rect; // Variant container if (option.IsDefaultVariant && !showDefaultVariant) { EditorGUILayout.LabelField(displayName, width); @@ -707,9 +703,9 @@ protected bool OptionGUI(Option option, int depth, bool showDefaultVariant = fal if (option.Variance == OptionVariance.Dictionary) { // Disable when editing the default variant - EditorGUI.BeginDisabledGroup(isDefault); + using (new EditorGUI.DisabledGroupScope(isDefault)) { - EditorGUI.BeginDisabledGroup(isDefault); + using (new EditorGUI.DisabledGroupScope(isDefault)) { var newParam = EditorGUILayout.DelayedTextField(option.VariantParameter, width); if (newParam != option.VariantParameter) { @@ -721,9 +717,7 @@ protected bool OptionGUI(Option option, int depth, bool showDefaultVariant = fal Option.changed = true; } } - EditorGUI.EndDisabledGroup(); } - EditorGUI.EndDisabledGroup(); } else { EditorGUILayout.PrefixLabel(" "); } @@ -759,7 +753,7 @@ protected bool OptionGUI(Option option, int depth, bool showDefaultVariant = fal color.a = 1; GUI.color = color; - EditorGUILayout.BeginHorizontal(includeBackground, GUILayout.Width(buildColumnWidth), GUILayout.Height(lineHeight)); + using (new EditorGUILayout.HorizontalScope(includeBackground, GUILayout.Width(buildColumnWidth), GUILayout.Height(lineHeight))) { if ( buildProfile != null @@ -769,25 +763,21 @@ protected bool OptionGUI(Option option, int depth, bool showDefaultVariant = fal || (option.Capabilities & OptionCapabilities.HasAssociatedFeature) != 0 ) ) { - EditorGUI.BeginDisabledGroup(!optionAvailable); + using var _ = new EditorGUI.DisabledGroupScope(!optionAvailable); var root = buildProfile.Store.GetOrCreateRoot(option.Name); GUILayout.Label(LabelForInclusion(root, option.Capabilities), inclusionLabel); if (optionAvailable) { DoInclusionMenu(root, option.Capabilities); } - EditorGUI.EndDisabledGroup(); } else { EditorGUILayout.Space(); } } - EditorGUILayout.EndHorizontal(); } else { // Not including a layout group here somehow makes the parent group taller - EditorGUILayout.BeginHorizontal(GUILayout.Width(0)); - EditorGUILayout.EndHorizontal(); + using var _ = new EditorGUILayout.HorizontalScope(GUILayout.Width(0)); } } - EditorGUILayout.EndHorizontal(); // Expansion toggle if (expandable) {