-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathCustomEditorBase.cs
88 lines (66 loc) · 2.01 KB
/
CustomEditorBase.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using UnityEngine.PlayerLoop;
namespace cmdwtf.UnityTools.Editor
{
public abstract class CustomEditorBase : UnityEditor.Editor
{
protected readonly List<string> IgnoredPropertyNames = new List<string>{ "m_Script" };
private readonly List<IEnumerator> _runningCoroutines;
private string ObjectName => target == null ? string.Empty : target.name;
protected CustomEditorBase()
{
_runningCoroutines = new List<IEnumerator>();
EditorApplication.update += Update;
}
private void Update()
{
if (_runningCoroutines.Count <= 0)
{
return;
}
int index = _runningCoroutines.Count - 1;
Debug.Log($"{ObjectName}: Executing Coroutine {index}");
bool coroutineFinished = !_runningCoroutines[index].MoveNext();
if (coroutineFinished)
{
Debug.Log($"{ObjectName}: Finished Coroutine {index}");
_runningCoroutines.RemoveAt(index);
}
}
protected bool DoInspector(SerializedObject serialized, bool skipFirst = false, bool recurse = true, bool showHidden = false)
{
SerializedProperty prop = serialized.GetIterator();
// next(true) must be called to get the first element.
System.Func<bool, bool> nextFunc = showHidden
? prop.Next
: prop.NextVisible;
nextFunc(true);
if (skipFirst)
{
EditorGUILayout.PropertyField(prop);
}
while (nextFunc(recurse))
{
if (IgnoredPropertyNames.Contains(prop.name) == false || !showHidden)
{
EditorGUILayout.PropertyField(prop);
}
}
prop.Reset();
return serialized.ApplyModifiedProperties();
}
protected void DoChildInspector(Component child, bool recurse = true)
{
if (child == null)
{
return;
}
var serialized = new SerializedObject(child);
DoInspector(serialized, skipFirst: true, recurse);
}
protected void StartCoroutine(IEnumerator cr) => _runningCoroutines.Add(cr);
}
}