Make the AtomEventInstancerEditor generic

This will make the last of the generated editors generic. The AtomTypes have also been updated to forfit generating new Editors and the templates have been removed.
The Raise button has been tested and is fully operational.
This commit is contained in:
CaseyDeCoder 2021-05-03 12:28:23 +02:00
parent 64d7f773ee
commit 46a186cca4
33 changed files with 22 additions and 415 deletions

View File

@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: 886e129ae72ecfe4e8f37cdbf27c8a0f
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,15 +0,0 @@
#if UNITY_2019_1_OR_NEWER
using UnityEditor;
using UnityEngine.UIElements;
using UnityAtoms.Editor;
namespace UnityAtoms.BaseAtoms.Editor
{
/// <summary>
/// Event property drawer of type `AtomBaseVariable`. Inherits from `AtomEventInstancerEditor&lt;AtomBaseVariable, AtomBaseVariableEvent&gt;`. Only availble in `UNITY_2019_1_OR_NEWER`.
/// </summary>
[CustomEditor(typeof(AtomBaseVariableEventInstancer))]
public sealed class AtomBaseVariableEventInstancerEditor : AtomEventInstancerEditor<AtomBaseVariable, AtomBaseVariableEvent> { }
}
#endif

View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 37216dd05e184614cba932342510554a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,15 +0,0 @@
#if UNITY_2019_1_OR_NEWER
using UnityEditor;
using UnityEngine.UIElements;
using UnityAtoms.Editor;
namespace UnityAtoms.BaseAtoms.Editor
{
/// <summary>
/// Event property drawer of type `bool`. Inherits from `AtomEventInstancerEditor&lt;bool, BoolEvent&gt;`. Only availble in `UNITY_2019_1_OR_NEWER`.
/// </summary>
[CustomEditor(typeof(BoolEventInstancer))]
public sealed class BoolEventInstancerEditor : AtomEventInstancerEditor<bool, BoolEvent> { }
}
#endif

View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: dab5bc16a7718614388e6a7812506e4f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,16 +0,0 @@
#if UNITY_2019_1_OR_NEWER
using UnityEditor;
using UnityEngine.UIElements;
using UnityAtoms.Editor;
using UnityEngine;
namespace UnityAtoms.BaseAtoms.Editor
{
/// <summary>
/// Event property drawer of type `Collider2D`. Inherits from `AtomEventInstancerEditor&lt;Collider2D, Collider2DEvent&gt;`. Only availble in `UNITY_2019_1_OR_NEWER`.
/// </summary>
[CustomEditor(typeof(Collider2DEventInstancer))]
public sealed class Collider2DEventInstancerEditor : AtomEventInstancerEditor<Collider2D, Collider2DEvent> { }
}
#endif

View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 5899d07497e6a4b47947c03973a8ef86
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,16 +0,0 @@
#if UNITY_2019_1_OR_NEWER
using UnityEditor;
using UnityEngine.UIElements;
using UnityAtoms.Editor;
using UnityEngine;
namespace UnityAtoms.BaseAtoms.Editor
{
/// <summary>
/// Event property drawer of type `Collider`. Inherits from `AtomEventInstancerEditor&lt;Collider, ColliderEvent&gt;`. Only availble in `UNITY_2019_1_OR_NEWER`.
/// </summary>
[CustomEditor(typeof(ColliderEventInstancer))]
public sealed class ColliderEventInstancerEditor : AtomEventInstancerEditor<Collider, ColliderEvent> { }
}
#endif

View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: c6654c6a70354b14a8a1f316de51bafb
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,16 +0,0 @@
#if UNITY_2019_1_OR_NEWER
using UnityEditor;
using UnityEngine.UIElements;
using UnityAtoms.Editor;
using UnityEngine;
namespace UnityAtoms.BaseAtoms.Editor
{
/// <summary>
/// Event property drawer of type `Color`. Inherits from `AtomEventInstancerEditor&lt;Color, ColorEvent&gt;`. Only availble in `UNITY_2019_1_OR_NEWER`.
/// </summary>
[CustomEditor(typeof(ColorEventInstancer))]
public sealed class ColorEventInstancerEditor : AtomEventInstancerEditor<Color, ColorEvent> { }
}
#endif

View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 08bee9520a1076f48b9853e4bd6c9d14
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,15 +0,0 @@
#if UNITY_2019_1_OR_NEWER
using UnityEditor;
using UnityEngine.UIElements;
using UnityAtoms.Editor;
namespace UnityAtoms.BaseAtoms.Editor
{
/// <summary>
/// Event property drawer of type `float`. Inherits from `AtomEventInstancerEditor&lt;float, FloatEvent&gt;`. Only availble in `UNITY_2019_1_OR_NEWER`.
/// </summary>
[CustomEditor(typeof(FloatEventInstancer))]
public sealed class FloatEventInstancerEditor : AtomEventInstancerEditor<float, FloatEvent> { }
}
#endif

View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 6002e99ca3def954f8681c8f505a17ea
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,16 +0,0 @@
#if UNITY_2019_1_OR_NEWER
using UnityEditor;
using UnityEngine.UIElements;
using UnityAtoms.Editor;
using UnityEngine;
namespace UnityAtoms.BaseAtoms.Editor
{
/// <summary>
/// Event property drawer of type `GameObject`. Inherits from `AtomEventInstancerEditor&lt;GameObject, GameObjectEvent&gt;`. Only availble in `UNITY_2019_1_OR_NEWER`.
/// </summary>
[CustomEditor(typeof(GameObjectEventInstancer))]
public sealed class GameObjectEventInstancerEditor : AtomEventInstancerEditor<GameObject, GameObjectEvent> { }
}
#endif

View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 31dd985586bbcf74496fd7dcfafe50e1
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,15 +0,0 @@
#if UNITY_2019_1_OR_NEWER
using UnityEditor;
using UnityEngine.UIElements;
using UnityAtoms.Editor;
namespace UnityAtoms.BaseAtoms.Editor
{
/// <summary>
/// Event property drawer of type `int`. Inherits from `AtomEventInstancerEditor&lt;int, IntEvent&gt;`. Only availble in `UNITY_2019_1_OR_NEWER`.
/// </summary>
[CustomEditor(typeof(IntEventInstancer))]
public sealed class IntEventInstancerEditor : AtomEventInstancerEditor<int, IntEvent> { }
}
#endif

View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 4ed65024b2d3ce04ab2e9a032c3094ac
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,15 +0,0 @@
#if UNITY_2019_1_OR_NEWER
using UnityEditor;
using UnityEngine.UIElements;
using UnityAtoms.Editor;
namespace UnityAtoms.BaseAtoms.Editor
{
/// <summary>
/// Event property drawer of type `string`. Inherits from `AtomEventInstancerEditor&lt;string, StringEvent&gt;`. Only availble in `UNITY_2019_1_OR_NEWER`.
/// </summary>
[CustomEditor(typeof(StringEventInstancer))]
public sealed class StringEventInstancerEditor : AtomEventInstancerEditor<string, StringEvent> { }
}
#endif

View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: d825191c91a7bf14ea21c3c85f881070
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,16 +0,0 @@
#if UNITY_2019_1_OR_NEWER
using UnityEditor;
using UnityEngine.UIElements;
using UnityAtoms.Editor;
using UnityEngine;
namespace UnityAtoms.BaseAtoms.Editor
{
/// <summary>
/// Event property drawer of type `Vector2`. Inherits from `AtomEventInstancerEditor&lt;Vector2, Vector2Event&gt;`. Only availble in `UNITY_2019_1_OR_NEWER`.
/// </summary>
[CustomEditor(typeof(Vector2EventInstancer))]
public sealed class Vector2EventInstancerEditor : AtomEventInstancerEditor<Vector2, Vector2Event> { }
}
#endif

View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: b63a197e7c4f0244fb404e2564ba49d8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,16 +0,0 @@
#if UNITY_2019_1_OR_NEWER
using UnityEditor;
using UnityEngine.UIElements;
using UnityAtoms.Editor;
using UnityEngine;
namespace UnityAtoms.BaseAtoms.Editor
{
/// <summary>
/// Event property drawer of type `Vector3`. Inherits from `AtomEventInstancerEditor&lt;Vector3, Vector3Event&gt;`. Only availble in `UNITY_2019_1_OR_NEWER`.
/// </summary>
[CustomEditor(typeof(Vector3EventInstancer))]
public sealed class Vector3EventInstancerEditor : AtomEventInstancerEditor<Vector3, Vector3Event> { }
}
#endif

View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: e165e33dc1595914cb450395dcca7ac8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,15 +0,0 @@
#if UNITY_2019_1_OR_NEWER
using UnityEditor;
using UnityEngine.UIElements;
using UnityAtoms.Editor;
namespace UnityAtoms.BaseAtoms.Editor
{
/// <summary>
/// Event property drawer of type `Void`. Inherits from `AtomEventInstancerEditor&lt;Void, VoidEvent&gt;`. Only availble in `UNITY_2019_1_OR_NEWER`.
/// </summary>
[CustomEditor(typeof(VoidEventInstancer))]
public sealed class VoidEventInstancerEditor : AtomEventInstancerEditor<Void, VoidEvent> { }
}
#endif

View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: c2c10c1b1cddf4440bbb64c77c25951c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,15 +1,15 @@
using System.Reflection;
using UnityEditor;
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 AtomEventInstancerEditor<T, E> : UnityEditor.Editor
where E : AtomEvent<T>
///// <summary>
///// Custom editor for Events. Adds the possiblity to raise an Event from Unity's Inspector.
///// </summary>
[CustomEditor(typeof(AtomEventInstancer<>), true)]
public class AtomEventInstancerEditor : UnityEditor.Editor
{
public override VisualElement CreateInspectorGUI()
{
@ -18,17 +18,23 @@ namespace UnityAtoms.Editor
IMGUIContainer defaultInspector = new IMGUIContainer(() => DrawDefaultInspector());
root.Add(defaultInspector);
var eventInstancer = target as AtomEventInstancer<T>;
AtomEvent<T> atomEvent = eventInstancer.Event;
var runtimeWrapper = new VisualElement();
runtimeWrapper.SetEnabled(Application.isPlaying);
runtimeWrapper.Add(new Button(() =>
{
atomEvent.Raise(eventInstancer.Event.InspectorRaiseValue);
var targetType = target.GetType();
var atomEventInstancerEventProperty = targetType.GetProperty(nameof(AtomEventInstancer<object>.Event), BindingFlags.Instance | BindingFlags.Public);
var atomEventInstancerEvent = atomEventInstancerEventProperty.GetValue(target);
var atomEventInstancerEventType = atomEventInstancerEvent.GetType();
var inspectorRaiseValueProperty = atomEventInstancerEventType.GetProperty(nameof(AtomEvent<object>.InspectorRaiseValue), BindingFlags.Instance | BindingFlags.Public);
var inspectorRaiseValue = inspectorRaiseValueProperty.GetValue(atomEventInstancerEvent);
var raiseMethod = atomEventInstancerEventType.GetMethod(nameof(AtomEvent<object>.Raise), new[] { inspectorRaiseValueProperty.PropertyType });
raiseMethod.Invoke(atomEventInstancerEvent, new[] { inspectorRaiseValue });
})
{
text = "Raise"
text = "Raise",
});
root.Add(runtimeWrapper);

View File

@ -14,14 +14,12 @@ namespace UnityAtoms.Editor
);
public static readonly AtomType EVENT = new AtomType(
displayName: "Event",
templateName: "UA_Template__Event.txt",
editorTemplateName: "UA_Template_AtomEditor__Event.txt"
templateName: "UA_Template__Event.txt"
);
public static readonly AtomType PAIR_EVENT = new AtomType(
displayName: "Pair Event",
name: "Event",
templateName: "UA_Template__Event.txt",
editorTemplateName: "UA_Template_AtomEditor__Event.txt"
templateName: "UA_Template__Event.txt"
);
public static readonly AtomType VALUE_LIST = new AtomType(
displayName: "Value List",
@ -60,8 +58,7 @@ namespace UnityAtoms.Editor
);
public static readonly AtomType VARIABLE = new AtomType(
displayName: "Variable",
templateName: "UA_Template__Variable.txt",
editorTemplateName: "UA_Template_AtomEditor__Variable.txt"
templateName: "UA_Template__Variable.txt"
);
public static readonly AtomType VARIABLE_INSTANCER = new AtomType(
displayName: "Variable Instancer",
@ -70,8 +67,7 @@ namespace UnityAtoms.Editor
);
public static readonly AtomType EVENT_INSTANCER = new AtomType(
displayName: "Event Instancer",
templateName: "UA_Template__EventInstancer.txt",
editorTemplateName: "UA_Template__AtomEditor_EventInstancer.txt"
templateName: "UA_Template__EventInstancer.txt"
);
public static readonly AtomType PAIR_EVENT_INSTANCER = new AtomType(
displayName: "Pair Event Instancer",

View File

@ -1,17 +0,0 @@
using UnityEditor;
using UnityEngine.UIElements;
using UnityAtoms.Editor;
<%IF TYPE_HAS_NAMESPACE%>using {TYPE_NAMESPACE};<%ENDIF%>
<%IF HAS_SUB_UA_NAMESPACE%>
namespace UnityAtoms.{SUB_UA_NAMESPACE}.Editor
<%ELSE%>
namespace UnityAtoms.Editor
<%ENDIF%>
{
/// <summary>
/// Event property drawer of type `{VALUE_TYPE}`. Inherits from `AtomEventEditor&lt;{VALUE_TYPE}&gt;`.
/// </summary>
[CustomEditor(typeof({VALUE_TYPE_NAME}Event))]
public sealed class {VALUE_TYPE_NAME}EventEditor : AtomEventEditor<{VALUE_TYPE}> { }
}

View File

@ -1,7 +0,0 @@
fileFormatVersion: 2
guid: b0da24b9cd61c4f5a83420ce5971b871
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,19 +0,0 @@
#if UNITY_2019_1_OR_NEWER
using UnityEditor;
using UnityEngine.UIElements;
using UnityAtoms.Editor;
<%IF TYPE_HAS_NAMESPACE%>using {TYPE_NAMESPACE};<%ENDIF%>
<%IF HAS_SUB_UA_NAMESPACE%>
namespace UnityAtoms.{SUB_UA_NAMESPACE}.Editor
<%ELSE%>
namespace UnityAtoms.Editor
<%ENDIF%>
{
/// <summary>
/// Event property drawer of type `{VALUE_TYPE}`. Inherits from `AtomEventInstancerEditor&lt;{VALUE_TYPE}, {VALUE_TYPE_NAME}Event&gt;`. Only availble in `UNITY_2019_1_OR_NEWER`.
/// </summary>
[CustomEditor(typeof({VALUE_TYPE_NAME}Event))]
public sealed class {VALUE_TYPE_NAME}EventInstancerEditor : AtomEventInstancerEditor<{VALUE_TYPE}, {VALUE_TYPE_NAME}Event> { }
}
#endif

View File

@ -1,7 +0,0 @@
fileFormatVersion: 2
guid: 64e895f0a21bf3644a484862531edaa2
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,16 +0,0 @@
using UnityEditor;
using UnityAtoms.Editor;
<%IF TYPE_HAS_NAMESPACE%>using {TYPE_NAMESPACE};<%ENDIF%>
<%IF HAS_SUB_UA_NAMESPACE%>
namespace UnityAtoms.{SUB_UA_NAMESPACE}.Editor
<%ELSE%>
namespace UnityAtoms.Editor
<%ENDIF%>
{
/// <summary>
/// Variable Inspector of type `{VALUE_TYPE}`. Inherits from `AtomVariableEditor&lt;{VALUE_TYPE}&gt;`
/// </summary>
[CustomEditor(typeof({VALUE_TYPE_NAME}Variable))]
public sealed class {VALUE_TYPE_NAME}VariableEditor : AtomVariableEditor<{VALUE_TYPE}> { }
}

View File

@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: 88c6cd99584540a0b9996d60416193d3
timeCreated: 1572554920