Search Unity

Clarification on EventTrigger

Discussion in 'UGUI & TextMesh Pro' started by jhow77, Apr 15, 2017.

  1. jhow77

    jhow77

    Joined:
    Jan 10, 2017
    Posts:
    19
    I've been looking into UI touch/mouse handling and have made my way to EventTriggers.

    I was curious if someone could help clarify a few things for me...

    1. "NOTE: Attaching this component to a GameObject will make that object intercept ALL events, and no events will propagate to parent objects."

    I'm a bit confused as to what they are trying to imply... Are they just trying to say that the object will use all the handlers from the interfaces that the Event Trigger class implements?

    And what do they mean by "no events will propagate to parent objects"? What are the parents in this scenario? Like superclasses? Or like parent objects in the game object hierarchy?

    2. "There are two ways to intercept events: You could extend EventTrigger, and override the functions for the events you are interested in intercepting; as shown in this example..."

    Are these two ways equivalent? Or are there any advantages one way or the other? Do these examples resolve the issues related to the NOTE mentioned in question 1 (for example, will the object no longer intercept all events if one of these ways is used instead of attaching the component)? Or are they completely unrelated?

    Thank you!
     
  2. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    Hey there. I hope this might help.
    1) I'm pretty positive that they mean parent game objects in the scene. If you attach an event trigger, it will get all of the events itself.

    2) I think for this, they were just showing 2 examples, but in the end they do almost exactly the same thing. One the subclass, and the other filling the data in for an attached component.
    nb. I do not believe this will change the behaviour to the note mentioned in question 1.

    Additionally: Depending on how many interfaces you want to include, you can implement interfaces explicitly, yourself.
    For example, if you're only interested in when the pointer goes down, you can handle that without the event trigger.
    Hope that helps. :)
     
    jhow77 likes this.
  3. jhow77

    jhow77

    Joined:
    Jan 10, 2017
    Posts:
    19
    Thank you for your response @methos5k.

    What's the different between if I (A) attach the EventTrigger to a GameObject vs. (B) if I extend EventTrigger & override the functions or specify the individual delegates? Or will they accomplish the same thing?

    It's a bit confusing because from the documentation, it looks like there are three ways to use EventTriggers, but only two examples are given. So it's hard to tell if they're supposed to accomplish the same thing or different things.
     
  4. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    I'm pretty certain that attaching and extending are the same thing.. the only difference would be that you could add more stuff to the extension, if you make one. (Which you could then re-use , as that extended type). You could do virtually the same thing with any script you write, though.
    As for specifying the individual interfaces (not sure if that's what you meant by delegates).. but , in my previous post, I said you can implement 1,some or all of the features of an event trigger with interfaces. That difference would be that you only intercept the ones you implement. So , that has a subtle difference, and depends on : What's easier for you, your use case, etc.. :)
     
    jhow77 likes this.
  5. jhow77

    jhow77

    Joined:
    Jan 10, 2017
    Posts:
    19
  6. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    No problem :)