mirror of
https://github.com/codewriter-packages/Tri-Inspector.git
synced 2025-01-22 00:08:51 -05:00
Implement Editor for AssetImporter and ScriptedImported (#112)
This commit is contained in:
parent
a292fece70
commit
04ad48abec
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user