PokeHandler.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using SC.XR.Unity.Module_InputSystem;
  2. using SC.XR.Unity.Module_InputSystem.InputDeviceHand;
  3. using UnityEngine;
  4. using UnityEngine.Events;
  5. namespace SC.XR.Unity.Module_InputSystem {
  6. [RequireComponent(typeof(Collider))]
  7. [RequireComponent(typeof(NearInteractionTouchable))]
  8. [AddComponentMenu("SDK/PokeHandler")]
  9. public class PokeHandler : MonoBehaviour, IPokeHandler {
  10. #region Event handlers
  11. /// <summary>
  12. /// A UnityEvent callback containing a TouchEventData payload.
  13. /// </summary>
  14. [System.Serializable]
  15. public class TouchEvent : UnityEvent<TouchPointer,SCPointEventData> { }
  16. [Header("Poke Events")]
  17. public TouchEvent PokeDown;
  18. public TouchEvent PokeUp;
  19. public TouchEvent PokeUpdated;
  20. #endregion
  21. [Header("Poke Audio")]
  22. [SerializeField]
  23. protected SCAudiosConfig.AudioType PokeDownAudio = SCAudiosConfig.AudioType.Null;
  24. [SerializeField]
  25. protected SCAudiosConfig.AudioType PokeUpAudio = SCAudiosConfig.AudioType.Null;
  26. public virtual void OnPokeDown(TouchPointer touchPointer, SCPointEventData eventData) {
  27. AudioSystem.getInstance.PlayAudioOneShot(gameObject, PokeDownAudio);
  28. PokeDown.Invoke(touchPointer,eventData);
  29. }
  30. public virtual void OnPokeUpdated(TouchPointer touchPointer, SCPointEventData eventData) {
  31. PokeUpdated.Invoke(touchPointer,eventData);
  32. }
  33. public virtual void OnPokeUp(TouchPointer touchPointer, SCPointEventData eventData) {
  34. AudioSystem.getInstance.PlayAudioOneShot(gameObject, PokeUpAudio);
  35. PokeUp.Invoke(touchPointer,eventData);
  36. }
  37. }
  38. }