-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathEditorHeaderHook.cs
More file actions
45 lines (37 loc) · 1.18 KB
/
EditorHeaderHook.cs
File metadata and controls
45 lines (37 loc) · 1.18 KB
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
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using Object = UnityEngine.Object;
[InitializeOnLoad]
static class EditorHeaderHook
{
private static Dictionary<Editor, (Object[] targets, MetadataEditor editor)> _targetsCache = new();
static EditorHeaderHook()
{
Editor.finishedDefaultHeaderGUI += DisplayMetadata;
}
static void DisplayMetadata(Editor editor)
{
if (!EditorUtility.IsPersistent(editor.target))
return;
if (!GUI.enabled)
return;
if (_targetsCache.TryGetValue(editor, out var cache) == false || Equality(cache.targets, editor.targets) == false)
{
cache.editor?.Dispose();
_targetsCache[editor] = cache = (editor.targets, new MetadataEditor(editor.targets));
}
cache.editor.OnInspectorGUI();
static bool Equality<T>(T[] a, T[] b)
{
if (a.Length != b.Length)
return false;
for (int i = 0; i < a.Length; i++)
{
if (ReferenceEquals(a[i], b[i]) == false)
return false;
}
return true;
}
}
}