BlueGit

blue-star ggj-2020

Files

ggj-2020 / Assets / Oculus / VR / Editor / OVRProjectConfig.cs

OVRProjectConfig.cs

Project Import
timfa Tim Falken · pushed by timfa · 6 years ago
b77834a1 History
OVRProjectConfig.cs 3.3 KiB Download Raw
1/************************************************************************************
2
3Copyright : Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved.
4
5Licensed under the Oculus SDK License Version 3.4.1 (the "License");
6you may not use the Oculus SDK except in compliance with the License,
7which is provided at the time of installation or download, or which
8otherwise accompanies this software in either electronic or hard copy form.
9
10You may obtain a copy of the License at
11
12https://developer.oculus.com/licenses/sdk-3.4.1
13
14Unless required by applicable law or agreed to in writing, the Oculus SDK
15distributed under the License is distributed on an "AS IS" BASIS,
16WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17See the License for the specific language governing permissions and
18limitations under the License.
19
20************************************************************************************/
21
22using System.Collections;
23using System.Collections.Generic;
24using UnityEngine;
25using UnityEditor;
26using System.IO;
27using System;
28
29[System.Serializable]
30public class OVRProjectConfig : ScriptableObject
31{
32 public enum DeviceType
33 {
34 GearVrOrGo = 0,
35 Quest = 1
36 }
37
38 public List<DeviceType> targetDeviceTypes;
39
40 //public const string OculusProjectConfigAssetPath = "Assets/Oculus/OculusProjectConfig.asset";
41
42 private static string GetOculusProjectConfigAssetPath()
43 {
44 var so = ScriptableObject.CreateInstance(typeof(OVRPluginUpdaterStub));
45 var script = MonoScript.FromScriptableObject(so);
46 string assetPath = AssetDatabase.GetAssetPath(script);
47 string editorDir = Directory.GetParent(assetPath).FullName;
48 string ovrDir = Directory.GetParent(editorDir).FullName;
49 string oculusDir = Directory.GetParent(ovrDir).FullName;
50 string configAssetPath = Path.GetFullPath(Path.Combine(oculusDir, "OculusProjectConfig.asset"));
51 Uri configUri = new Uri(configAssetPath);
52 Uri projectUri = new Uri(Application.dataPath);
53 Uri relativeUri = projectUri.MakeRelativeUri(configUri);
54
55 return relativeUri.ToString();
56 }
57
58 public static OVRProjectConfig GetProjectConfig()
59 {
60 OVRProjectConfig projectConfig = null;
61 string oculusProjectConfigAssetPath = GetOculusProjectConfigAssetPath();
62 try
63 {
64 projectConfig = AssetDatabase.LoadAssetAtPath(oculusProjectConfigAssetPath, typeof(OVRProjectConfig)) as OVRProjectConfig;
65 }
66 catch (System.Exception e)
67 {
68 Debug.LogWarningFormat("Unable to load ProjectConfig from {0}, error {1}", oculusProjectConfigAssetPath, e.Message);
69 }
70 if (projectConfig == null)
71 {
72 projectConfig = ScriptableObject.CreateInstance<OVRProjectConfig>();
73 projectConfig.targetDeviceTypes = new List<DeviceType>();
74 projectConfig.targetDeviceTypes.Add(DeviceType.GearVrOrGo);
75 AssetDatabase.CreateAsset(projectConfig, oculusProjectConfigAssetPath);
76 }
77 return projectConfig;
78 }
79
80 public static void CommitProjectConfig(OVRProjectConfig projectConfig)
81 {
82 string oculusProjectConfigAssetPath = GetOculusProjectConfigAssetPath();
83 if (AssetDatabase.GetAssetPath(projectConfig) != oculusProjectConfigAssetPath)
84 {
85 Debug.LogWarningFormat("The asset path of ProjectConfig is wrong. Expect {0}, get {1}", oculusProjectConfigAssetPath, AssetDatabase.GetAssetPath(projectConfig));
86 }
87 EditorUtility.SetDirty(projectConfig);
88 }
89}