-
Notifications
You must be signed in to change notification settings - Fork 0
/
XRPluginManagementSettings.cs
42 lines (38 loc) · 1.75 KB
/
XRPluginManagementSettings.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
using System;
using UnityEditor;
using UnityEditor.XR.Management;
using UnityEditor.XR.Management.Metadata;
#if UNITY_EDITOR
public static class XRPluginManagementSettings {
// ref. https://docs.unity3d.com/Packages/[email protected]/manual/EndUser.html
public enum Plugin {
OpenXR,
Oculus,
OpenVR,
Pico
}
public static void EnablePlugin(BuildTargetGroup buildTargetGroup, Plugin plugin) {
var buildTargetSettings = XRGeneralSettingsPerBuildTarget.XRGeneralSettingsForBuildTarget(buildTargetGroup);
var pluginsSettings = buildTargetSettings.AssignedSettings;
var success = XRPackageMetadataStore.AssignLoader(pluginsSettings, GetLoaderName(plugin), buildTargetGroup);
if (success) {
Console.WriteLine($":: XR Plug-in Management: Enabled {plugin} plugin on {buildTargetGroup}");
}
}
public static void DisablePlugin(BuildTargetGroup buildTargetGroup, Plugin plugin) {
var buildTargetSettings = XRGeneralSettingsPerBuildTarget.XRGeneralSettingsForBuildTarget(buildTargetGroup);
var pluginsSettings = buildTargetSettings.AssignedSettings;
var success = XRPackageMetadataStore.RemoveLoader(pluginsSettings, GetLoaderName(plugin), buildTargetGroup);
if (success) {
Console.WriteLine($":: XR Plug-in Management: Disabled {plugin} plugin on {buildTargetGroup}");
}
}
static string GetLoaderName(Plugin plugin) => plugin switch {
Plugin.OpenXR => "UnityEngine.XR.OpenXR.OpenXRLoader",
Plugin.Oculus => "Unity.XR.Oculus.OculusLoader",
Plugin.OpenVR => "Unity.XR.OpenVR.OpenVRLoader",
Plugin.Pico => "Unity.XR.PXR.PXR_Loader",
_ => throw new NotImplementedException()
};
}
#endif