Moved editor recursion check to TriEditor class

This commit is contained in:
VladV 2022-06-03 14:03:51 +03:00
parent 65e75ea953
commit ffb0e8f4c5
2 changed files with 37 additions and 41 deletions

View File

@ -78,43 +78,33 @@ namespace TriInspector.Elements
}
var lastEditorRect = Rect.zero;
var shouldDrawEditor = _property.IsExpanded && !_property.IsValueMixed;
if (TriGuiHelper.IsEditorTargetPushed((Object) _property.Value))
if (_editor == null && shouldDrawEditor && _property.Value is Object obj && obj != null)
{
GUI.Label(position, "Recursive inline editors not supported");
_editor = Editor.CreateEditor(obj);
}
lastEditorRect.height = EditorGUIUtility.singleLineHeight;
if (_editor != null && shouldDrawEditor)
{
Rect indentedEditorPosition;
using (TriGuiHelper.PushIndentLevel())
{
indentedEditorPosition = EditorGUI.IndentedRect(_editorPosition);
}
GUILayout.BeginArea(indentedEditorPosition);
GUILayout.BeginVertical();
_editor.OnInspectorGUI();
GUILayout.EndVertical();
lastEditorRect = GUILayoutUtility.GetLastRect();
GUILayout.EndArea();
}
else
{
var shouldDrawEditor = _property.IsExpanded && !_property.IsValueMixed;
if (_editor == null && shouldDrawEditor && _property.Value is Object obj && obj != null)
if (_editor != null)
{
_editor = Editor.CreateEditor(obj);
}
if (_editor != null && shouldDrawEditor)
{
Rect indentedEditorPosition;
using (TriGuiHelper.PushIndentLevel())
{
indentedEditorPosition = EditorGUI.IndentedRect(_editorPosition);
}
GUILayout.BeginArea(indentedEditorPosition);
GUILayout.BeginVertical();
_editor.OnInspectorGUI();
GUILayout.EndVertical();
lastEditorRect = GUILayoutUtility.GetLastRect();
GUILayout.EndArea();
}
else
{
if (_editor != null)
{
Object.DestroyImmediate(_editor);
}
Object.DestroyImmediate(_editor);
}
}

View File

@ -18,19 +18,25 @@ namespace TriInspector
public override void OnInspectorGUI()
{
if (serializedObject.targetObjects.Length == 0)
{
return;
}
if (serializedObject.targetObject == null)
{
EditorGUILayout.HelpBox("Script is missing", MessageType.Warning);
return;
}
if (TriGuiHelper.IsEditorTargetPushed(serializedObject.targetObject))
{
GUILayout.Label("Recursive inline editors not supported");
return;
}
if (_inspector == null)
{
if (serializedObject.targetObjects.Length == 0)
{
return;
}
if (serializedObject.targetObject == null)
{
EditorGUILayout.HelpBox("Script is missing", MessageType.Warning);
return;
}
_inspector = new TriPropertyTreeForSerializedObject(serializedObject);
}