Rework editors (Fix #114)

This commit is contained in:
VladV 2023-05-11 09:59:24 +04:00
parent 04ad48abec
commit 3908308611
11 changed files with 156 additions and 195 deletions

View File

@ -0,0 +1,78 @@
using TriInspector.Utilities;
using UnityEditor;
using UnityEngine;
namespace TriInspector.Editors
{
public abstract class TriEditor : Editor
{
private TriPropertyTreeForSerializedObject _inspector;
private void OnDisable()
{
OnDisable(this, ref _inspector);
}
public override void OnInspectorGUI()
{
OnInspectorGUI(this, ref _inspector);
}
public static void OnDisable(Editor editor, ref TriPropertyTreeForSerializedObject inspector)
{
inspector?.Dispose();
inspector = null;
}
public static void OnInspectorGUI(Editor editor,
ref TriPropertyTreeForSerializedObject inspector)
{
var serializedObject = editor.serializedObject;
if (serializedObject.targetObjects.Length == 0)
{
return;
}
if (serializedObject.targetObject == null)
{
EditorGUILayout.HelpBox("Script is missing", MessageType.Warning);
return;
}
foreach (var targetObject in serializedObject.targetObjects)
{
if (TriGuiHelper.IsEditorTargetPushed(targetObject))
{
GUILayout.Label("Recursive inline editors not supported");
return;
}
}
if (inspector == null)
{
inspector = new TriPropertyTreeForSerializedObject(serializedObject);
}
serializedObject.UpdateIfRequiredOrScript();
inspector.Update();
inspector.RunValidationIfRequired();
using (TriGuiHelper.PushEditorTarget(serializedObject.targetObject))
{
inspector.Draw();
}
if (serializedObject.ApplyModifiedProperties())
{
inspector.RequestValidation();
}
if (inspector.RepaintRequired)
{
editor.Repaint();
}
}
}
}

View File

@ -0,0 +1,11 @@
using UnityEditor;
using UnityEngine;
namespace TriInspector.Editors
{
[CanEditMultipleObjects]
[CustomEditor(typeof(MonoBehaviour), editorForChildClasses: true, isFallback = true)]
internal sealed class TriMonoBehaviourEditor : TriEditor
{
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: ebc893dd0ca44a789a00c03f7a71dc56
timeCreated: 1683784191

View File

@ -0,0 +1,11 @@
using UnityEditor;
using UnityEngine;
namespace TriInspector.Editors
{
[CanEditMultipleObjects]
[CustomEditor(typeof(ScriptableObject), editorForChildClasses: true, isFallback = true)]
internal sealed class TriScriptableObjectEditor : TriEditor
{
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 5fe6a72a9e734fcc8ab5f29cd13c9d53
timeCreated: 1683784197

View File

@ -0,0 +1,32 @@
using TriInspectorUnityInternalBridge;
using UnityEditor;
using UnityEditor.AssetImporters;
namespace TriInspector.Editors
{
[CanEditMultipleObjects]
[CustomEditor(typeof(ScriptedImporter), editorForChildClasses: true)]
public sealed class TriScriptedImporterEditor : ScriptedImporterEditor
{
private TriPropertyTreeForSerializedObject _inspector;
public override void OnDisable()
{
TriEditor.OnDisable(this, ref _inspector);
base.OnDisable();
}
public override void OnInspectorGUI()
{
TriEditor.OnInspectorGUI(this, ref _inspector);
if (extraDataType != null)
{
EditorProxy.DoDrawDefaultInspector(extraDataSerializedObject);
}
ApplyRevertGUI();
}
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 421d7c27350d45308b6a91b76560bb50
timeCreated: 1683784201

View File

@ -1,195 +0,0 @@
using TriInspector.Utilities;
using UnityEditor;
using UnityEditor.AssetImporters;
using UnityEngine;
namespace TriInspector
{
[CanEditMultipleObjects]
[CustomEditor(typeof(MonoBehaviour), editorForChildClasses: true, isFallback = true)]
internal sealed class TriMonoBehaviourEditor : TriEditor
{
}
[CanEditMultipleObjects]
[CustomEditor(typeof(ScriptableObject), editorForChildClasses: true, isFallback = true)]
internal sealed class TriScriptableObjectEditor : TriEditor
{
}
[CanEditMultipleObjects]
[CustomEditor(typeof(AssetImporter), editorForChildClasses: true)]
public sealed class TriAssetImporterEditor : AssetImporterEditor
{
private TriPropertyTreeForSerializedObject _inspector;
public override void OnDisable()
{
base.OnDisable();
_inspector?.Dispose();
_inspector = null;
}
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)
{
_inspector = new TriPropertyTreeForSerializedObject(serializedObject);
}
serializedObject.UpdateIfRequiredOrScript();
_inspector.Update();
_inspector.RunValidationIfRequired();
using (TriGuiHelper.PushEditorTarget(target))
{
_inspector.Draw();
ApplyRevertGUI();
}
if (serializedObject.ApplyModifiedProperties())
{
_inspector.RequestValidation();
}
if (_inspector.RepaintRequired)
{
Repaint();
}
}
}
[CanEditMultipleObjects]
[CustomEditor(typeof(ScriptedImporter), editorForChildClasses: true)]
public sealed class TriScriptedImporterEditor : ScriptedImporterEditor
{
private TriPropertyTreeForSerializedObject _inspector;
public override void OnDisable()
{
base.OnDisable();
_inspector?.Dispose();
_inspector = null;
}
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)
{
_inspector = new TriPropertyTreeForSerializedObject(serializedObject);
}
serializedObject.UpdateIfRequiredOrScript();
_inspector.Update();
_inspector.RunValidationIfRequired();
using (TriGuiHelper.PushEditorTarget(target))
{
_inspector.Draw();
ApplyRevertGUI();
}
if (serializedObject.ApplyModifiedProperties())
{
_inspector.RequestValidation();
}
if (_inspector.RepaintRequired)
{
Repaint();
}
}
}
public class TriEditor : Editor
{
private TriPropertyTreeForSerializedObject _inspector;
private void OnDisable()
{
_inspector?.Dispose();
_inspector = null;
}
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)
{
_inspector = new TriPropertyTreeForSerializedObject(serializedObject);
}
serializedObject.UpdateIfRequiredOrScript();
_inspector.Update();
_inspector.RunValidationIfRequired();
using (TriGuiHelper.PushEditorTarget(target))
{
_inspector.Draw();
}
if (serializedObject.ApplyModifiedProperties())
{
_inspector.RequestValidation();
}
if (_inspector.RepaintRequired)
{
Repaint();
}
}
}
}

View File

@ -0,0 +1,12 @@
using UnityEditor;
namespace TriInspectorUnityInternalBridge
{
internal static class EditorProxy
{
public static void DoDrawDefaultInspector(SerializedObject obj)
{
Editor.DoDrawDefaultInspector(obj);
}
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 993f9dfd66614ba68fcf95c0e7e098e3
timeCreated: 1683783433