Input Delegates
Overview
Most controls allow you to "listen" to the raw input they receive from user actions by passing a delegate to the control's AddInputDelegate() method. Such a delegate must conform to the EZInputDelegate definition: // C#
This delegate receives a reference to the POINTER_INFO object which pertains to the control being "listened" to. The delegate will be called before the control itself performs processing. This affords you the opportunity to modify the ptr variable as necessary, or otherwise take action to alter the behavior of the control. For more information, see POINTER_INFO in the Scripting Reference. |
Example
First, we'll define our delegate somewhere in one of our scripts. NOTE: Because of limitations in JavaScript/UnityScript, input delegates must be written in C#:
void MyDelegate(ref POINTER_INFO ptr)
The above code checks to see if the pointer event (.evt) is a drag event. Now we must tell our control about this delegate for it to be called:
void Start()
That's all there is to it. Now suppose we have a button and want it not to enter the "OVER" state by ignoring the MOVE event. We can "ignore" certain events by fooling the control into thinking the event is something other than what it is, simply by changing the value stored in the POINTER_INFO variable, like so: void MyDelegate(ref POINTER_INFO ptr)
Here we've changed the event to a "NO_CHANGE" event, which will be be ignored by the button. There is almost no limit to how you can extend the functionality or behavior of EZ GUI controls using input delegates. |