Skip to content

Commit 62a1690

Browse files
author
Yannick
committed
Better Quest Support
1 parent c259ed7 commit 62a1690

12 files changed

+81
-62
lines changed

Assets/Prefabs/Player.prefab

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ MonoBehaviour:
6363
m_Name:
6464
m_EditorClassIdentifier:
6565
m_priority: 0
66+
m_TiledMultiResLevel: 2
6667
--- !u!114 &4537370621232559901
6768
MonoBehaviour:
6869
m_ObjectHideFlags: 0

Assets/Scripts/Core/Input/DesktopInput.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ public float GetAxis(MWAxis axis)
2020
return 0.0f;
2121
}
2222

23-
public bool GetButton(MWButton button) => Input.GetButton(button.ToString());
24-
public bool GetButtonDown(MWButton button) => Input.GetButtonDown(button.ToString());
25-
public bool GetButtonUp(MWButton button) => Input.GetButtonUp(button.ToString());
23+
public bool Get(MWButton button) => Input.GetButton(button.ToString());
24+
public bool GetDown(MWButton button) => Input.GetButtonDown(button.ToString());
25+
public bool GetUp(MWButton button) => Input.GetButtonUp(button.ToString());
2626
}
2727
}

Assets/Scripts/Core/Input/IInputProvider.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ public interface IInputProvider
1010
{
1111
bool TryInitialize();
1212
float GetAxis(MWAxis axis);
13-
bool GetButton(MWButton button);
14-
bool GetButtonDown(MWButton button);
15-
bool GetButtonUp(MWButton button);
13+
bool Get(MWButton button);
14+
bool GetDown(MWButton button);
15+
bool GetUp(MWButton button);
1616
}
1717
}

Assets/Scripts/Core/Input/InputManager.cs

+17-19
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
using Demonixis.Toolbox.XR;
2-
using System.Collections.Generic;
1+
using System.Collections.Generic;
32
using UnityEngine;
4-
using UnityEngine.XR;
53

64
namespace TESUnity.Inputs
75
{
@@ -30,6 +28,16 @@ private static void EnsureStarted()
3028
#if WAVEVR_SDK
3129
InputProviders = new IInputProvider[] { new WaveVRInput() };
3230
#else
31+
#if OCULUS_SDK
32+
if (OVRManager.isHmdPresent)
33+
{
34+
var oculusInput = new OculusInput();
35+
oculusInput.TryInitialize();
36+
37+
InputProviders = new IInputProvider[] { oculusInput };
38+
return;
39+
}
40+
#endif
3341
var providers = new IInputProvider[]
3442
{
3543
new TouchInput(),
@@ -40,16 +48,6 @@ private static void EnsureStarted()
4048
var list = new List<IInputProvider>();
4149
var touchEnabled = false;
4250

43-
44-
45-
#if UNITY_ANDROID
46-
if (UnityXRDevice.IsOculus)
47-
{
48-
InputProviders = new IInputProvider[] { new OculusInput() };
49-
return;
50-
}
51-
#endif
52-
5351
foreach (var provider in providers)
5452
{
5553
if (provider.TryInitialize())
@@ -98,9 +96,9 @@ public static bool GetButton(MWButton button)
9896
{
9997
EnsureStarted();
10098

101-
foreach (var provider in InputProviders)
99+
foreach (var input in InputProviders)
102100
{
103-
if (provider.GetButton(button))
101+
if (input.Get(button))
104102
return true;
105103
}
106104

@@ -111,9 +109,9 @@ public static bool GetButtonUp(MWButton button)
111109
{
112110
EnsureStarted();
113111

114-
foreach (var provider in InputProviders)
112+
foreach (var input in InputProviders)
115113
{
116-
if (provider.GetButtonUp(button))
114+
if (input.GetUp(button))
117115
return true;
118116
}
119117

@@ -124,9 +122,9 @@ public static bool GetButtonDown(MWButton button)
124122
{
125123
EnsureStarted();
126124

127-
foreach (var provider in InputProviders)
125+
foreach (var input in InputProviders)
128126
{
129-
if (provider.GetButtonDown(button))
127+
if (input.GetDown(button))
130128
return true;
131129
}
132130

Assets/Scripts/Core/Input/OculusInput.cs

+39-23
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,74 @@
11
using Demonixis.Toolbox.XR;
2+
using UnityEngine;
23

34
namespace TESUnity.Inputs
45
{
56
public class OculusInput : IInputProvider
67
{
8+
#if OCULUS_SDK
79
public delegate bool GetAxisDelegate(OVRInput.Button virtualMask, OVRInput.Controller controllerMask = OVRInput.Controller.Active);
10+
#endif
811
private bool m_6DOFControllers = false;
912

1013
public bool TryInitialize()
1114
{
1215
#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
1921
return false;
22+
#endif
2023
}
2124

2225
public float GetAxis(MWAxis axis)
2326
{
24-
var result = 0.0f;
2527
#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);
3431

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+
}
3547
#endif
36-
return result;
48+
return 0.0f;
3749
}
3850

3951
private bool GetButtonState(GetAxisDelegate inputFunction, MWButton button)
4052
{
4153
#if OCULUS_SDK
4254
if (button == MWButton.Use)
4355
{
44-
return inputFunction(OVRInput.Button.PrimaryIndexTrigger, GetController(true));
56+
return inputFunction(OVRInput.Button.PrimaryIndexTrigger, RightController);
4557
}
4658
else if (button == MWButton.Menu)
4759
{
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);
5062
}
5163
else if (button == MWButton.Jump)
5264
{
53-
inputFunction(OVRInput.Button.One, GetController(false));
65+
inputFunction(OVRInput.Button.One, RightController);
5466
}
5567
#endif
5668
return false;
5769
}
5870

59-
public bool GetButton(MWButton button)
71+
public bool Get(MWButton button)
6072
{
6173
#if OCULUS_SDK
6274
return GetButtonState(OVRInput.Get, button);
@@ -65,7 +77,7 @@ public bool GetButton(MWButton button)
6577
#endif
6678
}
6779

68-
public bool GetButtonDown(MWButton button)
80+
public bool GetDown(MWButton button)
6981
{
7082
#if OCULUS_SDK
7183
return GetButtonState(OVRInput.GetDown, button);
@@ -74,7 +86,7 @@ public bool GetButtonDown(MWButton button)
7486
#endif
7587
}
7688

77-
public bool GetButtonUp(MWButton button)
89+
public bool GetUp(MWButton button)
7890
{
7991
#if OCULUS_SDK
8092
return GetButtonState(OVRInput.GetUp, button);
@@ -84,6 +96,10 @@ public bool GetButtonUp(MWButton button)
8496
}
8597

8698
#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+
87103
private OVRInput.Controller GetController(bool left)
88104
{
89105
if (m_6DOFControllers)

Assets/Scripts/Core/Input/TouchInput.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -55,23 +55,23 @@ public float GetAxis(MWAxis axis)
5555
return result;
5656
}
5757

58-
public bool GetButton(MWButton button)
58+
public bool Get(MWButton button)
5959
{
6060
if (button == MWButton.Use)
6161
return Input.touchCount > 0 && Input.touches[0].phase == TouchPhase.Moved || Input.touches[0].phase == TouchPhase.Stationary;
6262

6363
return false;
6464
}
6565

66-
public bool GetButtonDown(MWButton button)
66+
public bool GetDown(MWButton button)
6767
{
6868
if (button == MWButton.Use)
6969
return Input.touchCount > 0 && Input.touches[0].phase == TouchPhase.Began;
7070

7171
return false;
7272
}
7373

74-
public bool GetButtonUp(MWButton button)
74+
public bool GetUp(MWButton button)
7575
{
7676
if (button == MWButton.Use)
7777
return Input.touchCount > 0 && Input.touches[0].phase == TouchPhase.Ended;

Assets/Scripts/Core/Input/UnityXRInput.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public float GetAxis(MWAxis axis)
4040
return result;
4141
}
4242

43-
public bool GetButton(MWButton button)
43+
public bool Get(MWButton button)
4444
{
4545
if (m_XRMapping == null)
4646
InitializeMapping();
@@ -54,7 +54,7 @@ public bool GetButton(MWButton button)
5454
return false;
5555
}
5656

57-
public bool GetButtonDown(MWButton button)
57+
public bool GetDown(MWButton button)
5858
{
5959
if (m_XRMapping == null)
6060
InitializeMapping();
@@ -68,7 +68,7 @@ public bool GetButtonDown(MWButton button)
6868
return false;
6969
}
7070

71-
public bool GetButtonUp(MWButton button)
71+
public bool GetUp(MWButton button)
7272
{
7373
if (m_XRMapping == null)
7474
InitializeMapping();

Assets/Scripts/Core/Input/WaveVRInput.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public float GetAxis(MWAxis axis)
3030
return 0.0f;
3131
}
3232

33-
public bool GetButton(MWButton button)
33+
public bool Get(MWButton button)
3434
{
3535
#if WAVEVR_SDK
3636
if (button == MWButton.Use)
@@ -47,7 +47,7 @@ public bool GetButton(MWButton button)
4747
return false;
4848
}
4949

50-
public bool GetButtonDown(MWButton button)
50+
public bool GetDown(MWButton button)
5151
{
5252
#if WAVEVR_SDK
5353
if (button == MWButton.Use)
@@ -64,7 +64,7 @@ public bool GetButtonDown(MWButton button)
6464
return false;
6565
}
6666

67-
public bool GetButtonUp(MWButton button)
67+
public bool GetUp(MWButton button)
6868
{
6969
#if WAVEVR_SDK
7070
if (button == MWButton.Use)

Assets/Scripts/XR/UnityXRDevice.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,14 @@ public override void SetActive(bool active)
8181
OVRManager.tiledMultiResLevel = m_TiledMultiResLevel;
8282
}
8383
#endif
84+
85+
Debug.Log($"[GSPVR] IsOculus: {IsOculus}");
8486
}
8587

8688
public override void SetTrackingSpaceType(TrackingSpaceType type, Transform headTransform, float height)
8789
{
8890
#if UNITY_ANDROID
89-
if (XRManager.Instance.ForceSeatedOnMobile)
91+
if (XRManager.Instance.ForceSeatedOnMobile && GetVRHeadsetModel() == VRHeadsetModel.OculusQuest)
9092
type = TrackingSpaceType.Stationary;
9193
#endif
9294
XRDevice.SetTrackingSpaceType(type);

Packages/manifest.json

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"dependencies": {
3+
"com.unity.mobile.android-logcat": "0.2.7-preview",
34
"com.unity.package-manager-ui": "2.1.2",
45
"com.unity.postprocessing": "2.2.0",
56
"com.unity.xr.oculus.android": "1.36.0",

ProjectSettings/ProjectSettings.asset

+1-1
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ PlayerSettings:
446446
m_BuildTargetEnableVuforiaSettings: []
447447
openGLRequireES31: 0
448448
openGLRequireES31AEP: 0
449-
openGLRequireES32: 0
449+
openGLRequireES32: 1
450450
m_TemplateCustomTags: {}
451451
mobileMTRendering:
452452
Android: 1

ProjectSettings/QualitySettings.asset

+4-3
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ QualitySettings:
5656
skinWeights: 1
5757
textureQuality: 1
5858
anisotropicTextures: 0
59-
antiAliasing: 2
59+
antiAliasing: 4
6060
softParticles: 0
6161
softVegetation: 0
6262
realtimeReflectionProbes: 0
@@ -217,5 +217,6 @@ QualitySettings:
217217
resolutionScalingFixedDPIFactor: 1
218218
excludedTargetPlatforms: []
219219
m_PerPlatformDefaultQuality:
220-
Android: 0
221-
Standalone: 0
220+
Android: 1
221+
Standalone: 4
222+
Windows Store Apps: 4

0 commit comments

Comments
 (0)