Skip to content

Commit 3908308

Browse files
committed
Rework editors (Fix #114)
1 parent 04ad48a commit 3908308

11 files changed

+156
-195
lines changed

Editor/Editors/TriEditor.cs

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
using TriInspector.Utilities;
2+
using UnityEditor;
3+
using UnityEngine;
4+
5+
namespace TriInspector.Editors
6+
{
7+
public abstract class TriEditor : Editor
8+
{
9+
private TriPropertyTreeForSerializedObject _inspector;
10+
11+
private void OnDisable()
12+
{
13+
OnDisable(this, ref _inspector);
14+
}
15+
16+
public override void OnInspectorGUI()
17+
{
18+
OnInspectorGUI(this, ref _inspector);
19+
}
20+
21+
public static void OnDisable(Editor editor, ref TriPropertyTreeForSerializedObject inspector)
22+
{
23+
inspector?.Dispose();
24+
inspector = null;
25+
}
26+
27+
public static void OnInspectorGUI(Editor editor,
28+
ref TriPropertyTreeForSerializedObject inspector)
29+
{
30+
var serializedObject = editor.serializedObject;
31+
32+
if (serializedObject.targetObjects.Length == 0)
33+
{
34+
return;
35+
}
36+
37+
if (serializedObject.targetObject == null)
38+
{
39+
EditorGUILayout.HelpBox("Script is missing", MessageType.Warning);
40+
return;
41+
}
42+
43+
foreach (var targetObject in serializedObject.targetObjects)
44+
{
45+
if (TriGuiHelper.IsEditorTargetPushed(targetObject))
46+
{
47+
GUILayout.Label("Recursive inline editors not supported");
48+
return;
49+
}
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(serializedObject.targetObject))
63+
{
64+
inspector.Draw();
65+
}
66+
67+
if (serializedObject.ApplyModifiedProperties())
68+
{
69+
inspector.RequestValidation();
70+
}
71+
72+
if (inspector.RepaintRequired)
73+
{
74+
editor.Repaint();
75+
}
76+
}
77+
}
78+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using UnityEditor;
2+
using UnityEngine;
3+
4+
namespace TriInspector.Editors
5+
{
6+
[CanEditMultipleObjects]
7+
[CustomEditor(typeof(MonoBehaviour), editorForChildClasses: true, isFallback = true)]
8+
internal sealed class TriMonoBehaviourEditor : TriEditor
9+
{
10+
}
11+
}

Editor/Editors/TriMonoBehaviourEditor.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using UnityEditor;
2+
using UnityEngine;
3+
4+
namespace TriInspector.Editors
5+
{
6+
[CanEditMultipleObjects]
7+
[CustomEditor(typeof(ScriptableObject), editorForChildClasses: true, isFallback = true)]
8+
internal sealed class TriScriptableObjectEditor : TriEditor
9+
{
10+
}
11+
}

Editor/Editors/TriScriptableObjectEditor.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using TriInspectorUnityInternalBridge;
2+
using UnityEditor;
3+
using UnityEditor.AssetImporters;
4+
5+
namespace TriInspector.Editors
6+
{
7+
[CanEditMultipleObjects]
8+
[CustomEditor(typeof(ScriptedImporter), editorForChildClasses: true)]
9+
public sealed class TriScriptedImporterEditor : ScriptedImporterEditor
10+
{
11+
private TriPropertyTreeForSerializedObject _inspector;
12+
13+
public override void OnDisable()
14+
{
15+
TriEditor.OnDisable(this, ref _inspector);
16+
17+
base.OnDisable();
18+
}
19+
20+
public override void OnInspectorGUI()
21+
{
22+
TriEditor.OnInspectorGUI(this, ref _inspector);
23+
24+
if (extraDataType != null)
25+
{
26+
EditorProxy.DoDrawDefaultInspector(extraDataSerializedObject);
27+
}
28+
29+
ApplyRevertGUI();
30+
}
31+
}
32+
}

Editor/Editors/TriScriptedImporterEditor.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Editor/TriEditor.cs

Lines changed: 0 additions & 195 deletions
This file was deleted.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using UnityEditor;
2+
3+
namespace TriInspectorUnityInternalBridge
4+
{
5+
internal static class EditorProxy
6+
{
7+
public static void DoDrawDefaultInspector(SerializedObject obj)
8+
{
9+
Editor.DoDrawDefaultInspector(obj);
10+
}
11+
}
12+
}

0 commit comments

Comments
 (0)