From aecc04da020de438150e728b86040504eeaece1c Mon Sep 17 00:00:00 2001 From: xarpen <36118259+xarpen@users.noreply.github.com> Date: Sun, 7 May 2023 19:33:36 +0900 Subject: [PATCH 1/2] Implement Editor for AssetImporter and ScriptedImported --- Editor/TriEditor.cs | 119 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 119 insertions(+) diff --git a/Editor/TriEditor.cs b/Editor/TriEditor.cs index 4420144f..81549d32 100644 --- a/Editor/TriEditor.cs +++ b/Editor/TriEditor.cs @@ -1,5 +1,6 @@ using TriInspector.Utilities; using UnityEditor; +using UnityEditor.AssetImporters; using UnityEngine; namespace TriInspector @@ -16,6 +17,124 @@ internal sealed class TriScriptableObjectEditor : TriEditor { } + [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(); + } + } + } + + [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; From fe615d9f5215257abebb840d535897162c701480 Mon Sep 17 00:00:00 2001 From: xarpen <36118259+xarpen@users.noreply.github.com> Date: Tue, 9 May 2023 14:22:02 +0900 Subject: [PATCH 2/2] Revert [CanEditMultipleObjects] attribute --- Editor/TriEditor.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Editor/TriEditor.cs b/Editor/TriEditor.cs index 81549d32..dc3f88b4 100644 --- a/Editor/TriEditor.cs +++ b/Editor/TriEditor.cs @@ -1,4 +1,4 @@ -using TriInspector.Utilities; +using TriInspector.Utilities; using UnityEditor; using UnityEditor.AssetImporters; using UnityEngine; @@ -17,6 +17,7 @@ internal sealed class TriScriptableObjectEditor : TriEditor { } + [CanEditMultipleObjects] [CustomEditor(typeof(AssetImporter), editorForChildClasses: true)] public sealed class TriAssetImporterEditor : AssetImporterEditor { @@ -76,6 +77,7 @@ public override void OnInspectorGUI() } } + [CanEditMultipleObjects] [CustomEditor(typeof(ScriptedImporter), editorForChildClasses: true)] public sealed class TriScriptedImporterEditor : ScriptedImporterEditor {