#if UNITY_2019_1_OR_NEWER using UnityEditor; using UnityEngine; using UnityEngine.UIElements; using UnityEditor.UIElements; namespace UnityAtoms { public abstract class GameEventEditor : UnityEditor.Editor where E : GameEvent { protected T _raiseValue = default(T); protected virtual VisualElement GetRaiseValueInput() { return null; } public override VisualElement CreateInspectorGUI() { var uxmlVE = new VisualElement(); uxmlVE.SetEnabled(Application.isPlaying); var input = GetRaiseValueInput(); if (input != null) { uxmlVE.Add(input); } uxmlVE.Add(new Button(() => { E e = target as E; e.Raise(_raiseValue); }) { text = "Raise" }); return uxmlVE; } } [CustomEditor(typeof(BoolEvent))] public sealed class BoolEventEditor : GameEventEditor { 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 : GameEventEditor { 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 : GameEventEditor { 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 : GameEventEditor { 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 : GameEventEditor { 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 : GameEventEditor { 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 IntGameEventEditor : GameEventEditor { 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 : GameEventEditor { 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 : GameEventEditor { 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 : GameEventEditor { } [CustomEditor(typeof(StringEvent))] public sealed class StringEventEditor : GameEventEditor { 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