Skip to content

Commit 15c0583

Browse files
authored
Merge pull request #297 from ValveSoftware/beta
Version 2.2
2 parents a97cfac + 1007e50 commit 15c0583

File tree

415 files changed

+34058
-14515
lines changed

Some content is hidden

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

415 files changed

+34058
-14515
lines changed
Lines changed: 231 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,231 @@
1+
//======= Copyright (c) Valve Corporation, All rights reserved. ===============
2+
//
3+
// Purpose: Prompt developers to use settings most compatible with SteamVR.
4+
//
5+
//=============================================================================
6+
7+
using UnityEngine;
8+
using UnityEditor;
9+
using System.IO;
10+
using System.Collections.Generic;
11+
using System.Linq;
12+
13+
namespace Valve.VR
14+
{
15+
[InitializeOnLoad]
16+
public class SteamVR_AutoEnableVR
17+
{
18+
static SteamVR_AutoEnableVR()
19+
{
20+
EditorApplication.update += Update;
21+
}
22+
23+
protected const string openVRString = "OpenVR";
24+
protected const string openVRPackageString = "com.unity.xr.openvr.standalone";
25+
26+
#if UNITY_2018_1_OR_NEWER
27+
private enum PackageStates
28+
{
29+
None,
30+
WaitingForList,
31+
WaitingForAdd,
32+
WaitingForAddConfirm,
33+
Installed,
34+
Failed,
35+
}
36+
37+
private static UnityEditor.PackageManager.Requests.ListRequest listRequest;
38+
private static UnityEditor.PackageManager.Requests.AddRequest addRequest;
39+
private static PackageStates packageState = PackageStates.None;
40+
private static System.Diagnostics.Stopwatch addingPackageTime = new System.Diagnostics.Stopwatch();
41+
private static System.Diagnostics.Stopwatch addingPackageTimeTotal = new System.Diagnostics.Stopwatch();
42+
private static float estimatedTimeToInstall = 80;
43+
private static int addTryCount = 0;
44+
#endif
45+
46+
public static void Update()
47+
{
48+
if (SteamVR_Settings.instance.autoEnableVR)
49+
{
50+
bool enabledVR = false;
51+
52+
if (UnityEditor.PlayerSettings.virtualRealitySupported == false)
53+
{
54+
UnityEditor.PlayerSettings.virtualRealitySupported = true;
55+
enabledVR = true;
56+
Debug.Log("<b>[SteamVR Setup]</b> Enabled virtual reality support in Player Settings. (you can disable this by unchecking Assets/SteamVR/SteamVR_Settings.autoEnableVR)");
57+
}
58+
59+
UnityEditor.BuildTargetGroup currentTarget = UnityEditor.EditorUserBuildSettings.selectedBuildTargetGroup;
60+
61+
#if (UNITY_5_4 || UNITY_5_3 || UNITY_5_2 || UNITY_5_1 || UNITY_5_0)
62+
string[] devices = UnityEditorInternal.VR.VREditor.GetVREnabledDevices(currentTarget);
63+
#else
64+
string[] devices = UnityEditorInternal.VR.VREditor.GetVREnabledDevicesOnTargetGroup(currentTarget);
65+
#endif
66+
67+
bool hasOpenVR = devices.Any(device => string.Equals(device, openVRString, System.StringComparison.CurrentCultureIgnoreCase));
68+
69+
if (hasOpenVR == false || enabledVR)
70+
{
71+
string[] newDevices;
72+
if (enabledVR && hasOpenVR == false)
73+
{
74+
newDevices = new string[] { openVRString }; //only list openvr if we enabled it
75+
}
76+
else
77+
{
78+
List<string> devicesList = new List<string>(devices); //list openvr as the first option if it wasn't in the list.
79+
if (hasOpenVR)
80+
devicesList.Remove(openVRString);
81+
82+
devicesList.Insert(0, openVRString);
83+
newDevices = devicesList.ToArray();
84+
}
85+
86+
#if (UNITY_5_6 || UNITY_5_4 || UNITY_5_3 || UNITY_5_2 || UNITY_5_1 || UNITY_5_0)
87+
UnityEditorInternal.VR.VREditor.SetVREnabledDevices(currentTarget, newDevices);
88+
#else
89+
UnityEditorInternal.VR.VREditor.SetVREnabledDevicesOnTargetGroup(currentTarget, newDevices);
90+
#endif
91+
Debug.Log("<b>[SteamVR Setup]</b> Added OpenVR to supported VR SDKs list.");
92+
}
93+
94+
#if UNITY_2018_1_OR_NEWER
95+
//2018+ requires us to manually add the OpenVR package
96+
97+
switch (packageState)
98+
{
99+
case PackageStates.None:
100+
//see if we have the package
101+
listRequest = UnityEditor.PackageManager.Client.List(true);
102+
packageState = PackageStates.WaitingForList;
103+
break;
104+
105+
case PackageStates.WaitingForList:
106+
if (listRequest.IsCompleted)
107+
{
108+
if (listRequest.Error != null || listRequest.Status == UnityEditor.PackageManager.StatusCode.Failure)
109+
{
110+
packageState = PackageStates.Failed;
111+
break;
112+
}
113+
114+
bool hasPackage = listRequest.Result.Any(package => package.name == openVRPackageString);
115+
116+
if (hasPackage == false)
117+
{
118+
//if we don't have the package - then install it
119+
addRequest = UnityEditor.PackageManager.Client.Add(openVRPackageString);
120+
packageState = PackageStates.WaitingForAdd;
121+
addTryCount++;
122+
123+
Debug.Log("<b>[SteamVR Setup]</b> Installing OpenVR package...");
124+
addingPackageTime.Start();
125+
addingPackageTimeTotal.Start();
126+
}
127+
else
128+
{
129+
//if we do have the package do nothing
130+
packageState = PackageStates.Installed; //already installed
131+
}
132+
}
133+
break;
134+
135+
case PackageStates.WaitingForAdd:
136+
if (addRequest.IsCompleted)
137+
{
138+
if (addRequest.Error != null || addRequest.Status == UnityEditor.PackageManager.StatusCode.Failure)
139+
{
140+
packageState = PackageStates.Failed;
141+
break;
142+
}
143+
else
144+
{
145+
//if the package manager says we added it then confirm that with the list
146+
listRequest = UnityEditor.PackageManager.Client.List(true);
147+
packageState = PackageStates.WaitingForAddConfirm;
148+
}
149+
}
150+
else
151+
{
152+
if (addingPackageTimeTotal.Elapsed.TotalSeconds > estimatedTimeToInstall)
153+
estimatedTimeToInstall *= 2; // :)
154+
155+
string dialogText;
156+
if (addTryCount == 1)
157+
dialogText = "Installing OpenVR from Unity Package Manager...";
158+
else
159+
dialogText = "Retrying OpenVR install from Unity Package Manager...";
160+
161+
bool cancel = UnityEditor.EditorUtility.DisplayCancelableProgressBar("SteamVR", dialogText, (float)addingPackageTimeTotal.Elapsed.TotalSeconds / estimatedTimeToInstall);
162+
if (cancel)
163+
packageState = PackageStates.Failed;
164+
165+
if (addingPackageTime.Elapsed.TotalSeconds > 10)
166+
{
167+
Debug.Log("<b>[SteamVR Setup]</b> Waiting for package manager to install OpenVR package...");
168+
addingPackageTime.Stop();
169+
addingPackageTime.Reset();
170+
addingPackageTime.Start();
171+
}
172+
}
173+
break;
174+
175+
case PackageStates.WaitingForAddConfirm:
176+
if (listRequest.IsCompleted)
177+
{
178+
if (listRequest.Error != null)
179+
{
180+
packageState = PackageStates.Failed;
181+
break;
182+
}
183+
184+
bool hasPackage = listRequest.Result.Any(package => package.name == openVRPackageString);
185+
186+
if (hasPackage == false)
187+
{
188+
if (addTryCount == 1)
189+
{
190+
addRequest = UnityEditor.PackageManager.Client.Add(openVRPackageString);
191+
packageState = PackageStates.WaitingForAdd;
192+
addTryCount++;
193+
194+
Debug.Log("<b>[SteamVR Setup]</b> Retrying OpenVR package install...");
195+
}
196+
else
197+
{
198+
packageState = PackageStates.Failed;
199+
}
200+
}
201+
else
202+
{
203+
packageState = PackageStates.Installed; //installed successfully
204+
205+
Debug.Log("<b>[SteamVR Setup]</b> Successfully installed OpenVR package.");
206+
}
207+
}
208+
break;
209+
}
210+
211+
if (packageState == PackageStates.Failed || packageState == PackageStates.Installed)
212+
{
213+
addingPackageTime.Stop();
214+
addingPackageTimeTotal.Stop();
215+
UnityEditor.EditorUtility.ClearProgressBar();
216+
UnityEditor.EditorApplication.update -= Update; //we're done trying to auto-enable vr
217+
218+
if (packageState == PackageStates.Failed)
219+
{
220+
string failtext = "The Unity Package Manager failed to automatically install the OpenVR package. Please open the Package Manager Window and try to install it manually.";
221+
UnityEditor.EditorUtility.DisplayDialog("SteamVR", failtext, "Ok");
222+
Debug.Log("<b>[SteamVR Setup]</b> " + failtext);
223+
}
224+
}
225+
#else
226+
UnityEditor.EditorApplication.update -= Update;
227+
#endif
228+
}
229+
}
230+
}
231+
}

Assets/SteamVR/Editor/SteamVR_AutoEnableVR.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.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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": []
16+
}

Assets/SteamVR/Editor/SteamVR_Editor.asmdef.meta

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,2 @@
11
//======= Copyright (c) Valve Corporation, All rights reserved. ===============
2-
//
3-
// Purpose: Preferences pane for how SteamVR plugin behaves.
4-
//
5-
//=============================================================================
6-
7-
using UnityEngine;
8-
using UnityEditor;
9-
10-
namespace Valve.VR
11-
{
12-
public class SteamVR_Preferences
13-
{
14-
/// <summary>
15-
/// Should SteamVR automatically enable VR when opening Unity or pressing play.
16-
/// </summary>
17-
public static bool AutoEnableVR
18-
{
19-
get
20-
{
21-
return EditorPrefs.GetBool("SteamVR_AutoEnableVR", true);
22-
}
23-
set
24-
{
25-
EditorPrefs.SetBool("SteamVR_AutoEnableVR", value);
26-
}
27-
}
28-
29-
[PreferenceItem("SteamVR")]
30-
static void PreferencesGUI()
31-
{
32-
EditorGUILayout.BeginVertical();
33-
EditorGUILayout.Space();
34-
35-
// Automatically Enable VR
36-
{
37-
string title = "Automatically Enable VR";
38-
string tooltip = "Should SteamVR automatically enable VR on launch and play?";
39-
AutoEnableVR = EditorGUILayout.Toggle(new GUIContent(title, tooltip), AutoEnableVR);
40-
string helpMessage = "To enable VR manually:\n";
41-
helpMessage += "- go to Edit -> Project Settings -> Player,\n";
42-
helpMessage += "- tick 'Virtual Reality Supported',\n";
43-
helpMessage += "- make sure OpenVR is in the 'Virtual Reality SDKs' list.";
44-
EditorGUILayout.HelpBox(helpMessage, MessageType.Info);
45-
}
46-
47-
EditorGUILayout.EndVertical();
48-
}
49-
}
50-
}
2+
//removed and added to the SteamVR_Settings asset so it can be configured per project

Assets/SteamVR/Editor/SteamVR_SkyboxEditor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ public override void OnInspectorGUI()
337337
DestroyImmediate(fx);
338338

339339
timer.Stop();
340-
Debug.Log(string.Format("Screenshot took {0} seconds.", timer.Elapsed));
340+
Debug.Log(string.Format("<b>[SteamVR]</b> Screenshot took {0} seconds.", timer.Elapsed));
341341
}
342342

343343
if (tempCamera != null)

0 commit comments

Comments
 (0)