Author Topic: UIButton/Message double call?  (Read 4719 times)

Q

  • Guest
UIButton/Message double call?
« on: October 03, 2012, 06:21:57 PM »
Hello all,

Any suggestions or help would be appreciated. I'm coding in Javascript.

1. Can I have a single UIButton responsible for two types of input? In other words, can I have two UIButtonMessage scripts on a single button and have OnClick or OnPress on one, and OnDoubleClick for the other. Two different actions, using the same button. Test reveal that I cannot do this with NGUI out of the box, but sense tells me otherwise.
2. Other than using the InvokeRepeating/CancelInvoke type coding, is there a simple edit to the UIButtonMessage code that I can make to cause "OnPress" to send a repeating call to the function I specify? Again, to be clear, hold the button down and the laser (or whatever) function fires repeatedly.

Thanks for any scraps!

Q
« Last Edit: October 03, 2012, 07:25:56 PM by Q »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIButton/Message double call?
« Reply #1 on: October 03, 2012, 08:13:53 PM »
1. Of course you can. All events are sent to all scripts on the collider's game object, not just one script.

2. Consider simply saving the state in OnPress, then check it in the Update function. If the state is 'true', do your laser shooting logic. If you're asking if there is a built-in repeating event -- no, there isn't.

Q

  • Guest
Re: UIButton/Message double call?
« Reply #2 on: October 03, 2012, 11:22:21 PM »
1. Test are showing that this is not the case. I am trying the button with multiple UIButtonTweens and/or UIBottonMessages. I have tried OnDoubleClick with OnPress, as well as OnClick with OnPress thinking that they might be the most disparate cases. In both cases the touch event is being calculated for both cases. (ie. When I use OnDoubleClick, OnPress is triggering and when separately I am pressing longer for an OnPress, I am getting an OnDoubleClick trigger if I do the OnPress multiple times with some time in between.)

2. Actually, the function call is still only happening once as you are aware. As you say though, I could trigger an OnEvent, but once On, how to turn it off? No way to simply put in an OnRepeating type call so that for every Update that the button is being pressed, the function is being called? Obviously would be a boolean option. Just a thought.

Love NGUI thus far. Just asking about functionality that seems challenged or missing.

Q

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIButton/Message double call?
« Reply #3 on: October 04, 2012, 10:24:51 AM »
2. I never suggested using events. I said have a local boolean variable on your class such as "bool mIsPressed", and set it in OnPress like so:
  1. void OnPress (bool isPressed) { mIsPressed = isPressed; }
Then in the update you can do this:
  1. void FixedUpdate () { if (mIsPressed) { <do stuff> } }

1. The way I understood your original post's question is "is it possible to have one button have an event get picked up by multiple scripts?" -- to which the answer is yes. You can have as many scripts handling "OnClick" or any other event as you want on the button.

OnPress is the type of an event that always gets triggered when a touch / mouse button press occurs. OnDoubleClick is an event that occurs when you click twice in a short amount of time. These events don't cancel each other out, so for a double click the sequence of events that get sent out is:

OnPress(true)
OnPress(false)
OnClick()

OnPress(true)
OnPress(false)
OnClick()
OnDoubleClick()

Q

  • Guest
Re: UIButton/Message double call?
« Reply #4 on: October 04, 2012, 11:14:21 AM »
2. Ah, right. Perfect, thanks for that nudge.

1. Your later description was my question's actual intent, so that helps out greatly.

Thanks for clarifying in both cases!

Q