-
Notifications
You must be signed in to change notification settings - Fork 0
/
CustomOverrideEditor.cs
48 lines (42 loc) · 1.1 KB
/
CustomOverrideEditor.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using System;
using System.Reflection;
using UnityEditor;
using UnityEngine;
namespace Plugins.Editor.OverrideEditors
{
//[CustomEditor(typeof(TargetType)),CanEditMultipleObjects]
public abstract class CustomOverrideEditor : UnityEditor.Editor
{
protected abstract string DefaultEditorTypeName { get; } // => "UnityEditor.TargetTypeEditor";
private Type DefaultEditorType => Assembly.GetAssembly(typeof(UnityEditor.Editor)).GetType(DefaultEditorTypeName);
private UnityEditor.Editor _defaultEditor;
protected void OnEnable()
{
if (_defaultEditor)
{
CreateCachedEditor(targets, DefaultEditorType, ref _defaultEditor);
}
else
{
_defaultEditor = CreateEditor(targets, DefaultEditorType);
}
}
protected void OnDisable()
{
if (_defaultEditor)
{
DestroyImmediate(_defaultEditor);
}
}
public override void OnInspectorGUI()
{
if (_defaultEditor)
{
_defaultEditor.OnInspectorGUI();
}
GUI.enabled = false;
EditorGUILayout.ObjectField("Custom Editor",MonoScript.FromScriptableObject(this), typeof(MonoScript), true);
GUI.enabled = true;
}
}
}