In Unity events
are used as enhanced delegates
.
This is extremely helpful in developing clean concise event management scripts.
However, when debugging said scripts and complex arrangements, is there a way I can see which methods are in an event at any one time?
Simplified Example:
Game manager
using UnityEngine;
using System.Collections;
public class EventManager : MonoBehaviour
{
public delegate void ClickAction();
public static event ClickAction OnClicked;
void someMethod()
{
if(whatever = true && OnClicked != null)
{
//this is the event delegate:
OnClicked();
}
}
}
gameObject script
(one of several scripts that can add methods to an event
)
using UnityEngine;
using System.Collections;
public class TeleportScript : MonoBehaviour
{
void SomeMethod()
{
EventManager.OnClicked += Teleport;
}
void SomeOtherMethod(){
EventManager.OnClicked += Horses;
}
void OnDisable()
{
EventManager.OnClicked -= Teleport;
EventManager.OnClicked -= Horses;
}
void Teleport()
{
Vector3 pos = transform.position;
pos.y = Random.Range(1.0f, 3.0f);
transform.position = pos;
}
void Horses(){
instantiate(horses, new Vector3.zero, Quaternion.identity);
}
}
etc. etc.,
I have used Debug.Log(OnClicked.Method);
but this only returns one of multiple methods associated with an event.
So my issue is, that for debugging and general error resolution, how can I find out which method(s) are in the OnClicked()
event delegate without/before running this delegate?
For example:
Debug.Log(OnClicked(listMethods));
//Output to log:
void Teleport();
void Horses();