Skip to content

Commit c259ed7

Browse files
author
Yannick
committed
Updated the Oculus SDK. Added Oculus Quest initial support
1 parent 7514008 commit c259ed7

File tree

243 files changed

+23742
-1469
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

243 files changed

+23742
-1469
lines changed

Assets/Scripts/Core/Input/OculusInput.cs

+35-29
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
11
using Demonixis.Toolbox.XR;
2-
using UnityEngine.XR;
32

43
namespace TESUnity.Inputs
54
{
65
public class OculusInput : IInputProvider
76
{
8-
private bool m_LeftHandEnabled = false;
7+
public delegate bool GetAxisDelegate(OVRInput.Button virtualMask, OVRInput.Controller controllerMask = OVRInput.Controller.Active);
98
private bool m_6DOFControllers = false;
109

1110
public bool TryInitialize()
1211
{
1312
#if OCULUS_SDK
1413
if (UnityXRDevice.IsOculus)
1514
{
16-
var hand = OVRInput.GetDominantHand();
17-
m_LeftHandEnabled = hand == OVRInput.Handedness.LeftHanded;
18-
m_6DOFControllers = OVRInput.IsControllerConnected(OVRInput.Controller.LTouch) || OVRInput.IsControllerConnected(OVRInput.Controller.RTouch);
15+
m_6DOFControllers = UnityXRDevice.GetVRHeadsetModel() == VRHeadsetModel.OculusQuest;
1916
return true;
2017
}
2118
#endif
@@ -26,55 +23,64 @@ public float GetAxis(MWAxis axis)
2623
{
2724
var result = 0.0f;
2825
#if OCULUS_SDK
29-
var value = OVRInput.Get(OVRInput.Axis2D.PrimaryTouchpad, GetController(false));
26+
var leftValue = OVRInput.Get(OVRInput.Axis2D.PrimaryTouchpad, GetController(false));
3027

3128
if (axis == MWAxis.Vertical)
32-
result = value.y;
33-
if (axis == MWAxis.Vertical)
34-
result = value.x;
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;
34+
3535
#endif
3636
return result;
3737
}
3838

39-
public bool GetButton(MWButton button)
39+
private bool GetButtonState(GetAxisDelegate inputFunction, MWButton button)
4040
{
4141
#if OCULUS_SDK
4242
if (button == MWButton.Use)
43-
return OVRInput.Get(OVRInput.Button.PrimaryIndexTrigger, GetController(false));
43+
{
44+
return inputFunction(OVRInput.Button.PrimaryIndexTrigger, GetController(true));
45+
}
4446
else if (button == MWButton.Menu)
45-
return OVRInput.Get(OVRInput.Button.Back, GetController(false));
47+
{
48+
return inputFunction(OVRInput.Button.Back, GetController(false)) ||
49+
inputFunction(OVRInput.Button.Start, GetController(false));
50+
}
4651
else if (button == MWButton.Jump)
47-
OVRInput.Get(OVRInput.Button.One, GetController(false));
52+
{
53+
inputFunction(OVRInput.Button.One, GetController(false));
54+
}
4855
#endif
4956
return false;
5057
}
5158

52-
public bool GetButtonDown(MWButton button)
59+
public bool GetButton(MWButton button)
5360
{
5461
#if OCULUS_SDK
55-
if (button == MWButton.Use)
56-
return OVRInput.Get(OVRInput.Button.PrimaryIndexTrigger, GetController(false));
57-
else if (button == MWButton.Menu)
58-
return OVRInput.Get(OVRInput.Button.Back, GetController(false));
59-
else if (button == MWButton.Jump)
60-
OVRInput.GetDown(OVRInput.Button.One, GetController(false));
62+
return GetButtonState(OVRInput.Get, button);
63+
#else
64+
return false;
6165
#endif
66+
}
67+
68+
public bool GetButtonDown(MWButton button)
69+
{
70+
#if OCULUS_SDK
71+
return GetButtonState(OVRInput.GetDown, button);
72+
#else
6273
return false;
74+
#endif
6375
}
6476

6577
public bool GetButtonUp(MWButton button)
6678
{
6779
#if OCULUS_SDK
68-
if (button == MWButton.Use)
69-
return OVRInput.Get(OVRInput.Button.PrimaryIndexTrigger, GetController(false));
70-
else if (button == MWButton.Menu)
71-
return OVRInput.Get(OVRInput.Button.Back, GetController(false));
72-
else if (button == MWButton.Teleport)
73-
OVRInput.GetUp(OVRInput.Button.PrimaryThumbstickLeft, GetController(false));
74-
else if (button == MWButton.Jump)
75-
OVRInput.GetUp(OVRInput.Button.One, GetController(false));
76-
#endif
80+
return GetButtonState(OVRInput.GetUp, button);
81+
#else
7782
return false;
83+
#endif
7884
}
7985

8086
#if OCULUS_SDK

Assets/Scripts/Core/Input/UnityXRInput.cs

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

64
namespace TESUnity.Inputs
75
{

Assets/Scripts/TES/Components/VR/PlayerXR.cs

+1-3
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,7 @@ private IEnumerator Start()
5656

5757
// Setup RoomScale/Sitted mode.
5858
var trackingSpaceType = m_RoomScale ? TrackingSpaceType.RoomScale : TrackingSpaceType.Stationary;
59-
XRDevice.SetTrackingSpaceType(trackingSpaceType);
60-
if (trackingSpaceType == TrackingSpaceType.RoomScale)
61-
transform.GetChild(0).localPosition = Vector3.zero;
59+
XRManager.Instance.TrackingSpaceType = trackingSpaceType;
6260

6361
var uiManager = FindObjectOfType<UIManager>();
6462

Assets/Scripts/TES/GameSettingsOverride.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ private void Awake()
7878
settings.WaterTransparency = WaterTransparency;
7979
settings.KinematicRigidbody = KinematicRigidbodies;
8080
settings.CheckSettings();
81-
}
8281
#endif
82+
}
8383
}
8484
}

Assets/Scripts/XR/UnityXRDevice.cs

+35
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@
55

66
namespace Demonixis.Toolbox.XR
77
{
8+
public enum VRHeadsetModel
9+
{
10+
None = 0, OculusRift,
11+
OculusQuest, OculusGo,
12+
Vive, WindowsMR,
13+
PSVR, Other
14+
}
15+
816
/// <summary>
917
/// The UnityVRDevice is an abstract device that uses the UnityEngine.VR implementation.
1018
/// </summary>
@@ -32,6 +40,33 @@ public override float RenderScale
3240

3341
public static bool IsOculus => XRSettings.loadedDeviceName.ToLower() == "oculus";
3442

43+
public static VRHeadsetModel GetVRHeadsetModel()
44+
{
45+
if (!XRSettings.enabled)
46+
return VRHeadsetModel.None;
47+
48+
#if UNITY_PS4
49+
return VRHeadsetModel.PSVR;
50+
#endif
51+
52+
var device = XRDevice.model.ToLower();
53+
54+
if (device.Contains("oculus"))
55+
{
56+
#if UNITY_ANDROID
57+
return device.Contains("quest") ? VRHeadsetModel.OculusQuest : VRHeadsetModel.OculusGo;
58+
#else
59+
return return VRHeadsetModel.OculusRift;
60+
#endif
61+
}
62+
else if (device.Contains("vive"))
63+
return VRHeadsetModel.Vive;
64+
else if (device.Contains("windows"))
65+
return VRHeadsetModel.WindowsMR;
66+
67+
return VRHeadsetModel.Other;
68+
}
69+
3570
public override void Recenter() => InputTracking.Recenter();
3671

3772
public override void SetActive(bool active)

Assets/Vendors/Oculus/VR/Editor/AndroidManifest.OVRSubmission.xml

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?xml version="1.0" encoding="utf-8" standalone="no"?>
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
33
android:installLocation="auto">
4+
<!-- Request the headset DoF mode -->
45
<application
56
android:allowBackup="false">
67
<activity
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
/************************************************************************************
2+
3+
Copyright : Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved.
4+
5+
Licensed under the Oculus SDK License Version 3.4.1 (the "License");
6+
you may not use the Oculus SDK except in compliance with the License,
7+
which is provided at the time of installation or download, or which
8+
otherwise accompanies this software in either electronic or hard copy form.
9+
10+
You may obtain a copy of the License at
11+
12+
https://developer.oculus.com/licenses/sdk-3.4.1
13+
14+
Unless required by applicable law or agreed to in writing, the Oculus SDK
15+
distributed under the License is distributed on an "AS IS" BASIS,
16+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
See the License for the specific language governing permissions and
18+
limitations under the License.
19+
20+
************************************************************************************/
21+
22+
using System;
23+
using System.Collections;
24+
using System.Collections.Generic;
25+
using System.Diagnostics;
26+
using System.IO;
27+
using System.Text;
28+
using System.Threading;
29+
using UnityEngine;
30+
31+
using Debug = UnityEngine.Debug;
32+
33+
public class OVRADBTool
34+
{
35+
public bool isReady;
36+
37+
public string androidSdkRoot;
38+
public string androidPlatformToolsPath;
39+
public string adbPath;
40+
41+
public OVRADBTool(string androidSdkRoot)
42+
{
43+
if (!String.IsNullOrEmpty(androidSdkRoot))
44+
{
45+
this.androidSdkRoot = androidSdkRoot;
46+
}
47+
else
48+
{
49+
this.androidSdkRoot = String.Empty;
50+
}
51+
52+
if (this.androidSdkRoot.EndsWith("\\") || this.androidSdkRoot.EndsWith("/"))
53+
{
54+
this.androidSdkRoot = this.androidSdkRoot.Remove(this.androidSdkRoot.Length - 1);
55+
}
56+
androidPlatformToolsPath = Path.Combine(this.androidSdkRoot, "platform-tools");
57+
adbPath = Path.Combine(androidPlatformToolsPath, "adb.exe");
58+
isReady = File.Exists(adbPath);
59+
}
60+
61+
public static bool IsAndroidSdkRootValid(string androidSdkRoot)
62+
{
63+
OVRADBTool tool = new OVRADBTool(androidSdkRoot);
64+
return tool.isReady;
65+
}
66+
67+
public delegate void WaitingProcessToExitCallback();
68+
69+
public int StartServer(WaitingProcessToExitCallback waitingProcessToExitCallback)
70+
{
71+
string outputString;
72+
string errorString;
73+
74+
int exitCode = RunCommand(new string[] { "start-server" }, waitingProcessToExitCallback, out outputString, out errorString);
75+
return exitCode;
76+
}
77+
78+
public int KillServer(WaitingProcessToExitCallback waitingProcessToExitCallback)
79+
{
80+
string outputString;
81+
string errorString;
82+
83+
int exitCode = RunCommand(new string[] { "kill-server" }, waitingProcessToExitCallback, out outputString, out errorString);
84+
return exitCode;
85+
}
86+
87+
public int ForwardPort(int port, WaitingProcessToExitCallback waitingProcessToExitCallback)
88+
{
89+
string outputString;
90+
string errorString;
91+
92+
string portString = string.Format("tcp:{0}", port);
93+
94+
int exitCode = RunCommand(new string[] { "forward", portString, portString }, waitingProcessToExitCallback, out outputString, out errorString);
95+
return exitCode;
96+
}
97+
98+
public int ReleasePort(int port, WaitingProcessToExitCallback waitingProcessToExitCallback)
99+
{
100+
string outputString;
101+
string errorString;
102+
103+
string portString = string.Format("tcp:{0}", port);
104+
105+
int exitCode = RunCommand(new string[] { "forward", "--remove", portString }, waitingProcessToExitCallback, out outputString, out errorString);
106+
return exitCode;
107+
}
108+
109+
private StringBuilder outputStringBuilder = null;
110+
private StringBuilder errorStringBuilder = null;
111+
112+
public int RunCommand(string[] arguments, WaitingProcessToExitCallback waitingProcessToExitCallback, out string outputString, out string errorString)
113+
{
114+
int exitCode = -1;
115+
116+
if (!isReady)
117+
{
118+
Debug.LogWarning("OVRADBTool not ready");
119+
outputString = string.Empty;
120+
errorString = "OVRADBTool not ready";
121+
return exitCode;
122+
}
123+
124+
string args = string.Join(" ", arguments);
125+
126+
ProcessStartInfo startInfo = new ProcessStartInfo(adbPath, args);
127+
startInfo.WorkingDirectory = androidSdkRoot;
128+
startInfo.CreateNoWindow = true;
129+
startInfo.UseShellExecute = false;
130+
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
131+
startInfo.RedirectStandardOutput = true;
132+
startInfo.RedirectStandardError = true;
133+
134+
outputStringBuilder = new StringBuilder("");
135+
errorStringBuilder = new StringBuilder("");
136+
137+
Process process = Process.Start(startInfo);
138+
process.OutputDataReceived += new DataReceivedEventHandler(OutputDataReceivedHandler);
139+
140+
process.BeginOutputReadLine();
141+
process.BeginErrorReadLine();
142+
143+
try
144+
{
145+
do
146+
{
147+
if (waitingProcessToExitCallback != null)
148+
{
149+
waitingProcessToExitCallback();
150+
}
151+
} while (!process.WaitForExit(100));
152+
153+
process.WaitForExit();
154+
}
155+
catch (Exception e)
156+
{
157+
Debug.LogWarningFormat("[OVRADBTool.RunCommand] exception {0}", e.Message);
158+
}
159+
160+
exitCode = process.ExitCode;
161+
162+
process.Close();
163+
164+
outputString = outputStringBuilder.ToString();
165+
errorString = errorStringBuilder.ToString();
166+
167+
outputStringBuilder = null;
168+
errorStringBuilder = null;
169+
170+
return exitCode;
171+
}
172+
173+
private void OutputDataReceivedHandler(object sendingProcess, DataReceivedEventArgs args)
174+
{
175+
// Collect the sort command output.
176+
if (!string.IsNullOrEmpty(args.Data))
177+
{
178+
// Add the text to the collected output.
179+
outputStringBuilder.Append(args.Data);
180+
outputStringBuilder.Append(Environment.NewLine);
181+
}
182+
}
183+
184+
private void ErrorDataReceivedHandler(object sendingProcess, DataReceivedEventArgs args)
185+
{
186+
// Collect the sort command output.
187+
if (!string.IsNullOrEmpty(args.Data))
188+
{
189+
// Add the text to the collected output.
190+
errorStringBuilder.Append(args.Data);
191+
errorStringBuilder.Append(Environment.NewLine);
192+
}
193+
}
194+
}

0 commit comments

Comments
 (0)