Author Topic: NGUI 3.0 and OnPress Function question  (Read 9457 times)

kaz2057

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 26
    • View Profile
NGUI 3.0 and OnPress Function question
« on: October 07, 2013, 03:44:31 AM »
Dear Aren,

I always use NGUI <= 2.70 and in my next project I want to upgrade to > 3.0.

Following this your thread http://www.tasharen.com/forum/index.php?topic=3484.0 I read that OnPress (bool isPressed) function is "obsolete" and repleace with OnPressEvent|().

Next I will go to read your script interaction and I found however OnPress function ... (like OnClick, etc...)
So maybe I don't understand if OnPress is deprecated or not ...

Thanks for for time :)


ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NGUI 3.0 and OnPress Function question
« Reply #1 on: October 08, 2013, 03:01:42 AM »
Oof. In that post I talk about the upcoming Unity's GUI, not NGUI 3.0's features. It was more of me asking if people want 3.0.

NGUI 3.0 still uses OnPress (bool isPressed).

OnPressEvent() is for uGUI.

mishaps

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 65
    • View Profile
Re: NGUI 3.0 and OnPress Function question
« Reply #2 on: October 17, 2013, 07:17:08 PM »
Hi Aren, how can I subscribe to onPress events from buttons in 3.0.2? OnClick works fine for when a finger is lifted from the screen but I need to listen for when it touches the screen  :'(

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NGUI 3.0 and OnPress Function question
« Reply #3 on: October 18, 2013, 06:02:42 PM »
Use OnPress instead of OnClick. You're answering your own question.

mishaps

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 65
    • View Profile
Re: NGUI 3.0 and OnPress Function question
« Reply #4 on: October 18, 2013, 09:10:32 PM »
Doesn't work, perhaps I am doing something else wrong? I can get press/release by using two UIButtonMessage components but would be great to subscribe to the events instead.

in OnEnable() using "button.OnPress += OnBtnPress;" give this error:
error CS1656: Cannot assign to `OnPress' because it is a `method group'

or instead using "EventDelegate.Add (button.OnPress, OnBtnPress);" gives these error:
error CS1502: The best overloaded method match for `EventDelegate.Add(System.Collections.Generic.List<EventDelegate>, EventDelegate)' has some invalid arguments
error CS1503: Argument `#1' cannot convert `method group' expression to type `System.Collections.Generic.List<EventDelegate>'


ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NGUI 3.0 and OnPress Function question
« Reply #5 on: October 19, 2013, 04:46:29 PM »
Er, what? OnPress is a notification, not an event. Notifications are sent to game objects by the UICamera -- OnPress, OnClick, OnHover, OnTooltip, etc -- are all notifications. You implement their handling by having a script that has the appropriate function, such as:
  1. void OnPress (bool isPressed) { Debug.Log("Pressed? " + isPressed); }
If you are trying to subscribe to remote notifications, you need to use UIEventListener. This will cause a delegate to be called as a result of a notification coming in.

It's the same thing with the OnClick EventDelegate on the Button. When the button receives a click notification, it will trigger the event sent on the button. It's there for convenience.

It's very important to understand the difference.

mishaps

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 65
    • View Profile
Re: NGUI 3.0 and OnPress Function question
« Reply #6 on: October 19, 2013, 09:22:13 PM »
Personally I always liked the idea of delegate-events it just seemed strange I could subscribe to a button for finger-releasing (via onClick) but not finger-touching (aka down-state) even tho something called OnPress was there. I really like the down/release etc states UIMessage has it feels really intuitive.

EDIT An option on UIButtons in the inspector to select OnPress instead of OnClick would be very cool  ;D

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NGUI 3.0 and OnPress Function question
« Reply #7 on: October 20, 2013, 04:01:26 PM »
OnClick stuff is there for convenience.