Search Unity

Simple Event Question

Discussion in 'UGUI & TextMesh Pro' started by Shizen, Dec 12, 2014.

  1. Shizen

    Shizen

    Joined:
    Dec 31, 2012
    Posts:
    14
    I've been struggling with this for a few hours now, and I'm running out of things to try 8), so any help or thoughts would be great!

    I'm trying to pass an event received by one of my UI game objects to one of the objects beneath it. Specifically I'm trying to allow an underlying UI element to "drag" (even more specifically, a ScrollRect component).

    I can't use a CanvasGroup, because I *want* the front most UI object to receive most of the Events.

    I do not seem to be able to simply send the event with SendMessage to the object. The game object with the ScrollRect receives the event, but the ScrollRect itself does not "activate". From what I can tell from the Drag example, some part of the EventSystem caches some set of information on who handled/caught the original BeginDragEvent, and that object receives all subsequent events for that drag operation.

    So, I can "hack" it to work, by setting off its raycast blocking, and then routing all the Drag events to the ScrollRect's gameobject. That actually does work (and the ScrollRect will scroll), but...

    What I would like to do, and have yet to work out, is to actually have the EventSystem recognize that the ScrollRect is handling the event, such that I could catch OnBeginDrag, reroute it to the ScrollRect's object once, and let the EventSystem behave normally from there. Ideally, I'd like to do it "generically", such that I effectively recast the mouseEvent and let the EventSystem pick the appropriate handler.

    I also know how to create a fake mouse click with a custom input module, but the EventSystem has already cached the Drag target, so this doesn't work either. Ideally I'd like to say, EventSystem, reset this Drag event and retarget it with the same mouse position. Or in other words, I'd like to be able to say "pass" :). I haven't tried going so far as to cache the event, fake kill (release) the drag, then restart it. I assume the Drag event system triggers off elapsed time (even though EventSystem purportedly processes events/triggers in Update, from what I read in the documentation). This would make fake restarting a drag problematic.

    I'm sure I've missed some super obvious, trivial method for doing this. Anyone feel like taking me out of my misery?