| 1 | /************************************************************************************ |
| 2 | |
| 3 | Copyright : Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved. |
| 4 | |
| 5 | Licensed under the Oculus SDK License Version 3.4.1 (the "License"); |
| 6 | you may not use the Oculus SDK except in compliance with the License, |
| 7 | which is provided at the time of installation or download, or which |
| 8 | otherwise accompanies this software in either electronic or hard copy form. |
| 9 | |
| 10 | You may obtain a copy of the License at |
| 11 | |
| 12 | https://developer.oculus.com/licenses/sdk-3.4.1 |
| 13 | |
| 14 | Unless required by applicable law or agreed to in writing, the Oculus SDK |
| 15 | distributed under the License is distributed on an "AS IS" BASIS, |
| 16 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 17 | See the License for the specific language governing permissions and |
| 18 | limitations under the License. |
| 19 | |
| 20 | ************************************************************************************/ |
| 21 | |
| 22 | using System.Collections; |
| 23 | using System.Collections.Generic; |
| 24 | using UnityEngine; |
| 25 | using UnityEditor; |
| 26 | using System.IO; |
| 27 | using System; |
| 28 | |
| 29 | [System.Serializable] |
| 30 | public 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 | } |