Author Topic: UIButtonSound OnMouseOver plays during OnClick  (Read 5910 times)

Matthias

  • Guest
UIButtonSound OnMouseOver plays during OnClick
« 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

Matthias

  • Guest
Re: UIButtonSound OnMouseOver plays during OnClick
« Reply #1 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?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIButtonSound OnMouseOver plays during OnClick
« Reply #2 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.

Matthias

  • Guest
Re: UIButtonSound OnMouseOver plays during OnClick
« Reply #3 on: May 03, 2012, 07:00:02 PM »
Great thanks. I didn't think of using these callbacks. That should work.

MaverickDQ

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 10
    • View Profile
Re: UIButtonSound OnMouseOver plays during OnClick
« Reply #4 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.



Vertigus

  • Guest
Re: UIButtonSound OnMouseOver plays during OnClick
« Reply #5 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?

Vertigus

  • Guest
Re: UIButtonSound OnMouseOver plays during OnClick
« Reply #6 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.     }

MaverickDQ

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 10
    • View Profile
Re: UIButtonSound OnMouseOver plays during OnClick
« Reply #7 on: January 04, 2013, 04:25:49 AM »
Thanks.

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