Ok, now i´m confused and i´m not sure i´m understanding the diffrent Methods of using NGUI events and their subscruption. Let me try to restate, how i understand things at the moment:
- every Element wich has a collider/rigidbody and is on the EventMask Layer gets the events from the camera, like onHover or onClick. You can listen to these events, using void OnHover() method in a component on those gameobjects. Since i´m using a UIManager class i´m NOT utilising this.
- since i have 2D UI Elements combined with interactive elements in the 3D world, i use the UICameraScript on the UICamera (EventMask = 2D UI stuff) and the WorldCamera (EventMask = interactive 3D elements).
- by subscribing directly to the UICamera events in my UIManager, i get those events and can use my own callbacks to process the events. All i need is a callback method wich recieves the same arguments as get passed by the event. Every interactive Element will call the event and it´s NOT possible to add custom callsbacks with custom parameters.
- if i need to pass custom arguments to events, i used the UIEventTrigger, since it allows me to setup an EventDelegate like so:
EventDelegate ed
= new EventDelegate
(this,
"GetHoverIndex");ed.parameters[0].value = 0;
EventDelegate.Set(staticBuild.transform.FindChild("BuildTower1").GetComponent<UIEventTrigger>().onHoverOver, ed);
This method needs the EventTrigger component attached to each interactive element, even if i´m using code to subscribe like above.
- The UIEventlistener works like the subscription to UICamera events, only that i can subscribe specific callbacks to specific elements like so:
UIEventListener.Get(staticBuild.transform.FindChild("BuildTower1").gameObject).onTooltip += TestToolTip;
So the advantage is, that i only get callbacks from the elements i want AND i can route them to diffrent callbacks, event they get triggered by the same even. I have not found a way to subscribe an EventDelegate to this though.
So what i want to do is have tooltips on several elments. the tooltip content differes based on the elements for sure. my plan was to give each element an id and have the content found based on the ID. So what i did was, i used the onHover Event from the Trigger as in the example above to get the hovered button ID and stored it. Then i subscribed to the UICamera.onTooltip Event. When this event was called, i used the stored ID to get the right content in place and showed the tooltip.
I´m not 100% sure how to do something similar with the EventListener. The only thing i can think of is to have for each element a custom callback wich carrys the content (or the ID to call the content).
So is there a way to add additional parameters to UICamera or EventListener events? or even completely customize the EventDelegate like with the EventTrigger?