1
1
using Demonixis . Toolbox . XR ;
2
+ using UnityEngine ;
2
3
3
4
namespace TESUnity . Inputs
4
5
{
5
6
public class OculusInput : IInputProvider
6
7
{
8
+ #if OCULUS_SDK
7
9
public delegate bool GetAxisDelegate ( OVRInput . Button virtualMask , OVRInput . Controller controllerMask = OVRInput . Controller . Active ) ;
10
+ #endif
8
11
private bool m_6DOFControllers = false ;
9
12
10
13
public bool TryInitialize ( )
11
14
{
12
15
#if OCULUS_SDK
13
- if ( UnityXRDevice . IsOculus )
14
- {
15
- m_6DOFControllers = UnityXRDevice . GetVRHeadsetModel ( ) == VRHeadsetModel . OculusQuest ;
16
- return true ;
17
- }
18
- #endif
16
+ var model = UnityXRDevice . GetVRHeadsetModel ( ) ;
17
+ m_6DOFControllers = model == VRHeadsetModel . OculusQuest ;
18
+ Debug . Log ( $ "[TESUnity] Oculus Input Initialized. 6DoF:{ m_6DOFControllers } ") ;
19
+ return true ;
20
+ #else
19
21
return false ;
22
+ #endif
20
23
}
21
24
22
25
public float GetAxis ( MWAxis axis )
23
26
{
24
- var result = 0.0f ;
25
27
#if OCULUS_SDK
26
- var leftValue = OVRInput . Get ( OVRInput . Axis2D . PrimaryTouchpad , GetController ( false ) ) ;
27
-
28
- if ( axis == MWAxis . Vertical )
29
- result = leftValue . y ;
30
- else if ( axis == MWAxis . Horizontal )
31
- result = leftValue . x ;
32
- else if ( axis == MWAxis . MouseX )
33
- return OVRInput . Get ( OVRInput . Axis2D . PrimaryTouchpad , GetController ( true ) ) . x ;
28
+ if ( m_6DOFControllers )
29
+ {
30
+ var value = OVRInput . Get ( OVRInput . Axis2D . PrimaryThumbstick , LeftController ) ;
34
31
32
+ if ( axis == MWAxis . Vertical )
33
+ return value . y ;
34
+ else if ( axis == MWAxis . Horizontal )
35
+ return value . x ;
36
+ else if ( axis == MWAxis . MouseX )
37
+ return OVRInput . Get ( OVRInput . Axis2D . PrimaryThumbstick , RightController ) . x ;
38
+ }
39
+ else
40
+ {
41
+ var leftValue = OVRInput . Get ( OVRInput . Axis2D . PrimaryTouchpad , LeftController ) ;
42
+ if ( axis == MWAxis . Vertical )
43
+ return leftValue . y ;
44
+ else if ( axis == MWAxis . Horizontal )
45
+ return leftValue . x ;
46
+ }
35
47
#endif
36
- return result ;
48
+ return 0.0f ;
37
49
}
38
50
39
51
private bool GetButtonState ( GetAxisDelegate inputFunction , MWButton button )
40
52
{
41
53
#if OCULUS_SDK
42
54
if ( button == MWButton . Use )
43
55
{
44
- return inputFunction ( OVRInput . Button . PrimaryIndexTrigger , GetController ( true ) ) ;
56
+ return inputFunction ( OVRInput . Button . PrimaryIndexTrigger , RightController ) ;
45
57
}
46
58
else if ( button == MWButton . Menu )
47
59
{
48
- return inputFunction ( OVRInput . Button . Back , GetController ( false ) ) ||
49
- inputFunction ( OVRInput . Button . Start , GetController ( false ) ) ;
60
+ return inputFunction ( OVRInput . Button . Back , LeftController ) ||
61
+ inputFunction ( OVRInput . Button . Start , LeftController ) ;
50
62
}
51
63
else if ( button == MWButton . Jump )
52
64
{
53
- inputFunction ( OVRInput . Button . One , GetController ( false ) ) ;
65
+ inputFunction ( OVRInput . Button . One , RightController ) ;
54
66
}
55
67
#endif
56
68
return false ;
57
69
}
58
70
59
- public bool GetButton ( MWButton button )
71
+ public bool Get ( MWButton button )
60
72
{
61
73
#if OCULUS_SDK
62
74
return GetButtonState ( OVRInput . Get , button ) ;
@@ -65,7 +77,7 @@ public bool GetButton(MWButton button)
65
77
#endif
66
78
}
67
79
68
- public bool GetButtonDown ( MWButton button )
80
+ public bool GetDown ( MWButton button )
69
81
{
70
82
#if OCULUS_SDK
71
83
return GetButtonState ( OVRInput . GetDown , button ) ;
@@ -74,7 +86,7 @@ public bool GetButtonDown(MWButton button)
74
86
#endif
75
87
}
76
88
77
- public bool GetButtonUp ( MWButton button )
89
+ public bool GetUp ( MWButton button )
78
90
{
79
91
#if OCULUS_SDK
80
92
return GetButtonState ( OVRInput . GetUp , button ) ;
@@ -84,6 +96,10 @@ public bool GetButtonUp(MWButton button)
84
96
}
85
97
86
98
#if OCULUS_SDK
99
+
100
+ public OVRInput . Controller LeftController => m_6DOFControllers ? OVRInput . Controller . LTouch : OVRInput . Controller . Remote ;
101
+ public OVRInput . Controller RightController => m_6DOFControllers ? OVRInput . Controller . RTouch : OVRInput . Controller . Remote ;
102
+
87
103
private OVRInput . Controller GetController ( bool left )
88
104
{
89
105
if ( m_6DOFControllers )
0 commit comments