I was wondering what the best(or good) way to handle deregistering delegates from uieventlisteners?
If I write a simple script like this(and attach it to a gameobject):
void OnEnable () {
UIEventListener.Get(myButton).onClick = myButtonHandlerDelegate;
}
void OnDisable(){
UIEventListener.Get(myButton).onClick = null;
}
If the UIEventListener object gets cleaned up before this object, then the Get() request ends up throwing an error, since it is accessing a gameobject that has been deleted when the program shuts down.
So this makes me wonder... What is the right way to wire up game logic to these UIEventListeners?
The options I'm aware of:
1) wire up a listener to a custom OnClick() handler that is on the same game object that would
2) don't deregester, not a great option in many cases
3) cache the monobehaviour
4)

What is the best practices that you use or is there a hard and fast "right" way to couple game logic to buttons using ngui, while still making sure to register/deregester delegates?