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