revival/game/Assets/Scripts/UI/NoisyUIElement.cs

75 lines
1.8 KiB
C#
Raw Normal View History

2021-03-25 13:19:44 +01:00
using System.Collections;
using System.Collections.Generic;
using FMODUnity;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Serialization;
using UnityEngine.UI;
public class NoisyUIElement : MonoBehaviour, ISelectHandler, ISubmitHandler, IPointerClickHandler, IMoveHandler
{
[SerializeField]
[EventRef]
private string ClickSfx;
[SerializeField]
[EventRef]
private string BloopSfx;
[SerializeField]
private bool _clickHorizontal;
[SerializeField]
private bool _clickVertical;
private void PlayClickSfx()
{
if ( !string.IsNullOrEmpty( ClickSfx ) )
{
RuntimeManager.PlayOneShot( ClickSfx );
}
}
private void PlayBloopSfx()
{
if ( !string.IsNullOrEmpty( BloopSfx ) )
{
RuntimeManager.PlayOneShot( BloopSfx );
}
}
public void OnSelect( BaseEventData eventData )
=> PlayClickSfx();
public void OnSubmit( BaseEventData eventData )
=> PlayBloopSfx();
public void OnPointerClick( PointerEventData eventData )
=> PlayBloopSfx();
public void OnDrag( PointerEventData eventData )
=> PlayBloopSfx();
public void OnMove( AxisEventData eventData )
{
switch ( eventData.moveDir )
{
case MoveDirection.Left:
case MoveDirection.Right:
if ( _clickHorizontal )
{
PlayClickSfx();
}
break;
case MoveDirection.Up:
case MoveDirection.Down:
if ( _clickVertical )
{
PlayClickSfx();
}
break;
}
}
}