Skip to content

Commit 7a7828a

Browse files
committed
Release 0.2.1
Develop @971c9b38d327d5915fd62893f128de7bef40a79a
1 parent 57cd3ef commit 7a7828a

File tree

115 files changed

+2801
-974
lines changed

Some content is hidden

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

115 files changed

+2801
-974
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,5 @@ ReferenceProject/Assets/Samples
5858
ReferenceProject/Assets/Samples.meta
5959
ReferenceProject/UIElementsSchema
6060
ReferenceProject/Assets/Utilities/Git/Resources
61+
ReferenceProject/Assets/Utilities/Git/Resources.git
6162
ReferenceProject/Assets/Resources.meta
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
using System;
2+
using System.ComponentModel;
3+
using System.IO;
4+
using System.Net;
5+
using UnityEditor;
6+
using UnityEditor.Callbacks;
7+
using UnityEditor.Compilation;
8+
using UnityEngine;
9+
using UnityEngine.Rendering;
10+
11+
namespace Unity.ReferenceProject.Editor
12+
{
13+
public class Focus3ProjectSettings : UnityEditor.Editor
14+
{
15+
static readonly string s_PipeLineName = "URP-Performant";
16+
static readonly AndroidSdkVersions s_MinAndroidVersion = AndroidSdkVersions.AndroidApiLevel22;
17+
18+
static readonly string s_PackageName = "com.htc.upm.wave.openxr";
19+
static readonly string s_Url = "https://github.com/ViveSoftware/VIVE-OpenXR-AIO/releases/download/versions%2F1.0.5/com.htc.upm.wave.openxr-1.0.5.tgz";
20+
21+
static readonly string s_PackageFileName = Path.GetFileName(s_Url);
22+
static readonly string s_SavePath = Path.GetDirectoryName(Application.dataPath) + $@"\Packages\{s_PackageFileName}";
23+
static readonly string s_PackagePath = $"file:{s_PackageFileName}";
24+
static readonly string s_EditroPrefs = "Focus3ChangeSettings";
25+
26+
[MenuItem("ReferenceProject/VR/Switch/To Focus3 project", false, 11)]
27+
public static void DownloadPackage()
28+
{
29+
DownloadFile(s_Url, s_SavePath, (o, e) =>
30+
{
31+
if (e.Error == null)
32+
{
33+
SetupPackage();
34+
}
35+
else
36+
{
37+
Debug.LogError($"Error downloading file: {e.Error}");
38+
}
39+
});
40+
}
41+
42+
static void SetupPackage()
43+
{
44+
if (SetupVR.AddPackages(s_PackagePath))
45+
{
46+
EditorPrefs.SetBool(s_EditroPrefs, true);
47+
CompilationPipeline.RequestScriptCompilation();
48+
}
49+
}
50+
51+
[DidReloadScripts]
52+
static void DidRecompile()
53+
{
54+
if (EditorPrefs.GetBool(s_EditroPrefs, false))
55+
{
56+
EditorPrefs.DeleteKey(s_EditroPrefs);
57+
58+
EditorApplication.update += UpdateChangeSettings;
59+
60+
Debug.Log("Started to update settings. Please wait...");
61+
}
62+
}
63+
64+
static void UpdateChangeSettings()
65+
{
66+
// We need to run update only once
67+
EditorApplication.update -= UpdateChangeSettings;
68+
69+
if (!SetupVR.CheckPackagesExistence(s_PackageName))
70+
{
71+
Debug.LogError("Focus3 switch failed");
72+
return;
73+
}
74+
75+
SetupPlayerSettings();
76+
Debug.Log("Focus3 switch completed");
77+
}
78+
79+
static void SetupPlayerSettings()
80+
{
81+
SetupVR.EnsureAndroidBuildTarget();
82+
83+
SetupVR.SetupOpenXR(SetupVR.DeviceTarget.Focus3);
84+
SetupVR.SetVRBuildScenes();
85+
86+
try
87+
{
88+
EditorApplication.LockReloadAssemblies();
89+
try
90+
{
91+
SetupVR.PrepareRendererPipelineAsset(s_PipeLineName);
92+
SetAndroidSettings();
93+
}
94+
finally
95+
{
96+
EditorApplication.UnlockReloadAssemblies();
97+
}
98+
99+
AssetDatabase.Refresh(ImportAssetOptions.ForceSynchronousImport);
100+
}
101+
catch (Exception e)
102+
{
103+
Debug.LogError($"Focus3 settings could not be set: {e.GetType().Name}; {e.Message}; {e.StackTrace}");
104+
throw;
105+
}
106+
}
107+
108+
static void SetAndroidSettings()
109+
{
110+
// Enable multi-threaded rendering
111+
PlayerSettings.SetMobileMTRendering(BuildTargetGroup.Android, true);
112+
113+
// Set Minimum Android version
114+
// https://developer.vive.com/resources/openxr/openxr-mobile/tutorials/unity/getting-started-openxr-mobile/
115+
if (PlayerSettings.Android.minSdkVersion < s_MinAndroidVersion || PlayerSettings.Android.targetSdkVersion < s_MinAndroidVersion)
116+
{
117+
PlayerSettings.Android.minSdkVersion = s_MinAndroidVersion;
118+
}
119+
120+
PlayerSettings.defaultInterfaceOrientation = UIOrientation.LandscapeLeft;
121+
122+
PlayerSettings.colorSpace = ColorSpace.Linear;
123+
PlayerSettings.gpuSkinning = false;
124+
125+
// Set IL2CPP
126+
PlayerSettings.SetScriptingBackend(BuildTargetGroup.Android, ScriptingImplementation.IL2CPP);
127+
PlayerSettings.Android.targetArchitectures = AndroidArchitecture.ARM64;
128+
129+
// Remove the "Auto Graphics API" option
130+
PlayerSettings.SetUseDefaultGraphicsAPIs(BuildTarget.Android, false);
131+
PlayerSettings.SetGraphicsAPIs(BuildTarget.Android, new[] { GraphicsDeviceType.OpenGLES3 });
132+
133+
PlayerSettings.Android.androidTVCompatibility = false;
134+
PlayerSettings.Android.preferredInstallLocation = AndroidPreferredInstallLocation.Auto;
135+
}
136+
137+
static void DownloadFile(string url, string savePath, AsyncCompletedEventHandler callback)
138+
{
139+
using (WebClient client = new WebClient())
140+
{
141+
client.DownloadFileCompleted += callback;
142+
client.DownloadFileAsync(new Uri (url), savePath);
143+
Debug.Log("Downloading started");
144+
}
145+
}
146+
}
147+
}

ReferenceProject/Assets/_Application/Scripts/AppStates/SwitchFlag.cs.meta renamed to ReferenceProject/Assets/Editor/Scripts/Focus3ProjectSettings.cs.meta

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ReferenceProject/Assets/Editor/Scripts/QuestProjectSettings.cs

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
using System;
2-
using System.Linq;
32
using UnityEditor;
43
using UnityEngine;
54
using UnityEngine.Rendering;
6-
using UnityEngine.Rendering.Universal;
75

86
namespace Unity.ReferenceProject.Editor
97
{
@@ -12,10 +10,10 @@ public class QuestProjectSettings : UnityEditor.Editor
1210
static string s_PipeLineName = "URP-Performant";
1311
static readonly AndroidSdkVersions s_MinAndroidVersion = AndroidSdkVersions.AndroidApiLevel29;
1412

15-
[MenuItem("ReferenceProject/VR/Switch to Quest project", false, 10)]
13+
[MenuItem("ReferenceProject/VR/Switch/To Quest project", false, 10)]
1614
public static void Switch2Quest()
1715
{
18-
EnsureAndroidBuildTarget();
16+
SetupVR.EnsureAndroidBuildTarget();
1917

2018
SetupVR.SetupOpenXR(SetupVR.DeviceTarget.Standalone); // Added to be able to test in Editor
2119
SetupVR.SetupOpenXR(SetupVR.DeviceTarget.Quest);
@@ -26,7 +24,7 @@ public static void Switch2Quest()
2624
EditorApplication.LockReloadAssemblies();
2725
try
2826
{
29-
PrepareRendererPipelineAsset();
27+
SetupVR.PrepareRendererPipelineAsset(s_PipeLineName);
3028
SetAndroidSettings();
3129
}
3230
finally
@@ -43,29 +41,6 @@ public static void Switch2Quest()
4341
}
4442
}
4543

46-
static void EnsureAndroidBuildTarget()
47-
{
48-
if (EditorUserBuildSettings.activeBuildTarget != BuildTarget.Android || EditorUserBuildSettings.selectedBuildTargetGroup != BuildTargetGroup.Android)
49-
{
50-
EditorUserBuildSettings.SwitchActiveBuildTarget(BuildTargetGroup.Android, BuildTarget.Android);
51-
AssetDatabase.Refresh(ImportAssetOptions.ForceSynchronousImport);
52-
}
53-
}
54-
55-
static void PrepareRendererPipelineAsset()
56-
{
57-
foreach (var pipeline in GraphicsSettings.allConfiguredRenderPipelines.OfType<UniversalRenderPipelineAsset>())
58-
{
59-
if (pipeline.name == s_PipeLineName)
60-
{
61-
GraphicsSettings.defaultRenderPipeline = pipeline;
62-
EditorUtility.SetDirty(pipeline);
63-
AssetDatabase.SaveAssetIfDirty(pipeline);
64-
return;
65-
}
66-
}
67-
}
68-
6944
static void SetAndroidSettings()
7045
{
7146
// Enable multi-threaded rendering

ReferenceProject/Assets/Editor/Scripts/SetupVR.cs

Lines changed: 118 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,16 @@
33
using System.IO;
44
using System.Linq;
55
using System.Reflection;
6+
using System.Threading;
7+
using System.Threading.Tasks;
68
using UnityEditor;
9+
using UnityEditor.PackageManager;
710
using UnityEditor.PackageManager.Requests;
811
using UnityEditor.XR.Management;
912
using UnityEditor.XR.Management.Metadata;
1013
using UnityEngine;
14+
using UnityEngine.Rendering;
15+
using UnityEngine.Rendering.Universal;
1116
using UnityEngine.XR.Management;
1217
using UnityEngine.XR.OpenXR;
1318

@@ -87,6 +92,12 @@ public static void SetupOpenXR(DeviceTarget deviceTarget = 0)
8792
case "MockRuntime Standalone":
8893
feature.enabled = false;
8994
break;
95+
case "VIVEFocus3Feature Android":
96+
feature.enabled = false;
97+
break;
98+
case "VIVEFocus3Profile Android":
99+
feature.enabled = false;
100+
break;
90101
case "OculusTouchControllerProfile Android":
91102
feature.enabled = true;
92103
break;
@@ -101,13 +112,16 @@ public static void SetupOpenXR(DeviceTarget deviceTarget = 0)
101112
case "MockRuntime Standalone":
102113
feature.enabled = false;
103114
break;
104-
case "HTCViveControllerProfile Android":
105-
feature.enabled = true;
115+
case "OculusTouchControllerProfile Android":
116+
feature.enabled = false;
106117
break;
107-
case "ValveIndexControllerProfile Android":
118+
case "MetaQuestFeature Android":
119+
feature.enabled = false;
120+
break;
121+
case "VIVEFocus3Feature Android":
108122
feature.enabled = true;
109123
break;
110-
case "VIVEFocus3ControllerInteraction Android": // This one needs to be checked
124+
case "VIVEFocus3Profile Android":
111125
feature.enabled = true;
112126
break;
113127
}
@@ -116,7 +130,7 @@ public static void SetupOpenXR(DeviceTarget deviceTarget = 0)
116130
}
117131
}
118132

119-
static OpenXRSettings GetOrCreateOpenXRSettings(BuildTargetGroup buildTargetGroup)
133+
public static OpenXRSettings GetOrCreateOpenXRSettings(BuildTargetGroup buildTargetGroup)
120134
{
121135
var settings = OpenXRSettings.Instance;
122136
if (settings == null)
@@ -183,5 +197,104 @@ static void AddBuildScenes(string[] scenes)
183197

184198
EditorBuildSettings.scenes = editorBuildSettingsScenes.ToArray();
185199
}
200+
201+
public static void EnsureAndroidBuildTarget()
202+
{
203+
if (EditorUserBuildSettings.activeBuildTarget != BuildTarget.Android || EditorUserBuildSettings.selectedBuildTargetGroup != BuildTargetGroup.Android)
204+
{
205+
EditorUserBuildSettings.SwitchActiveBuildTarget(BuildTargetGroup.Android, BuildTarget.Android);
206+
AssetDatabase.Refresh(ImportAssetOptions.ForceSynchronousImport);
207+
}
208+
}
209+
210+
public static void PrepareRendererPipelineAsset(string pipeLineName)
211+
{
212+
foreach (var pipeline in GraphicsSettings.allConfiguredRenderPipelines.OfType<UniversalRenderPipelineAsset>())
213+
{
214+
if (pipeline.name == pipeLineName)
215+
{
216+
GraphicsSettings.defaultRenderPipeline = pipeline;
217+
EditorUtility.SetDirty(pipeline);
218+
AssetDatabase.SaveAssetIfDirty(pipeline);
219+
return;
220+
}
221+
}
222+
}
223+
224+
public static bool AddPackages(params string[] packs)
225+
{
226+
var request = Client.List(true);
227+
228+
if(!WaitRequestForCompletion(request))
229+
{
230+
Debug.LogError($"Could not obtain the list of packages. Can not continue. ErrorCode:{request.Error.errorCode} message: {request.Error.message}");
231+
return false;
232+
}
233+
234+
foreach (var pack in packs)
235+
{
236+
if (request.Result.Any(x => x.name.Equals(pack)))
237+
{
238+
Debug.LogWarning($"{pack} is already in the project and cannot be added. Skipping");
239+
continue;
240+
}
241+
242+
var addRequest = Client.Add(pack);
243+
244+
if(WaitRequestForCompletion(addRequest))
245+
{
246+
Debug.Log($"{pack} was added");
247+
}
248+
else
249+
{
250+
Debug.LogError($"{pack} cannot be added: errorCode:{addRequest.Error.errorCode}; message: {addRequest.Error.message}");
251+
return false;
252+
}
253+
}
254+
255+
return true;
256+
}
257+
258+
public static bool CheckPackagesExistence(params string[] packageNames)
259+
{
260+
var request = Client.List(true);
261+
262+
if(!WaitRequestForCompletion(request))
263+
{
264+
Debug.LogError($"Could not obtain the list of packages. Can not continue. ErrorCode:{request.Error.errorCode} message: {request.Error.message}");
265+
return false;
266+
}
267+
268+
int packagesCount = 0;
269+
270+
foreach (var package in request.Result)
271+
{
272+
foreach (var packageName in packageNames)
273+
{
274+
if (package.name == packageName)
275+
{
276+
packagesCount++;
277+
break;
278+
}
279+
}
280+
}
281+
282+
return packagesCount == packageNames.Length;
283+
}
284+
285+
static bool WaitRequestForCompletion(Request request)
286+
{
287+
while (!request.IsCompleted)
288+
{
289+
// Wait for completion.
290+
}
291+
292+
if (request.Status != StatusCode.Success)
293+
{
294+
return false;
295+
}
296+
297+
return true;
298+
}
186299
}
187300
}

0 commit comments

Comments
 (0)