Search Unity

EventTrigger using UnittyEngine.EventSystems

Discussion in 'Scripting' started by Meri, Jan 4, 2017.

  1. Meri

    Meri

    Joined:
    May 25, 2013
    Posts:
    14
    Hola Guys!
    I have been doing some simple events on my app and suddenly I thought - wouldn't it be rad to add your own event to the EventTrigger dropdown list?
    I have spent a good part of day trying to figure it out, but I can't find a neat way of doing so, everything seems, does any of you mates have any idea how to approach the problem?


    Kind regards
    M
     
  2. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,531
    Well, EventTrigger has to do with EventSystem, which is to deal with input events (though I find the name bad... it should be called something like InputEventSystem or something).

    Of course though, Unity has triggers/events that can be custom defined with UnityEvent:
    https://docs.unity3d.com/ScriptReference/Events.UnityEvent.html

    And you could create scripts that have any number of UnityEvents on them, and wire them up to trigger however you want them to.
     
    Meri likes this.
  3. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,689
    My reading of the source code is that the specific events are hard-coded into the EventTrigger.cs class.

    You can see the full source for Unity UI here:

    https://bitbucket.org/Unity-Technol...rigger.cs?at=5.2&fileviewer=file-view-default

    I think you'd have to subclass EventTrigger into your own class to do what you contemplate.

    BTW, that entire UI source database is an excellent read if you wanna know more about how Unity's internal UI functions.
     
    Meri likes this.
  4. Meri

    Meri

    Joined:
    May 25, 2013
    Posts:
    14
    Thanks for replies guys.

    Aye that's what I looked at and I did try to subclass it and everything works(eg. event is listened for and it fires) except for having the event visible on the pulldown list. So instead of being able to setup the event by clicking I have to code it entirely, which is alright but not what i'd want too.
    Unfortunately due to my limited knowledge and experience right now I was unable to do it.