From 04ad48abecd8bdb52b1ac569c59a2c9da59742f4 Mon Sep 17 00:00:00 2001 From: Xarpen <36118259+xarpen@users.noreply.github.com> Date: Tue, 9 May 2023 14:37:01 +0900 Subject: [PATCH] Implement Editor for AssetImporter and ScriptedImported (#112) --- Editor/TriEditor.cs | 123 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 122 insertions(+), 1 deletion(-) diff --git a/Editor/TriEditor.cs b/Editor/TriEditor.cs index 4420144..dc3f88b 100644 --- a/Editor/TriEditor.cs +++ b/Editor/TriEditor.cs @@ -1,5 +1,6 @@ -using TriInspector.Utilities; +using TriInspector.Utilities; using UnityEditor; +using UnityEditor.AssetImporters; using UnityEngine; namespace TriInspector @@ -16,6 +17,126 @@ namespace TriInspector { } + [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;