UI Button: Play sound on button down

This commit is contained in:
Nahuel Rocchetti 2024-07-09 04:28:56 -03:00
parent 790a64d457
commit 561917e60d

View file

@ -17,7 +17,7 @@ namespace OpenTS2.UI
public class UIButtonComponent : UIComponent, IPointerEnterHandler, IPointerExitHandler, IPointerDownHandler, IPointerUpHandler public class UIButtonComponent : UIComponent, IPointerEnterHandler, IPointerExitHandler, IPointerDownHandler, IPointerUpHandler
{ {
/// <summary> /// <summary>
/// Triggers when this button is clicked. Boolean argument specifies whether it was a double click. /// Triggers when this button is clicked.
/// </summary> /// </summary>
public Action OnClick; public Action OnClick;
public bool GreyedOut = false; public bool GreyedOut = false;
@ -87,6 +87,7 @@ namespace OpenTS2.UI
{ {
if (eventData.button != PointerEventData.InputButton.Left && eventData.button != PointerEventData.InputButton.Right) if (eventData.button != PointerEventData.InputButton.Left && eventData.button != PointerEventData.InputButton.Right)
return; return;
AudioManager.Instance.PlayUISound(ClickSound);
_held = true; _held = true;
} }
@ -95,16 +96,8 @@ namespace OpenTS2.UI
if (eventData.button != PointerEventData.InputButton.Left && eventData.button != PointerEventData.InputButton.Right) if (eventData.button != PointerEventData.InputButton.Left && eventData.button != PointerEventData.InputButton.Right)
return; return;
if (_held && _hovering) if (_held && _hovering)
{ OnClick?.Invoke();
Click();
}
_held = false; _held = false;
} }
void Click()
{
AudioManager.Instance.PlayUISound(ClickSound);
OnClick?.Invoke();
}
} }
} }