WelcomeWindow.cs 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. #if !DISABLE_SRDEBUGGER
  2. using SRF;
  3. using UnityEditor;
  4. using UnityEngine;
  5. namespace SRDebugger.Editor
  6. {
  7. [InitializeOnLoad]
  8. class WelcomeWindow : EditorWindow
  9. {
  10. private const string WelcomeWindowPlayerPrefsKey = "SRDEBUGGER_WELCOME_SHOWN_VERSION";
  11. private Texture2D _demoSprite;
  12. private Vector2 _scrollPosition;
  13. static WelcomeWindow()
  14. {
  15. EditorApplication.update += OpenUpdate;
  16. }
  17. private static void OpenUpdate()
  18. {
  19. if (ShouldOpen())
  20. {
  21. Open();
  22. }
  23. EditorApplication.update -= OpenUpdate;
  24. }
  25. [MenuItem(SRDebugEditorPaths.WelcomeItemPath)]
  26. public static void Open()
  27. {
  28. GetWindowWithRect<WelcomeWindow>(new Rect(0, 0, 449, 500), true, "SRDebugger - Welcome", true);
  29. }
  30. private static bool ShouldOpen()
  31. {
  32. var settings = Settings.GetInstance();
  33. if (settings != null)
  34. {
  35. if (settings.DisableWelcomePopup)
  36. {
  37. return false;
  38. }
  39. }
  40. var hasKey = EditorPrefs.HasKey(WelcomeWindowPlayerPrefsKey);
  41. if (!hasKey)
  42. {
  43. return true;
  44. }
  45. var value = EditorPrefs.GetString(WelcomeWindowPlayerPrefsKey);
  46. if (value != SRDebug.Version)
  47. {
  48. return true;
  49. }
  50. return false;
  51. }
  52. private void OnEnable()
  53. {
  54. EditorPrefs.SetString(WelcomeWindowPlayerPrefsKey, SRDebug.Version);
  55. }
  56. private void OnGUI()
  57. {
  58. // Draw header area
  59. SRInternalEditorUtil.BeginDrawBackground();
  60. SRInternalEditorUtil.DrawLogo(SRInternalEditorUtil.GetWelcomeLogo());
  61. SRInternalEditorUtil.EndDrawBackground();
  62. // Draw header/content divider
  63. EditorGUILayout.BeginVertical(SRInternalEditorUtil.Styles.SettingsHeaderBoxStyle);
  64. EditorGUILayout.EndVertical();
  65. _scrollPosition = EditorGUILayout.BeginScrollView(_scrollPosition);
  66. GUILayout.Label("Welcome", SRInternalEditorUtil.Styles.HeaderLabel);
  67. GUILayout.Label(
  68. "Thank you for purchasing SRDebugger, your support is very much appreciated and we hope you find it useful for your project. " +
  69. "This window contains a quick guide to get to help get you started with SRDebugger.",
  70. SRInternalEditorUtil.Styles.ParagraphLabel);
  71. if (SRInternalEditorUtil.ClickableLabel(
  72. "Note: For more detailed information <color={0}>click here</color> to visit the online documentation."
  73. .Fmt(SRInternalEditorUtil.Styles.LinkColour),
  74. SRInternalEditorUtil.Styles.ParagraphLabel))
  75. {
  76. Application.OpenURL(SRDebugEditorStrings.Current.SettingsDocumentationUrl);
  77. }
  78. GUILayout.Label("Quick Start", SRInternalEditorUtil.Styles.HeaderLabel);
  79. GUILayout.Label(
  80. "Now that you have imported the package, you should find the trigger available in the top-left of your game window when in play mode. " +
  81. "Triple-clicking this trigger will bring up the debug panel. The trigger is hidden until clicked.",
  82. SRInternalEditorUtil.Styles.ParagraphLabel);
  83. GUILayout.Label(
  84. "By default, SRDebugger loads automatically when your game starts. " +
  85. "You can change this behaviour from the SRDebugger Settings window.",
  86. SRInternalEditorUtil.Styles.ParagraphLabel);
  87. DrawVideo();
  88. EditorGUILayout.Space();
  89. GUILayout.Label("Customization", SRInternalEditorUtil.Styles.HeaderLabel);
  90. if (SRInternalEditorUtil.ClickableLabel(
  91. "Many features of SRDebugger can be configured from the <color={0}>SRDebugger Settings</color> window."
  92. .Fmt(
  93. SRInternalEditorUtil.Styles.LinkColour), SRInternalEditorUtil.Styles.ParagraphLabel))
  94. {
  95. SRDebuggerSettingsWindow.Open();
  96. }
  97. GUILayout.Label(
  98. "From the settings window you can configure loading behaviour, trigger position, docked tools layout, and more. " +
  99. "You can enable the bug reporter service by using the sign-up form to get a free API key.",
  100. SRInternalEditorUtil.Styles.ParagraphLabel);
  101. GUILayout.Label("What Next?", SRInternalEditorUtil.Styles.HeaderLabel);
  102. if (SRInternalEditorUtil.ClickableLabel(
  103. "For more detailed information about SRDebugger's features or details about the Options Tab and script API, check the <color={0}>online documentation</color>."
  104. .Fmt(SRInternalEditorUtil.Styles.LinkColour), SRInternalEditorUtil.Styles.ParagraphLabel))
  105. {
  106. Application.OpenURL(SRDebugEditorStrings.Current.SettingsDocumentationUrl);
  107. }
  108. GUILayout.Label(
  109. "Thanks again for purchasing SRDebugger. " +
  110. "If you find it useful please consider leaving a rating or review on the Asset Store page as this helps us continue to provide updates and support to our users. ",
  111. SRInternalEditorUtil.Styles.ParagraphLabel);
  112. GUILayout.Label(
  113. "If you have any questions or concerns please do not hesitate to get in touch with us via email or the Unity forums.",
  114. SRInternalEditorUtil.Styles.ParagraphLabel);
  115. SRInternalEditorUtil.DrawFooterLayout(position.width - 15);
  116. EditorGUILayout.EndScrollView();
  117. Repaint();
  118. }
  119. private void DrawVideo()
  120. {
  121. if (_demoSprite == null)
  122. {
  123. _demoSprite = SRInternalEditorUtil.LoadResource<Texture2D>("Editor/DemoSprite.png");
  124. }
  125. if (_demoSprite == null)
  126. return;
  127. var frameWidth = 400;
  128. var frameHeight = 300;
  129. var framePadding = 0;
  130. var extraFramesStart = 5;
  131. var extraFramesEnd = 20;
  132. var totalFrames = 29;
  133. var fps = 16f;
  134. EditorGUILayout.Space();
  135. EditorGUILayout.BeginHorizontal();
  136. GUILayout.FlexibleSpace();
  137. var rect = GUILayoutUtility.GetRect(400*0.75f, 300*0.75f, GUILayout.ExpandHeight(false),
  138. GUILayout.ExpandWidth(false));
  139. var frame = ((int) (EditorApplication.timeSinceStartup*fps))%
  140. (totalFrames + extraFramesStart + extraFramesEnd);
  141. frame -= extraFramesStart;
  142. var actualFrame = Mathf.Clamp(frame, 0, totalFrames);
  143. SRInternalEditorUtil.RenderGif(rect, _demoSprite, actualFrame, frameWidth, frameHeight, 5, framePadding,
  144. framePadding);
  145. GUILayout.FlexibleSpace();
  146. EditorGUILayout.EndHorizontal();
  147. }
  148. }
  149. }
  150. #endif