unity-atoms/Source/Editor/Editors/AtomEventEditor.cs

41 lines
959 B
C#
Raw Normal View History

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