unity-atoms/Source/Editor/Editors/AtomEventEditor.cs
2019-09-30 00:02:54 +02:00

41 lines
959 B
C#

#if UNITY_2019_1_OR_NEWER
using UnityEditor;
using UnityEngine;
using UnityEngine.UIElements;
using UnityEditor.UIElements;
namespace UnityAtoms.Editor
{
public abstract class AtomEventEditor<T, E> : UnityEditor.Editor
where E : AtomEvent<T>
{
protected T _raiseValue = default(T);
protected virtual VisualElement GetRaiseValueInput() { return null; }
public override VisualElement CreateInspectorGUI()
{
var wrapper = new VisualElement();
wrapper.SetEnabled(Application.isPlaying);
var input = GetRaiseValueInput();
if (input != null)
{
wrapper.Add(input);
}
wrapper.Add(new Button(() =>
{
E e = target as E;
e.Raise(_raiseValue);
})
{
text = "Raise"
});
return wrapper;
}
}
}
#endif