Author Topic: OnMouseUp interfering with OnClick  (Read 9368 times)

Vunpac

  • Guest
OnMouseUp interfering with OnClick
« on: March 23, 2013, 12:32:06 AM »
alright so basically the issue here is I have a grid of nodes and you can select one (uses OnMouseUp) and clicking anywhere unselects it. The problem here is that OnMouseUp is called even on NGUI objects.

Is there a way to have OnClick ignore OnMouseUp? or maybe have NGUI widgets block unity ray events? That way the underlying nodes would never get hit with a ray causing the OnMouseUp to activate.

Thanks.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: OnMouseUp interfering with OnClick
« Reply #1 on: March 23, 2013, 01:42:03 PM »
OnMouseUp is a Unity event that will be deprecated in a future release of Unity. You should not rely on it. Use NGUI's OnPress(false) instead.

Vunpac

  • Guest
Re: OnMouseUp interfering with OnClick
« Reply #2 on: March 23, 2013, 02:20:35 PM »
To do that I just need to add UICamera to my main camera then replace OnMouseUp with OnPress(false) and should have the same results with proper workings?

I won't have time to check today. But I thank you for your reply and I eagerly await the results once implemented.

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: OnMouseUp interfering with OnClick
« Reply #3 on: March 23, 2013, 08:33:21 PM »
To do that I just need to add UICamera to my main camera then replace OnMouseUp with OnPress(false) and should have the same results with proper workings?

Yes.

void OnPress(bool pressed)
{
if (pressed == false)
{
//Same as OnMouseUp
}
}

Cawas

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 11
  • fucking programmer
    • View Profile
Re: OnMouseUp interfering with OnClick
« Reply #4 on: September 19, 2013, 10:42:54 AM »
OnPress(false) is not same as OnMouseUp.

If I press mouse button or tap on screen outside of the collider then move into inside the collider, OnMouseUp will trigger while OnPress(false) will not.

So, other than making our own even controller, is there any way within NGUI to get a true OnMouseUp?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: OnMouseUp interfering with OnClick
« Reply #5 on: September 19, 2013, 04:05:07 PM »
It will trigger if "sticky press"  is turned off on your UICamera.

Cawas

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 11
  • fucking programmer
    • View Profile
Re: OnMouseUp interfering with OnClick
« Reply #6 on: September 19, 2013, 04:07:10 PM »
It will trigger if "sticky press"  is turned off on your UICamera.

Nice! But then I suppose we can't have both... Can we?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: OnMouseUp interfering with OnClick
« Reply #7 on: September 19, 2013, 04:09:28 PM »
Both what? Try it.

Cawas

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 11
  • fucking programmer
    • View Profile
Re: OnMouseUp interfering with OnClick
« Reply #8 on: September 19, 2013, 04:12:48 PM »
Yes, I just tried it. It works! But I was then instantly wondering... If I want some buttons with sticky and others without it (which I'm not even sure if I do need). I suppose we can make 2 cameras... Still, seems like having a OnPressUp would make more sense, but I'm not sure. Thus, I asked "can we have both". :-)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: OnMouseUp interfering with OnClick
« Reply #9 on: September 19, 2013, 04:13:35 PM »
No you can't. It's a per-camera setting.

Cawas

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 11
  • fucking programmer
    • View Profile
Re: OnMouseUp interfering with OnClick
« Reply #10 on: September 19, 2013, 04:17:34 PM »
Thinking about the code produced, I guess it makes more sense having them as separated events (OnPressUp, OnPressDown, OnPressUpAsButton), rather than sensitive to a setting. I think it'd make it more evident: when you read it you know what it is. As it is now you'd have to know first if the camera is sticky or not.

In any case, thanks! That's quite good. ;D

NGUI is friggin' awesome. I don't say it out loud enough.
« Last Edit: November 18, 2013, 07:49:00 AM by Cawas »