Author Topic: Keeping Clicking NGUI widget from going through  (Read 10909 times)

Lautaro

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 44
    • View Profile
Keeping Clicking NGUI widget from going through
« on: February 12, 2014, 09:00:53 PM »
Hi!

Do NGUI has a solution to prevent gui clicks to go through and trigger other scripts? My droid goes where i click and when i click an NGUI button the droid moves to that position. :P

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Keeping Clicking NGUI widget from going through
« Reply #1 on: February 13, 2014, 12:17:30 AM »
If you are using NGUI events everywhere, then this is done for you automatically. If you are doing your own Input.Get processing, then you need to do your own logic (UICamera.hoveredObject != null, do your thing).

Lautaro

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 44
    • View Profile
Re: Keeping Clicking NGUI widget from going through
« Reply #2 on: February 13, 2014, 05:26:13 AM »
Ok, so if i get it correctly i can use GUICamera on my main camera so that my gameobjects can use NGUI events. And then i dont need to check what is hit first by the mouse?

Lautaro

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 44
    • View Profile
Re: Keeping Clicking NGUI widget from going through
« Reply #3 on: February 13, 2014, 07:07:52 AM »
I have a main camera and a NGUI camera for the UI. I have attached the UICamera on the main camera to get the NGUI events.
My player droid is drawn with the main camera (but its not underneath the main camera in the hierarchy). The droid has a box collider2D.  The droid script has this on it:

  1.         void OnHover (bool isOver)
  2.                 {
  3.                                 if (isOver) {
  4.                                                 print ("i am hovered");
  5.                                 } else {
  6.                                                 print ("NOT");
  7.                                 }
  8.                 }

But nothing happens when i mouse over it. Should it work with 2dcolliders?

Lautaro

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 44
    • View Profile
Re: Keeping Clicking NGUI widget from going through
« Reply #4 on: February 13, 2014, 07:19:50 AM »
This is what the Main Camera looks like http://i.imgur.com/wJiC1TY.png
I also tried with a 3D capsule with a normal collider but it does not work.

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: Keeping Clicking NGUI widget from going through
« Reply #5 on: February 13, 2014, 06:02:47 PM »
As far as I know, no it doesn't work with 2d colliders as the physics system is fundamentally different and 2d can't collide with 3d. It's fairly straight forward to make your own though - like arenmook wrote, check for if UICamera.hoveredObject == null, then your game can use the touch that can be found in the Input class.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Keeping Clicking NGUI widget from going through
« Reply #6 on: February 14, 2014, 05:27:47 AM »
Yeah it has to be a 3D collider. For 2D you would need to do your own custom input logic (just Raycast2D basically).

Lautaro

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 44
    • View Profile
Re: Keeping Clicking NGUI widget from going through
« Reply #7 on: February 14, 2014, 12:33:38 PM »
Nicki. Thanks for the help, but could you give an example even if it is pseudo code? Im having a hard time getting my head around it.

Lautaro

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 44
    • View Profile
Re: Keeping Clicking NGUI widget from going through
« Reply #8 on: February 14, 2014, 04:12:32 PM »
AreenMook Would you suggest that i use 3D rigidbodies and colliders for my 2D game instead of 2D so that i can use NGUI events and make sure the clicks dont go through or will that be a bad choice for a 2D game?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Keeping Clicking NGUI widget from going through
« Reply #9 on: February 15, 2014, 01:27:26 AM »
Naw... I'll just go ahead and add support for the 2D system raycasts into NGUI 3.5.0.

Edit: Done. It's in the Pro repository now so you will see it when it goes live.
« Last Edit: February 15, 2014, 01:33:46 AM by ArenMook »

Lautaro

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 44
    • View Profile
Re: Keeping Clicking NGUI widget from going through
« Reply #10 on: February 15, 2014, 01:37:33 PM »
Sorry. Does that mean that i can get the update from the Unity Asset Store?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Keeping Clicking NGUI widget from going through
« Reply #11 on: February 16, 2014, 02:15:22 AM »
No, professional repository = Pro licenses. It gets updated more frequently because with full version history and all versions available I can update it more frequently without worrying about impacting / breaking things as much. Asset store will have it once I'm done tweaking it.

Lautaro

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 44
    • View Profile
Re: Keeping Clicking NGUI widget from going through
« Reply #12 on: February 17, 2014, 07:26:11 AM »
Im using the paid NGUI version, but you are talking about the Pro Unity version right? If i use the free Unity i will have to wait untill you release the update in the asset store?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Keeping Clicking NGUI widget from going through
« Reply #13 on: February 17, 2014, 12:01:52 PM »
Professional version of NGUI is not the same thing as the Professional version of Unity. You can have NGUI Pro in Unity free. As I mentioned, NGUI Pro just gives you access to the latest features that may or may not be fully polished. It's a different license.

Lautaro

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 44
    • View Profile
Re: Keeping Clicking NGUI widget from going through
« Reply #14 on: February 21, 2014, 08:36:43 PM »
I just downloaded the latest NGUI . The readme says
"3.5.0
.........
- NEW: UICamera now has a new event type that supports 2D colliders."

I have this script on one gameObject with a normal collider and another with a 2dCollider but the 2Dcollider do not get any events.

  1. void OnHover (bool isOver)
  2.                 {
  3.                                 if (isOver) {
  4.                                                 print ("NGUI FTW");
  5.                                 }
  6.  
  7.                 }
  8.  
  9.                 void OnPress (bool isDown)
  10.                 {
  11.                                 if (isDown) {
  12.                                                 print ("NGUI CLICK!");
  13.                                 }
  14.                 }

The main camera has the UICamera script on it.