#if UNITY_2019_1_OR_NEWER using UnityEditor; using UnityEngine; using UnityEngine.UIElements; using UnityEditor.UIElements; namespace UnityAtoms.Editor { public abstract class AtomEventEditor : UnityEditor.Editor where E : AtomEvent { 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; } } [CustomEditor(typeof(BoolEvent))] public sealed class BoolEventEditor : AtomEventEditor { protected override VisualElement GetRaiseValueInput() { var input = new Toggle() { label = "Raise value", name = "Raise value", viewDataKey = "Raise value" }; input.RegisterCallback>((evt) => { _raiseValue = evt.newValue; }); return input; } } [CustomEditor(typeof(ColliderEvent))] public sealed class ColliderEventEventEditor : AtomEventEditor { protected override VisualElement GetRaiseValueInput() { var input = new ObjectField() { label = "Raise value", name = "Raise value", viewDataKey = "Raise value", objectType = typeof(Collider) }; input.RegisterCallback>((evt) => { _raiseValue = evt.newValue; }); return input; } } [CustomEditor(typeof(Collider2DEvent))] public sealed class Collider2DEventEditor : AtomEventEditor { protected override VisualElement GetRaiseValueInput() { var input = new ObjectField() { label = "Raise value", name = "Raise value", viewDataKey = "Raise value", objectType = typeof(Collider2D) }; input.RegisterCallback>((evt) => { _raiseValue = evt.newValue; }); return input; } } [CustomEditor(typeof(ColorEvent))] public sealed class ColorEventEditor : AtomEventEditor { protected override VisualElement GetRaiseValueInput() { var input = new ColorField() { label = "Raise value", name = "Raise value", viewDataKey = "Raise value" }; input.RegisterCallback>((evt) => { _raiseValue = evt.newValue; }); return input; } } [CustomEditor(typeof(FloatEvent))] public sealed class FloatEventEditor : AtomEventEditor { protected override VisualElement GetRaiseValueInput() { var input = new FloatField() { label = "Raise value", name = "Raise value", viewDataKey = "Raise value" }; input.RegisterCallback>((evt) => { _raiseValue = evt.newValue; }); return input; } } [CustomEditor(typeof(GameObjectEvent))] public sealed class GameObjectEventEditor : AtomEventEditor { protected override VisualElement GetRaiseValueInput() { var input = new ObjectField() { label = "Raise value", name = "Raise value", viewDataKey = "Raise value", objectType = typeof(GameObject) }; input.RegisterCallback>((evt) => { _raiseValue = evt.newValue; }); return input; } } [CustomEditor(typeof(IntEvent))] public sealed class IntEventEditor : AtomEventEditor { protected override VisualElement GetRaiseValueInput() { var input = new IntegerField() { label = "Raise value", name = "Raise value", viewDataKey = "Raise value" }; input.RegisterCallback>((evt) => { _raiseValue = evt.newValue; }); return input; } } [CustomEditor(typeof(Vector2Event))] public sealed class Vector2EventEditor : AtomEventEditor { protected override VisualElement GetRaiseValueInput() { var input = new Vector2Field() { label = "Raise value", name = "Raise value", viewDataKey = "Raise value" }; input.RegisterCallback>((evt) => { _raiseValue = evt.newValue; }); return input; } } [CustomEditor(typeof(Vector3Event))] public sealed class Vector3EventEditor : AtomEventEditor { protected override VisualElement GetRaiseValueInput() { var input = new Vector3Field() { label = "Raise value", name = "Raise value", viewDataKey = "Raise value" }; input.RegisterCallback>((evt) => { _raiseValue = evt.newValue; }); return input; } } [CustomEditor(typeof(VoidEvent))] public sealed class VoidEventEditor : AtomEventEditor { } [CustomEditor(typeof(StringEvent))] public sealed class StringEventEditor : AtomEventEditor { protected override VisualElement GetRaiseValueInput() { var input = new TextField() { label = "Raise value", name = "Raise value", viewDataKey = "Raise value" }; input.RegisterCallback>((evt) => { _raiseValue = evt.newValue; }); return input; } } } #endif