Author Topic: Prevent interaction behind the ngui objects  (Read 8968 times)

Lumind

  • Newbie
  • *
  • Thank You
  • -Given: 5
  • -Receive: 0
  • Posts: 14
    • View Profile
Prevent interaction behind the ngui objects
« on: June 18, 2014, 02:16:50 PM »
I know that this question was asked many times but I didn't figure that out
I have buttons, sprites and etc. When I click them - I usually interact with them and every thing which is behind the button, sprite and etc. How to prevent this? (I've seen 1 video on YouTube, where it was shown but I can't find it anymore and seems that browser's history doesn't contain it)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Prevent interaction behind the ngui objects
« Reply #1 on: June 18, 2014, 05:06:54 PM »
ALT+SHIFT+W, ALT+SHIFT+C, resize to cover your screen, adjust depth so that it's in front of everything.

If you have multiple panels, create a new panel for this container widget and bring it to front.

Lumind

  • Newbie
  • *
  • Thank You
  • -Given: 5
  • -Receive: 0
  • Posts: 14
    • View Profile
Re: Prevent interaction behind the ngui objects
« Reply #2 on: June 19, 2014, 02:43:54 AM »
thanks for advice but it still influence not-NGUI objects when I click on NGUI objects. Also, collider on container, resized to cover my screen. doesn't allow to work with other NGUI objects (which are in container's collider). I think I did it incorrectly. Here's the pic:

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Prevent interaction behind the ngui objects
« Reply #3 on: June 19, 2014, 06:08:34 PM »
If your non-NGUI objects are being influenced, then you are not using an NGUI event system with them.

NGUI has no way to "cancel" Input.events -- this is Unity's functionality, not NGUI. You either have to check to see if the event is over the UI in your handling, or use NGUI's events fully -- even with your game objects.

Remember -- having a UICamera attached to the game camera is all it takes for it to send out NGUI events like OnHover, OnPress, OnClick, etc.

Lumind

  • Newbie
  • *
  • Thank You
  • -Given: 5
  • -Receive: 0
  • Posts: 14
    • View Profile
Re: Prevent interaction behind the ngui objects
« Reply #4 on: June 20, 2014, 02:08:39 AM »
Well then about 1st NGUI object(sprite) when clicked influencing 2-nd NGUI object which is behind the first <-- about this were the words about container? I still don't get it
the first picture show without container and the second with. But the second doesn't allow to work with them
(the button is blue when the mouse is over it)

UPD:
Ohhh, that was stupid from my side) I just didn't mention that this container should be attached to the needed object (not to the entire root) thanks a lot
« Last Edit: June 20, 2014, 04:19:40 AM by Lumind »

Lumind

  • Newbie
  • *
  • Thank You
  • -Given: 5
  • -Receive: 0
  • Posts: 14
    • View Profile
Re: Prevent interaction behind the ngui objects
« Reply #5 on: June 21, 2014, 05:45:44 AM »
Remember -- having a UICamera attached to the game camera is all it takes for it to send out NGUI events like OnHover, OnPress, OnClick, etc.
Did it, but after this mouse doesn't interact with non-NGUI game objects
as I understand I need somehow to work with UICamera.fallThrough but how can I set the hovered object to it, if it doesn't respond to Input functions like OnMouseOver?
« Last Edit: June 21, 2014, 06:32:30 AM by Lumind »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Prevent interaction behind the ngui objects
« Reply #6 on: June 21, 2014, 03:56:07 PM »
'fallThrough' is used if no other object intercepted the event. Placing UICamera on your main camera means that all your game objects will be getting events (assuming they have colliders), so 'fallThrough' is less likely to work. For example if you have a Terrain, clicking on the Terrain will then call its OnClick on any script attached to it, rather than going to your fallThrough object.

If you want a copy of all events, whether they were handled or not, use UICamera.genericEventHandler instead.

OnMouse* events are Unity events, not NGUI. NGUI's equivalents are OnHover, OnPress, and OnClick.

Lumind

  • Newbie
  • *
  • Thank You
  • -Given: 5
  • -Receive: 0
  • Posts: 14
    • View Profile
Re: Prevent interaction behind the ngui objects
« Reply #7 on: June 22, 2014, 01:33:53 AM »
I attached UICamera script to main camera. In that script (UICamera) I set event type to "UI"(also tried "World") and event mask to "nothing".
But game objects that have colliders (box, mesh and etc) still don't respond OnClick, OnHover and I think all the rest functions.
Do I miss something?
I test that with
  1. void OnHover () {
  2.                 Debug.Log("Clicked");
  3.         }

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Prevent interaction behind the ngui objects
« Reply #8 on: June 22, 2014, 10:49:18 PM »
OnHover is supposed to have a boolean parameter:
  1. void OnHover (bool isOver)
You need to set the event type to "World" on the main camera, and the event mask to "everything".

"Nothing" means that nothing will be getting your events -- kind of pointless.