-
Notifications
You must be signed in to change notification settings - Fork 121
/
AtomEventEditor.cs
43 lines (37 loc) · 1.25 KB
/
AtomEventEditor.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
#if UNITY_2019_1_OR_NEWER
using UnityEngine;
using UnityEngine.UIElements;
namespace UnityAtoms.Editor
{
/// <summary>
/// Custom editor for Events. Adds the possiblity to raise an Event from Unity's Inspector.
/// </summary>
/// <typeparam name="T">The type of this event..</typeparam>
/// <typeparam name="E">Event of type T.</typeparam>
public abstract class AtomEventEditor<T, E> : UnityEditor.Editor
where E : AtomEvent<T>
{
public override VisualElement CreateInspectorGUI()
{
var root = new VisualElement();
IMGUIContainer defaultInspector = new IMGUIContainer(() => DrawDefaultInspector());
root.Add(defaultInspector);
E atomEvent = target as E;
var runtimeWrapper = new VisualElement();
runtimeWrapper.SetEnabled(Application.isPlaying);
runtimeWrapper.Add(new Button(() =>
{
atomEvent.Raise(atomEvent.InspectorRaiseValue);
})
{
text = "Raise"
});
root.Add(runtimeWrapper);
#if !UNITY_ATOMS_GENERATE_DOCS
StackTraceEditor.RenderStackTrace(root, atomEvent.GetInstanceID());
#endif
return root;
}
}
}
#endif