Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: Matthias on May 02, 2012, 06:52:30 PM

Title: UIButtonSound OnMouseOver plays during OnClick
Post by: Matthias on May 02, 2012, 06:52:30 PM
Is it desired behavior that the UIButtonSound OnMouseOver plays also during OnClick ?
If I have two sounds for both these events assigned to a button, clicking the button plays both of them.

Matthias
Title: Re: UIButtonSound OnMouseOver plays during OnClick
Post by: Matthias on May 02, 2012, 08:08:22 PM
While I am at it, here is a related question. Is there an easy way to add a sound to UIInput that is played on every keyboard keystroke without messing with the NGUI code?
Title: Re: UIButtonSound OnMouseOver plays during OnClick
Post by: ArenMook on May 03, 2012, 08:27:43 AM
Double check your code. UIButtonSound's code for OnHover is:

  1.         void OnHover (bool isOver)
  2.         {
  3.                 if (enabled && ((isOver && trigger == Trigger.OnMouseOver) || (!isOver && trigger == Trigger.OnMouseOut)))
  4.                 {
  5.                         NGUITools.PlaySound(audioClip, volume, pitch);
  6.                 }
  7.         }

OnClick uses a different trigger -- Trigger.OnClick.

For the keystroke sound, create a script that listens to OnInput. Each time it's triggered, play your sound.
Title: Re: UIButtonSound OnMouseOver plays during OnClick
Post by: Matthias on May 03, 2012, 07:00:02 PM
Great thanks. I didn't think of using these callbacks. That should work.
Title: Re: UIButtonSound OnMouseOver plays during OnClick
Post by: MaverickDQ on January 03, 2013, 07:38:23 AM
Sorry to bring this up again.

I an topic you said that the order of events are (and this is still true, at least from my tests):

- OnHover(True)
- OnPress(True)
- OnPress(False)
- OnHover(True)
- OnClick

Now I have separate sounds for OnHover and OnClick, but I get played them both when clicking. Is it because of this:

...
- OnPress(True)
- OnPress(False)
- OnHover(True) sound played
- OnClick sound played
...

How it can be avoided?

Thanks.


Title: Re: UIButtonSound OnMouseOver plays during OnClick
Post by: Vertigus on January 03, 2013, 06:13:02 PM
Sorry to bring this up again.

I an topic you said that the order of events are (and this is still true, at least from my tests):

- OnHover(True)
- OnPress(True)
- OnPress(False)
- OnHover(True)
- OnClick

Now I have separate sounds for OnHover and OnClick, but I get played them both when clicking. Is it because of this:

...
- OnPress(True)
- OnPress(False)
- OnHover(True) sound played
- OnClick sound played
...

How it can be avoided?

Thanks.

I'm having this same issue. I play a sound in OnHover, and a different sound in OnClick. Since the OnHover event happens during a click, both sounds play. What is the recommended way to fix this?
Title: Re: UIButtonSound OnMouseOver plays during OnClick
Post by: Vertigus on January 03, 2013, 06:17:16 PM
This is what I have working currently. It requires saving state.

  1.     void OnHover(bool isOver)
  2.     {
  3.         // ignore if the mouse is already over - this happens since the OnHover event happens when the button is clicked
  4.         if (isOver && isMouseOver) return;
  5.  
  6.         if (isOver)
  7.         {
  8.             isMouseOver = true;
  9.             NGUITools.PlaySound(hoverSound);
  10.         }
  11.         else
  12.         {
  13.             isMouseOver = false;
  14.         }
  15.     }
Title: Re: UIButtonSound OnMouseOver plays during OnClick
Post by: MaverickDQ on January 04, 2013, 04:25:49 AM
Thanks.

I'll have to think on something in between UIButtonSound and Your code. :)