Author Topic: Capturing events from a third party asset in a widget  (Read 16679 times)

dogfacedesign

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 3
  • Posts: 33
    • View Profile
Capturing events from a third party asset in a widget
« on: February 16, 2016, 09:35:40 PM »
I have a third party asset that I am integrating with.  I have successfully managed to anchor it to the rest of my UI by attaching a UIWidget component to it at runtime.  My problem is that I can't seem to figure out a way to capture the mouse events and what not from this asset due to NGUI intercepting them.

I've created a separate layer for this asset, and have set the UI Root/Camera to not cull it (the main camera does the culling).  And I've taken this new layer out of the UI Root/Camera event mask.  I thought that would be the right approach, but perhaps I am missing something.  Unfortunately, converting this asset to use the NGUI style event handling is not really an option.

Any ideas/suggestions would be greatly appreciated!

Cheers.

dogfacedesign

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 3
  • Posts: 33
    • View Profile
Re: Capturing events from a third party asset in a widget
« Reply #1 on: February 16, 2016, 10:03:10 PM »
Of course, as soon I post the message above, I realized my mistake.  Well, it's working now, but now my anchoring is broken. :(  Back to the drawing board hehe.

dogfacedesign

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 3
  • Posts: 33
    • View Profile
Re: Capturing events from a third party asset in a widget
« Reply #2 on: February 17, 2016, 09:35:43 AM »
Building on to this thread a bit.

Can I assume that if a layer is culled to a specific camera, that only that camera can process events for widgets on that layer?  What I am trying to do may be impossible - not sure.  I'm trying to get this third party asset (that has a widget component that I added to it for layout purposes) to be managed by NGUI for the purposes of layout/anchoring, but have its events processed by a separate camera.  Any thoughts out there?
« Last Edit: February 18, 2016, 09:03:32 AM by dogfacedesign »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Capturing events from a third party asset in a widget
« Reply #3 on: February 18, 2016, 06:59:20 PM »
Only cameras that have UICamera attached will be sending events to the objects visible by that camera. You can attach a UICamera script to each camera in your scene.

dogfacedesign

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 3
  • Posts: 33
    • View Profile
Re: Capturing events from a third party asset in a widget
« Reply #4 on: February 18, 2016, 07:29:06 PM »
That's the thing, I have a UICamera script attached to my main camera as well.

dogfacedesign

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 3
  • Posts: 33
    • View Profile
Re: Capturing events from a third party asset in a widget
« Reply #5 on: February 18, 2016, 07:36:19 PM »
I should add what is actually happening.  When I flip the debug option on the UIRoot camera, it shows the info for the third party widget when it shouldn't.  That widget's events should be picked up by the main game camera.  Also, nothing else on the UI works except stuff in the NGUI layer. :(  If I remove the UICamera script from my main camera, everything works except for the third party widget.

dogfacedesign

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 3
  • Posts: 33
    • View Profile
Re: Capturing events from a third party asset in a widget
« Reply #6 on: February 18, 2016, 07:53:40 PM »
Actually, the more I think about it, I don't think what I am trying to do is possible.  I need to figure out some other approach I think.

dogfacedesign

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 3
  • Posts: 33
    • View Profile
Re: Capturing events from a third party asset in a widget
« Reply #7 on: February 18, 2016, 08:19:20 PM »
Let me pose another scenario, as I am trying different things to get this to work.

I am trying to anchor this third party asset (in layer called "X") to an NGUI widget (in the "NGUI" layer).  I do this by adding a UIWidget component to the third party asset, then setting its transform to the NGUI widget's transform.  Sadly, this doesn't seem to work either.  No matter what I do, I get it in the center of the screen, rather than where I want it (lower right of the screen).  But at least it works.  Just doesn't seem to be anchoring properly or something.  Shouldn't this be possible, or no? Do all anchored assets need to be in the same layer as the NGUI stuff?

Thanks!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Capturing events from a third party asset in a widget
« Reply #8 on: February 22, 2016, 07:04:16 PM »
Use UIAnchor to anchor that 3rd-party asset. There is no need to add a widget to it. NGUI's events go to colliders visible by the camera. A simple raycast is performed, and whichever collider is hit first will receive the event.

What you're doing is a bit of a gray area. NGUI's anchoring is meant to work with widgets, for the UI -- there isn't anything concrete I can suggest to make it work with 3rd party non-NGUI content aside from trying to use UIAnchor.

dogfacedesign

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 3
  • Posts: 33
    • View Profile
Re: Capturing events from a third party asset in a widget
« Reply #9 on: February 22, 2016, 08:33:12 PM »
I managed to get some "reasonable" results by doing creative Screen.w/h math and positioning it that way.  But I will definitely try the UIAnchor approach - a much better solution if I can get it to work with it.  Thanks!

Cheers.