Assignment for RMIT Mixed Reality in 2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

475 lines
10 KiB

  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Runtime.Serialization.Formatters.Binary;
  5. using UnityEditor;
  6. using UnityEngine;
  7. namespace Assets.Oculus.VR.Editor
  8. {
  9. #if UNITY_EDITOR
  10. [UnityEditor.InitializeOnLoad]
  11. #endif
  12. public sealed class OVRPlatformToolSettings : ScriptableObject
  13. {
  14. private const string DEFAULT_RELEASE_CHANNEL = "Alpha";
  15. public enum GamepadType
  16. {
  17. OFF,
  18. TWINSTICK,
  19. RIGHT_D_PAD,
  20. LEFT_D_PAD,
  21. };
  22. public static string AppID
  23. {
  24. get
  25. {
  26. if (Instance.targetPlatform < OVRPlatformTool.TargetPlatform.None &&
  27. EditorPrefs.HasKey("OVRPlatformToolSettings_AppID" + (int)Instance.targetPlatform))
  28. {
  29. return EditorPrefs.GetString("OVRPlatformToolSettings_AppID" + (int)Instance.targetPlatform);
  30. }
  31. else
  32. {
  33. return "";
  34. }
  35. }
  36. set
  37. {
  38. if (Instance.targetPlatform < OVRPlatformTool.TargetPlatform.None)
  39. {
  40. EditorPrefs.SetString("OVRPlatformToolSettings_AppID" + (int)Instance.targetPlatform, value);
  41. }
  42. }
  43. }
  44. public static string ReleaseNote
  45. {
  46. get
  47. {
  48. if (Instance.targetPlatform < OVRPlatformTool.TargetPlatform.None &&
  49. EditorPrefs.HasKey("OVRPlatformToolSettings_ReleaseNote" + (int)Instance.targetPlatform))
  50. {
  51. return EditorPrefs.GetString("OVRPlatformToolSettings_ReleaseNote" + (int)Instance.targetPlatform);
  52. }
  53. else
  54. {
  55. return "";
  56. }
  57. }
  58. set
  59. {
  60. if (Instance.targetPlatform < OVRPlatformTool.TargetPlatform.None)
  61. {
  62. EditorPrefs.SetString("OVRPlatformToolSettings_ReleaseNote" + (int)Instance.targetPlatform, value);
  63. }
  64. }
  65. }
  66. public static string ReleaseChannel
  67. {
  68. get
  69. {
  70. if (Instance.targetPlatform < OVRPlatformTool.TargetPlatform.None &&
  71. EditorPrefs.HasKey("OVRPlatformToolSettings_ReleaseChannel" + (int)Instance.targetPlatform))
  72. {
  73. return EditorPrefs.GetString("OVRPlatformToolSettings_ReleaseChannel" + (int)Instance.targetPlatform);
  74. }
  75. else
  76. {
  77. return "";
  78. }
  79. }
  80. set
  81. {
  82. if (Instance.targetPlatform < OVRPlatformTool.TargetPlatform.None)
  83. {
  84. EditorPrefs.SetString("OVRPlatformToolSettings_ReleaseChannel" + (int)Instance.targetPlatform, value);
  85. }
  86. }
  87. }
  88. public static string ApkBuildPath
  89. {
  90. get
  91. {
  92. if (Instance.targetPlatform < OVRPlatformTool.TargetPlatform.None &&
  93. EditorPrefs.HasKey("OVRPlatformToolSettings_ApkBuildPath" + (int)Instance.targetPlatform))
  94. {
  95. return EditorPrefs.GetString("OVRPlatformToolSettings_ApkBuildPath" + (int)Instance.targetPlatform);
  96. }
  97. else
  98. {
  99. return "";
  100. }
  101. }
  102. set
  103. {
  104. if (Instance.targetPlatform < OVRPlatformTool.TargetPlatform.None)
  105. {
  106. EditorPrefs.SetString("OVRPlatformToolSettings_ApkBuildPath" + (int)Instance.targetPlatform, value);
  107. }
  108. }
  109. }
  110. public static string ObbFilePath
  111. {
  112. get
  113. {
  114. if (Instance.targetPlatform < OVRPlatformTool.TargetPlatform.None &&
  115. EditorPrefs.HasKey("OVRPlatformToolSettings_ObbFilePath" + (int)Instance.targetPlatform))
  116. {
  117. return EditorPrefs.GetString("OVRPlatformToolSettings_ObbFilePath" + (int)Instance.targetPlatform);
  118. }
  119. else
  120. {
  121. return "";
  122. }
  123. }
  124. set
  125. {
  126. if (Instance.targetPlatform < OVRPlatformTool.TargetPlatform.None)
  127. {
  128. EditorPrefs.SetString("OVRPlatformToolSettings_ObbFilePath" + (int)Instance.targetPlatform, value);
  129. }
  130. }
  131. }
  132. public static string AssetsDirectory
  133. {
  134. get
  135. {
  136. if (Instance.targetPlatform < OVRPlatformTool.TargetPlatform.None &&
  137. EditorPrefs.HasKey("OVRPlatformToolSettings_AssetsDirectory" + (int)Instance.targetPlatform))
  138. {
  139. return EditorPrefs.GetString("OVRPlatformToolSettings_AssetsDirectory" + (int)Instance.targetPlatform);
  140. }
  141. else
  142. {
  143. return "";
  144. }
  145. }
  146. set
  147. {
  148. if (Instance.targetPlatform < OVRPlatformTool.TargetPlatform.None)
  149. {
  150. EditorPrefs.SetString("OVRPlatformToolSettings_AssetsDirectory" + (int)Instance.targetPlatform, value);
  151. }
  152. }
  153. }
  154. public static string RiftBuildDirectory
  155. {
  156. get
  157. {
  158. if (EditorPrefs.HasKey("OVRPlatformToolSettings_RiftBuildDirectory"))
  159. {
  160. return EditorPrefs.GetString("OVRPlatformToolSettings_RiftBuildDirectory");
  161. }
  162. else
  163. {
  164. return "";
  165. }
  166. }
  167. set
  168. {
  169. EditorPrefs.SetString("OVRPlatformToolSettings_RiftBuildDirectory", value);
  170. }
  171. }
  172. public static string RiftBuildVersion
  173. {
  174. get
  175. {
  176. if (EditorPrefs.HasKey("OVRPlatformToolSettings_RiftBuildVersion"))
  177. {
  178. return EditorPrefs.GetString("OVRPlatformToolSettings_RiftBuildVersion");
  179. }
  180. else
  181. {
  182. return "";
  183. }
  184. }
  185. set
  186. {
  187. EditorPrefs.SetString("OVRPlatformToolSettings_RiftBuildVersion", value);
  188. }
  189. }
  190. public static string RiftLaunchFile
  191. {
  192. get
  193. {
  194. if (EditorPrefs.HasKey("OVRPlatformToolSettings_RiftLaunchFile"))
  195. {
  196. return EditorPrefs.GetString("OVRPlatformToolSettings_RiftLaunchFile");
  197. }
  198. else
  199. {
  200. return "";
  201. }
  202. }
  203. set
  204. {
  205. EditorPrefs.SetString("OVRPlatformToolSettings_RiftLaunchFile", value);
  206. }
  207. }
  208. public static string RiftLaunchParams
  209. {
  210. get
  211. {
  212. if (EditorPrefs.HasKey("OVRPlatformToolSettings_RiftLaunchParams"))
  213. {
  214. return EditorPrefs.GetString("OVRPlatformToolSettings_RiftLaunchParams");
  215. }
  216. else
  217. {
  218. return "";
  219. }
  220. }
  221. set
  222. {
  223. EditorPrefs.SetString("OVRPlatformToolSettings_RiftLaunchParams", value);
  224. }
  225. }
  226. public static string Rift2DLaunchFile
  227. {
  228. get
  229. {
  230. if (EditorPrefs.HasKey("OVRPlatformToolSettings_Rift2DLaunchFile"))
  231. {
  232. return EditorPrefs.GetString("OVRPlatformToolSettings_Rift2DLaunchFile");
  233. }
  234. else
  235. {
  236. return "";
  237. }
  238. }
  239. set
  240. {
  241. EditorPrefs.SetString("OVRPlatformToolSettings_Rift2DLaunchFile", value);
  242. }
  243. }
  244. public static string Rift2DLaunchParams
  245. {
  246. get
  247. {
  248. if (EditorPrefs.HasKey("OVRPlatformToolSettings_Rift2DLaunchParams"))
  249. {
  250. return EditorPrefs.GetString("OVRPlatformToolSettings_Rift2DLaunchParams");
  251. }
  252. else
  253. {
  254. return "";
  255. }
  256. }
  257. set
  258. {
  259. EditorPrefs.SetString("OVRPlatformToolSettings_Rift2DLaunchParams", value);
  260. }
  261. }
  262. public static bool RiftFirewallException
  263. {
  264. get
  265. {
  266. if (EditorPrefs.HasKey("OVRPlatformToolSettings_RiftFirewallException"))
  267. {
  268. return EditorPrefs.GetBool("OVRPlatformToolSettings_RiftFirewallException");
  269. }
  270. else
  271. {
  272. return false;
  273. }
  274. }
  275. set
  276. {
  277. EditorPrefs.SetBool("OVRPlatformToolSettings_RiftFirewallException", value);
  278. }
  279. }
  280. public static GamepadType RiftGamepadEmulation
  281. {
  282. get
  283. {
  284. if (EditorPrefs.HasKey("OVRPlatformToolSettings_RiftGamepadEmulation"))
  285. {
  286. return (GamepadType)EditorPrefs.GetInt("OVRPlatformToolSettings_RiftGamepadEmulation");
  287. }
  288. else
  289. {
  290. return GamepadType.OFF;
  291. }
  292. }
  293. set
  294. {
  295. EditorPrefs.SetInt("OVRPlatformToolSettings_RiftGamepadEmulation", (int)value);
  296. }
  297. }
  298. public static List<RedistPackage> RiftRedistPackages
  299. {
  300. get { return Instance.riftRedistPackages; }
  301. set { Instance.riftRedistPackages = value; }
  302. }
  303. public static string LanguagePackDirectory
  304. {
  305. get { return Instance.languagePackDirectory; }
  306. set { Instance.languagePackDirectory = value; }
  307. }
  308. public static List<AssetConfig> AssetConfigs
  309. {
  310. get
  311. {
  312. return Instance.targetPlatform < OVRPlatformTool.TargetPlatform.None ? Instance.assetConfigs[(int)Instance.targetPlatform].configList : new List<AssetConfig>();
  313. }
  314. set
  315. {
  316. if (Instance.targetPlatform < OVRPlatformTool.TargetPlatform.None)
  317. {
  318. Instance.assetConfigs[(int)Instance.targetPlatform].configList = value;
  319. }
  320. }
  321. }
  322. public static OVRPlatformTool.TargetPlatform TargetPlatform
  323. {
  324. get { return Instance.targetPlatform; }
  325. set { Instance.targetPlatform = value; }
  326. }
  327. public static bool RunOvrLint
  328. {
  329. get { return Instance.runOvrLint; }
  330. set { Instance.runOvrLint = value; }
  331. }
  332. [SerializeField]
  333. private List<RedistPackage> riftRedistPackages;
  334. [SerializeField]
  335. private string languagePackDirectory = "";
  336. [SerializeField]
  337. private AssetConfigList[] assetConfigs = new AssetConfigList[(int)OVRPlatformTool.TargetPlatform.None];
  338. [SerializeField]
  339. private OVRPlatformTool.TargetPlatform targetPlatform = OVRPlatformTool.TargetPlatform.None;
  340. [SerializeField]
  341. private bool runOvrLint = true;
  342. private static OVRPlatformToolSettings instance;
  343. public static OVRPlatformToolSettings Instance
  344. {
  345. get
  346. {
  347. if (instance == null)
  348. {
  349. instance = Resources.Load<OVRPlatformToolSettings>("OVRPlatformToolSettings");
  350. if (instance == null)
  351. {
  352. instance = ScriptableObject.CreateInstance<OVRPlatformToolSettings>();
  353. string properPath = System.IO.Path.Combine(UnityEngine.Application.dataPath, "Resources");
  354. if (!System.IO.Directory.Exists(properPath))
  355. {
  356. UnityEditor.AssetDatabase.CreateFolder("Assets", "Resources");
  357. }
  358. string fullPath = System.IO.Path.Combine(
  359. System.IO.Path.Combine("Assets", "Resources"),
  360. "OVRPlatformToolSettings.asset"
  361. );
  362. UnityEditor.AssetDatabase.CreateAsset(instance, fullPath);
  363. // Initialize cross platform default values for the new instance of OVRPlatformToolSettings here
  364. if (instance != null)
  365. {
  366. for (int i = 0; i < (int)OVRPlatformTool.TargetPlatform.None; i++)
  367. {
  368. EditorPrefs.SetString("OVRPlatformToolSettings_ReleaseChannel" + i, DEFAULT_RELEASE_CHANNEL);
  369. instance.assetConfigs[i] = new AssetConfigList();
  370. }
  371. instance.riftRedistPackages = new List<RedistPackage>();
  372. }
  373. }
  374. }
  375. return instance;
  376. }
  377. set
  378. {
  379. instance = value;
  380. }
  381. }
  382. }
  383. // Wrapper for asset config list so that it can be serialized properly
  384. [System.Serializable]
  385. public class AssetConfigList
  386. {
  387. public List<AssetConfig> configList;
  388. public AssetConfigList()
  389. {
  390. configList = new List<AssetConfig>();
  391. }
  392. }
  393. [System.Serializable]
  394. public class AssetConfig
  395. {
  396. public enum AssetType
  397. {
  398. DEFAULT,
  399. STORE,
  400. LANGUAGE_PACK,
  401. };
  402. public string name;
  403. public bool required;
  404. public AssetType type;
  405. public string sku;
  406. private bool foldout;
  407. public AssetConfig(string assetName)
  408. {
  409. name = assetName;
  410. }
  411. public bool GetFoldoutState()
  412. {
  413. return foldout;
  414. }
  415. public void SetFoldoutState(bool state)
  416. {
  417. foldout = state;
  418. }
  419. }
  420. [System.Serializable]
  421. public class RedistPackage
  422. {
  423. public bool include = false;
  424. public string name;
  425. public string id;
  426. public RedistPackage(string pkgName, string pkgId)
  427. {
  428. name = pkgName;
  429. id = pkgId;
  430. }
  431. }
  432. }