AstarUpdateWindow.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. #if UNITY_4_6 || UNITY_5_0
  18. window.title = "New Version of the A* Pathfinding Project";
  19. #else
  20. window.titleContent = new GUIContent("New Version of the A* Pathfinding Project");
  21. #endif
  22. return window;
  23. }
  24. public void OnDestroy () {
  25. if (version != null && !setReminder) {
  26. Debug.Log("Closed window, reminding again tomorrow");
  27. EditorPrefs.SetString("AstarRemindUpdateDate", DateTime.UtcNow.AddDays(1).ToString(System.Globalization.CultureInfo.InvariantCulture));
  28. EditorPrefs.SetString("AstarRemindUpdateVersion", version.ToString());
  29. }
  30. }
  31. void OnGUI () {
  32. if (largeStyle == null) {
  33. largeStyle = new GUIStyle(EditorStyles.largeLabel);
  34. largeStyle.fontSize = 32;
  35. largeStyle.alignment = TextAnchor.UpperCenter;
  36. largeStyle.richText = true;
  37. normalStyle = new GUIStyle(EditorStyles.label);
  38. normalStyle.wordWrap = true;
  39. normalStyle.richText = true;
  40. }
  41. if (version == null) {
  42. return;
  43. }
  44. GUILayout.Label("New Update Available!", largeStyle);
  45. GUILayout.Label("There is a new version of the <b>A* Pathfinding Project</b> available for download.\n" +
  46. "The new version is <b>" + version + "</b> you have <b>" + AstarPath.Version + "</b>\n\n"+
  47. "<i>Summary:</i>\n"+summary, normalStyle
  48. );
  49. GUILayout.FlexibleSpace();
  50. GUILayout.BeginHorizontal();
  51. GUILayout.FlexibleSpace();
  52. GUILayout.BeginVertical();
  53. Color col = GUI.color;
  54. GUI.backgroundColor *= new Color(0.5f, 1f, 0.5f);
  55. if (GUILayout.Button("Take me to the download page!", GUILayout.Height(30), GUILayout.MaxWidth(300))) {
  56. Application.OpenURL(AstarUpdateChecker.GetURL("download"));
  57. }
  58. GUI.backgroundColor = col;
  59. if (GUILayout.Button("What's new? (full changelog)")) {
  60. Application.OpenURL(AstarUpdateChecker.GetURL("changelog"));
  61. }
  62. GUILayout.EndVertical();
  63. GUILayout.FlexibleSpace();
  64. GUILayout.EndHorizontal();
  65. GUILayout.FlexibleSpace();
  66. GUILayout.BeginHorizontal();
  67. if (GUILayout.Button("Skip this version", GUILayout.MaxWidth(100))) {
  68. EditorPrefs.SetString("AstarSkipUpToVersion", version.ToString());
  69. setReminder = true;
  70. Close();
  71. }
  72. if (GUILayout.Button("Remind me later ( 1 week )", GUILayout.MaxWidth(200))) {
  73. EditorPrefs.SetString("AstarRemindUpdateDate", DateTime.UtcNow.AddDays(7).ToString(System.Globalization.CultureInfo.InvariantCulture));
  74. EditorPrefs.SetString("AstarRemindUpdateVersion", version.ToString());
  75. setReminder = true;
  76. Close();
  77. }
  78. GUILayout.FlexibleSpace();
  79. GUILayout.EndHorizontal();
  80. }
  81. }
  82. }