From a70848d4a7c80daa1ac7daefe991d2951e3f74f1 Mon Sep 17 00:00:00 2001 From: BlackMATov Date: Sun, 3 Jan 2021 19:42:50 +0700 Subject: [PATCH] more readable world settings inspector --- .../Scripts/Internal/Editor/IsoEditorUtils.cs | 12 +++++++ .../Internal/Editor/IsoObjectEditor.cs | 24 +++++++++++--- .../Internal/Editor/IsoParentEditor.cs | 31 +++++++++++++++++-- Assets/IsoTools/Scripts/IsoWorld.cs | 2 +- 4 files changed, 60 insertions(+), 9 deletions(-) diff --git a/Assets/IsoTools/Scripts/Internal/Editor/IsoEditorUtils.cs b/Assets/IsoTools/Scripts/Internal/Editor/IsoEditorUtils.cs index f267b13..f4c2827 100644 --- a/Assets/IsoTools/Scripts/Internal/Editor/IsoEditorUtils.cs +++ b/Assets/IsoTools/Scripts/Internal/Editor/IsoEditorUtils.cs @@ -31,6 +31,18 @@ namespace IsoTools.Internal { } } + public static bool DoFoldoutHeaderGroup(bool foldout, string header, System.Action act) { + foldout = EditorGUILayout.BeginFoldoutHeaderGroup(foldout, header); + try { + if ( foldout ) { + act(); + } + } finally { + EditorGUILayout.EndFoldoutHeaderGroup(); + } + return foldout; + } + public static void DrawWorldProperties(IsoWorld[] iso_worlds) { if ( iso_worlds.Length > 0 ) { var so = new SerializedObject(iso_worlds); diff --git a/Assets/IsoTools/Scripts/Internal/Editor/IsoObjectEditor.cs b/Assets/IsoTools/Scripts/Internal/Editor/IsoObjectEditor.cs index a57d044..4c4ad01 100644 --- a/Assets/IsoTools/Scripts/Internal/Editor/IsoObjectEditor.cs +++ b/Assets/IsoTools/Scripts/Internal/Editor/IsoObjectEditor.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; namespace IsoTools.Internal { [CustomEditor(typeof(IsoObject)), CanEditMultipleObjects] class IsoObjectEditor : Editor { + static bool _showWorldSettings = false; Dictionary> _isoObjects = new Dictionary>(); Dictionary> _otherObjects = new Dictionary>(); @@ -41,20 +42,33 @@ namespace IsoTools.Internal { } void DrawCustomInspector() { + if ( DrawDetachedInspector() ) { + return; + } + var iso_worlds = _isoObjects.Keys.ToArray(); - IsoEditorUtils.DrawWorldProperties(iso_worlds); - IsoEditorUtils.DrawSelfWorldProperty(iso_worlds); - DrawDetachedInspector(); + if ( iso_worlds.Length == 0 ) { + return; + } + + _showWorldSettings = IsoEditorUtils.DoFoldoutHeaderGroup(_showWorldSettings, "World Settings", () => { + IsoEditorUtils.DrawSelfWorldProperty(iso_worlds); + IsoEditorUtils.DrawWorldProperties(iso_worlds); + }); } - void DrawDetachedInspector() { + bool DrawDetachedInspector() { var iso_object = targets.Length == 1 ? target as IsoObject : null; - if ( iso_object && iso_object.IsActive() && !iso_object.isoWorld ) { + var detached = iso_object && iso_object.IsActive() && !iso_object.isoWorld; + + if ( detached ) { EditorGUILayout.HelpBox( "Detached IsoObject\nNeed to be a child of IsoWorld", MessageType.Warning, true); } + + return detached; } // --------------------------------------------------------------------- diff --git a/Assets/IsoTools/Scripts/Internal/Editor/IsoParentEditor.cs b/Assets/IsoTools/Scripts/Internal/Editor/IsoParentEditor.cs index c61db10..dfb4441 100644 --- a/Assets/IsoTools/Scripts/Internal/Editor/IsoParentEditor.cs +++ b/Assets/IsoTools/Scripts/Internal/Editor/IsoParentEditor.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; namespace IsoTools.Internal { [CustomEditor(typeof(IsoParent)), CanEditMultipleObjects] public class IsoParentEditor : Editor { + static bool _showWorldSettings = false; Dictionary> _isoParents = new Dictionary>(); Dictionary> _isoObjects = new Dictionary>(); @@ -44,9 +45,33 @@ namespace IsoTools.Internal { } void DrawCustomInspector() { - var iso_worlds = _isoParents.Keys.ToArray(); - IsoEditorUtils.DrawWorldProperties(iso_worlds); - IsoEditorUtils.DrawSelfWorldProperty(iso_worlds); + if ( DrawDetachedInspector() ) { + return; + } + + var iso_worlds = _isoObjects.Keys.ToArray(); + if ( iso_worlds.Length == 0 ) { + return; + } + + _showWorldSettings = IsoEditorUtils.DoFoldoutHeaderGroup(_showWorldSettings, "World Settings", () => { + IsoEditorUtils.DrawSelfWorldProperty(iso_worlds); + IsoEditorUtils.DrawWorldProperties(iso_worlds); + }); + } + + bool DrawDetachedInspector() { + var iso_parent = targets.Length == 1 ? target as IsoParent : null; + var detached = iso_parent && iso_parent.IsActive() && !iso_parent.isoWorld; + + if ( detached ) { + EditorGUILayout.HelpBox( + "Detached IsoParent\nNeed to be a child of IsoWorld", + MessageType.Warning, + true); + } + + return detached; } // --------------------------------------------------------------------- diff --git a/Assets/IsoTools/Scripts/IsoWorld.cs b/Assets/IsoTools/Scripts/IsoWorld.cs index f4d7035..fb393e8 100644 --- a/Assets/IsoTools/Scripts/IsoWorld.cs +++ b/Assets/IsoTools/Scripts/IsoWorld.cs @@ -75,7 +75,7 @@ namespace IsoTools { // // --------------------------------------------------------------------- - [Header("World Settings")] + [Header("Isometric Settings")] [SerializeField] float _tileSize = DefTileSize; public float tileSize {