Implement Editor for AssetImporter and ScriptedImported (#112)

This commit is contained in:
Xarpen 2023-05-09 14:37:01 +09:00 committed by GitHub
parent a292fece70
commit 04ad48abec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,5 +1,6 @@
using TriInspector.Utilities; using TriInspector.Utilities;
using UnityEditor; using UnityEditor;
using UnityEditor.AssetImporters;
using UnityEngine; using UnityEngine;
namespace TriInspector 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 public class TriEditor : Editor
{ {
private TriPropertyTreeForSerializedObject _inspector; private TriPropertyTreeForSerializedObject _inspector;