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) {
if ( iso_worlds.Length > 0 ) {
var so = new SerializedObject(iso_worlds);

View File

@@ -6,6 +6,7 @@ using System.Collections.Generic;
namespace IsoTools.Internal {
[CustomEditor(typeof(IsoObject)), CanEditMultipleObjects]
class IsoObjectEditor : Editor {
static bool _showWorldSettings = false;
Dictionary<IsoWorld, List<IsoObject>> _isoObjects = new Dictionary<IsoWorld, List<IsoObject>>();
Dictionary<IsoWorld, List<IsoObject>> _otherObjects = new Dictionary<IsoWorld, List<IsoObject>>();
@@ -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;
}
// ---------------------------------------------------------------------

View File

@@ -6,6 +6,7 @@ using System.Collections.Generic;
namespace IsoTools.Internal {
[CustomEditor(typeof(IsoParent)), CanEditMultipleObjects]
public class IsoParentEditor : Editor {
static bool _showWorldSettings = false;
Dictionary<IsoWorld, List<IsoParent>> _isoParents = new Dictionary<IsoWorld, List<IsoParent>>();
Dictionary<IsoWorld, List<IsoObject>> _isoObjects = new Dictionary<IsoWorld, List<IsoObject>>();
@@ -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;
}
// ---------------------------------------------------------------------

View File

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