MediaPlayerEditor.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682
  1. #define AVPROVIDEO_SUPPORT_LIVEEDITMODE
  2. using UnityEngine;
  3. using UnityEditor;
  4. using System.Collections.Generic;
  5. //-----------------------------------------------------------------------------
  6. // Copyright 2015-2021 RenderHeads Ltd. All rights reserved.
  7. //-----------------------------------------------------------------------------
  8. namespace RenderHeads.Media.AVProVideo.Editor
  9. {
  10. /// <summary>
  11. /// Editor for the MediaPlayer component
  12. /// </summary>
  13. [CanEditMultipleObjects]
  14. [CustomEditor(typeof(MediaPlayer))]
  15. public partial class MediaPlayerEditor : UnityEditor.Editor
  16. {
  17. internal const string SettingsPrefix = "AVProVideo-MediaPlayerEditor-";
  18. private SerializedProperty _propAutoOpen;
  19. private SerializedProperty _propAutoStart;
  20. private SerializedProperty _propLoop;
  21. private SerializedProperty _propRate;
  22. private SerializedProperty _propPersistent;
  23. private SerializedProperty _propFilter;
  24. private SerializedProperty _propWrap;
  25. private SerializedProperty _propAniso;
  26. #if AVPRO_FEATURE_VIDEORESOLVE
  27. private SerializedProperty _propUseVideoResolve;
  28. private SerializedProperty _propVideoResolve;
  29. private SerializedProperty _propVideoResolveOptions;
  30. #endif
  31. private SerializedProperty _propResample;
  32. private SerializedProperty _propResampleMode;
  33. private SerializedProperty _propResampleBufferSize;
  34. private SerializedProperty _propVideoMapping;
  35. private SerializedProperty _propForceFileFormat;
  36. private SerializedProperty _propFallbackMediaHints;
  37. private static Texture2D _icon;
  38. private static bool _isTrialVersion = false;
  39. private static GUIStyle _styleSectionBox = null;
  40. private AnimCollapseSection _sectionMediaInfo;
  41. private AnimCollapseSection _sectionDebug;
  42. private AnimCollapseSection _sectionSettings;
  43. private AnimCollapseSection _sectionAboutHelp;
  44. private List<AnimCollapseSection> _settingSections = new List<AnimCollapseSection>(16);
  45. private List<AnimCollapseSection> _platformSections = new List<AnimCollapseSection>(8);
  46. [MenuItem("GameObject/Video/AVPro Video - Media Player", false, 100)]
  47. public static void CreateMediaPlayerEditor()
  48. {
  49. GameObject go = new GameObject("MediaPlayer");
  50. go.AddComponent<MediaPlayer>();
  51. Selection.activeGameObject = go;
  52. }
  53. [MenuItem("GameObject/Video/AVPro Video - Media Player with Unity Audio", false, 101)]
  54. public static void CreateMediaPlayerWithUnityAudioEditor()
  55. {
  56. GameObject go = new GameObject("MediaPlayer");
  57. go.AddComponent<MediaPlayer>();
  58. go.AddComponent<AudioSource>();
  59. AudioOutput ao = go.AddComponent<AudioOutput>();
  60. // Move the AudioOutput component above the AudioSource so that it acts as the audio generator
  61. UnityEditorInternal.ComponentUtility.MoveComponentUp(ao);
  62. Selection.activeGameObject = go;
  63. }
  64. private static void LoadSettings()
  65. {
  66. _platformIndex = EditorPrefs.GetInt(SettingsPrefix + "PlatformIndex", -1);
  67. _showAlpha = EditorPrefs.GetBool(SettingsPrefix + "ShowAlphaChannel", false);
  68. _showPreview = EditorPrefs.GetBool(SettingsPrefix + "ShowPreview", true);
  69. _allowDeveloperMode = EditorPrefs.GetBool(SettingsPrefix + "AllowDeveloperMode", false);
  70. _HTTPHeadersToggle = EditorPrefs.GetBool(SettingsPrefix + "HTTPHeadersToggle", false);
  71. RecentItems.Load();
  72. }
  73. private void SaveSettings()
  74. {
  75. _sectionMediaInfo.Save();
  76. _sectionDebug.Save();
  77. _sectionSettings.Save();
  78. _sectionAboutHelp.Save();
  79. foreach (AnimCollapseSection section in _settingSections)
  80. {
  81. section.Save();
  82. }
  83. foreach (AnimCollapseSection section in _platformSections)
  84. {
  85. section.Save();
  86. }
  87. _sectionDevModeState.Save();
  88. _sectionDevModeTexture.Save();
  89. _sectionDevModePlaybackQuality.Save();
  90. _sectionDevModeHapNotchLCDecoder.Save();
  91. _sectionDevModeBufferedFrames.Save();
  92. EditorPrefs.SetInt(SettingsPrefix + "PlatformIndex", _platformIndex);
  93. EditorPrefs.SetBool(SettingsPrefix + "ShowAlphaChannel", _showAlpha);
  94. EditorPrefs.SetBool(SettingsPrefix + "ShowPreview", _showPreview);
  95. EditorPrefs.SetBool(SettingsPrefix + "AllowDeveloperMode", _allowDeveloperMode);
  96. EditorPrefs.SetBool(SettingsPrefix + "HTTPHeadersToggle", _HTTPHeadersToggle);
  97. RecentItems.Save();
  98. }
  99. //[MenuItem("RenderHeads/AVPro Video/Reset Settings", false, 101)]
  100. internal static void DeleteSettings()
  101. {
  102. EditorPrefs.DeleteKey(SettingsPrefix + "PlatformIndex");
  103. EditorPrefs.DeleteKey(SettingsPrefix + "ShowAlphaChannel");
  104. EditorPrefs.DeleteKey(SettingsPrefix + "AllowDeveloperMode");
  105. EditorPrefs.DeleteKey(SettingsPrefix + "HTTPHeadersToggle");
  106. EditorPrefs.DeleteKey(AnimCollapseSection.GetPrefName("Media"));
  107. EditorPrefs.DeleteKey(AnimCollapseSection.GetPrefName("Debug"));
  108. EditorPrefs.DeleteKey(AnimCollapseSection.GetPrefName("Settings"));
  109. EditorPrefs.DeleteKey(AnimCollapseSection.GetPrefName("About / Help"));
  110. EditorPrefs.DeleteKey(AnimCollapseSection.GetPrefName("Source"));
  111. EditorPrefs.DeleteKey(AnimCollapseSection.GetPrefName("Main"));
  112. EditorPrefs.DeleteKey(AnimCollapseSection.GetPrefName("Audio"));
  113. EditorPrefs.DeleteKey(AnimCollapseSection.GetPrefName("Visual"));
  114. EditorPrefs.DeleteKey(AnimCollapseSection.GetPrefName("Network"));
  115. EditorPrefs.DeleteKey(AnimCollapseSection.GetPrefName("Media"));
  116. EditorPrefs.DeleteKey(AnimCollapseSection.GetPrefName("Subtitles"));
  117. EditorPrefs.DeleteKey(AnimCollapseSection.GetPrefName("Events"));
  118. EditorPrefs.DeleteKey(AnimCollapseSection.GetPrefName("Platform Specific"));
  119. EditorPrefs.DeleteKey(AnimCollapseSection.GetPrefName("Global"));
  120. EditorPrefs.DeleteKey(AnimCollapseSection.GetPrefName(GetPlatformButtonContent(Platform.Windows).text));
  121. EditorPrefs.DeleteKey(AnimCollapseSection.GetPrefName(GetPlatformButtonContent(Platform.macOS).text));
  122. EditorPrefs.DeleteKey(AnimCollapseSection.GetPrefName(GetPlatformButtonContent(Platform.Android).text));
  123. EditorPrefs.DeleteKey(AnimCollapseSection.GetPrefName(GetPlatformButtonContent(Platform.iOS).text));
  124. EditorPrefs.DeleteKey(AnimCollapseSection.GetPrefName(GetPlatformButtonContent(Platform.tvOS).text));
  125. EditorPrefs.DeleteKey(AnimCollapseSection.GetPrefName(GetPlatformButtonContent(Platform.visionOS).text));
  126. EditorPrefs.DeleteKey(AnimCollapseSection.GetPrefName(GetPlatformButtonContent(Platform.WindowsUWP).text));
  127. EditorPrefs.DeleteKey(AnimCollapseSection.GetPrefName(GetPlatformButtonContent(Platform.WebGL).text));
  128. }
  129. private void CreateSections()
  130. {
  131. const float colorSaturation = 0.66f;
  132. Color mediaInfoColor = Color.HSVToRGB(0.55f, colorSaturation, 1f);
  133. Color sourceColor = Color.HSVToRGB(0.4f, colorSaturation, 1f);
  134. Color platformSpecificColor = Color.HSVToRGB(0.85f, colorSaturation, 1f);
  135. Color platformColor = platformSpecificColor;
  136. if (EditorGUIUtility.isProSkin)
  137. {
  138. platformColor *= 0.66f;
  139. }
  140. _sectionMediaInfo = new AnimCollapseSection("Media Info", false, false, OnInspectorGUI_MediaInfo, this, mediaInfoColor);
  141. _sectionDebug = new AnimCollapseSection("Debug", false, true, OnInspectorGUI_Debug, this, Color.white);
  142. _sectionSettings = new AnimCollapseSection("Settings", false, true, OnInspectorGUI_Settings, this, Color.white);
  143. _sectionAboutHelp = new AnimCollapseSection("About / Help", false, false, OnInspectorGUI_About, this, Color.white);
  144. _settingSections.Clear();
  145. _settingSections.Add(new AnimCollapseSection("Source", false, true, OnInspectorGUI_Source, this, sourceColor));
  146. _settingSections.Add(new AnimCollapseSection("Main", false, false, OnInspectorGUI_Main, this, Color.white));
  147. _settingSections.Add(new AnimCollapseSection("Audio", false, false, OnInspectorGUI_Audio, this, Color.white));
  148. _settingSections.Add(new AnimCollapseSection("Visual", true, false, OnInspectorGUI_Visual, this, Color.white));
  149. //_settingSections.Add(new AnimCollapseSection("Network", true, false, OnInspectorGUI_Network, this, Color.white));
  150. _settingSections.Add(new AnimCollapseSection("Subtitles", true, false, OnInspectorGUI_Subtitles, this, Color.white));
  151. _settingSections.Add(new AnimCollapseSection("Events", true, false, OnInspectorGUI_Events, this, Color.white));
  152. _settingSections.Add(new AnimCollapseSection("Platform Specific", true, false, OnInspectorGUI_PlatformOverrides, this, platformSpecificColor));
  153. _settingSections.Add(new AnimCollapseSection("Global", true, false, OnInspectorGUI_GlobalSettings, this, Color.white));
  154. _platformSections.Clear();
  155. _platformSections.Add(new AnimCollapseSection(GetPlatformButtonContent(Platform.Windows), true, false, OnInspectorGUI_Override_Windows, this, platformColor, _platformSections));
  156. _platformSections.Add(new AnimCollapseSection(GetPlatformButtonContent(Platform.macOS), true, false, OnInspectorGUI_Override_MacOSX, this, platformColor, _platformSections));
  157. _platformSections.Add(new AnimCollapseSection(GetPlatformButtonContent(Platform.Android), true, false, OnInspectorGUI_Override_Android, this, platformColor, _platformSections));
  158. _platformSections.Add(new AnimCollapseSection(GetPlatformButtonContent(Platform.iOS), true, false, OnInspectorGUI_Override_iOS, this, platformColor, _platformSections));
  159. _platformSections.Add(new AnimCollapseSection(GetPlatformButtonContent(Platform.tvOS), true, false, OnInspectorGUI_Override_tvOS, this, platformColor, _platformSections));
  160. _platformSections.Add(new AnimCollapseSection(GetPlatformButtonContent(Platform.visionOS), true, false, OnInspectorGUI_Override_visionOS, this, platformColor, _platformSections));
  161. _platformSections.Add(new AnimCollapseSection(GetPlatformButtonContent(Platform.WindowsUWP), true, false, OnInspectorGUI_Override_WindowsUWP, this, platformColor, _platformSections));
  162. _platformSections.Add(new AnimCollapseSection(GetPlatformButtonContent(Platform.WebGL), true, false, OnInspectorGUI_Override_WebGL, this, platformColor, _platformSections));
  163. _sectionDevModeState = new AnimCollapseSection("State", false, false, OnInspectorGUI_DevMode_State, this, Color.white);
  164. _sectionDevModeTexture = new AnimCollapseSection("Texture", false, false, OnInspectorGUI_DevMode_Texture, this, Color.white);
  165. _sectionDevModePlaybackQuality = new AnimCollapseSection("Presentation Quality", false, false, OnInspectorGUI_DevMode_PresentationQuality, this, Color.white);
  166. _sectionDevModeHapNotchLCDecoder = new AnimCollapseSection("Hap/NotchLC Decoder", false, false, OnInspectorGUI_DevMode_HapNotchLCDecoder, this, Color.white);
  167. _sectionDevModeBufferedFrames = new AnimCollapseSection("Buffers", false, false, OnInspectorGUI_DevMode_BufferedFrames, this, Color.white);
  168. }
  169. private void ResolveProperties()
  170. {
  171. _propMediaSource = this.CheckFindProperty("_mediaSource");
  172. _propMediaReference = this.CheckFindProperty("_mediaReference");
  173. _propMediaPath = this.CheckFindProperty("_mediaPath");
  174. _propAutoOpen = this.CheckFindProperty("_autoOpen");
  175. _propAutoStart = this.CheckFindProperty("_autoPlayOnStart");
  176. _propLoop = this.CheckFindProperty("_loop");
  177. _propRate = this.CheckFindProperty("_playbackRate");
  178. _propVolume = this.CheckFindProperty("_audioVolume");
  179. _propBalance = this.CheckFindProperty("_audioBalance");
  180. _propMuted = this.CheckFindProperty("_audioMuted");
  181. _propPersistent = this.CheckFindProperty("_persistent");
  182. _propEvents = this.CheckFindProperty("_events");
  183. _propEventMask = this.CheckFindProperty("_eventMask");
  184. _propPauseMediaOnAppPause = this.CheckFindProperty("_pauseMediaOnAppPause");
  185. _propPlayMediaOnAppUnpause = this.CheckFindProperty("_playMediaOnAppUnpause");
  186. _propFilter = this.CheckFindProperty("_textureFilterMode");
  187. _propWrap = this.CheckFindProperty("_textureWrapMode");
  188. _propAniso = this.CheckFindProperty("_textureAnisoLevel");
  189. #if AVPRO_FEATURE_VIDEORESOLVE
  190. _propUseVideoResolve = this.CheckFindProperty("_useVideoResolve");
  191. _propVideoResolve = this.CheckFindProperty("_videoResolve");
  192. _propVideoResolveOptions = this.CheckFindProperty("_videoResolveOptions");
  193. #endif
  194. _propVideoMapping = this.CheckFindProperty("_videoMapping");
  195. _propForceFileFormat = this.CheckFindProperty("_forceFileFormat");
  196. _propFallbackMediaHints = this.CheckFindProperty("_fallbackMediaHints");
  197. _propSubtitles = this.CheckFindProperty("_sideloadSubtitles");
  198. _propSubtitlePath = this.CheckFindProperty("_subtitlePath");
  199. _propResample = this.CheckFindProperty("_useResampler");
  200. _propResampleMode = this.CheckFindProperty("_resampleMode");
  201. _propResampleBufferSize = this.CheckFindProperty("_resampleBufferSize");
  202. _propAudioHeadTransform = this.CheckFindProperty("_audioHeadTransform");
  203. _propAudioEnableFocus = this.CheckFindProperty("_audioFocusEnabled");
  204. _propAudioFocusOffLevelDB = this.CheckFindProperty("_audioFocusOffLevelDB");
  205. _propAudioFocusWidthDegrees = this.CheckFindProperty("_audioFocusWidthDegrees");
  206. _propAudioFocusTransform = this.CheckFindProperty("_audioFocusTransform");
  207. }
  208. private static Texture GetPlatformIcon(Platform platform)
  209. {
  210. string iconName = string.Empty;
  211. switch (platform)
  212. {
  213. case Platform.Windows:
  214. case Platform.macOS:
  215. iconName = "BuildSettings.Standalone.Small";
  216. break;
  217. case Platform.Android:
  218. iconName = "BuildSettings.Android.Small";
  219. break;
  220. case Platform.iOS:
  221. iconName = "BuildSettings.iPhone.Small";
  222. break;
  223. case Platform.tvOS:
  224. iconName = "BuildSettings.tvOS.Small";
  225. break;
  226. case Platform.visionOS:
  227. iconName = "BuildSettings.visionOS.Small";
  228. break;
  229. case Platform.WindowsUWP:
  230. iconName = "BuildSettings.Metro.Small";
  231. break;
  232. case Platform.WebGL:
  233. iconName = "BuildSettings.WebGL.Small";
  234. break;
  235. }
  236. Texture iconTexture = null;
  237. // if (!string.IsNullOrEmpty(iconName))
  238. // {
  239. // iconTexture = EditorGUIUtility.IconContent(iconName).image;
  240. // }
  241. return iconTexture;
  242. }
  243. private static GUIContent GetPlatformButtonContent(Platform platform)
  244. {
  245. return new GUIContent(Helper.GetPlatformName(platform), GetPlatformIcon(platform));
  246. }
  247. private void FixRogueEditorBug()
  248. {
  249. // NOTE: There seems to be a bug in Unity where the editor script will call OnEnable and OnDisable twice.
  250. // This is resolved by setting the Window Layout mode to Default.
  251. // It causes a problem (at least in Unity 2020.1.11) where the System.Action invocations (usd by AnimCollapseSection)
  252. // seem to be in a different 'this' context and so their pointers to serializedObject is not the same, resulting in
  253. // properties modified not marking the serialisedObject as dirty. To get around this issue we use this static bool
  254. // so that OnEnable can only be called once.
  255. // https://answers.unity.com/questions/1216599/custom-editor-gets-created-multiple-times-and-rece.html
  256. var remainingBuggedEditors = FindObjectsOfType<MediaPlayerEditor>();
  257. foreach(var editor in remainingBuggedEditors)
  258. {
  259. if (editor == this)
  260. {
  261. continue;
  262. }
  263. DestroyImmediate(editor);
  264. }
  265. }
  266. private void OnEnable()
  267. {
  268. FixRogueEditorBug();
  269. CreateSections();
  270. LoadSettings();
  271. _isTrialVersion = IsTrialVersion();
  272. if (_platformNames == null)
  273. {
  274. _platformNames = new GUIContent[]
  275. {
  276. GetPlatformButtonContent(Platform.Windows),
  277. GetPlatformButtonContent(Platform.macOS),
  278. GetPlatformButtonContent(Platform.iOS),
  279. GetPlatformButtonContent(Platform.tvOS),
  280. GetPlatformButtonContent(Platform.visionOS),
  281. GetPlatformButtonContent(Platform.Android),
  282. GetPlatformButtonContent(Platform.WindowsUWP),
  283. GetPlatformButtonContent(Platform.WebGL)
  284. };
  285. }
  286. ResolveProperties();
  287. }
  288. private void OnDisable()
  289. {
  290. ClosePreview();
  291. SaveSettings();
  292. if (!Application.isPlaying)
  293. {
  294. // NOTE: For some reason when transitioning into Play mode, Dispose() is not called in the MediaPlayer if
  295. // it was playing before the transition because all members are reset to null. So we must force this
  296. // dispose of all resources to handle this case.
  297. // Sadly it means we can't keep persistent playback in the inspector when it loses focus, but
  298. // hopefully we can find a way to achieve this in the future
  299. /*if (EditorApplication.isPlayingOrWillChangePlaymode)
  300. {
  301. // NOTE: This seems to work for the above issue, but
  302. // we'd need to move it to the global event for when the play state changes
  303. MediaPlayer.EditorAllPlayersDispose();
  304. }*/
  305. foreach (MediaPlayer player in this.targets)
  306. {
  307. player.ForceDispose();
  308. }
  309. }
  310. }
  311. private void CreateStyles()
  312. {
  313. if (_styleSectionBox == null)
  314. {
  315. _styleSectionBox = new GUIStyle(GUI.skin.box);
  316. if (!EditorGUIUtility.isProSkin)
  317. {
  318. _styleSectionBox = new GUIStyle(GUI.skin.box);
  319. //_styleSectionBox.normal.background = Texture2D.redTexture;
  320. }
  321. }
  322. _iconPlayButton = EditorGUIUtility.IconContent("d_PlayButton");
  323. _iconPauseButton = EditorGUIUtility.IconContent("d_PauseButton");
  324. _iconSceneViewAudio = EditorGUIUtility.IconContent("d_SceneViewAudio");
  325. _iconProject = EditorGUIUtility.IconContent("d_Project");
  326. _iconRotateTool = EditorGUIUtility.IconContent("d_RotateTool");
  327. AnimCollapseSection.CreateStyles();
  328. }
  329. public override void OnInspectorGUI()
  330. {
  331. MediaPlayer media = (this.target) as MediaPlayer;
  332. // NOTE: It is important that serializedObject.Update() is called before media.EditorUpdate()
  333. // as otherwise the serializedPropertys are not correctly detected as modified
  334. serializedObject.Update();
  335. #if AVPROVIDEO_SUPPORT_LIVEEDITMODE
  336. bool isPlayingInEditor = false;
  337. // Update only during the layout event so that nothing updates for the render event
  338. if (!Application.isPlaying && Event.current.type == EventType.Layout)
  339. {
  340. isPlayingInEditor = media.EditorUpdate();
  341. }
  342. #endif
  343. if (media == null || _propMediaPath == null)
  344. {
  345. return;
  346. }
  347. CreateStyles();
  348. _icon = GetIcon(_icon);
  349. ShowImportantMessages();
  350. if (media != null)
  351. {
  352. OnInspectorGUI_Player(media, media.TextureProducer);
  353. }
  354. AnimCollapseSection.Show(_sectionMediaInfo);
  355. if (_allowDeveloperMode)
  356. {
  357. AnimCollapseSection.Show(_sectionDebug);
  358. }
  359. AnimCollapseSection.Show(_sectionSettings);
  360. if (serializedObject.ApplyModifiedProperties())
  361. {
  362. EditorUtility.SetDirty(target);
  363. }
  364. AnimCollapseSection.Show(_sectionAboutHelp);
  365. #if AVPROVIDEO_SUPPORT_LIVEEDITMODE
  366. if (isPlayingInEditor)
  367. {
  368. GL.InvalidateState();
  369. // NOTE: there seems to be a bug in Unity (2019.3.13) where if you don't have
  370. // GL.sRGBWrite = true and then call RepaintAllViews() it makes the current Inspector
  371. // background turn black. This only happens when using D3D12
  372. // UPDATE: this is happening in Unity 2019.4.15 as well, and in D3D11 mode. It only
  373. // happens when loading a video via the Recent Menu.
  374. bool originalSRGBWrite = GL.sRGBWrite;
  375. GL.sRGBWrite = true;
  376. //this.Repaint();
  377. UnityEditorInternal.InternalEditorUtility.RepaintAllViews();
  378. GL.sRGBWrite = originalSRGBWrite;
  379. }
  380. // TODO: OnDisable - stop the video if it's playing (and unload it?)
  381. #endif
  382. }
  383. private void OnInspectorGUI_Settings()
  384. {
  385. foreach (AnimCollapseSection section in _settingSections)
  386. {
  387. AnimCollapseSection.Show(section, indentLevel:1);
  388. }
  389. }
  390. private void ShowSupportWindowButton()
  391. {
  392. //GUI.backgroundColor = new Color(0.96f, 0.25f, 0.47f);
  393. //if (GUILayout.Button("◄ AVPro Video ►\nHelp & Support"))
  394. if (GUILayout.Button("Click here for \nHelp & Support"))
  395. {
  396. SupportWindow.Init();
  397. }
  398. //GUI.backgroundColor = Color.white;
  399. }
  400. private void ShowImportantMessages()
  401. {
  402. // Describe the watermark for trial version
  403. if (_isTrialVersion)
  404. {
  405. string message = string.Empty;
  406. if (Application.isPlaying)
  407. {
  408. #if UNITY_EDITOR_WIN
  409. MediaPlayer media = (this.target) as MediaPlayer;
  410. message = "The watermark is the horizontal bar that moves vertically and the small 'AVPRO TRIAL' text.";
  411. if (media.Info != null && media.Info.GetPlayerDescription().Contains("MF-MediaEngine-Hardware"))
  412. {
  413. message = "The watermark is the RenderHeads logo that moves around the image.";
  414. }
  415. #elif UNITY_EDITOR_OSX
  416. message = "The RenderHeads logo is the watermark.";
  417. #endif
  418. }
  419. EditorHelper.IMGUI.BeginWarningTextBox("AVPRO VIDEO - TRIAL WATERMARK", message, Color.yellow, Color.yellow, Color.white);
  420. if (GUILayout.Button("Purchase"))
  421. {
  422. Application.OpenURL(LinkPurchase);
  423. }
  424. EditorHelper.IMGUI.EndWarningTextBox();
  425. }
  426. // Warning about not using multi-threaded rendering
  427. {
  428. bool showWarningMT = false;
  429. if (/*EditorUserBuildSettings.selectedBuildTargetGroup == BuildTargetGroup.iOS ||
  430. EditorUserBuildSettings.selectedBuildTargetGroup == BuildTargetGroup.tvOS ||*/
  431. EditorUserBuildSettings.selectedBuildTargetGroup == BuildTargetGroup.Android)
  432. {
  433. #if UNITY_2017_2_OR_NEWER
  434. showWarningMT = !UnityEditor.PlayerSettings.GetMobileMTRendering(BuildTargetGroup.Android);
  435. #else
  436. showWarningMT = !UnityEditor.PlayerSettings.mobileMTRendering;
  437. #endif
  438. }
  439. /*if (EditorUserBuildSettings.selectedBuildTargetGroup == BuildTargetGroup.WSA)
  440. {
  441. }*/
  442. if (showWarningMT)
  443. {
  444. EditorHelper.IMGUI.WarningTextBox("Performance Warning", "Deploying to Android with multi-threaded rendering disabled is not recommended. Enable multi-threaded rendering in the Player Settings > Other Settings panel.", Color.yellow, Color.yellow, Color.white);
  445. }
  446. }
  447. #if !UNITY_2019_3_OR_NEWER
  448. if (SystemInfo.graphicsDeviceType == UnityEngine.Rendering.GraphicsDeviceType.Direct3D12)
  449. {
  450. EditorHelper.IMGUI.WarningTextBox("Compatibility Warning", "Direct3D 12 is not supported until Unity 2019.3", Color.yellow, Color.yellow, Color.white);
  451. }
  452. #endif
  453. }
  454. private void OnInspectorGUI_Main()
  455. {
  456. /////////////////// STARTUP FIELDS
  457. EditorGUILayout.BeginVertical(_styleSectionBox);
  458. GUILayout.Label("Startup", EditorStyles.boldLabel);
  459. EditorGUILayout.PropertyField(_propAutoOpen);
  460. EditorGUILayout.PropertyField(_propAutoStart, new GUIContent("Auto Play"));
  461. EditorGUILayout.EndVertical();
  462. /////////////////// PLAYBACK FIELDS
  463. EditorGUILayout.BeginVertical(GUI.skin.box);
  464. GUILayout.Label("Playback", EditorStyles.boldLabel);
  465. EditorGUI.BeginChangeCheck();
  466. EditorGUILayout.PropertyField(_propLoop);
  467. if (EditorGUI.EndChangeCheck())
  468. {
  469. Undo.RecordObject(target, "Loop");
  470. foreach (MediaPlayer player in this.targets)
  471. {
  472. player.Loop = _propLoop.boolValue;
  473. }
  474. }
  475. EditorGUI.BeginChangeCheck();
  476. EditorGUILayout.PropertyField(_propRate);
  477. if (EditorGUI.EndChangeCheck())
  478. {
  479. Undo.RecordObject(target, "PlaybackRate");
  480. foreach (MediaPlayer player in this.targets)
  481. {
  482. player.PlaybackRate = _propRate.floatValue;
  483. }
  484. }
  485. EditorGUILayout.EndVertical();
  486. EditorGUILayout.BeginVertical(GUI.skin.box);
  487. GUILayout.Label("Other", EditorStyles.boldLabel);
  488. EditorGUILayout.PropertyField(_propPersistent, new GUIContent("Persistent", "Use DontDestroyOnLoad so this object isn't destroyed between level loads"));
  489. if (_propForceFileFormat != null)
  490. {
  491. GUIContent label = new GUIContent("Force File Format", "Override automatic format detection when using non-standard file extensions");
  492. _propForceFileFormat.enumValueIndex = EditorGUILayout.Popup(label, _propForceFileFormat.enumValueIndex, _fileFormatGuiNames);
  493. }
  494. EditorGUILayout.EndVertical();
  495. }
  496. private void OnInspectorGUI_Visual()
  497. {
  498. #if AVPRO_FEATURE_VIDEORESOLVE
  499. {
  500. EditorGUILayout.BeginVertical(GUI.skin.box);
  501. GUILayout.Label("Resolve", EditorStyles.boldLabel);
  502. EditorGUI.BeginChangeCheck();
  503. EditorGUILayout.PropertyField(_propUseVideoResolve);
  504. if (EditorGUI.EndChangeCheck())
  505. {
  506. Undo.RecordObject(target, "UseVideoResolve");
  507. foreach (MediaPlayer player in this.targets)
  508. {
  509. player.UseVideoResolve = _propUseVideoResolve.boolValue;
  510. }
  511. }
  512. if (_propUseVideoResolve.boolValue)
  513. {
  514. EditorGUILayout.PropertyField(_propVideoResolve);
  515. /*EditorGUI.indentLevel++;
  516. EditorGUILayout.PropertyField(_propVideoResolveOptions, true);
  517. EditorGUI.indentLevel--;*/
  518. }
  519. GUILayout.EndVertical();
  520. }
  521. #endif
  522. EditorGUILayout.BeginVertical(GUI.skin.box);
  523. GUILayout.Label("Texture", EditorStyles.boldLabel);
  524. EditorGUI.BeginChangeCheck();
  525. EditorGUILayout.PropertyField(_propFilter, new GUIContent("Filter"));
  526. if (EditorGUI.EndChangeCheck())
  527. {
  528. Undo.RecordObject(target, "TextureFilterMode");
  529. foreach (MediaPlayer player in this.targets)
  530. {
  531. player.TextureFilterMode = (FilterMode)_propFilter.enumValueIndex;
  532. }
  533. }
  534. EditorGUI.BeginChangeCheck();
  535. EditorGUILayout.PropertyField(_propWrap, new GUIContent("Wrap"));
  536. if (EditorGUI.EndChangeCheck())
  537. {
  538. Undo.RecordObject(target, "TextureWrapMode");
  539. foreach (MediaPlayer player in this.targets)
  540. {
  541. player.TextureWrapMode = (TextureWrapMode)_propWrap.enumValueIndex;
  542. }
  543. }
  544. EditorGUI.BeginChangeCheck();
  545. EditorGUILayout.PropertyField(_propAniso, new GUIContent("Aniso"));
  546. if (EditorGUI.EndChangeCheck())
  547. {
  548. Undo.RecordObject(target, "TextureAnisoLevel");
  549. foreach (MediaPlayer player in this.targets)
  550. {
  551. player.TextureAnisoLevel = _propAniso.intValue;
  552. }
  553. }
  554. EditorGUILayout.EndVertical();
  555. EditorGUILayout.BeginVertical(GUI.skin.box);
  556. GUILayout.Label("Layout Mapping", EditorStyles.boldLabel);
  557. EditorGUILayout.PropertyField(_propVideoMapping);
  558. EditorGUILayout.EndVertical();
  559. {
  560. EditorGUILayout.BeginVertical(GUI.skin.box);
  561. GUILayout.Label("Resampler (BETA)", EditorStyles.boldLabel);
  562. EditorGUILayout.PropertyField(_propResample);
  563. EditorGUI.BeginDisabledGroup(!_propResample.boolValue);
  564. EditorGUILayout.PropertyField(_propResampleMode);
  565. EditorGUILayout.PropertyField(_propResampleBufferSize);
  566. EditorGUI.EndDisabledGroup();
  567. EditorGUILayout.EndVertical();
  568. }
  569. }
  570. private static bool IsTrialVersion()
  571. {
  572. string version = GetPluginVersion();
  573. return version.Contains("-trial");
  574. }
  575. //private int _updateFrameCount = -1;
  576. public override bool RequiresConstantRepaint()
  577. {
  578. MediaPlayer media = (this.target) as MediaPlayer;
  579. if (media != null && media.Control != null && media.isActiveAndEnabled && media.Info.GetDuration() > 0.0)
  580. {
  581. if (!media.Info.HasVideo())
  582. {
  583. if (media.Info.HasAudio())
  584. {
  585. return true;
  586. }
  587. }
  588. else if (media.TextureProducer.GetTexture() != null)
  589. {
  590. //int frameCount = media.TextureProducer.GetTextureFrameCount();
  591. //if (_updateFrameCount != frameCount)
  592. {
  593. //_updateFrameCount = frameCount;
  594. return true;
  595. }
  596. }
  597. }
  598. return false;
  599. }
  600. }
  601. }