AstarUpdateWindow.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. using System;
  2. using UnityEditor;
  3. using UnityEngine;
  4. namespace Pathfinding {
  5. public class AstarUpdateWindow : EditorWindow {
  6. static GUIStyle largeStyle;
  7. static GUIStyle normalStyle;
  8. Version version;
  9. string summary;
  10. bool setReminder;
  11. public static AstarUpdateWindow Init (Version version, string summary) {
  12. // Get existing open window or if none, make a new one:
  13. AstarUpdateWindow window = EditorWindow.GetWindow<AstarUpdateWindow>(true, "", true);
  14. window.position = new Rect(Screen.currentResolution.width/2 - 300, Mathf.Max(5, Screen.currentResolution.height/3 - 150), 600, 400);
  15. window.version = version;
  16. window.summary = summary;
  17. window.titleContent = new GUIContent("New Version of the A* Pathfinding Project");
  18. return window;
  19. }
  20. public void OnDestroy () {
  21. if (version != null && !setReminder) {
  22. Debug.Log("Closed window, reminding again tomorrow");
  23. EditorPrefs.SetString("AstarRemindUpdateDate", DateTime.UtcNow.AddDays(1).ToString(System.Globalization.CultureInfo.InvariantCulture));
  24. EditorPrefs.SetString("AstarRemindUpdateVersion", version.ToString());
  25. }
  26. }
  27. void OnGUI () {
  28. if (largeStyle == null) {
  29. largeStyle = new GUIStyle(EditorStyles.largeLabel);
  30. largeStyle.fontSize = 32;
  31. largeStyle.alignment = TextAnchor.UpperCenter;
  32. largeStyle.richText = true;
  33. normalStyle = new GUIStyle(EditorStyles.label);
  34. normalStyle.wordWrap = true;
  35. normalStyle.richText = true;
  36. }
  37. if (version == null) {
  38. return;
  39. }
  40. GUILayout.Label("New Update Available!", largeStyle);
  41. GUILayout.Label("There is a new version of the <b>A* Pathfinding Project</b> available for download.\n" +
  42. "The new version is <b>" + version + "</b> you have <b>" + AstarPath.Version + "</b>\n\n"+
  43. "<i>Summary:</i>\n"+summary, normalStyle
  44. );
  45. GUILayout.FlexibleSpace();
  46. GUILayout.BeginHorizontal();
  47. GUILayout.FlexibleSpace();
  48. GUILayout.BeginVertical();
  49. Color col = GUI.color;
  50. GUI.backgroundColor *= new Color(0.5f, 1f, 0.5f);
  51. if (GUILayout.Button("Take me to the download page!", GUILayout.Height(30), GUILayout.MaxWidth(300))) {
  52. Application.OpenURL(AstarUpdateChecker.GetURL("download"));
  53. }
  54. GUI.backgroundColor = col;
  55. if (GUILayout.Button("What's new? (full changelog)")) {
  56. Application.OpenURL(AstarUpdateChecker.GetURL("changelog"));
  57. }
  58. GUILayout.EndVertical();
  59. GUILayout.FlexibleSpace();
  60. GUILayout.EndHorizontal();
  61. GUILayout.FlexibleSpace();
  62. GUILayout.BeginHorizontal();
  63. if (GUILayout.Button("Skip this version", GUILayout.MaxWidth(100))) {
  64. EditorPrefs.SetString("AstarSkipUpToVersion", version.ToString());
  65. setReminder = true;
  66. Close();
  67. }
  68. if (GUILayout.Button("Remind me later ( 1 week )", GUILayout.MaxWidth(200))) {
  69. EditorPrefs.SetString("AstarRemindUpdateDate", DateTime.UtcNow.AddDays(7).ToString(System.Globalization.CultureInfo.InvariantCulture));
  70. EditorPrefs.SetString("AstarRemindUpdateVersion", version.ToString());
  71. setReminder = true;
  72. Close();
  73. }
  74. GUILayout.FlexibleSpace();
  75. GUILayout.EndHorizontal();
  76. }
  77. }
  78. }