Adding custom BaseEventData to UnityEngine.EventSystems NOT Unity.Events

Hi all,

I am currently trying to use the UnityEngine.EventSystems (developed for the UI but which also has a 3D Physics Raycaster) in a game. The reason I want to use it is to make use of all the already available (an handy) editor features of this system over the UnityEngine.Events.

However, the system has been developed for the UI and I would need to be able to add events to the system which trigger on certain game actions.

For example, in the EventTrigger component I would like to see in the dropdown menu a “OnUKeyPressed” events in addition to all the others (eg: PointerClick).

There is a wealth of pretty good tutorials out there for the UnityEngine.Events but not that much for the UnityEngine.EventSystems.

Any help would be much appreciated !

as i understood from your comment you need something that can register events and use them

ill show you 2 examples try to play with them since i dont have the time

//first example

 using UnityEngine;
 using System.Collections;
 using System;
 using UnityEngine.Events;
 using UnityEngine.EventSystems;
 
 
 public class MyClickTrigger : MonoBehaviour , IPointerClickHandler
 {
     #region IPointerClickHandler implementation
 
     public void OnPointerClick (PointerEventData eventData)
     {
         MyOwnEventTriggered ();
     }
 
     #endregion
 
     //my event
     [Serializable]
     public class MyOwnEvent : UnityEvent { }
 
     [SerializeField]
     private MyOwnEvent myOwnEvent = new MyOwnEvent();
     public MyOwnEvent onMyOwnEvent { get { return myOwnEvent; } set { myOwnEvent = value; } }
 
     public void MyOwnEventTriggered()
     {
         onMyOwnEvent.Invoke();
     }
 
 }
 ///add a collider to the object as well so the OnPointerClick can work

//second example

create a script like this one

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI.Extensions;

using UnityEngine.Events;



public class MyEventManager : MonoBehaviour {


	private Dictionary<string,UnityEvent> eventDictionary;
	private static MyEventManager eventManager;

	public static MyEventManager instance
	{
		get
		{
			if (!eventManager)
			{
				eventManager = FindObjectOfType (typeof (MyEventManager)) as MyEventManager;

				if (!eventManager)
				{
					Debug.LogError ("There needs to be one active EventManger script on a GameObject in your scene.");
				}
				else
				{
					eventManager.Init (); 
				}
			}

			return eventManager;
		}
	}
	void Init ()
	{
		if (eventDictionary == null)
		{
			eventDictionary = new Dictionary<string, UnityEvent>();
		}
	}
	public static void StartListening (string eventName, UnityAction listener)
	{
		UnityEvent thisEvent = null;
		if (instance.eventDictionary.TryGetValue (eventName, out thisEvent))
		{
			thisEvent.AddListener (listener);
		} 
		else
		{
			thisEvent = new UnityEvent ();
			thisEvent.AddListener (listener);
			instance.eventDictionary.Add (eventName, thisEvent);
		}
	}

	public static void StopListening (string eventName, UnityAction listener)
	{
		if (eventManager == null) return;
		UnityEvent thisEvent = null;
		if (instance.eventDictionary.TryGetValue (eventName, out thisEvent))
		{
			thisEvent.RemoveListener (listener);
		}
	}

	public static void TriggerEvent (string eventName)
	{
		UnityEvent thisEvent = null;
		if (instance.eventDictionary.TryGetValue (eventName, out thisEvent))
		{
			thisEvent.Invoke ();
		}
	}
}

and then you register an event this way

public class LastPageTriggers : MonoBehaviour {

	void OnEnable()
	{
		MyEventManager.StartListening ("lastPage",LastPage);

	}
	void OnDisable()
	{
		MyEventManager.StopListening ("lastPage", LastPage);
	}
	void LastPage()
	{
		Debug.Log ("Last Page function");
	}
	public static void TriggerLastPage()
	{
		MyEventManager.TriggerEvent ("lastPage");
	}
}

//do not forget to stop listening on disable
//if you want to invoke the method LastPage from anywhere you just call //the static method of TriggerLastPage
//so somewhere else you would have

	void Update () {

		if (Input.GetKeyDown ("u"))
		{
			MyEventManager.TriggerEvent ("lastPage");
//or LastPageTriggers.TriggerLastPage();
		}

	}