-
Notifications
You must be signed in to change notification settings - Fork 0
Events Extending
Extending the event system to make events that pass around any datatype is simple, you need only extend four classes.
Unity Events are used by the Event Handler classes as a convenient way to connect events to script functionality.
- Inherit from
UnityEvent<T>withTbeing the type you want.
public class ByteUnityEvent : UnityEvent<byte> {}The Event Backing stores registered event handlers and triggers them all when the event is fired.
- Inherit from
BaseEventBacking<T, Y>withTbeing the type you want to be the event argument, andYbeing a UnityEvent of the same datatype. - Give it a
CreateAssetMenuattribute.
[CreateAssetMenu(fileName = "NewByteEvent", menuName = "Scriptable Objects/Events/Byte")]
public class ByteEvent : BaseEventHandler<byte, ByteUnityEvent> {}The Event Handler is a script added to Game Objects that are meant to receive events. They act a the connection between Event Backings and the code that should execute on the event.
- Inherit from
BaseEventHandler<T, Y, Z>withTbeing the argument type,Ybeing the Event Backing, andZbeing the Unity Event.
public class ByteEventHandler : BaseEventHandler<byte, ByteEventBacking, ByteUnityEvent>The Event Field is what you define inside of a script to expose a reference to an event. It can be set to reference an Event Backing or directly reference a Handler.
- Inherit from
BaseEvent<T, Y, Z>withTbeing the argument type,Ybeing the Event Backing, andZbeing the Event Handler. - Give it the
Serializableattribute.
[Serializable]
public class ByteEvent : BaseEvent<byte, ByteEventBacking, ByteEventHandler> { }Custom property drawers are used to clean up the look of Event Fields in the editor while maintaining the flexibility gained by using an Event Field rather than simply referencing the Event Backing.
- Define a class that inherits from
EventDrawer. (This need only be done once, it can be used for all custom variables) - Add a
CustomPropertyDrawerattribute to theEventDrawerclass.
[CustomPropertyDrawer(typeof(ByteEvent))]Custom Inspectors are used to give the user the ability to trigger Event Backings manually from the editor with test values.
- Define a custom inspector for the Event Backing.
- Give it the
CustomEditorattribute.
[CustomEditor(typeof(ByteEventBacking))]
public class ByteEventInspector : BaseEventInspector<byte> { }- Events
- Variables
- Conditions
- Extras
- GUI Elements
- Systems