AboutWindow.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. using UnityEngine;
  2. using UnityEditor;
  3. using System.IO;
  4. namespace Cinemachine.Editor
  5. {
  6. [InitializeOnLoad]
  7. internal class AboutWindow : EditorWindow
  8. {
  9. private const string kLastVersionOpened = "CNMCN_Last_Version_Loaded";
  10. private const string kInvalidVersionNumber = "0.0";
  11. private static readonly Vector2 kMinWindowSize = new Vector2(550f, 550f);
  12. private static string LastVersionLoaded
  13. {
  14. get { return EditorPrefs.GetString(kLastVersionOpened, kInvalidVersionNumber); }
  15. set { EditorPrefs.SetString(kLastVersionOpened, value); }
  16. }
  17. private GUIStyle mButtonStyle;
  18. private GUIStyle mLabelStyle;
  19. private GUIStyle mHeaderStyle;
  20. private GUIStyle mNotesStyle;
  21. private Vector2 mReleaseNoteScrollPos = Vector2.zero;
  22. string mReleaseNotes;
  23. private void OnEnable()
  24. {
  25. string path = ScriptableObjectUtility.CinemachineInstallPath + "/Extras~/ReleaseNotes.txt";
  26. try
  27. {
  28. StreamReader reader = new StreamReader(path);
  29. mReleaseNotes = reader.ReadToEnd();
  30. reader.Close();
  31. }
  32. catch (System.Exception)
  33. {
  34. mReleaseNotes = path + " not found";
  35. }
  36. }
  37. private void OnGUI()
  38. {
  39. if (EditorApplication.isCompiling)
  40. {
  41. Close();
  42. }
  43. if (mButtonStyle == null)
  44. {
  45. mButtonStyle = new GUIStyle(GUI.skin.button);
  46. mButtonStyle.richText = true;
  47. }
  48. if (mLabelStyle == null)
  49. {
  50. mLabelStyle = new GUIStyle(EditorStyles.label);
  51. mLabelStyle.wordWrap = true;
  52. mLabelStyle.richText = true;
  53. }
  54. if (mHeaderStyle == null)
  55. {
  56. mHeaderStyle = new GUIStyle(EditorStyles.boldLabel);
  57. mHeaderStyle.wordWrap = true;
  58. }
  59. if (mNotesStyle == null)
  60. {
  61. mNotesStyle = new GUIStyle(EditorStyles.textArea);
  62. mNotesStyle.richText = true;
  63. mNotesStyle.wordWrap = true;
  64. }
  65. using (var vertScope = new EditorGUILayout.VerticalScope())
  66. {
  67. if (CinemachineSettings.CinemachineHeader != null)
  68. {
  69. float headerWidth = position.width;
  70. float aspectRatio = (float)CinemachineSettings.CinemachineHeader.height / (float)CinemachineSettings.CinemachineHeader.width;
  71. GUILayout.BeginScrollView(Vector2.zero, false, false, GUILayout.Width(headerWidth), GUILayout.Height(headerWidth * aspectRatio));
  72. Rect texRect = new Rect(0f, 0f, headerWidth, headerWidth * aspectRatio);
  73. GUILayout.FlexibleSpace();
  74. GUILayout.BeginArea(texRect);
  75. GUI.DrawTexture(texRect, CinemachineSettings.CinemachineHeader, ScaleMode.ScaleToFit);
  76. GUILayout.EndArea();
  77. GUILayout.FlexibleSpace();
  78. GUILayout.EndScrollView();
  79. }
  80. EditorGUILayout.LabelField("Welcome to Cinemachine!", mLabelStyle);
  81. EditorGUILayout.LabelField("Smart camera tools for passionate creators.", mLabelStyle);
  82. EditorGUILayout.LabelField("Below are links to the forums, please reach out if you have any questions or feedback", mLabelStyle);
  83. if (GUILayout.Button("<b>Forum</b>\n<i>Discuss</i>", mButtonStyle))
  84. {
  85. Application.OpenURL("https://forum.unity3d.com/forums/cinemachine.136/");
  86. }
  87. if (GUILayout.Button("<b>Rate it!</b>\nUnity Asset Store", mButtonStyle))
  88. {
  89. Application.OpenURL("https://www.assetstore.unity3d.com/en/#!/content/79898");
  90. }
  91. }
  92. EditorGUILayout.LabelField("Release Notes", mHeaderStyle);
  93. using (var scrollScope = new EditorGUILayout.ScrollViewScope(mReleaseNoteScrollPos, GUI.skin.box))
  94. {
  95. mReleaseNoteScrollPos = scrollScope.scrollPosition;
  96. EditorGUILayout.LabelField(mReleaseNotes, mNotesStyle);
  97. }
  98. }
  99. [MenuItem("Cinemachine/About")]
  100. private static void OpenWindow()
  101. {
  102. EditorApplication.update += ShowWindowDeferred;
  103. }
  104. private static void ShowWindowDeferred()
  105. {
  106. string loadedVersion = LastVersionLoaded;
  107. if (loadedVersion != CinemachineCore.kVersionString)
  108. LastVersionLoaded = CinemachineCore.kVersionString;
  109. AboutWindow window = EditorWindow.GetWindow<AboutWindow>();
  110. window.titleContent = new UnityEngine.GUIContent(
  111. "About", CinemachineSettings.CinemachineLogoTexture);
  112. window.minSize = kMinWindowSize;
  113. window.Show(true);
  114. EditorApplication.update -= ShowWindowDeferred;
  115. }
  116. }
  117. }