Fixed it by creating a wrapper for the OnPointerDown function, for those who care how:
public class UIInput : MonoBehaviour, IPointerDownHandler
{
public List<Action<PointerEventData>> OnMouseDownListeners = new List<Action<PointerEventData>>();
public void OnPointerDown(PointerEventData eventData)
{
foreach (var callback in OnMouseDownListeners)
{
callback(eventData);
}
}
public void AddOnMouseDownListener(Action<PointerEventData> action)
{
OnMouseDownListeners.Add(action);
}
}
Attach this script to the UI element and you’re good to go.
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.EventSystems;
public class AvailableTrayItem : MonoBehaviour, ISelectHandler {
public void OnSelect (BaseEventData eventData)
{
Debug.Log (this.gameObject.name + " was selected");
}
}
public class AvailableTray : MonoBehaviour {
public GameObject prefabButton;
void Start(){
addButton();
}
void addButton(){
GameObject gameButton = GameObject.Instantiate( prefabButton );
gameButton.AddComponent<AvailableTrayItem>();
}
}