Skip to content

Commit 792afc1

Browse files
committed
Merge branch 'beta'
2 parents 29aa1eb + 5573ecc commit 792afc1

File tree

104 files changed

+54954
-47123
lines changed

Some content is hidden

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

104 files changed

+54954
-47123
lines changed

Assets/SteamVR/Editor/SteamVR_AutoEnableVR.cs

Lines changed: 134 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,21 @@
99
using System.IO;
1010
using System.Collections.Generic;
1111
using System.Linq;
12+
using System;
13+
using System.Reflection;
14+
15+
using Valve.VR.InteractionSystem;
16+
17+
#if OPENVR_XR_API
18+
using UnityEditor.XR.Management.Metadata;
19+
using UnityEngine.XR.Management;
20+
#endif
21+
22+
#if UNITY_2018_2_OR_NEWER
23+
#pragma warning disable CS0618
24+
#pragma warning disable CS0219
25+
#pragma warning disable CS0414
26+
#endif
1227

1328
namespace Valve.VR
1429
{
@@ -21,7 +36,13 @@ static SteamVR_AutoEnableVR()
2136
}
2237

2338
protected const string openVRString = "OpenVR";
24-
protected const string openVRPackageString = "com.unity.xr.openvr.standalone";
39+
protected const string unityOpenVRPackageString = "com.unity.xr.openvr.standalone";
40+
protected const string valveOpenVRPackageString = "com.valvesoftware.unity.openvr";
41+
42+
#if UNITY_2020_1_OR_NEWER || OPENVR_XR_API
43+
protected const string valveEnabledLoaderKeyTemplate = "valve.enablexddrloader.{0}";
44+
protected const string valveOpenVRLoaderType = "Unity.XR.OpenVR.OpenVRLoader";
45+
#endif
2546

2647
#if UNITY_2018_2_OR_NEWER
2748
private enum PackageStates
@@ -41,6 +62,14 @@ private enum PackageStates
4162
private static System.Diagnostics.Stopwatch addingPackageTimeTotal = new System.Diagnostics.Stopwatch();
4263
private static float estimatedTimeToInstall = 80;
4364
private static int addTryCount = 0;
65+
66+
private static string enabledLoaderKey = null;
67+
68+
private static MethodInfo isLoaderAssigned;
69+
private static MethodInfo installPackageAndAssignLoaderForBuildTarget;
70+
71+
private static Type[] isLoaderAssignedMethodParameters;
72+
private static object[] isLoaderAssignedCallParameters;
4473
#endif
4574

4675
public static void Update()
@@ -49,6 +78,67 @@ public static void Update()
4978
{
5079
bool enabledVR = false;
5180

81+
#if UNITY_2020_1_OR_NEWER || OPENVR_XR_API
82+
#if !UNITY_2020_2_OR_NEWER
83+
if (UnityEditor.PlayerSettings.virtualRealitySupported == true)
84+
{
85+
UnityEditor.PlayerSettings.virtualRealitySupported = false;
86+
enabledVR = true;
87+
Debug.Log("<b>[SteamVR Setup]</b> Disabled virtual reality support in Player Settings. <b>Because you're using XR Manager. Make sure OpenVR Loader is enabled in XR Manager UI.</b> (you can disable this by unchecking Assets/SteamVR/SteamVR_Settings.autoEnableVR)");
88+
}
89+
#endif
90+
91+
#if OPENVR_XR_API
92+
//little hacky, but the public methods weren't working.
93+
94+
if (isLoaderAssignedMethodParameters == null)
95+
isLoaderAssignedMethodParameters = new Type[] { typeof(string), typeof(BuildTargetGroup) };
96+
if (isLoaderAssignedCallParameters == null)
97+
isLoaderAssignedCallParameters = new object[] { valveOpenVRLoaderType, BuildTargetGroup.Standalone };
98+
if (isLoaderAssigned == null)
99+
isLoaderAssigned = GetMethod("IsLoaderAssigned", isLoaderAssignedMethodParameters);
100+
101+
if (installPackageAndAssignLoaderForBuildTarget == null)
102+
installPackageAndAssignLoaderForBuildTarget = GetMethod("InstallPackageAndAssignLoaderForBuildTarget");
103+
104+
if (isLoaderAssigned != null && installPackageAndAssignLoaderForBuildTarget != null)
105+
{
106+
bool isAssigned = (bool)isLoaderAssigned.Invoke(null, isLoaderAssignedCallParameters);
107+
108+
if (isAssigned == false)
109+
{
110+
if (enabledLoaderKey == null)
111+
enabledLoaderKey = string.Format(valveEnabledLoaderKeyTemplate, SteamVR_Settings.instance.editorAppKey);
112+
113+
if (EditorPrefs.HasKey(enabledLoaderKey) == false)
114+
{
115+
installPackageAndAssignLoaderForBuildTarget.Invoke(null, new object[] { valveOpenVRPackageString, valveOpenVRLoaderType, BuildTargetGroup.Standalone });
116+
117+
isAssigned = (bool)isLoaderAssigned.Invoke(null, isLoaderAssignedCallParameters);
118+
if (isAssigned)
119+
{
120+
EditorPrefs.SetBool(enabledLoaderKey, true);
121+
122+
Debug.Log("<b>[SteamVR Setup]</b> Enabled OpenVR Loader in XR Management");
123+
UnityEditor.EditorApplication.update -= Update;
124+
}
125+
}
126+
else
127+
{
128+
UnityEditor.EditorApplication.update -= Update;
129+
}
130+
131+
}
132+
else
133+
{
134+
UnityEditor.EditorApplication.update -= Update;
135+
}
136+
}
137+
138+
#elif UNITY_2020_1_OR_NEWER
139+
StartAutoUpdater();
140+
#endif
141+
#else
52142
if (UnityEditor.PlayerSettings.virtualRealitySupported == false)
53143
{
54144
UnityEditor.PlayerSettings.virtualRealitySupported = true;
@@ -89,10 +179,12 @@ public static void Update()
89179
UnityEditorInternal.VR.VREditor.SetVREnabledDevicesOnTargetGroup(currentTarget, newDevices);
90180
#endif
91181
Debug.Log("<b>[SteamVR Setup]</b> Added OpenVR to supported VR SDKs list.");
182+
92183
}
93184

94185
#if UNITY_2018_2_OR_NEWER
95186
//2018+ requires us to manually add the OpenVR package
187+
//2020.1+ has a separate script that does installs
96188

97189
switch (packageState)
98190
{
@@ -111,12 +203,16 @@ public static void Update()
111203
break;
112204
}
113205

114-
bool hasPackage = listRequest.Result.Any(package => package.name == openVRPackageString);
206+
string packageName = null;
207+
208+
packageName = unityOpenVRPackageString;
209+
210+
bool hasPackage = listRequest.Result.Any(package => package.name == packageName);
115211

116212
if (hasPackage == false)
117213
{
118214
//if we don't have the package - then install it
119-
addRequest = UnityEditor.PackageManager.Client.Add(openVRPackageString);
215+
addRequest = UnityEditor.PackageManager.Client.Add(packageName);
120216
packageState = PackageStates.WaitingForAdd;
121217
addTryCount++;
122218

@@ -126,7 +222,7 @@ public static void Update()
126222
}
127223
else
128224
{
129-
//if we do have the package do nothing
225+
//if we do have the package, do nothing
130226
packageState = PackageStates.Installed; //already installed
131227
}
132228
}
@@ -180,14 +276,15 @@ public static void Update()
180276
packageState = PackageStates.Failed;
181277
break;
182278
}
279+
string packageName = unityOpenVRPackageString;
183280

184-
bool hasPackage = listRequest.Result.Any(package => package.name == openVRPackageString);
281+
bool hasPackage = listRequest.Result.Any(package => package.name == packageName);
185282

186283
if (hasPackage == false)
187284
{
188285
if (addTryCount == 1)
189286
{
190-
addRequest = UnityEditor.PackageManager.Client.Add(openVRPackageString);
287+
addRequest = UnityEditor.PackageManager.Client.Add(packageName);
191288
packageState = PackageStates.WaitingForAdd;
192289
addTryCount++;
193290

@@ -225,7 +322,38 @@ public static void Update()
225322
#else
226323
UnityEditor.EditorApplication.update -= Update;
227324
#endif
325+
#endif
326+
}
327+
}
328+
private static void StartAutoUpdater()
329+
{
330+
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
331+
for (int assemblyIndex = 0; assemblyIndex < assemblies.Length; assemblyIndex++)
332+
{
333+
Assembly assembly = assemblies[assemblyIndex];
334+
Type type = assembly.GetType("Unity.XR.OpenVR.OpenVRAutoUpdater");
335+
if (type != null)
336+
{
337+
MethodInfo preinitMethodInfo = type.GetMethod("Start");
338+
if (preinitMethodInfo != null)
339+
{
340+
preinitMethodInfo.Invoke(null, null);
341+
return;
342+
}
343+
}
228344
}
229345
}
346+
347+
private static Type xrMetadataStoreType;
348+
private static MethodInfo GetMethod(string methodName, Type[] parameters = null)
349+
{
350+
if (xrMetadataStoreType == null)
351+
xrMetadataStoreType = SteamVR_Utils.FindType("UnityEditor.XR.Management.Metadata.XRPackageMetadataStore");
352+
353+
if (parameters == null)
354+
return xrMetadataStoreType.GetMethod(methodName, BindingFlags.Static | BindingFlags.NonPublic);
355+
else
356+
return xrMetadataStoreType.GetMethod(methodName, BindingFlags.Static | BindingFlags.NonPublic, null, parameters, null);
357+
}
230358
}
231359
}
Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,36 @@
1-
{
2-
"name": "SteamVR_Editor",
3-
"references": [
4-
"SteamVR"
5-
],
6-
"optionalUnityReferences": [],
7-
"includePlatforms": [
8-
"Editor"
9-
],
10-
"excludePlatforms": [],
11-
"allowUnsafeCode": false,
12-
"overrideReferences": false,
13-
"precompiledReferences": [],
14-
"autoReferenced": true,
15-
"defineConstraints": []
1+
{
2+
"name": "SteamVR_Editor",
3+
"references": [
4+
"SteamVR",
5+
"Unity.XR.OpenVR",
6+
"Unity.XR.Management.Editor",
7+
"Unity.XR.Management"
8+
],
9+
"includePlatforms": [
10+
"Editor"
11+
],
12+
"excludePlatforms": [],
13+
"allowUnsafeCode": false,
14+
"overrideReferences": false,
15+
"precompiledReferences": [],
16+
"autoReferenced": true,
17+
"defineConstraints": [],
18+
"versionDefines": [
19+
{
20+
"name": "com.valvesoftware.unity.openvr",
21+
"expression": "",
22+
"define": "OPENVR_XR_API"
23+
},
24+
{
25+
"name": "com.unity.xr.management",
26+
"expression": "3.2.0",
27+
"define": "XR_MGMT_GTE_320"
28+
},
29+
{
30+
"name": "com.unity.xr.management",
31+
"expression": "",
32+
"define": "XR_MGMT"
33+
}
34+
],
35+
"noEngineReferences": false
1636
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using UnityEngine;
2+
using System.Collections;
3+
4+
namespace Valve.VR
5+
{
6+
public class SteamVR_CameraHelper : MonoBehaviour
7+
{
8+
void Start()
9+
{
10+
#if OPENVR_XR_API && UNITY_LEGACY_INPUT_HELPERS
11+
if (this.gameObject.GetComponent<UnityEngine.SpatialTracking.TrackedPoseDriver>() == null)
12+
{
13+
this.gameObject.AddComponent<UnityEngine.SpatialTracking.TrackedPoseDriver>();
14+
}
15+
#endif
16+
}
17+
}
18+
}

Assets/SteamVR/Extras/SteamVR_CameraHelper.cs.meta

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)