SupportWindow.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  1. 
  2. using UnityEngine;
  3. using UnityEditor;
  4. //-----------------------------------------------------------------------------
  5. // Copyright 2016-2021 RenderHeads Ltd. All rights reserved.
  6. //-----------------------------------------------------------------------------
  7. namespace RenderHeads.Media.AVProVideo.Editor
  8. {
  9. /// <summary>
  10. /// A window to display options to the user to help them report bugs
  11. /// Also collects some metadata about the machine specs, plugin version etc
  12. /// </summary>
  13. public class SupportWindow : EditorWindow
  14. {
  15. private class MyPopupWindow : PopupWindowContent
  16. {
  17. private string _text;
  18. private string _url;
  19. private string _buttonMessage;
  20. public MyPopupWindow(string text, string buttonMessage,string url)
  21. {
  22. _text = text;
  23. _url = url;
  24. _buttonMessage = buttonMessage;
  25. }
  26. public override Vector2 GetWindowSize()
  27. {
  28. return new Vector2(400, 520);
  29. }
  30. public override void OnGUI(Rect rect)
  31. {
  32. GUILayout.BeginHorizontal();
  33. GUILayout.Label("Copy-Paste this text, then ", EditorStyles.boldLabel);
  34. GUI.color = Color.green;
  35. if (GUILayout.Button(_buttonMessage, GUILayout.ExpandWidth(true)))
  36. {
  37. Application.OpenURL(_url);
  38. }
  39. GUILayout.EndHorizontal();
  40. GUI.color = Color.white;
  41. EditorGUILayout.TextArea(_text);
  42. }
  43. }
  44. private static bool _isCreated = false;
  45. private static bool _isInit = false;
  46. private const string SettingsPrefix = "AVProVideo.SupportWindow.";
  47. private string _emailDescription = string.Empty;
  48. private string _emailTopic = string.Empty;
  49. private string _emailVideoFormat = string.Empty;
  50. private string _emailDeviceSpecs = string.Empty;
  51. //private bool _askForHelp = false;
  52. private bool _trySelfSolve = false;
  53. private Vector2 _scroll = Vector2.zero;
  54. private int _selectionIndex = 0;
  55. private static string[] _gridNames = { "Help Resources", "Ask for Help", "FAQ" };
  56. [MenuItem("Window/AVPro Video Support")]
  57. public static void Init()
  58. {
  59. // Close window if it is already open
  60. if (_isInit || _isCreated)
  61. {
  62. SupportWindow window = (SupportWindow)EditorWindow.GetWindow(typeof(SupportWindow));
  63. window.Close();
  64. return;
  65. }
  66. _isCreated = true;
  67. // Get existing open window or if none, make a new one:
  68. SupportWindow window2 = ScriptableObject.CreateInstance<SupportWindow>();
  69. if (window2 != null)
  70. {
  71. window2.SetupWindow();
  72. }
  73. }
  74. private void SetupWindow()
  75. {
  76. _isCreated = true;
  77. float width = 512f;
  78. float height = 512f;
  79. this.position = new Rect((Screen.width / 2) - (width / 2f), (Screen.height / 2) - (height / 2f), width, height);
  80. this.minSize = new Vector2(530f, 510f);
  81. this.titleContent = new GUIContent("AVPro Video - Help & Support");
  82. this.CreateGUI();
  83. LoadSettings();
  84. this.ShowUtility();
  85. this.Repaint();
  86. }
  87. private void CreateGUI()
  88. {
  89. _isInit = true;
  90. }
  91. void OnEnable()
  92. {
  93. if (!_isCreated)
  94. {
  95. SetupWindow();
  96. }
  97. }
  98. void OnDisable()
  99. {
  100. _isInit = false;
  101. _isCreated = false;
  102. SaveSettings();
  103. Repaint();
  104. }
  105. private void SaveSettings()
  106. {
  107. EditorPrefs.SetString(SettingsPrefix + "EmailTopic", _emailTopic);
  108. EditorPrefs.SetString(SettingsPrefix + "EmailDescription", _emailDescription);
  109. EditorPrefs.SetString(SettingsPrefix + "EmailDeviceSpecs", _emailDeviceSpecs);
  110. EditorPrefs.SetString(SettingsPrefix + "EmailVideoSpecs", _emailVideoFormat);
  111. EditorPrefs.SetBool(SettingsPrefix + "ExpandSelfSolve", _trySelfSolve);
  112. EditorPrefs.SetInt(SettingsPrefix + "SelectionIndex", _selectionIndex);
  113. }
  114. private void LoadSettings()
  115. {
  116. _emailTopic = EditorPrefs.GetString(SettingsPrefix + "EmailTopic", _emailTopic);
  117. _emailDescription = EditorPrefs.GetString(SettingsPrefix + "EmailDescription", _emailDescription);
  118. _emailDeviceSpecs = EditorPrefs.GetString(SettingsPrefix + "EmailDeviceSpecs", _emailDeviceSpecs);
  119. _emailVideoFormat = EditorPrefs.GetString(SettingsPrefix + "EmailVideoSpecs", _emailVideoFormat);
  120. _trySelfSolve = EditorPrefs.GetBool(SettingsPrefix + "ExpandSelfSolve", _trySelfSolve);
  121. _selectionIndex = EditorPrefs.GetInt(SettingsPrefix + "SelectionIndex", _selectionIndex);
  122. }
  123. private string CollectSupportData()
  124. {
  125. string nl = System.Environment.NewLine;
  126. string version = string.Format("AVPro Video: v{0} (plugin v{1})", Helper.AVProVideoVersion, GetPluginVersion());
  127. string targetPlatform = "Target Platform: " + EditorUserBuildSettings.selectedBuildTargetGroup.ToString();
  128. string unityVersion = "Unity: v" + Application.unityVersion + " " + Application.platform.ToString();
  129. string deviceInfo = "OS: " + SystemInfo.deviceType + " - " + SystemInfo.deviceModel + " - " + SystemInfo.operatingSystem + " - " + Application.systemLanguage;
  130. string cpuInfo = "CPU: " + SystemInfo.processorType + " - " + SystemInfo.processorCount + " threads - " + + SystemInfo.systemMemorySize + "KB";
  131. string gfxInfo = "GPU: " + SystemInfo.graphicsDeviceName + " - " + SystemInfo.graphicsDeviceVendor + " - " + SystemInfo.graphicsDeviceVersion + " - " + SystemInfo.graphicsMemorySize + "KB - " + SystemInfo.maxTextureSize;
  132. return version + nl + targetPlatform + nl + unityVersion + nl + deviceInfo + nl + cpuInfo + nl + gfxInfo;
  133. }
  134. void OnGUI()
  135. {
  136. if (!_isInit)
  137. {
  138. EditorGUILayout.LabelField("Initialising...");
  139. return;
  140. }
  141. GUILayout.Label("Having problems? We'll do our best to help.\n\nBelow is a collection of resources to help solve any issues you may encounter.", EditorStyles.wordWrappedLabel);
  142. GUILayout.Space(16f);
  143. /*GUI.color = Color.white;
  144. GUI.backgroundColor = Color.clear;
  145. if (_trySelfSolve)
  146. {
  147. GUI.color = Color.white;
  148. GUI.backgroundColor = new Color(0.8f, 0.8f, 0.8f, 0.1f);
  149. if (EditorGUIUtility.isProSkin)
  150. {
  151. GUI.backgroundColor = Color.black;
  152. }
  153. }
  154. GUILayout.BeginVertical("box");
  155. GUI.backgroundColor = Color.white;*/
  156. _selectionIndex = GUILayout.Toolbar(_selectionIndex, _gridNames);
  157. GUILayout.Space(16f);
  158. /*if (GUILayout.Button("Try Solve the Issue Yourself", EditorStyles.toolbarButton))
  159. {
  160. //_trySelfSolve = !_trySelfSolve;
  161. _trySelfSolve = true;
  162. }
  163. GUI.color = Color.white;
  164. if (_trySelfSolve)*/
  165. if (_selectionIndex == 0)
  166. {
  167. GUILayout.BeginHorizontal();
  168. GUILayout.Label("1) ");
  169. GUILayout.Label("Check you're using the latest version of AVPro Video via the Asset Store. This is version " + Helper.AVProVideoVersion, EditorStyles.wordWrappedLabel);
  170. GUILayout.FlexibleSpace();
  171. GUILayout.EndHorizontal();
  172. GUILayout.BeginHorizontal();
  173. GUILayout.Label("2) ");
  174. GUILayout.Label("Look at the example projects and scripts in the Demos folder");
  175. GUILayout.FlexibleSpace();
  176. GUILayout.EndHorizontal();
  177. GUILayout.BeginHorizontal();
  178. GUILayout.Label("3) ");
  179. GUI.color = Color.green;
  180. if (GUILayout.Button("Read the Documentation", GUILayout.ExpandWidth(false)))
  181. {
  182. Application.OpenURL(MediaPlayerEditor.LinkUserManual);
  183. }
  184. GUI.color = Color.white;
  185. GUILayout.FlexibleSpace();
  186. GUILayout.EndHorizontal();
  187. GUILayout.BeginHorizontal();
  188. GUILayout.Label("4) ");
  189. GUI.color = Color.green;
  190. if (GUILayout.Button("Read the GitHub Issues", GUILayout.ExpandWidth(false)))
  191. {
  192. Application.OpenURL(MediaPlayerEditor.LinkGithubIssues);
  193. }
  194. GUI.color = Color.white;
  195. GUILayout.FlexibleSpace();
  196. GUILayout.EndHorizontal();
  197. GUILayout.BeginHorizontal();
  198. GUILayout.Label("5) ");
  199. GUI.color = Color.green;
  200. if (GUILayout.Button("Read the Scripting Reference", GUILayout.ExpandWidth(false)))
  201. {
  202. Application.OpenURL(MediaPlayerEditor.LinkScriptingClassReference);
  203. }
  204. GUI.color = Color.white;
  205. GUILayout.FlexibleSpace();
  206. GUILayout.EndHorizontal();
  207. GUILayout.BeginHorizontal();
  208. GUILayout.Label("6) ");
  209. GUI.color = Color.green;
  210. if (GUILayout.Button("Visit the AVPro Video Website", GUILayout.ExpandWidth(false)))
  211. {
  212. Application.OpenURL(MediaPlayerEditor.LinkPluginWebsite);
  213. }
  214. GUI.color = Color.white;
  215. GUILayout.FlexibleSpace();
  216. GUILayout.EndHorizontal();
  217. GUILayout.BeginHorizontal();
  218. GUILayout.Label("7) ");
  219. GUI.color = Color.green;
  220. if (GUILayout.Button("Browse the Unity Forum", GUILayout.ExpandWidth(false)))
  221. {
  222. Application.OpenURL(MediaPlayerEditor.LinkForumPage);
  223. }
  224. GUI.color = Color.white;
  225. GUILayout.FlexibleSpace();
  226. GUILayout.EndHorizontal();
  227. }
  228. else if (_selectionIndex == 2)
  229. {
  230. GUILayout.Label("Coming soon...");
  231. }
  232. else if (_selectionIndex == 1)
  233. {
  234. GUILayout.Label("Please fill out these fields when sending us a new issue.\nThis makes it much easier and faster to resolve the issue.", EditorStyles.wordWrappedLabel);
  235. GUILayout.Space(16f);
  236. GUILayout.BeginVertical("box");
  237. _scroll = GUILayout.BeginScrollView(_scroll);
  238. GUILayout.Label("Issue/Question Title", EditorStyles.boldLabel);
  239. _emailTopic = GUILayout.TextField(_emailTopic);
  240. GUILayout.Space(8f);
  241. GUILayout.Label("What's the problem?", EditorStyles.boldLabel);
  242. _emailDescription = EditorGUILayout.TextArea(_emailDescription, GUILayout.Height(64f));
  243. GUILayout.Space(8f);
  244. GUILayout.BeginHorizontal();
  245. GUILayout.Label("Tell us about your videos", EditorStyles.boldLabel);
  246. GUILayout.Label("- Number of videos, resolution, codec, frame-rate, example URLs", EditorStyles.miniBoldLabel);
  247. GUILayout.FlexibleSpace();
  248. GUILayout.EndHorizontal();
  249. _emailVideoFormat = EditorGUILayout.TextArea(_emailVideoFormat, GUILayout.Height(32f));
  250. GUILayout.Space(8f);
  251. GUILayout.BeginHorizontal();
  252. GUILayout.Label("Which devices are you having the issue with?", EditorStyles.boldLabel);
  253. GUILayout.Label("- Model, OS version number", EditorStyles.miniBoldLabel);
  254. GUILayout.FlexibleSpace();
  255. GUILayout.EndHorizontal();
  256. _emailDeviceSpecs = EditorGUILayout.TextField(_emailDeviceSpecs);
  257. //GUILayout.Space(16f);
  258. ////GUILayout.Label("System Information");
  259. //GUILayout.TextArea(CollectSupportData());
  260. string emailBody = System.Environment.NewLine + System.Environment.NewLine;
  261. emailBody += "Problem description:" + System.Environment.NewLine + System.Environment.NewLine + _emailDescription + System.Environment.NewLine + System.Environment.NewLine;
  262. emailBody += "Device (which devices are you having the issue with - model, OS version number):" + System.Environment.NewLine + System.Environment.NewLine + _emailDeviceSpecs + System.Environment.NewLine + System.Environment.NewLine;
  263. emailBody += "Media (tell us about your videos - number of videos, resolution, codec, frame-rate, example URLs):" + System.Environment.NewLine + System.Environment.NewLine + _emailVideoFormat + System.Environment.NewLine + System.Environment.NewLine;
  264. emailBody += "System Information:" + System.Environment.NewLine + System.Environment.NewLine + CollectSupportData() + System.Environment.NewLine + System.Environment.NewLine;
  265. //GUILayout.Space(16f);
  266. //
  267. //GUILayout.Label("Email Content");
  268. //EditorGUILayout.TextArea(emailBody);
  269. GUILayout.EndScrollView();
  270. GUILayout.EndVertical();
  271. GUILayout.Space(16f);
  272. GUILayout.BeginHorizontal();
  273. GUILayout.FlexibleSpace();
  274. GUI.color = Color.green;
  275. if (GUILayout.Button("Send at GitHub Issues ➔", GUILayout.ExpandWidth(false), GUILayout.Height(32f)))
  276. {
  277. PopupWindow.Show(buttonRect, new MyPopupWindow(emailBody, "Go to GitHub", MediaPlayerEditor.LinkGithubIssuesNew));
  278. }
  279. /*if (GUILayout.Button("Send at the Unity Forum ➔", GUILayout.ExpandWidth(false), GUILayout.Height(32f)))
  280. {
  281. PopupWindow.Show(buttonRect, new MyPopupWindow(emailBody, "Go to Forum", MediaPlayerEditor.LinkForumLastPage));
  282. }*/
  283. if (Event.current.type == EventType.Repaint)
  284. {
  285. buttonRect = GUILayoutUtility.GetLastRect();
  286. }
  287. GUI.color = Color.white;
  288. GUILayout.FlexibleSpace();
  289. GUILayout.EndHorizontal();
  290. }
  291. //GUILayout.EndVertical();
  292. GUILayout.FlexibleSpace();
  293. if (GUILayout.Button("Close"))
  294. {
  295. this.Close();
  296. }
  297. }
  298. private Rect buttonRect;
  299. private struct Native
  300. {
  301. #if UNITY_EDITOR_WIN
  302. [System.Runtime.InteropServices.DllImport("AVProVideo")]
  303. public static extern System.IntPtr GetPluginVersion();
  304. #elif UNITY_EDITOR_OSX
  305. [System.Runtime.InteropServices.DllImport("AVProVideo")]
  306. public static extern string AVPGetVersion();
  307. #endif
  308. }
  309. private static string GetPluginVersion()
  310. {
  311. string version = "Unknown";
  312. try
  313. {
  314. #if UNITY_EDITOR_WIN
  315. version = System.Runtime.InteropServices.Marshal.PtrToStringAnsi(Native.GetPluginVersion());
  316. #elif UNITY_EDITOR_OSX
  317. version = Native.AVPGetVersion();
  318. #endif
  319. }
  320. catch (System.DllNotFoundException e)
  321. {
  322. Debug.LogError("[AVProVideo] Failed to load DLL. " + e.Message);
  323. }
  324. return version;
  325. }
  326. }
  327. }