-
Notifications
You must be signed in to change notification settings - Fork 3
Description
I realize that since you open-sourced this, you probably don't want to have to deal with it much anymore, so I can understand if you don't feel like going into it but I did have a question about the UIEvent backend. I wanted to try and modify it a slight bit to track non-UI related events.
I am using the ScriptableObject Event Architecture described in Ryan Hipples 2017 Unity talk in some areas of my project. So the few events that I do have, I am not sure they qualify as "UI Events", but I don't see any EventTriggerType (Ex. PointerEnter, PointerDown, etc) that match the actual type the invocation would be, as I am calling the invoke manually using a Raise() method, which gets sent out to whatever listeners there are for the particular event type. So, in the UIEventUtility, when GetEventRefs is looking for EventTriggerType's it isn't finding anything.
These two sections pretty much make up the entirety of the system, with a few more that only derive from the GameEvent class in order to be considered individual events, then I just pop the GameEventListener on whatever GameObject I want to call something on when an event gets invoked:
Event Base class
// @formatter:off ----------------------------------------------------------- Event Base Object
// -- Event Base Object -----------------------------------------------------------------------
public class GameEventBaseObject : ScriptableObject {} // @formatter:on
[Serializable]
[CreateAssetMenu(fileName = "GameEvent", menuName = "Events/GameEventEvent", order = 0)]
public class GameEvent : GameEventBaseObject
{
// ---------------------------------------------------------------- List of event Listeners
// -- List of event Listeners -------------------------------------------------------------
[SerializeField] private List<GameEventListener> listeners = new List<GameEventListener>();
// ---------------------------------------------------------------------------- Raise Event
// -- Raise Event -------------------------------------------------------------------------
public void Raise()
{
for (int i = listeners.Count - 1; i >= 0; i--)
listeners[i].OnEventRaised();
}
// @formatter:off ------------------------------------------------------ Event Registration
// -- Event Registration ------------------------------------------------------------------
#region Event Registration
public void RegisterListener(GameEventListener listener) // @formatter:on
{
if (!(listener is null)) listeners.Add(listener);
}
public void UnregisterListener(GameEventListener listener)
{
if (!(listener is null)) listeners.Remove(listener);
}
#endregion
}Event Listener
[Serializable]
[ExecuteInEditMode]
// @formatter:off -------------------------------------------------------------- Event Listener
// -- Event Listener --------------------------------------------------------------------------
public class GameEventListener : MonoBehaviour
{
public GameEvent @event;
public UnityEvent Response;
private void OnEnable() { if(!(@event is null)) @event.RegisterListener(this);}
private void OnDisable() { if(!(@event is null)) @event.UnregisterListener(this); }
public void OnEventRaised() { Response.Invoke(); }
} // @formatter:onReally, my only question is, do you happen to have any recommendation on how I might adapt the UIEvent base in this situation? Something that might point me in the right direction as to what might be best to try and have RelationshipInspector look for, so I can map out and keep track of the events and where they are going.
As I mentioned, I understand if you are not up to it, or simply don't feel like worrying about RelationshipInspector related things anymore, so no hard feelings if that is the case.
Thanks,
-MH