more readable world settings inspector

This commit is contained in:
BlackMATov
2021-01-03 19:42:50 +07:00
parent aab6b65b01
commit a70848d4a7
4 changed files with 60 additions and 9 deletions

View File

@@ -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) { public static void DrawWorldProperties(IsoWorld[] iso_worlds) {
if ( iso_worlds.Length > 0 ) { if ( iso_worlds.Length > 0 ) {
var so = new SerializedObject(iso_worlds); var so = new SerializedObject(iso_worlds);

View File

@@ -6,6 +6,7 @@ using System.Collections.Generic;
namespace IsoTools.Internal { namespace IsoTools.Internal {
[CustomEditor(typeof(IsoObject)), CanEditMultipleObjects] [CustomEditor(typeof(IsoObject)), CanEditMultipleObjects]
class IsoObjectEditor : Editor { class IsoObjectEditor : Editor {
static bool _showWorldSettings = false;
Dictionary<IsoWorld, List<IsoObject>> _isoObjects = new Dictionary<IsoWorld, List<IsoObject>>(); Dictionary<IsoWorld, List<IsoObject>> _isoObjects = new Dictionary<IsoWorld, List<IsoObject>>();
Dictionary<IsoWorld, List<IsoObject>> _otherObjects = new Dictionary<IsoWorld, List<IsoObject>>(); Dictionary<IsoWorld, List<IsoObject>> _otherObjects = new Dictionary<IsoWorld, List<IsoObject>>();
@@ -41,20 +42,33 @@ namespace IsoTools.Internal {
} }
void DrawCustomInspector() { void DrawCustomInspector() {
if ( DrawDetachedInspector() ) {
return;
}
var iso_worlds = _isoObjects.Keys.ToArray(); var iso_worlds = _isoObjects.Keys.ToArray();
IsoEditorUtils.DrawWorldProperties(iso_worlds); if ( iso_worlds.Length == 0 ) {
IsoEditorUtils.DrawSelfWorldProperty(iso_worlds); return;
DrawDetachedInspector(); }
_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; 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( EditorGUILayout.HelpBox(
"Detached IsoObject\nNeed to be a child of IsoWorld", "Detached IsoObject\nNeed to be a child of IsoWorld",
MessageType.Warning, MessageType.Warning,
true); true);
} }
return detached;
} }
// --------------------------------------------------------------------- // ---------------------------------------------------------------------

View File

@@ -6,6 +6,7 @@ using System.Collections.Generic;
namespace IsoTools.Internal { namespace IsoTools.Internal {
[CustomEditor(typeof(IsoParent)), CanEditMultipleObjects] [CustomEditor(typeof(IsoParent)), CanEditMultipleObjects]
public class IsoParentEditor : Editor { public class IsoParentEditor : Editor {
static bool _showWorldSettings = false;
Dictionary<IsoWorld, List<IsoParent>> _isoParents = new Dictionary<IsoWorld, List<IsoParent>>(); Dictionary<IsoWorld, List<IsoParent>> _isoParents = new Dictionary<IsoWorld, List<IsoParent>>();
Dictionary<IsoWorld, List<IsoObject>> _isoObjects = new Dictionary<IsoWorld, List<IsoObject>>(); Dictionary<IsoWorld, List<IsoObject>> _isoObjects = new Dictionary<IsoWorld, List<IsoObject>>();
@@ -44,9 +45,33 @@ namespace IsoTools.Internal {
} }
void DrawCustomInspector() { void DrawCustomInspector() {
var iso_worlds = _isoParents.Keys.ToArray(); if ( DrawDetachedInspector() ) {
IsoEditorUtils.DrawWorldProperties(iso_worlds); return;
IsoEditorUtils.DrawSelfWorldProperty(iso_worlds); }
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;
} }
// --------------------------------------------------------------------- // ---------------------------------------------------------------------

View File

@@ -75,7 +75,7 @@ namespace IsoTools {
// //
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
[Header("World Settings")] [Header("Isometric Settings")]
[SerializeField] [SerializeField]
float _tileSize = DefTileSize; float _tileSize = DefTileSize;
public float tileSize { public float tileSize {