OVRProjectConfig.cs
5.73 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/************************************************************************************
Copyright : Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved.
Licensed under the Oculus SDK License Version 3.4.1 (the "License");
you may not use the Oculus SDK except in compliance with the License,
which is provided at the time of installation or download, or which
otherwise accompanies this software in either electronic or hard copy form.
You may obtain a copy of the License at
https://developer.oculus.com/licenses/sdk-3.4.1
Unless required by applicable law or agreed to in writing, the Oculus SDK
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
************************************************************************************/
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System.IO;
using System;
[System.Serializable]
#if UNITY_EDITOR
[UnityEditor.InitializeOnLoad]
#endif
public class OVRProjectConfig : ScriptableObject
{
public enum DeviceType
{
//GearVrOrGo = 0, // DEPRECATED
Quest = 1,
Quest2 = 2
}
public enum HandTrackingSupport
{
ControllersOnly = 0,
ControllersAndHands = 1,
HandsOnly = 2
}
public enum HandTrackingFrequency
{
LOW = 0,
HIGH = 1,
MAX = 2
}
public List<DeviceType> targetDeviceTypes = new List<DeviceType> {DeviceType.Quest, DeviceType.Quest2};
public bool allowOptional3DofHeadTracking = false;
public HandTrackingSupport handTrackingSupport = HandTrackingSupport.ControllersOnly;
public HandTrackingFrequency handTrackingFrequency = HandTrackingFrequency.LOW;
public bool disableBackups = true;
public bool enableNSCConfig = true;
public string securityXmlPath;
public bool skipUnneededShaders = false;
public bool focusAware = true;
public bool requiresSystemKeyboard = false;
public Texture2D systemSplashScreen;
//public const string OculusProjectConfigAssetPath = "Assets/Oculus/OculusProjectConfig.asset";
static OVRProjectConfig()
{
// BuildPipeline.isBuildingPlayer cannot be called in a static constructor
// Run Update once to call GetProjectConfig then remove delegate
EditorApplication.update += Update;
}
static void Update()
{
// Initialize the asset if it doesn't exist
GetProjectConfig();
// Stop running Update
EditorApplication.update -= Update;
}
private static string GetOculusProjectConfigAssetPath()
{
var so = ScriptableObject.CreateInstance(typeof(OVRPluginUpdaterStub));
var script = MonoScript.FromScriptableObject(so);
string assetPath = AssetDatabase.GetAssetPath(script);
string editorDir = Directory.GetParent(assetPath).FullName;
string ovrDir = Directory.GetParent(editorDir).FullName;
string oculusDir = Directory.GetParent(ovrDir).FullName;
if (OVRPluginUpdaterStub.IsInsidePackageDistribution())
{
oculusDir = Path.GetFullPath(Path.Combine(Application.dataPath, "Oculus"));
if (!Directory.Exists(oculusDir))
{
Directory.CreateDirectory(oculusDir);
}
}
string configAssetPath = Path.GetFullPath(Path.Combine(oculusDir, "OculusProjectConfig.asset"));
Uri configUri = new Uri(configAssetPath);
Uri projectUri = new Uri(Application.dataPath);
Uri relativeUri = projectUri.MakeRelativeUri(configUri);
return relativeUri.ToString();
}
public static OVRProjectConfig GetProjectConfig()
{
OVRProjectConfig projectConfig = null;
string oculusProjectConfigAssetPath = GetOculusProjectConfigAssetPath();
try
{
projectConfig = AssetDatabase.LoadAssetAtPath(oculusProjectConfigAssetPath, typeof(OVRProjectConfig)) as OVRProjectConfig;
}
catch (System.Exception e)
{
Debug.LogWarningFormat("Unable to load ProjectConfig from {0}, error {1}", oculusProjectConfigAssetPath, e.Message);
}
// Initialize the asset only if a build is not currently running.
if (projectConfig == null && !BuildPipeline.isBuildingPlayer)
{
projectConfig = ScriptableObject.CreateInstance<OVRProjectConfig>();
projectConfig.targetDeviceTypes = new List<DeviceType>();
projectConfig.targetDeviceTypes.Add(DeviceType.Quest);
projectConfig.targetDeviceTypes.Add(DeviceType.Quest2);
projectConfig.allowOptional3DofHeadTracking = false;
projectConfig.handTrackingSupport = HandTrackingSupport.ControllersOnly;
projectConfig.handTrackingFrequency = HandTrackingFrequency.LOW;
projectConfig.disableBackups = true;
projectConfig.enableNSCConfig = true;
projectConfig.skipUnneededShaders = false;
projectConfig.focusAware = true;
projectConfig.requiresSystemKeyboard = false;
AssetDatabase.CreateAsset(projectConfig, oculusProjectConfigAssetPath);
}
// Force migration to Quest device if still on legacy GearVR/Go device type
if (projectConfig.targetDeviceTypes.Contains((DeviceType)0)) // deprecated GearVR/Go device
{
projectConfig.targetDeviceTypes.Remove((DeviceType)0); // deprecated GearVR/Go device
if (!projectConfig.targetDeviceTypes.Contains(DeviceType.Quest))
{
projectConfig.targetDeviceTypes.Add(DeviceType.Quest);
}
if (!projectConfig.targetDeviceTypes.Contains(DeviceType.Quest2))
{
projectConfig.targetDeviceTypes.Add(DeviceType.Quest2);
}
}
return projectConfig;
}
public static void CommitProjectConfig(OVRProjectConfig projectConfig)
{
string oculusProjectConfigAssetPath = GetOculusProjectConfigAssetPath();
if (AssetDatabase.GetAssetPath(projectConfig) != oculusProjectConfigAssetPath)
{
Debug.LogWarningFormat("The asset path of ProjectConfig is wrong. Expect {0}, get {1}", oculusProjectConfigAssetPath, AssetDatabase.GetAssetPath(projectConfig));
}
EditorUtility.SetDirty(projectConfig);
}
}