Documentation for the Unity C# Library
Loading...
Searching...
No Matches
InputListener.cs
Go to the documentation of this file.
1using System;
2using System.Collections;
3using System.Collections.Generic;
4using Autohand;
5using Autohand.Demo;
6using PixoVR.Core;
7using PixoVR.Event;
8using UnityEngine;
9
10public class InputListener : MonoBehaviour
11{
12 public event Action<Hand> TriggerPressed;
13 public event Action<Hand> TriggerReleased;
14
15 [SerializeField] private XRHandControllerLink _rightController;
16 [SerializeField] private XRHandControllerLink _leftController;
17
18 private bool _rightTriggerPressed;
19 private bool _leftTriggerPressed;
20
21 public bool IsButtonPressed(Hand hand, CommonButton button)
22 {
23 if (_rightController.hand == hand && _rightController.ButtonPressed(button))
24 {
25 return true;
26 }
28 if (_leftController.hand == hand && _leftController.ButtonPressed(button))
29 {
30 return true;
31 }
32
33 return false;
34 }
35
36 private void Update()
37 {
38 if (_rightController.ButtonPressed(CommonButton.triggerButton) && !_rightTriggerPressed)
39 {
41 TriggerPressed?.Invoke(_rightController.hand);
42 }
43 if (!_rightController.ButtonPressed(CommonButton.triggerButton) && _rightTriggerPressed)
44 {
47 }
48
49 if (_leftController.ButtonPressed(CommonButton.triggerButton) && !_leftTriggerPressed)
50 {
52 TriggerPressed?.Invoke(_leftController.hand);
53 }
54 if (!_leftController.ButtonPressed(CommonButton.triggerButton) && _leftTriggerPressed)
55 {
56 _leftTriggerPressed = false;
57 TriggerReleased?.Invoke(_leftController.hand);
58 }
59 }
60
61 public Vector2 GetAxis(Hand hand)
62 {
63 if (_rightController.hand == hand )
64 {
65 return _rightController.GetAxis2D(Common2DAxis.primaryAxis);
66 }
67
68 if (_leftController.hand == hand)
69 {
70 return _leftController.GetAxis2D(Common2DAxis.primaryAxis);
71 }
72
73 return Vector2.zero;
74 }
75}
bool _leftTriggerPressed
Vector2 GetAxis(Hand hand)
bool _rightTriggerPressed
Action< Hand > TriggerPressed
bool IsButtonPressed(Hand hand, CommonButton button)
XRHandControllerLink _rightController
[SerializeField]
XRHandControllerLink _leftController
[SerializeField]
Action< Hand > TriggerReleased