Author Topic: event tunneling  (Read 1993 times)

moctezuma

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1
    • View Profile
event tunneling
« on: August 14, 2014, 12:28:39 AM »
Sometimes we are in the situation that we have overlapping colliders where all (or a couple of them) should get events from UICamera ... here comes event tunneling in place. because you are doing a raycastall in your raycast function anyway we would store the sorted list of hitted objects (with respect of being active and transparancy of cause) in a queue and in the "notify" function of UICamera we would have a struct like:

struct ParamStruct {
   Queue<GameObject> hittedObjects;
   object param;
}

and always send this struct in the SendMessage function. Therefore each function in the user defined scripts would get the list of hitted objects and can define by themself if they want to consume the event (by simple ignoring the queue of hitted objects) or send it further to the next nearest hitted gameobject by calling a SendMessage to the next object in the queue (and remove the first entry in the queue of cause).

Do you think it's a good idea and could be part of NGUI?

Thanks in advance,
Silvio

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: event tunneling
« Reply #1 on: August 14, 2014, 07:46:31 AM »
Changing something like that at this stage of NGUI wouldn't make sense. You can already achieve this by attaching UIForwardEvents script to the object. Also if you want some object's events to be ignored, just disable its collider.

Remember, all the functions like OnClick, OnPress etc they all go to all components attached to the same game object. What if you have a button with UIButton on it that reacts to OnClick, as well as UIPlaySound? Both need to receive OnClick. What if you then attach a 3rd component that does your logic inside regarding "should I really get this event?"

How do you plan on making it so that your script will get this event first, and then somehow magically cancel it for the other 2 attached components? Remember, when you SendMessage to a game object, all attached scripts get this event, and you can't control the order regarding which script will get it first.

Bottom line... it's too late for a change like that in NGUI. The way it works now is how it will remain.