ProjectTipsWindow.cs 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870
  1. /****************************************************************************
  2. * Copyright 2019 Nreal Techonology Limited.All rights reserved.
  3. *
  4. * This file is part of NRSDK.
  5. *
  6. * https://www.nreal.ai/
  7. *
  8. *****************************************************************************/
  9. namespace NRKernal
  10. {
  11. using UnityEditor;
  12. using UnityEngine;
  13. using System.IO;
  14. using UnityEngine.Rendering;
  15. using System.Collections.Generic;
  16. using NRKernal.Release;
  17. using LitJson;
  18. using System.Linq;
  19. using System;
  20. using System.Text;
  21. /// <summary> Form for viewing the project tips. </summary>
  22. [InitializeOnLoad]
  23. public class ProjectTipsWindow : EditorWindow
  24. {
  25. /// <summary> A check. </summary>
  26. private abstract class Check
  27. {
  28. /// <summary> The key. </summary>
  29. protected string _key;
  30. protected MessageType _level;
  31. public MessageType level
  32. {
  33. get
  34. {
  35. return _level;
  36. }
  37. }
  38. public Check(MessageType level)
  39. {
  40. _level = level;
  41. }
  42. /// <summary> Ignores this object. </summary>
  43. public void Ignore()
  44. {
  45. EditorPrefs.SetBool(ignorePrefix + _key, true);
  46. }
  47. /// <summary> Query if this object is ignored. </summary>
  48. /// <returns> True if ignored, false if not. </returns>
  49. public bool IsIgnored()
  50. {
  51. return EditorPrefs.HasKey(ignorePrefix + _key);
  52. }
  53. /// <summary> Deletes the ignore. </summary>
  54. public void DeleteIgnore()
  55. {
  56. EditorPrefs.DeleteKey(ignorePrefix + _key);
  57. }
  58. /// <summary> Query if this object is valid. </summary>
  59. /// <returns> True if valid, false if not. </returns>
  60. public abstract bool IsValid();
  61. /// <summary> Draw graphical user interface. </summary>
  62. public abstract void DrawGUI();
  63. /// <summary> Query if this object is fixable. </summary>
  64. /// <returns> True if fixable, false if not. </returns>
  65. public abstract bool IsFixable();
  66. /// <summary> Fixes this object. </summary>
  67. public abstract void Fix();
  68. protected void DrawContent(string title, string message)
  69. {
  70. EditorGUILayout.HelpBox(title, level);
  71. EditorGUILayout.LabelField(message, EditorStyles.textArea);
  72. }
  73. }
  74. /// <summary> A ckeck for buildTarget . </summary>
  75. private class CkeckBuildTargetAndroid : Check
  76. {
  77. /// <summary> Default constructor. </summary>
  78. public CkeckBuildTargetAndroid(MessageType level) : base(level)
  79. {
  80. _key = this.GetType().Name;
  81. }
  82. /// <summary> Query if this object is valid. </summary>
  83. /// <returns> True if valid, false if not. </returns>
  84. public override bool IsValid()
  85. {
  86. return EditorUserBuildSettings.activeBuildTarget == BuildTarget.Android;
  87. }
  88. /// <summary> Draw graphical user interface. </summary>
  89. public override void DrawGUI()
  90. {
  91. string message = @"In order to develop on NRSDK, BuildTarget must be set to Android.
  92. in panel of Player Settings, choose 'Androi' in platform list, and click 'Switch Platform' button.";
  93. DrawContent("BuildTarget is Android", message);
  94. }
  95. /// <summary> Query if this object is fixable. </summary>
  96. /// <returns> True if fixable, false if not. </returns>
  97. public override bool IsFixable()
  98. {
  99. return true;
  100. }
  101. /// <summary> Fixes this object. </summary>
  102. public override void Fix()
  103. {
  104. if (EditorUserBuildSettings.activeBuildTarget != BuildTarget.Android)
  105. {
  106. EditorUserBuildSettings.SwitchActiveBuildTarget(BuildTargetGroup.Android, BuildTarget.Android);
  107. }
  108. }
  109. }
  110. /// <summary> A ckeck android vsyn. </summary>
  111. private class CkeckAndroidVsyn : Check
  112. {
  113. /// <summary> Default constructor. </summary>
  114. public CkeckAndroidVsyn(MessageType level) : base(level)
  115. {
  116. _key = this.GetType().Name;
  117. }
  118. /// <summary> Query if this object is valid. </summary>
  119. /// <returns> True if valid, false if not. </returns>
  120. public override bool IsValid()
  121. {
  122. return QualitySettings.vSyncCount == 0;
  123. }
  124. /// <summary> Draw graphical user interface. </summary>
  125. public override void DrawGUI()
  126. {
  127. string message = @"In order to render correct on mobile devices, the vSyn in quality settings must be disabled.
  128. in dropdown list of Quality Settings > V Sync Count, choose 'Dont't Sync' for all levels.";
  129. DrawContent("vSyn is opened on Mobile Devices", message);
  130. }
  131. /// <summary> Query if this object is fixable. </summary>
  132. /// <returns> True if fixable, false if not. </returns>
  133. public override bool IsFixable()
  134. {
  135. return true;
  136. }
  137. /// <summary> Fixes this object. </summary>
  138. public override void Fix()
  139. {
  140. if (EditorUserBuildSettings.activeBuildTarget == BuildTarget.Android ||
  141. EditorUserBuildSettings.activeBuildTarget == BuildTarget.iOS)
  142. {
  143. QualitySettings.vSyncCount = 0;
  144. }
  145. }
  146. }
  147. /// <summary> Ckeck android SD card permission descriptor. </summary>
  148. private class CkeckAndroidSDCardPermission : Check
  149. {
  150. /// <summary> Default constructor. </summary>
  151. public CkeckAndroidSDCardPermission(MessageType level) : base(level)
  152. {
  153. _key = this.GetType().Name;
  154. }
  155. /// <summary> Query if this object is valid. </summary>
  156. /// <returns> True if valid, false if not. </returns>
  157. public override bool IsValid()
  158. {
  159. if (EditorUserBuildSettings.activeBuildTarget == BuildTarget.Android)
  160. {
  161. return PlayerSettings.Android.forceSDCardPermission;
  162. }
  163. else
  164. {
  165. return false;
  166. }
  167. }
  168. /// <summary> Draw graphical user interface. </summary>
  169. public override void DrawGUI()
  170. {
  171. string message = @"In order to run correct on mobile devices, the sdcard write permission should be set.
  172. in dropdown list of Player Settings > Other Settings > Write Permission, choose 'External(SDCard)'.";
  173. DrawContent("Sdcard permission not available", message);
  174. }
  175. /// <summary> Query if this object is fixable. </summary>
  176. /// <returns> True if fixable, false if not. </returns>
  177. public override bool IsFixable()
  178. {
  179. return true;
  180. }
  181. /// <summary> Fixes this object. </summary>
  182. public override void Fix()
  183. {
  184. if (EditorUserBuildSettings.activeBuildTarget == BuildTarget.Android)
  185. {
  186. PlayerSettings.Android.forceSDCardPermission = true;
  187. }
  188. }
  189. }
  190. /// <summary> Android minSdkVersion should be higher than 26. </summary>
  191. private class CkeckAndroidMinAPILevel : Check
  192. {
  193. public CkeckAndroidMinAPILevel(MessageType level) : base(level)
  194. {
  195. _key = this.GetType().Name;
  196. }
  197. public override bool IsValid()
  198. {
  199. if (EditorUserBuildSettings.activeBuildTarget == BuildTarget.Android)
  200. {
  201. return PlayerSettings.Android.minSdkVersion >= AndroidSdkVersions.AndroidApiLevel26 ||
  202. PlayerSettings.Android.minSdkVersion == AndroidSdkVersions.AndroidApiLevelAuto;
  203. }
  204. else
  205. {
  206. return false;
  207. }
  208. }
  209. /// <summary> Draw graphical user interface. </summary>
  210. public override void DrawGUI()
  211. {
  212. string message = @"In order to run correct on mobile devices, Android minSdkVersion should be higher than 26.";
  213. DrawContent("Android minSdkVersion should be higher than 26", message);
  214. }
  215. /// <summary> Query if this object is fixable. </summary>
  216. /// <returns> True if fixable, false if not. </returns>
  217. public override bool IsFixable()
  218. {
  219. return true;
  220. }
  221. /// <summary> Fixes this object. </summary>
  222. public override void Fix()
  223. {
  224. if (EditorUserBuildSettings.activeBuildTarget == BuildTarget.Android)
  225. {
  226. PlayerSettings.Android.minSdkVersion = AndroidSdkVersions.AndroidApiLevel26;
  227. }
  228. }
  229. }
  230. /// <summary> A ckeck android orientation. </summary>
  231. private class CkeckAndroidOrientation : Check
  232. {
  233. /// <summary> Default constructor. </summary>
  234. public CkeckAndroidOrientation(MessageType level) : base(level)
  235. {
  236. _key = this.GetType().Name;
  237. }
  238. /// <summary> Query if this object is valid. </summary>
  239. /// <returns> True if valid, false if not. </returns>
  240. public override bool IsValid()
  241. {
  242. return PlayerSettings.defaultInterfaceOrientation == UIOrientation.Portrait;
  243. }
  244. /// <summary> Draw graphical user interface. </summary>
  245. public override void DrawGUI()
  246. {
  247. string message = @"In order to display correct on mobile devices, the orientation should be set to portrait.
  248. in dropdown list of Player Settings > Resolution and Presentation > Default Orientation, choose 'Portrait'.";
  249. DrawContent("Orientation is not portrait", message);
  250. }
  251. /// <summary> Query if this object is fixable. </summary>
  252. /// <returns> True if fixable, false if not. </returns>
  253. public override bool IsFixable()
  254. {
  255. return true;
  256. }
  257. /// <summary> Fixes this object. </summary>
  258. public override void Fix()
  259. {
  260. if (EditorUserBuildSettings.activeBuildTarget == BuildTarget.Android)
  261. {
  262. PlayerSettings.defaultInterfaceOrientation = UIOrientation.Portrait;
  263. }
  264. }
  265. }
  266. /// <summary> A ckeck android graphics a pi. </summary>
  267. private class CkeckAndroidGraphicsAPI : Check
  268. {
  269. /// <summary> Default constructor. </summary>
  270. public CkeckAndroidGraphicsAPI(MessageType level) : base(level)
  271. {
  272. _key = this.GetType().Name;
  273. }
  274. /// <summary> Query if this object is valid. </summary>
  275. /// <returns> True if valid, false if not. </returns>
  276. public override bool IsValid()
  277. {
  278. if (EditorUserBuildSettings.activeBuildTarget == BuildTarget.Android)
  279. {
  280. var graphics = PlayerSettings.GetGraphicsAPIs(BuildTarget.Android);
  281. if (graphics != null && graphics.Length == 1 &&
  282. graphics[0] == UnityEngine.Rendering.GraphicsDeviceType.OpenGLES3)
  283. {
  284. return true;
  285. }
  286. return false;
  287. }
  288. else
  289. {
  290. return false;
  291. }
  292. }
  293. /// <summary> Draw graphical user interface. </summary>
  294. public override void DrawGUI()
  295. {
  296. string message = @"In order to render correct on mobile devices, the graphicsAPIs should be set to OpenGLES3.
  297. in dropdown list of Player Settings > Other Settings > Graphics APIs , choose 'OpenGLES3'.";
  298. DrawContent("GraphicsAPIs is not OpenGLES3", message);
  299. }
  300. /// <summary> Query if this object is fixable. </summary>
  301. /// <returns> True if fixable, false if not. </returns>
  302. public override bool IsFixable()
  303. {
  304. return true;
  305. }
  306. /// <summary> Fixes this object. </summary>
  307. public override void Fix()
  308. {
  309. if (EditorUserBuildSettings.activeBuildTarget == BuildTarget.Android)
  310. {
  311. PlayerSettings.SetGraphicsAPIs(BuildTarget.Android, new GraphicsDeviceType[1] { GraphicsDeviceType.OpenGLES3 });
  312. }
  313. }
  314. }
  315. /// <summary> A ckeck color space. </summary>
  316. private class CkeckColorSpace : Check
  317. {
  318. /// <summary> Default constructor. </summary>
  319. public CkeckColorSpace(MessageType level) : base(level)
  320. {
  321. _key = this.GetType().Name;
  322. }
  323. /// <summary> Query if this object is valid. </summary>
  324. /// <returns> True if valid, false if not. </returns>
  325. public override bool IsValid()
  326. {
  327. return PlayerSettings.colorSpace == ColorSpace.Linear;
  328. }
  329. /// <summary> Draw graphical user interface. </summary>
  330. public override void DrawGUI()
  331. {
  332. string message = @"In order to display correct on mobile devices, the colorSpace should be set to linear.
  333. in dropdown list of Player Settings > Other Settings > Color Space, choose 'Linear'.";
  334. DrawContent("ColorSpace is not Linear", message);
  335. }
  336. /// <summary> Query if this object is fixable. </summary>
  337. /// <returns> True if fixable, false if not. </returns>
  338. public override bool IsFixable()
  339. {
  340. return true;
  341. }
  342. /// <summary> Fixes this object. </summary>
  343. public override void Fix()
  344. {
  345. if (EditorUserBuildSettings.activeBuildTarget == BuildTarget.Android)
  346. {
  347. PlayerSettings.colorSpace = ColorSpace.Linear;
  348. }
  349. }
  350. }
  351. /// <summary> A ckeck color space. </summary>
  352. private class CkeckXRDefine : Check
  353. {
  354. /// <summary> Default constructor. </summary>
  355. public CkeckXRDefine(MessageType level) : base(level)
  356. {
  357. _key = this.GetType().Name;
  358. }
  359. /// <summary> Query if this object is valid. </summary>
  360. /// <returns> True if valid, false if not. </returns>
  361. public override bool IsValid()
  362. {
  363. var dict = PackageUtility.GetAllPackagesByManifest();
  364. if (dict.Count == 0 || !dict.ContainsKey(NativeConstants.XRPLUGIN))
  365. {
  366. return !DefineSymbolsUtility.HasSymbol(NativeConstants.XRDEFINE);
  367. }
  368. else
  369. {
  370. return DefineSymbolsUtility.HasSymbol(NativeConstants.XRDEFINE);
  371. }
  372. }
  373. /// <summary> Draw graphical user interface. </summary>
  374. public override void DrawGUI()
  375. {
  376. string message = @"Not configured correctly.";
  377. DrawContent("Define is not correctly.", message);
  378. }
  379. /// <summary> Query if this object is fixable. </summary>
  380. /// <returns> True if fixable, false if not. </returns>
  381. public override bool IsFixable()
  382. {
  383. return true;
  384. }
  385. /// <summary> Fixes this object. </summary>
  386. public override void Fix()
  387. {
  388. var dict = PackageUtility.GetAllPackagesByManifest();
  389. if (dict.Count == 0 || !dict.ContainsKey(NativeConstants.XRPLUGIN))
  390. {
  391. DefineSymbolsUtility.RemoveSymbol(NativeConstants.XRDEFINE);
  392. }
  393. else
  394. {
  395. DefineSymbolsUtility.AddSymbol(NativeConstants.XRDEFINE);
  396. }
  397. }
  398. }
  399. /// <summary> A ckeck color space. </summary>
  400. private class CkeckDependency : Check
  401. {
  402. public class PackageInfo
  403. {
  404. public string name;
  405. public string version;
  406. }
  407. private PackageInfo XRPluginPackageInfo;
  408. /// <summary> Default constructor. </summary>
  409. public CkeckDependency(MessageType level) : base(level)
  410. {
  411. _key = this.GetType().Name;
  412. }
  413. private void FreshXRPluginVersion(Action<PackageInfo> callback = null)
  414. {
  415. PackageUtility.GetAllPackages((info) =>
  416. {
  417. if (!info.isSuccess)
  418. {
  419. NRDebugger.Warning("Can not get all packages info...");
  420. return;
  421. }
  422. var package_result = info.packages.Select((package) =>
  423. {
  424. UnityEditor.PackageManager.PackageInfo p = null;
  425. if (package.name.Equals(NativeConstants.XRPLUGIN))
  426. {
  427. p = package;
  428. }
  429. return p;
  430. }).First();
  431. if (XRPluginPackageInfo == null)
  432. {
  433. XRPluginPackageInfo = new PackageInfo();
  434. }
  435. if (package_result != null)
  436. {
  437. XRPluginPackageInfo.name = package_result.name;
  438. XRPluginPackageInfo.version = package_result.version;
  439. }
  440. callback?.Invoke(XRPluginPackageInfo);
  441. });
  442. }
  443. /// <summary> Query if this object is valid. </summary>
  444. /// <returns> True if valid, false if not. </returns>
  445. public override bool IsValid()
  446. {
  447. if (XRPluginPackageInfo == null)
  448. {
  449. FreshXRPluginVersion();
  450. return true;
  451. }
  452. bool result = true;
  453. if (string.Compare(XRPluginPackageInfo.version, NativeConstants.XRPLUGIN_MIN_VERSION) < 0)
  454. {
  455. result = false;
  456. }
  457. if (!result)
  458. {
  459. FreshXRPluginVersion();
  460. }
  461. return result;
  462. }
  463. public override void DrawGUI()
  464. {
  465. const string title = "Check dependencies";
  466. const string messageFormat = "package \"{0}\" version is \"{1}\", need to upgrade to \"{2}\"";
  467. StringBuilder st = new StringBuilder();
  468. if (XRPluginPackageInfo != null)
  469. {
  470. if (string.Compare(XRPluginPackageInfo.version, NativeConstants.XRPLUGIN_MIN_VERSION) < 0)
  471. {
  472. st.AppendLine(string.Format(messageFormat, XRPluginPackageInfo.name, XRPluginPackageInfo.version, NativeConstants.XRPLUGIN_MIN_VERSION));
  473. }
  474. }
  475. else
  476. {
  477. FreshXRPluginVersion();
  478. st.AppendLine("Waitting to get dependencies version...");
  479. }
  480. DrawContent(title, st.ToString());
  481. }
  482. /// <summary> Query if this object is fixable. </summary>
  483. /// <returns> True if fixable, false if not. </returns>
  484. public override bool IsFixable()
  485. {
  486. return true;
  487. }
  488. /// <summary> Fixes this object. </summary>
  489. public override void Fix()
  490. {
  491. if (string.Compare(XRPluginPackageInfo.version, NativeConstants.XRPLUGIN_MIN_VERSION) < 0)
  492. {
  493. Debug.LogFormat("[CkeckDependency] Fix dependency , current:{0} dependency:{1}",
  494. XRPluginPackageInfo.version, NativeConstants.XRPLUGIN_MIN_VERSION);
  495. FixedXRProviderPlugin(NativeConstants.XRPLUGIN, NativeConstants.XRPLUGIN_MIN_VERSION);
  496. }
  497. }
  498. public static void FixedXRProviderPlugin(string key, string version)
  499. {
  500. string path = Path.Combine(Directory.GetParent(Application.dataPath).FullName, "Packages/manifest.json");
  501. var contents = File.ReadAllLines(path);
  502. var json = JsonMapper.ToObject(File.ReadAllText(path));
  503. for (int i = 0; i < contents.Length; i++)
  504. {
  505. if (contents[i].Contains(key) && !contents[i].Contains('{'))
  506. {
  507. var valueofkey = json["dependencies"][key].ToString();
  508. if (key.Equals(NativeConstants.XRPLUGIN))
  509. {
  510. if (valueofkey.Contains('#'))
  511. {
  512. var value_params = valueofkey.Split('#');
  513. if (value_params.Length != 2)
  514. {
  515. NRDebugger.Warning("Dependencie format error:[{0}]", valueofkey);
  516. break;
  517. }
  518. valueofkey = string.Format("{0}#{1}", value_params[0], version);
  519. }
  520. else
  521. {
  522. valueofkey = string.Format("{0}#{1}", valueofkey, version);
  523. }
  524. }
  525. else
  526. {
  527. valueofkey = version;
  528. }
  529. contents[i] = string.Format(" \"{0}\": \"{1}\",", key, valueofkey.Replace("\"", ""));
  530. }
  531. }
  532. File.WriteAllLines(path, contents);
  533. }
  534. }
  535. /// <summary> A ckeck that android build system is gradle. </summary>
  536. private class CkeckAndroidBuildGradle: Check
  537. {
  538. /// <summary> Default constructor. </summary>
  539. public CkeckAndroidBuildGradle(MessageType level) : base(level)
  540. {
  541. _key = this.GetType().Name;
  542. }
  543. /// <summary> Query if this object is valid. </summary>
  544. /// <returns> True if valid, false if not. </returns>
  545. public override bool IsValid()
  546. {
  547. return EditorUserBuildSettings.androidBuildSystem == AndroidBuildSystem.Gradle;
  548. }
  549. /// <summary> Draw graphical user interface. </summary>
  550. public override void DrawGUI()
  551. {
  552. string message = @"";
  553. DrawContent("Gradle plugin is valid", message);
  554. }
  555. /// <summary> Query if this object is fixable. </summary>
  556. /// <returns> True if fixable, false if not. </returns>
  557. public override bool IsFixable()
  558. {
  559. return true;
  560. }
  561. /// <summary> Fixes this object. </summary>
  562. public override void Fix()
  563. {
  564. EditorUserBuildSettings.androidBuildSystem = AndroidBuildSystem.Gradle;
  565. }
  566. }
  567. /// <summary> The checks. </summary>
  568. private static Check[] checks = new Check[]
  569. {
  570. new CkeckBuildTargetAndroid(MessageType.Error),
  571. new CkeckAndroidVsyn(MessageType.Error),
  572. new CkeckAndroidMinAPILevel(MessageType.Error),
  573. //new CkeckAndroidSDCardPermission(),
  574. new CkeckAndroidOrientation(MessageType.Warning),
  575. new CkeckAndroidGraphicsAPI(MessageType.Error),
  576. new CkeckXRDefine(MessageType.Error),
  577. #if USING_XR_SDK
  578. new CkeckDependency(MessageType.Error)
  579. #endif
  580. new CkeckAndroidBuildGradle(MessageType.Error),
  581. //new CkeckColorSpace(Level.Error),
  582. };
  583. /// <summary> The window. </summary>
  584. private static ProjectTipsWindow m_Window;
  585. /// <summary> The scroll position. </summary>
  586. private Vector2 m_ScrollPosition;
  587. /// <summary> The ignore prefix. </summary>
  588. private const string ignorePrefix = "NRKernal.ignore";
  589. static ProjectTipsWindow()
  590. {
  591. EditorApplication.update -= Update;
  592. }
  593. /// <summary> Shows the window. </summary>
  594. [MenuItem("NRSDK/Project Tips", false, 50)]
  595. public static void ShowWindow()
  596. {
  597. m_Window = GetWindow<ProjectTipsWindow>(true);
  598. m_Window.minSize = new Vector2(320, 300);
  599. m_Window.maxSize = new Vector2(320, 800);
  600. m_Window.titleContent = new GUIContent("NRSDK | Project Tips");
  601. }
  602. /// <summary> Updates this object. </summary>
  603. private static void Update()
  604. {
  605. bool show = false;
  606. foreach (Check check in checks)
  607. {
  608. if (!check.IsIgnored() && !check.IsValid() && check.level > MessageType.Warning)
  609. {
  610. show = true;
  611. }
  612. }
  613. if (show)
  614. {
  615. ShowWindow();
  616. }
  617. EditorApplication.update -= Update;
  618. }
  619. /// <summary> Executes the 'graphical user interface' action. </summary>
  620. public void OnGUI()
  621. {
  622. var resourcePath = GetResourcePath();
  623. var logo = AssetDatabase.LoadAssetAtPath<Texture2D>(resourcePath + "icon.png");
  624. var rect = GUILayoutUtility.GetRect(position.width, 80, GUI.skin.box);
  625. GUI.DrawTexture(rect, logo, ScaleMode.ScaleToFit);
  626. string aboutText = "This window provides tips to help fix common issues with the NRSDK and your project.";
  627. EditorGUILayout.LabelField(aboutText, EditorStyles.textArea);
  628. int ignoredCount = 0;
  629. int fixableCount = 0;
  630. int invalidNotIgnored = 0;
  631. for (int i = 0; i < checks.Length; i++)
  632. {
  633. Check check = checks[i];
  634. bool ignored = check.IsIgnored();
  635. bool valid = check.IsValid();
  636. bool fixable = check.IsFixable();
  637. if (!valid && !ignored && fixable)
  638. {
  639. fixableCount++;
  640. }
  641. if (!valid && !ignored)
  642. {
  643. invalidNotIgnored++;
  644. }
  645. if (ignored)
  646. {
  647. ignoredCount++;
  648. }
  649. }
  650. Rect issuesRect = EditorGUILayout.GetControlRect();
  651. GUI.Box(new Rect(issuesRect.x - 4, issuesRect.y, issuesRect.width + 8, issuesRect.height), "Tips", EditorStyles.toolbarButton);
  652. if (invalidNotIgnored > 0)
  653. {
  654. m_ScrollPosition = GUILayout.BeginScrollView(m_ScrollPosition);
  655. {
  656. for (int i = 0; i < checks.Length; i++)
  657. {
  658. Check check = checks[i];
  659. if (!check.IsIgnored() && !check.IsValid())
  660. {
  661. invalidNotIgnored++;
  662. GUILayout.BeginVertical("box");
  663. {
  664. check.DrawGUI();
  665. EditorGUILayout.BeginHorizontal();
  666. {
  667. // Aligns buttons to the right
  668. GUILayout.FlexibleSpace();
  669. if (check.IsFixable())
  670. {
  671. if (GUILayout.Button("Fix"))
  672. check.Fix();
  673. }
  674. //if (GUILayout.Button("Ignore"))
  675. // check.Ignore();
  676. }
  677. EditorGUILayout.EndHorizontal();
  678. }
  679. GUILayout.EndVertical();
  680. }
  681. }
  682. }
  683. GUILayout.EndScrollView();
  684. }
  685. GUILayout.FlexibleSpace();
  686. if (invalidNotIgnored == 0)
  687. {
  688. GUILayout.BeginHorizontal();
  689. {
  690. GUILayout.FlexibleSpace();
  691. GUILayout.BeginVertical();
  692. {
  693. GUILayout.Label("No issues found");
  694. if (GUILayout.Button("Close Window"))
  695. Close();
  696. }
  697. GUILayout.EndVertical();
  698. GUILayout.FlexibleSpace();
  699. }
  700. GUILayout.EndHorizontal();
  701. GUILayout.FlexibleSpace();
  702. }
  703. EditorGUILayout.BeginHorizontal("box");
  704. {
  705. if (fixableCount > 0)
  706. {
  707. if (GUILayout.Button("Accept All"))
  708. {
  709. if (EditorUtility.DisplayDialog("Accept All", "Are you sure?", "Yes, Accept All", "Cancel"))
  710. {
  711. for (int i = 0; i < checks.Length; i++)
  712. {
  713. Check check = checks[i];
  714. if (!check.IsIgnored() &&
  715. !check.IsValid())
  716. {
  717. if (check.IsFixable())
  718. check.Fix();
  719. }
  720. }
  721. }
  722. }
  723. }
  724. //if (invalidNotIgnored > 0)
  725. //{
  726. // if (GUILayout.Button("Ignore All"))
  727. // {
  728. // if (EditorUtility.DisplayDialog("Ignore All", "Are you sure?", "Yes, Ignore All", "Cancel"))
  729. // {
  730. // for (int i = 0; i < checks.Length; i++)
  731. // {
  732. // Check check = checks[i];
  733. // if (!check.IsIgnored())
  734. // check.Ignore();
  735. // }
  736. // }
  737. // }
  738. //}
  739. //if (ignoredCount > 0)
  740. //{
  741. // if (GUILayout.Button("Show Ignored"))
  742. // {
  743. // foreach (Check check in checks)
  744. // check.DeleteIgnore();
  745. // }
  746. //}
  747. }
  748. GUILayout.EndHorizontal();
  749. }
  750. /// <summary> Gets resource path. </summary>
  751. /// <returns> The resource path. </returns>
  752. private string GetResourcePath()
  753. {
  754. var ms = MonoScript.FromScriptableObject(this);
  755. var path = AssetDatabase.GetAssetPath(ms);
  756. path = Path.GetDirectoryName(path);
  757. return path.Substring(0, path.Length - "Editor".Length - 1) + "Textures/";
  758. }
  759. }
  760. }