Assignment for RMIT Mixed Reality in 2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

78 lines
2.0 KiB

  1. //======= Copyright (c) Valve Corporation, All rights reserved. ===============
  2. //
  3. // Purpose: Sends simple controller button events to UnityEvents
  4. //
  5. //=============================================================================
  6. using UnityEngine;
  7. using UnityEngine.Events;
  8. namespace Valve.VR.InteractionSystem
  9. {
  10. //-------------------------------------------------------------------------
  11. [RequireComponent( typeof( Interactable ) )]
  12. public class InteractableButtonEvents : MonoBehaviour
  13. {
  14. public UnityEvent onTriggerDown;
  15. public UnityEvent onTriggerUp;
  16. public UnityEvent onGripDown;
  17. public UnityEvent onGripUp;
  18. public UnityEvent onTouchpadDown;
  19. public UnityEvent onTouchpadUp;
  20. public UnityEvent onTouchpadTouch;
  21. public UnityEvent onTouchpadRelease;
  22. //-------------------------------------------------
  23. void Update()
  24. {
  25. for ( int i = 0; i < Player.instance.handCount; i++ )
  26. {
  27. Hand hand = Player.instance.GetHand( i );
  28. if ( hand.controller != null )
  29. {
  30. if ( hand.controller.GetPressDown( Valve.VR.EVRButtonId.k_EButton_SteamVR_Trigger ) )
  31. {
  32. onTriggerDown.Invoke();
  33. }
  34. if ( hand.controller.GetPressUp( Valve.VR.EVRButtonId.k_EButton_SteamVR_Trigger ) )
  35. {
  36. onTriggerUp.Invoke();
  37. }
  38. if ( hand.controller.GetPressDown( Valve.VR.EVRButtonId.k_EButton_Grip ) )
  39. {
  40. onGripDown.Invoke();
  41. }
  42. if ( hand.controller.GetPressUp( Valve.VR.EVRButtonId.k_EButton_Grip ) )
  43. {
  44. onGripUp.Invoke();
  45. }
  46. if ( hand.controller.GetPressDown( Valve.VR.EVRButtonId.k_EButton_SteamVR_Touchpad ) )
  47. {
  48. onTouchpadDown.Invoke();
  49. }
  50. if ( hand.controller.GetPressUp( Valve.VR.EVRButtonId.k_EButton_SteamVR_Touchpad ) )
  51. {
  52. onTouchpadUp.Invoke();
  53. }
  54. if ( hand.controller.GetTouchDown( Valve.VR.EVRButtonId.k_EButton_SteamVR_Touchpad ) )
  55. {
  56. onTouchpadTouch.Invoke();
  57. }
  58. if ( hand.controller.GetTouchUp( Valve.VR.EVRButtonId.k_EButton_SteamVR_Touchpad ) )
  59. {
  60. onTouchpadRelease.Invoke();
  61. }
  62. }
  63. }
  64. }
  65. }
  66. }