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.

701 lines
20 KiB

  1. /************************************************************************************
  2. Copyright : Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved.
  3. Licensed under the Oculus SDK License Version 3.4.1 (the "License");
  4. you may not use the Oculus SDK except in compliance with the License,
  5. which is provided at the time of installation or download, or which
  6. otherwise accompanies this software in either electronic or hard copy form.
  7. You may obtain a copy of the License at
  8. https://developer.oculus.com/licenses/sdk-3.4.1
  9. Unless required by applicable law or agreed to in writing, the Oculus SDK
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. ************************************************************************************/
  15. using UnityEngine;
  16. using UnityEditor;
  17. using UnityEditor.Callbacks;
  18. using System;
  19. using System.Collections.Generic;
  20. using System.Linq;
  21. using System.Text.RegularExpressions;
  22. using System.IO;
  23. using System.Diagnostics;
  24. [InitializeOnLoad]
  25. class OVRPluginUpdater
  26. {
  27. enum PluginPlatform
  28. {
  29. Android,
  30. AndroidUniversal,
  31. OSXUniversal,
  32. Win,
  33. Win64,
  34. }
  35. class PluginPackage
  36. {
  37. public string RootPath;
  38. public System.Version Version;
  39. public Dictionary<PluginPlatform, string> Plugins = new Dictionary<PluginPlatform, string>();
  40. public bool IsBundledPluginPackage()
  41. {
  42. return (RootPath == GetBundledPluginRootPath());
  43. }
  44. public bool IsEnabled()
  45. {
  46. // TODO: Check each individual platform rather than using the Win64 DLL status for the overall package status.
  47. string path = "";
  48. if (Plugins.TryGetValue(PluginPlatform.Win64, out path))
  49. {
  50. return File.Exists(path);
  51. }
  52. return false;
  53. }
  54. public bool IsAndroidUniversalEnabled()
  55. {
  56. string path = "";
  57. if (Plugins.TryGetValue(PluginPlatform.AndroidUniversal, out path))
  58. {
  59. if (File.Exists(path))
  60. {
  61. string basePath = GetCurrentProjectPath();
  62. string relPath = path.Substring(basePath.Length + 1);
  63. PluginImporter pi = PluginImporter.GetAtPath(relPath) as PluginImporter;
  64. if (pi != null)
  65. {
  66. return pi.GetCompatibleWithPlatform(BuildTarget.Android);
  67. }
  68. }
  69. }
  70. return false;
  71. }
  72. public bool IsAndroidUniversalPresent()
  73. {
  74. string path = "";
  75. if (Plugins.TryGetValue(PluginPlatform.AndroidUniversal, out path))
  76. {
  77. string disabledPath = path + GetDisabledPluginSuffix();
  78. if (File.Exists(path) || File.Exists(disabledPath))
  79. {
  80. return true;
  81. }
  82. }
  83. return false;
  84. }
  85. }
  86. private static bool restartPending = false;
  87. private static bool unityRunningInBatchmode = false;
  88. private static bool unityVersionSupportsAndroidUniversal = false;
  89. private static bool enableAndroidUniversalSupport = true;
  90. private static System.Version invalidVersion = new System.Version("0.0.0");
  91. static OVRPluginUpdater()
  92. {
  93. EditorApplication.delayCall += OnDelayCall;
  94. }
  95. static void OnDelayCall()
  96. {
  97. if (System.Environment.CommandLine.Contains("-batchmode"))
  98. {
  99. unityRunningInBatchmode = true;
  100. }
  101. if (enableAndroidUniversalSupport)
  102. {
  103. #if UNITY_2018_3_OR_NEWER
  104. unityVersionSupportsAndroidUniversal = true;
  105. #endif
  106. }
  107. if (ShouldAttemptPluginUpdate())
  108. {
  109. AttemptPluginUpdate(true);
  110. }
  111. }
  112. private static PluginPackage GetPluginPackage(string rootPath)
  113. {
  114. return new PluginPackage()
  115. {
  116. RootPath = rootPath,
  117. Version = GetPluginVersion(rootPath),
  118. Plugins = new Dictionary<PluginPlatform, string>()
  119. {
  120. { PluginPlatform.Android, rootPath + GetPluginBuildTargetSubPath(PluginPlatform.Android) },
  121. { PluginPlatform.AndroidUniversal, rootPath + GetPluginBuildTargetSubPath(PluginPlatform.AndroidUniversal) },
  122. { PluginPlatform.OSXUniversal, rootPath + GetPluginBuildTargetSubPath(PluginPlatform.OSXUniversal) },
  123. { PluginPlatform.Win, rootPath + GetPluginBuildTargetSubPath(PluginPlatform.Win) },
  124. { PluginPlatform.Win64, rootPath + GetPluginBuildTargetSubPath(PluginPlatform.Win64) },
  125. }
  126. };
  127. }
  128. private static PluginPackage GetBundledPluginPackage()
  129. {
  130. return GetPluginPackage(GetBundledPluginRootPath());
  131. }
  132. private static List<PluginPackage> GetAllUtilitiesPluginPackages()
  133. {
  134. string pluginRootPath = GetUtilitiesPluginRootPath();
  135. List<PluginPackage> packages = new List<PluginPackage>();
  136. if (Directory.Exists(pluginRootPath))
  137. {
  138. var dirs = Directory.GetDirectories(pluginRootPath);
  139. foreach(string dir in dirs)
  140. {
  141. packages.Add(GetPluginPackage(dir));
  142. }
  143. }
  144. return packages;
  145. }
  146. private static string GetCurrentProjectPath()
  147. {
  148. return Directory.GetParent(Application.dataPath).FullName;
  149. }
  150. private static string GetUtilitiesPluginRootPath()
  151. {
  152. return GetUtilitiesRootPath() + @"/Plugins";
  153. }
  154. private static string GetUtilitiesRootPath()
  155. {
  156. var so = ScriptableObject.CreateInstance(typeof(OVRPluginUpdaterStub));
  157. var script = MonoScript.FromScriptableObject(so);
  158. string assetPath = AssetDatabase.GetAssetPath(script);
  159. string editorDir = Directory.GetParent(assetPath).FullName;
  160. string ovrDir = Directory.GetParent(editorDir).FullName;
  161. return ovrDir;
  162. }
  163. private static string GetBundledPluginRootPath()
  164. {
  165. string basePath = EditorApplication.applicationContentsPath;
  166. string pluginPath = @"/UnityExtensions/Unity/VR";
  167. return basePath + pluginPath;
  168. }
  169. private static string GetPluginBuildTargetSubPath(PluginPlatform target)
  170. {
  171. string path = string.Empty;
  172. switch (target)
  173. {
  174. case PluginPlatform.Android:
  175. path = @"/Android/OVRPlugin.aar";
  176. break;
  177. case PluginPlatform.AndroidUniversal:
  178. path = @"/AndroidUniversal/OVRPlugin.aar";
  179. break;
  180. case PluginPlatform.OSXUniversal:
  181. path = @"/OSXUniversal/OVRPlugin.bundle";
  182. break;
  183. case PluginPlatform.Win:
  184. path = @"/Win/OVRPlugin.dll";
  185. break;
  186. case PluginPlatform.Win64:
  187. path = @"/Win64/OVRPlugin.dll";
  188. break;
  189. default:
  190. throw new ArgumentException("Attempted GetPluginBuildTargetSubPath() for unsupported BuildTarget: " + target);
  191. }
  192. return path;
  193. }
  194. private static string GetDisabledPluginSuffix()
  195. {
  196. return @".disabled";
  197. }
  198. private static System.Version GetPluginVersion(string path)
  199. {
  200. System.Version pluginVersion = invalidVersion;
  201. try
  202. {
  203. pluginVersion = new System.Version(Path.GetFileName(path));
  204. }
  205. catch
  206. {
  207. pluginVersion = invalidVersion;
  208. }
  209. if (pluginVersion == invalidVersion)
  210. {
  211. //Unable to determine version from path, fallback to Win64 DLL meta data
  212. path += GetPluginBuildTargetSubPath(PluginPlatform.Win64);
  213. if (!File.Exists(path))
  214. {
  215. path += GetDisabledPluginSuffix();
  216. if (!File.Exists(path))
  217. {
  218. return invalidVersion;
  219. }
  220. }
  221. FileVersionInfo pluginVersionInfo = FileVersionInfo.GetVersionInfo(path);
  222. if (pluginVersionInfo == null || pluginVersionInfo.ProductVersion == null || pluginVersionInfo.ProductVersion == "")
  223. {
  224. return invalidVersion;
  225. }
  226. pluginVersion = new System.Version(pluginVersionInfo.ProductVersion);
  227. }
  228. return pluginVersion;
  229. }
  230. public static string GetVersionDescription(System.Version version)
  231. {
  232. bool isVersionValid = (version != invalidVersion);
  233. return isVersionValid ? version.ToString() : "(Unknown)";
  234. }
  235. private static bool ShouldAttemptPluginUpdate()
  236. {
  237. if (unityRunningInBatchmode)
  238. {
  239. return false;
  240. }
  241. else
  242. {
  243. return !UnitySupportsEnabledAndroidPlugin() || (autoUpdateEnabled && !restartPending && !Application.isPlaying);
  244. }
  245. }
  246. private static void DisableAllUtilitiesPluginPackages()
  247. {
  248. List<PluginPackage> allUtilsPluginPkgs = GetAllUtilitiesPluginPackages();
  249. foreach(PluginPackage pluginPkg in allUtilsPluginPkgs)
  250. {
  251. foreach(string path in pluginPkg.Plugins.Values)
  252. {
  253. if ((Directory.Exists(path)) || (File.Exists(path)))
  254. {
  255. string basePath = GetCurrentProjectPath();
  256. string relPath = path.Substring(basePath.Length + 1);
  257. string relDisabledPath = relPath + GetDisabledPluginSuffix();
  258. AssetDatabase.MoveAsset(relPath, relDisabledPath);
  259. AssetDatabase.ImportAsset(relDisabledPath, ImportAssetOptions.ForceUpdate);
  260. }
  261. }
  262. }
  263. AssetDatabase.Refresh();
  264. AssetDatabase.SaveAssets();
  265. }
  266. private static void EnablePluginPackage(PluginPackage pluginPkg)
  267. {
  268. foreach(var kvp in pluginPkg.Plugins)
  269. {
  270. PluginPlatform platform = kvp.Key;
  271. string path = kvp.Value;
  272. if ((Directory.Exists(path + GetDisabledPluginSuffix())) || (File.Exists(path + GetDisabledPluginSuffix())))
  273. {
  274. string basePath = GetCurrentProjectPath();
  275. string relPath = path.Substring(basePath.Length + 1);
  276. string relDisabledPath = relPath + GetDisabledPluginSuffix();
  277. AssetDatabase.MoveAsset(relDisabledPath, relPath);
  278. AssetDatabase.ImportAsset(relPath, ImportAssetOptions.ForceUpdate);
  279. PluginImporter pi = PluginImporter.GetAtPath(relPath) as PluginImporter;
  280. if (pi == null)
  281. {
  282. continue;
  283. }
  284. // Disable support for all platforms, then conditionally enable desired support below
  285. pi.SetCompatibleWithEditor(false);
  286. pi.SetCompatibleWithAnyPlatform(false);
  287. pi.SetCompatibleWithPlatform(BuildTarget.Android, false);
  288. pi.SetCompatibleWithPlatform(BuildTarget.StandaloneWindows, false);
  289. pi.SetCompatibleWithPlatform(BuildTarget.StandaloneWindows64, false);
  290. #if UNITY_2017_3_OR_NEWER
  291. pi.SetCompatibleWithPlatform(BuildTarget.StandaloneOSX, false);
  292. #else
  293. pi.SetCompatibleWithPlatform(BuildTarget.StandaloneOSXUniversal, false);
  294. pi.SetCompatibleWithPlatform(BuildTarget.StandaloneOSXIntel, false);
  295. pi.SetCompatibleWithPlatform(BuildTarget.StandaloneOSXIntel64, false);
  296. #endif
  297. switch (platform)
  298. {
  299. case PluginPlatform.Android:
  300. pi.SetCompatibleWithPlatform(BuildTarget.Android, !unityVersionSupportsAndroidUniversal);
  301. if (!unityVersionSupportsAndroidUniversal)
  302. {
  303. pi.SetPlatformData(BuildTarget.Android, "CPU", "ARMv7");
  304. }
  305. break;
  306. case PluginPlatform.AndroidUniversal:
  307. pi.SetCompatibleWithPlatform(BuildTarget.Android, unityVersionSupportsAndroidUniversal);
  308. break;
  309. case PluginPlatform.OSXUniversal:
  310. #if UNITY_2017_3_OR_NEWER
  311. pi.SetCompatibleWithPlatform(BuildTarget.StandaloneOSX, true);
  312. #else
  313. pi.SetCompatibleWithPlatform(BuildTarget.StandaloneOSXUniversal, true);
  314. pi.SetCompatibleWithPlatform(BuildTarget.StandaloneOSXIntel, true);
  315. pi.SetCompatibleWithPlatform(BuildTarget.StandaloneOSXIntel64, true);
  316. #endif
  317. pi.SetCompatibleWithEditor(true);
  318. pi.SetEditorData("CPU", "AnyCPU");
  319. pi.SetEditorData("OS", "OSX");
  320. pi.SetPlatformData("Editor", "CPU", "AnyCPU");
  321. pi.SetPlatformData("Editor", "OS", "OSX");
  322. break;
  323. case PluginPlatform.Win:
  324. pi.SetCompatibleWithPlatform(BuildTarget.StandaloneWindows, true);
  325. pi.SetCompatibleWithEditor(true);
  326. pi.SetEditorData("CPU", "X86");
  327. pi.SetEditorData("OS", "Windows");
  328. pi.SetPlatformData("Editor", "CPU", "X86");
  329. pi.SetPlatformData("Editor", "OS", "Windows");
  330. break;
  331. case PluginPlatform.Win64:
  332. pi.SetCompatibleWithPlatform(BuildTarget.StandaloneWindows64, true);
  333. pi.SetCompatibleWithEditor(true);
  334. pi.SetEditorData("CPU", "X86_64");
  335. pi.SetEditorData("OS", "Windows");
  336. pi.SetPlatformData("Editor", "CPU", "X86_64");
  337. pi.SetPlatformData("Editor", "OS", "Windows");
  338. break;
  339. default:
  340. throw new ArgumentException("Attempted EnablePluginPackage() for unsupported BuildTarget: " + platform);
  341. }
  342. AssetDatabase.ImportAsset(relPath, ImportAssetOptions.ForceUpdate);
  343. }
  344. }
  345. AssetDatabase.Refresh();
  346. AssetDatabase.SaveAssets();
  347. }
  348. private static readonly string autoUpdateEnabledKey = "Oculus_Utilities_OVRPluginUpdater_AutoUpdate_" + OVRManager.utilitiesVersion;
  349. private static bool autoUpdateEnabled
  350. {
  351. get {
  352. return PlayerPrefs.GetInt(autoUpdateEnabledKey, 1) == 1;
  353. }
  354. set {
  355. PlayerPrefs.SetInt(autoUpdateEnabledKey, value ? 1 : 0);
  356. }
  357. }
  358. [MenuItem("Oculus/Tools/Disable OVR Utilities Plugin")]
  359. private static void AttemptPluginDisable()
  360. {
  361. PluginPackage bundledPluginPkg = GetBundledPluginPackage();
  362. List<PluginPackage> allUtilsPluginPkgs = GetAllUtilitiesPluginPackages();
  363. PluginPackage enabledUtilsPluginPkg = null;
  364. foreach(PluginPackage pluginPkg in allUtilsPluginPkgs)
  365. {
  366. if (pluginPkg.IsEnabled())
  367. {
  368. if ((enabledUtilsPluginPkg == null) || (pluginPkg.Version > enabledUtilsPluginPkg.Version))
  369. {
  370. enabledUtilsPluginPkg = pluginPkg;
  371. }
  372. }
  373. }
  374. if (enabledUtilsPluginPkg == null)
  375. {
  376. if (unityRunningInBatchmode
  377. #if UNITY_2018_3_OR_NEWER
  378. || EditorUtility.DisplayDialog("Disable Oculus Utilities Plugin",
  379. "The OVRPlugin included with Oculus Utilities is already disabled."
  380. + " The OVRPlugin installed through the Package Manager will continue to be used.\n",
  381. "Ok",
  382. ""))
  383. #else
  384. || EditorUtility.DisplayDialog("Disable Oculus Utilities Plugin",
  385. "The OVRPlugin included with Oculus Utilities is already disabled."
  386. + " The OVRPlugin bundled with the Unity Editor will continue to be used.\n\n"
  387. + "Bundled version: "
  388. + GetVersionDescription(bundledPluginPkg.Version),
  389. "Ok",
  390. ""))
  391. #endif
  392. {
  393. return;
  394. }
  395. }
  396. else
  397. {
  398. if (unityRunningInBatchmode
  399. #if UNITY_2018_3_OR_NEWER
  400. || EditorUtility.DisplayDialog("Disable Oculus Utilities Plugin",
  401. "Do you want to disable the OVRPlugin included with Oculus Utilities and revert to the OVRPlugin installed through the Package Manager?\n\n"
  402. + "Current version: " + GetVersionDescription(enabledUtilsPluginPkg.Version),
  403. "Yes",
  404. "No"))
  405. #else
  406. || EditorUtility.DisplayDialog("Disable Oculus Utilities Plugin",
  407. "Do you want to disable the OVRPlugin included with Oculus Utilities and revert to the OVRPlugin bundled with the Unity Editor?\n\n"
  408. + "Current version: " + GetVersionDescription(enabledUtilsPluginPkg.Version)
  409. + "\nBundled version: " + GetVersionDescription(bundledPluginPkg.Version),
  410. "Yes",
  411. "No"))
  412. #endif
  413. {
  414. DisableAllUtilitiesPluginPackages();
  415. if (unityRunningInBatchmode
  416. #if UNITY_2018_3_OR_NEWER
  417. || EditorUtility.DisplayDialog("Restart Unity",
  418. "Now you will be using the OVRPlugin installed through Package Manager."
  419. + "\n\nPlease restart the Unity Editor to complete the update process.",
  420. "Restart",
  421. "Not Now"))
  422. #else
  423. || EditorUtility.DisplayDialog("Restart Unity",
  424. "OVRPlugin has been updated to "
  425. + GetVersionDescription(bundledPluginPkg.Version)
  426. + ".\n\nPlease restart the Unity Editor to complete the update process."
  427. #if !UNITY_2017_1_OR_NEWER
  428. + " You may need to manually relaunch Unity if you are using Unity 5.6 and higher."
  429. #endif
  430. ,
  431. "Restart",
  432. "Not Now"))
  433. #endif
  434. {
  435. RestartUnityEditor();
  436. }
  437. }
  438. }
  439. }
  440. [MenuItem("Oculus/Tools/Update OVR Utilities Plugin")]
  441. private static void RunPluginUpdate()
  442. {
  443. autoUpdateEnabled = true;
  444. AttemptPluginUpdate(false);
  445. }
  446. // Separate entry point needed since "-executeMethod" does not support parameters or default parameter values
  447. private static void BatchmodePluginUpdate()
  448. {
  449. OnDelayCall(); // manually invoke when running editor in batchmode
  450. AttemptPluginUpdate(false);
  451. }
  452. private static void AttemptPluginUpdate(bool triggeredByAutoUpdate)
  453. {
  454. OVRPlugin.SendEvent("attempt_plugin_update_auto", triggeredByAutoUpdate.ToString());
  455. PluginPackage bundledPluginPkg = GetBundledPluginPackage();
  456. List<PluginPackage> allUtilsPluginPkgs = GetAllUtilitiesPluginPackages();
  457. PluginPackage enabledUtilsPluginPkg = null;
  458. PluginPackage newestUtilsPluginPkg = null;
  459. foreach(PluginPackage pluginPkg in allUtilsPluginPkgs)
  460. {
  461. if ((newestUtilsPluginPkg == null) || (pluginPkg.Version > newestUtilsPluginPkg.Version))
  462. {
  463. newestUtilsPluginPkg = pluginPkg;
  464. }
  465. if (pluginPkg.IsEnabled())
  466. {
  467. if ((enabledUtilsPluginPkg == null) || (pluginPkg.Version > enabledUtilsPluginPkg.Version))
  468. {
  469. enabledUtilsPluginPkg = pluginPkg;
  470. }
  471. }
  472. }
  473. bool reenableCurrentPluginPkg = false;
  474. PluginPackage targetPluginPkg = null;
  475. if ((newestUtilsPluginPkg != null) && (newestUtilsPluginPkg.Version > bundledPluginPkg.Version))
  476. {
  477. if ((enabledUtilsPluginPkg == null) || (enabledUtilsPluginPkg.Version != newestUtilsPluginPkg.Version))
  478. {
  479. targetPluginPkg = newestUtilsPluginPkg;
  480. }
  481. }
  482. else if ((enabledUtilsPluginPkg != null) && (enabledUtilsPluginPkg.Version < bundledPluginPkg.Version))
  483. {
  484. targetPluginPkg = bundledPluginPkg;
  485. }
  486. PluginPackage currentPluginPkg = (enabledUtilsPluginPkg != null) ? enabledUtilsPluginPkg : bundledPluginPkg;
  487. if ((targetPluginPkg == null) && !UnitySupportsEnabledAndroidPlugin())
  488. {
  489. // Force reenabling the current package to configure the correct android plugin for this unity version.
  490. reenableCurrentPluginPkg = true;
  491. targetPluginPkg = currentPluginPkg;
  492. }
  493. if (targetPluginPkg == null)
  494. {
  495. if (!triggeredByAutoUpdate && !unityRunningInBatchmode)
  496. {
  497. #if UNITY_2018_3_OR_NEWER
  498. EditorUtility.DisplayDialog("Update Oculus Utilities Plugin",
  499. "OVRPlugin is already up to date.\n\nCurrent version: "
  500. + GetVersionDescription(currentPluginPkg.Version),
  501. "Ok",
  502. "");
  503. #else
  504. EditorUtility.DisplayDialog("Update Oculus Utilities Plugin",
  505. "OVRPlugin is already up to date.\n\nCurrent version: "
  506. + GetVersionDescription(currentPluginPkg.Version) + "\nBundled version: "
  507. + GetVersionDescription(bundledPluginPkg.Version),
  508. "Ok",
  509. "");
  510. #endif
  511. }
  512. return; // No update necessary.
  513. }
  514. System.Version targetVersion = targetPluginPkg.Version;
  515. bool userAcceptsUpdate = false;
  516. if (unityRunningInBatchmode)
  517. {
  518. userAcceptsUpdate = true;
  519. }
  520. else
  521. {
  522. string dialogBody = "Oculus Utilities has detected that a newer OVRPlugin is available."
  523. + " Using the newest version is recommended. Do you want to enable it?\n\n"
  524. + "Current version: "
  525. + GetVersionDescription(currentPluginPkg.Version)
  526. + "\nAvailable version: "
  527. + targetVersion;
  528. if (reenableCurrentPluginPkg)
  529. {
  530. dialogBody = "Oculus Utilities has detected a configuration change that requires re-enabling the current OVRPlugin."
  531. + " Do you want to proceed?\n\nCurrent version: "
  532. + GetVersionDescription(currentPluginPkg.Version);
  533. }
  534. int dialogResult = EditorUtility.DisplayDialogComplex("Update Oculus Utilities Plugin", dialogBody, "Yes", "No, Don't Ask Again", "No");
  535. switch (dialogResult)
  536. {
  537. case 0: // "Yes"
  538. userAcceptsUpdate = true;
  539. break;
  540. case 1: // "No, Don't Ask Again"
  541. autoUpdateEnabled = false;
  542. EditorUtility.DisplayDialog("Oculus Utilities OVRPlugin",
  543. "To manually update in the future, use the following menu option:\n\n"
  544. + "[Oculus -> Tools -> Update OVR Utilities Plugin]",
  545. "Ok",
  546. "");
  547. return;
  548. case 2: // "No"
  549. return;
  550. }
  551. }
  552. if (userAcceptsUpdate)
  553. {
  554. DisableAllUtilitiesPluginPackages();
  555. if (!targetPluginPkg.IsBundledPluginPackage())
  556. {
  557. EnablePluginPackage(targetPluginPkg);
  558. }
  559. if (unityRunningInBatchmode
  560. || EditorUtility.DisplayDialog("Restart Unity",
  561. "OVRPlugin has been updated to "
  562. + GetVersionDescription(targetPluginPkg.Version)
  563. + ".\n\nPlease restart the Unity Editor to complete the update process."
  564. #if !UNITY_2017_1_OR_NEWER
  565. + " You may need to manually relaunch Unity if you are using Unity 5.6 and higher."
  566. #endif
  567. ,
  568. "Restart",
  569. "Not Now"))
  570. {
  571. RestartUnityEditor();
  572. }
  573. }
  574. }
  575. private static bool UnitySupportsEnabledAndroidPlugin()
  576. {
  577. List<PluginPackage> allUtilsPluginPkgs = GetAllUtilitiesPluginPackages();
  578. foreach(PluginPackage pluginPkg in allUtilsPluginPkgs)
  579. {
  580. if (pluginPkg.IsEnabled())
  581. {
  582. if (pluginPkg.IsAndroidUniversalEnabled() && !unityVersionSupportsAndroidUniversal)
  583. {
  584. // Android Universal should only be enabled on supported Unity versions since it can prevent app launch.
  585. return false;
  586. }
  587. else if (!pluginPkg.IsAndroidUniversalEnabled() && pluginPkg.IsAndroidUniversalPresent() && unityVersionSupportsAndroidUniversal)
  588. {
  589. // Android Universal is present and should be enabled on supported Unity versions since ARM64 config will fail otherwise.
  590. return false;
  591. }
  592. }
  593. }
  594. return true;
  595. }
  596. private static void RestartUnityEditor()
  597. {
  598. if (unityRunningInBatchmode)
  599. {
  600. EditorApplication.Exit(0);
  601. }
  602. else
  603. {
  604. restartPending = true;
  605. EditorApplication.OpenProject(GetCurrentProjectPath());
  606. }
  607. }
  608. }