Skip to content

Commit 04ad48a

Browse files
authored
Implement Editor for AssetImporter and ScriptedImported (#112)
1 parent a292fec commit 04ad48a

File tree

1 file changed

+122
-1
lines changed

1 file changed

+122
-1
lines changed

Editor/TriEditor.cs

Lines changed: 122 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
using TriInspector.Utilities;
1+
using TriInspector.Utilities;
22
using UnityEditor;
3+
using UnityEditor.AssetImporters;
34
using UnityEngine;
45

56
namespace TriInspector
@@ -16,6 +17,126 @@ internal sealed class TriScriptableObjectEditor : TriEditor
1617
{
1718
}
1819

20+
[CanEditMultipleObjects]
21+
[CustomEditor(typeof(AssetImporter), editorForChildClasses: true)]
22+
public sealed class TriAssetImporterEditor : AssetImporterEditor
23+
{
24+
private TriPropertyTreeForSerializedObject _inspector;
25+
26+
public override void OnDisable()
27+
{
28+
base.OnDisable();
29+
_inspector?.Dispose();
30+
_inspector = null;
31+
}
32+
33+
public override void OnInspectorGUI()
34+
{
35+
if (serializedObject.targetObjects.Length == 0)
36+
{
37+
return;
38+
}
39+
40+
if (serializedObject.targetObject == null)
41+
{
42+
EditorGUILayout.HelpBox("Script is missing", MessageType.Warning);
43+
return;
44+
}
45+
46+
if (TriGuiHelper.IsEditorTargetPushed(serializedObject.targetObject))
47+
{
48+
GUILayout.Label("Recursive inline editors not supported");
49+
return;
50+
}
51+
52+
if (_inspector == null)
53+
{
54+
_inspector = new TriPropertyTreeForSerializedObject(serializedObject);
55+
}
56+
57+
serializedObject.UpdateIfRequiredOrScript();
58+
59+
_inspector.Update();
60+
_inspector.RunValidationIfRequired();
61+
62+
using (TriGuiHelper.PushEditorTarget(target))
63+
{
64+
_inspector.Draw();
65+
ApplyRevertGUI();
66+
}
67+
68+
if (serializedObject.ApplyModifiedProperties())
69+
{
70+
_inspector.RequestValidation();
71+
}
72+
73+
if (_inspector.RepaintRequired)
74+
{
75+
Repaint();
76+
}
77+
}
78+
}
79+
80+
[CanEditMultipleObjects]
81+
[CustomEditor(typeof(ScriptedImporter), editorForChildClasses: true)]
82+
public sealed class TriScriptedImporterEditor : ScriptedImporterEditor
83+
{
84+
private TriPropertyTreeForSerializedObject _inspector;
85+
86+
public override void OnDisable()
87+
{
88+
base.OnDisable();
89+
_inspector?.Dispose();
90+
_inspector = null;
91+
}
92+
93+
public override void OnInspectorGUI()
94+
{
95+
if (serializedObject.targetObjects.Length == 0)
96+
{
97+
return;
98+
}
99+
100+
if (serializedObject.targetObject == null)
101+
{
102+
EditorGUILayout.HelpBox("Script is missing", MessageType.Warning);
103+
return;
104+
}
105+
106+
if (TriGuiHelper.IsEditorTargetPushed(serializedObject.targetObject))
107+
{
108+
GUILayout.Label("Recursive inline editors not supported");
109+
return;
110+
}
111+
112+
if (_inspector == null)
113+
{
114+
_inspector = new TriPropertyTreeForSerializedObject(serializedObject);
115+
}
116+
117+
serializedObject.UpdateIfRequiredOrScript();
118+
119+
_inspector.Update();
120+
_inspector.RunValidationIfRequired();
121+
122+
using (TriGuiHelper.PushEditorTarget(target))
123+
{
124+
_inspector.Draw();
125+
ApplyRevertGUI();
126+
}
127+
128+
if (serializedObject.ApplyModifiedProperties())
129+
{
130+
_inspector.RequestValidation();
131+
}
132+
133+
if (_inspector.RepaintRequired)
134+
{
135+
Repaint();
136+
}
137+
}
138+
}
139+
19140
public class TriEditor : Editor
20141
{
21142
private TriPropertyTreeForSerializedObject _inspector;

0 commit comments

Comments
 (0)