CaptureBaseEditor.cs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631
  1. #if UNITY_EDITOR
  2. using UnityEngine;
  3. using UnityEditor;
  4. using System.Collections;
  5. //-----------------------------------------------------------------------------
  6. // Copyright 2012-2017 RenderHeads Ltd. All rights reserved.
  7. //-----------------------------------------------------------------------------
  8. namespace RenderHeads.Media.AVProMovieCapture.Editor
  9. {
  10. [CanEditMultipleObjects]
  11. [CustomEditor(typeof(CaptureBase), true)]
  12. public class CaptureBaseEditor : UnityEditor.Editor
  13. {
  14. private const string SettingsPrefix = "AVProMovieCapture-BaseEditor-";
  15. public readonly static string[] ResolutionStrings = { "8192x8192 (1:1)", "8192x4096 (2:1)", "4096x4096 (1:1)", "4096x2048 (2:1)", "2048x4096 (1:2)", "3840x2160 (16:9)", "3840x2048 (15:8)", "3840x1920 (2:1)", "2048x2048 (1:1)", "2048x1024 (2:1)", "1920x1080 (16:9)", "1280x720 (16:9)", "1024x768 (4:3)", "800x600 (4:3)", "800x450 (16:9)", "640x480 (4:3)", "640x360 (16:9)", "320x240 (4:3)", "Original", "Custom" };
  16. private static bool _isTrialVersion = false;
  17. private SerializedProperty _propCaptureOnStart;
  18. private SerializedProperty _propCaptureKey;
  19. private SerializedProperty _propListCodecsOnStart;
  20. private SerializedProperty _propMinimumDiskSpaceMB;
  21. private SerializedProperty _propIsRealtime;
  22. private SerializedProperty _propIsStartPaused;
  23. private SerializedProperty _propOutputType;
  24. private SerializedProperty _propOutputFolderType;
  25. private SerializedProperty _propOutputFolderPath;
  26. private SerializedProperty _propAutoGenerateFileName;
  27. private SerializedProperty _propAutoFileNamePrefix;
  28. private SerializedProperty _propFileNameExtension;
  29. private SerializedProperty _propForceFileName;
  30. private SerializedProperty _propVideoCodecPriority;
  31. private SerializedProperty _propForceVideoCodecIndex;
  32. private SerializedProperty _propUseMediaFoundationH264;
  33. private SerializedProperty _propAudioCodecPriority;
  34. private SerializedProperty _propForceAudioCodecIndex;
  35. private SerializedProperty _propForceAudioDeviceIndex;
  36. private SerializedProperty _propNoAudio;
  37. private SerializedProperty _propUnityAudioCapture;
  38. private SerializedProperty _propStopMode;
  39. private SerializedProperty _propStopFrames;
  40. private SerializedProperty _propStopSeconds;
  41. private SerializedProperty _propDownScale;
  42. private SerializedProperty _propMaxVideoSize;
  43. private SerializedProperty _propFrameRate;
  44. private SerializedProperty _propFlipVertically;
  45. private SerializedProperty _propSupportAlpha;
  46. private SerializedProperty _propUseMotionBlur;
  47. private SerializedProperty _propMotionBlurSamples;
  48. private SerializedProperty _propMotionBlurCameras;
  49. private SerializedProperty _propAllowVsyncDisable;
  50. private SerializedProperty _propSupportTextureRecreate;
  51. private static bool _isExpandedStartStop = false;
  52. private static bool _isExpandedOutput = false;
  53. private static bool _isExpandedVisual = false;
  54. private static bool _isExpandedAudio = false;
  55. private static bool _isExpandedMisc = false;
  56. private static bool _isExpandedTrial = true;
  57. private static bool _isExpandedAbout = false;
  58. protected CaptureBase _baseCapture;
  59. public override void OnInspectorGUI()
  60. {
  61. // Warning if the base component is used
  62. if (this.target.GetType() == typeof(CaptureBase))
  63. {
  64. GUI.color = Color.yellow;
  65. GUILayout.BeginVertical("box");
  66. GUILayout.TextArea("Error: This is not a component, this is the base class.\n\nPlease add one of the components\n(eg:CaptureFromScene / CaptureFromCamera etc)");
  67. GUILayout.EndVertical();
  68. return;
  69. }
  70. GUI_Header();
  71. GUI_BaseOptions();
  72. }
  73. protected virtual void GUI_User()
  74. {
  75. }
  76. protected void GUI_Header()
  77. {
  78. // Describe the watermark for trial version
  79. if (_isTrialVersion)
  80. {
  81. EditorUtils.DrawSectionColored("- AVPRO MOVIE CAPTURE -\nFREE TRIAL VERSION", ref _isExpandedTrial, DrawTrialMessage, Color.yellow, Color.yellow, Color.yellow);
  82. }
  83. // Button to launch the capture window
  84. {
  85. GUI.backgroundColor = new Color(0.96f, 0.25f, 0.47f);
  86. if (GUILayout.Button("\n◄ Open Movie Capture Window ►\n"))
  87. {
  88. CaptureEditorWindow.Init();
  89. }
  90. GUI.backgroundColor = Color.white;
  91. }
  92. }
  93. protected void DrawTrialMessage()
  94. {
  95. string message = "The free trial version is limited to 10 seconds of capture time. UPGRADE to the full package for unlimited use.";
  96. GUI.backgroundColor = Color.yellow;
  97. EditorGUILayout.BeginVertical(GUI.skin.box);
  98. //GUI.color = Color.yellow;
  99. //GUILayout.Label("AVPRO MOVIE CAPTURE - FREE TRIAL VERSION", EditorStyles.boldLabel);
  100. GUI.color = Color.white;
  101. GUILayout.Label(message, EditorStyles.wordWrappedLabel);
  102. if (GUILayout.Button("Upgrade Now"))
  103. {
  104. Application.OpenURL("https://www.assetstore.unity3d.com/en/#!/content/2670");
  105. }
  106. EditorGUILayout.EndVertical();
  107. GUI.backgroundColor = Color.white;
  108. GUI.color = Color.white;
  109. }
  110. protected void GUI_BaseOptions()
  111. {
  112. serializedObject.Update();
  113. if (_baseCapture == null)
  114. {
  115. return;
  116. }
  117. //DrawDefaultInspector();
  118. if (!_baseCapture.IsCapturing())
  119. {
  120. GUILayout.Space(8f);
  121. EditorUtils.BoolAsDropdown("Capture Mode", _propIsRealtime, "Realtime Capture", "Offline Render");
  122. GUILayout.Space(8f);
  123. if (serializedObject.ApplyModifiedProperties())
  124. {
  125. EditorUtility.SetDirty(target);
  126. }
  127. GUI_User();
  128. // After the user mode we must update the serialised object again
  129. serializedObject.Update();
  130. EditorUtils.DrawSection("Start / Stop", ref _isExpandedStartStop, GUI_StartStop);
  131. EditorUtils.DrawSection("Output", ref _isExpandedOutput, GUI_OutputFilePath);
  132. EditorUtils.DrawSection("Visual", ref _isExpandedVisual, GUI_Visual);
  133. EditorUtils.DrawSection("Audio", ref _isExpandedAudio, GUI_Audio);
  134. EditorUtils.DrawSection("Misc", ref _isExpandedMisc, GUI_Misc);
  135. EditorUtils.DrawSection("About", ref _isExpandedAbout, GUI_About);
  136. if (serializedObject.ApplyModifiedProperties())
  137. {
  138. EditorUtility.SetDirty(target);
  139. }
  140. GUI_Controls();
  141. }
  142. else
  143. {
  144. GUI_Stats();
  145. GUI_Progress();
  146. GUI_Controls();
  147. }
  148. }
  149. protected void GUI_Progress()
  150. {
  151. if (_baseCapture == null)
  152. {
  153. return;
  154. }
  155. if (_propStopMode.enumValueIndex != (int)StopMode.None)
  156. {
  157. Rect r = GUILayoutUtility.GetRect(128f, EditorStyles.label.CalcHeight(GUIContent.none, 32f), GUILayout.ExpandWidth(true));
  158. float progress = _baseCapture.GetProgress();
  159. EditorGUI.ProgressBar(r, progress, (progress * 100f).ToString("F1") + "%");
  160. }
  161. }
  162. protected void GUI_Stats()
  163. {
  164. if (_baseCapture == null)
  165. {
  166. return;
  167. }
  168. if (Application.isPlaying && _baseCapture.IsCapturing())
  169. {
  170. CaptureEditorWindow.DrawBaseCapturingGUI(_baseCapture);
  171. if (!_baseCapture._isRealTime)
  172. {
  173. long lastFileSize = _baseCapture.GetCaptureFileSize();
  174. uint lastEncodedSeconds = (uint)Mathf.FloorToInt((float)_baseCapture.NumEncodedFrames / (float)_baseCapture._frameRate);
  175. if (_baseCapture._isRealTime)
  176. {
  177. lastEncodedSeconds = _baseCapture.TotalEncodedSeconds;
  178. }
  179. uint lastEncodedMinutes = lastEncodedSeconds / 60;
  180. lastEncodedSeconds = lastEncodedSeconds % 60;
  181. uint lastEncodedFrame = _baseCapture.NumEncodedFrames % (uint)_baseCapture._frameRate;
  182. EditorGUILayout.BeginVertical("box");
  183. EditorGUI.indentLevel++;
  184. EditorGUILayout.LabelField("File Size", ((float)lastFileSize / (1024f * 1024f)).ToString("F1") + "MB");
  185. EditorGUILayout.LabelField("Video Length", lastEncodedMinutes.ToString("00") + ":" + lastEncodedSeconds.ToString("00") + "." + lastEncodedFrame.ToString("000"));
  186. EditorGUI.indentLevel--;
  187. EditorGUILayout.EndVertical();
  188. }
  189. }
  190. }
  191. protected void GUI_Controls()
  192. {
  193. if (_baseCapture == null)
  194. {
  195. return;
  196. }
  197. GUILayout.Space(8.0f);
  198. EditorGUI.BeginDisabledGroup(!Application.isPlaying);
  199. {
  200. if (!_baseCapture.IsCapturing())
  201. {
  202. GUI.backgroundColor = Color.green;
  203. string startString = "Start Capture";
  204. if (!_baseCapture._isRealTime)
  205. {
  206. startString = "Start Render";
  207. }
  208. if (GUILayout.Button(startString, GUILayout.Height(32f)))
  209. {
  210. _baseCapture.SelectCodec(false);
  211. _baseCapture.SelectAudioDevice(false);
  212. // We have to queue the start capture otherwise Screen.width and height aren't correct
  213. _baseCapture.QueueStartCapture();
  214. }
  215. GUI.backgroundColor = Color.white;
  216. }
  217. else
  218. {
  219. GUILayout.BeginHorizontal();
  220. if (!_baseCapture.IsPaused())
  221. {
  222. GUI.backgroundColor = Color.yellow;
  223. if (GUILayout.Button("Pause", GUILayout.Height(32f)))
  224. {
  225. _baseCapture.PauseCapture();
  226. }
  227. }
  228. else
  229. {
  230. GUI.backgroundColor = Color.green;
  231. if (GUILayout.Button("Resume", GUILayout.Height(32f)))
  232. {
  233. _baseCapture.ResumeCapture();
  234. }
  235. }
  236. GUI.backgroundColor = Color.cyan;
  237. if (GUILayout.Button("Cancel", GUILayout.Height(32f)))
  238. {
  239. _baseCapture.CancelCapture();
  240. }
  241. GUI.backgroundColor = Color.red;
  242. if (GUILayout.Button("Stop", GUILayout.Height(32f)))
  243. {
  244. _baseCapture.StopCapture();
  245. }
  246. GUI.backgroundColor = Color.white;
  247. GUILayout.EndHorizontal();
  248. }
  249. }
  250. EditorGUI.EndDisabledGroup();
  251. EditorGUILayout.Space();
  252. EditorGUI.BeginDisabledGroup(string.IsNullOrEmpty(CaptureBase.LastFileSaved));
  253. GUILayout.BeginHorizontal();
  254. if (GUILayout.Button("Browse Last"))
  255. {
  256. if (!string.IsNullOrEmpty(CaptureBase.LastFileSaved))
  257. {
  258. Utils.ShowInExplorer(CaptureBase.LastFileSaved);
  259. }
  260. }
  261. if (GUILayout.Button("View Last Capture"))
  262. {
  263. if (!string.IsNullOrEmpty(CaptureBase.LastFileSaved))
  264. {
  265. Utils.OpenInDefaultApp(CaptureBase.LastFileSaved);
  266. }
  267. }
  268. GUILayout.EndHorizontal();
  269. EditorGUI.EndDisabledGroup();
  270. }
  271. protected void GUI_OutputFilePath()
  272. {
  273. EditorUtils.EnumAsDropdown("Output Type", _propOutputType, new string[] { "Video File", "Named Pipe" });
  274. if (_propOutputType.enumValueIndex == (int)CaptureBase.OutputType.VideoFile)
  275. {
  276. GUILayout.Label("Folder", EditorStyles.boldLabel);
  277. EditorGUILayout.PropertyField(_propOutputFolderType, new GUIContent("Folder"));
  278. if (_propOutputFolderType.enumValueIndex == (int)CaptureBase.OutputPath.Absolute)
  279. {
  280. EditorGUILayout.BeginHorizontal();
  281. EditorGUILayout.PropertyField(_propOutputFolderPath, new GUIContent("Path"));
  282. if (GUILayout.Button(">", GUILayout.Width(22)))
  283. {
  284. _propOutputFolderPath.stringValue = EditorUtility.SaveFolderPanel("Select Folder To Store Video Captures", System.IO.Path.GetFullPath(System.IO.Path.Combine(Application.dataPath, "../")), "");
  285. }
  286. EditorGUILayout.EndHorizontal();
  287. }
  288. else
  289. {
  290. EditorGUILayout.PropertyField(_propOutputFolderPath, new GUIContent("Subfolder(s)"));
  291. }
  292. GUILayout.Label("File Name", EditorStyles.boldLabel);
  293. EditorGUILayout.PropertyField(_propAutoGenerateFileName, new GUIContent("Auto Generate"));
  294. if (_propAutoGenerateFileName.boolValue)
  295. {
  296. EditorGUILayout.PropertyField(_propAutoFileNamePrefix, new GUIContent("Prefix"));
  297. EditorGUILayout.PropertyField(_propFileNameExtension, new GUIContent("Extension"));
  298. }
  299. else
  300. {
  301. EditorGUILayout.PropertyField(_propForceFileName, new GUIContent("File Name"));
  302. }
  303. }
  304. else
  305. {
  306. EditorGUILayout.PropertyField(_propForceFileName, new GUIContent("Pipe Path"));
  307. }
  308. /*// File path
  309. EditorGUILayout.LabelField("File Path", EditorStyles.boldLabel);
  310. EditorGUI.indentLevel++;
  311. _outputFolderIndex = EditorGUILayout.Popup("Relative to", _outputFolderIndex, _outputFolders);
  312. if (_outputFolderIndex == 0 || _outputFolderIndex == 1)
  313. {
  314. _outputFolderRelative = EditorGUILayout.TextField("SubFolder(s)", _outputFolderRelative);
  315. }
  316. else
  317. {
  318. EditorGUILayout.BeginHorizontal();
  319. _outputFolderAbsolute = EditorGUILayout.TextField("Path", _outputFolderAbsolute);
  320. if (GUILayout.Button(">", GUILayout.Width(22)))
  321. {
  322. _outputFolderAbsolute = EditorUtility.SaveFolderPanel("Select Folder To Store Video Captures", System.IO.Path.GetFullPath(System.IO.Path.Combine(Application.dataPath, "../")), "");
  323. EditorUtility.SetDirty(this);
  324. }
  325. EditorGUILayout.EndHorizontal();
  326. }
  327. EditorGUI.indentLevel--;*/
  328. }
  329. protected void GUI_StartStop()
  330. {
  331. EditorGUILayout.PropertyField(_propCaptureOnStart);
  332. EditorGUILayout.PropertyField(_propIsStartPaused);
  333. EditorGUILayout.PropertyField(_propCaptureKey, new GUIContent("Capture Toggle Key"));
  334. EditorGUILayout.PropertyField(_propStopMode, new GUIContent("Stop Mode"));
  335. if ((StopMode)_propStopMode.enumValueIndex == StopMode.FramesEncoded)
  336. {
  337. EditorGUILayout.PropertyField(_propStopFrames, new GUIContent("Frames"));
  338. }
  339. else if ((StopMode)_propStopMode.enumValueIndex == StopMode.SecondsElapsed || (StopMode)_propStopMode.enumValueIndex == StopMode.SecondsEncoded)
  340. {
  341. EditorGUILayout.PropertyField(_propStopSeconds, new GUIContent("Seconds"));
  342. }
  343. }
  344. protected virtual void GUI_Misc()
  345. {
  346. EditorGUILayout.PropertyField(_propAllowVsyncDisable);
  347. EditorGUILayout.PropertyField(_propSupportTextureRecreate, new GUIContent("Support Texture Recreate", "Using this option will slow rendering (forces GPU sync), but is needed to handle cases where texture resources are recreated, due to alt-tab or window resizing."));
  348. EditorGUILayout.PropertyField(_propMinimumDiskSpaceMB);
  349. EditorGUILayout.PropertyField(_propListCodecsOnStart);
  350. }
  351. protected virtual void GUI_About()
  352. {
  353. CaptureEditorWindow.DrawConfigGUI_About();
  354. }
  355. protected void GUI_Visual()
  356. {
  357. EditorGUILayout.PropertyField(_propDownScale);
  358. if (_propDownScale.enumValueIndex == 5)
  359. {
  360. EditorGUILayout.PropertyField(_propMaxVideoSize, new GUIContent("Size"));
  361. _propMaxVideoSize.vector2Value = new Vector2(Mathf.Clamp((int)_propMaxVideoSize.vector2Value.x, 1, NativePlugin.MaxRenderWidth), Mathf.Clamp((int)_propMaxVideoSize.vector2Value.y, 1, NativePlugin.MaxRenderHeight));
  362. }
  363. EditorUtils.EnumAsDropdown("Frame Rate", _propFrameRate, new string[] { "1", "10", "15", "24", "25", "30", "50", "60", "75", "90", "120" });
  364. EditorGUILayout.PropertyField(_propFlipVertically);
  365. EditorGUILayout.PropertyField(_propSupportAlpha);
  366. EditorGUILayout.Space();
  367. EditorGUI.BeginDisabledGroup(_propOutputType.enumValueIndex != (int)CaptureBase.OutputType.VideoFile);
  368. GUILayout.Label("Codecs", EditorStyles.boldLabel);
  369. if (_propOutputType.enumValueIndex == (int)CaptureBase.OutputType.VideoFile)
  370. {
  371. GUI_VisualCodecs();
  372. }
  373. else
  374. {
  375. GUI.color = Color.yellow;
  376. EditorGUILayout.TextArea("Codec selection not available when using named pipe output");
  377. GUI.color = Color.white;
  378. }
  379. EditorGUI.EndDisabledGroup();
  380. EditorGUILayout.Space();
  381. EditorGUI.BeginDisabledGroup(_propIsRealtime.boolValue);
  382. GUILayout.Label("Motion Blur", EditorStyles.boldLabel);
  383. if (_propIsRealtime.boolValue)
  384. {
  385. GUI.color = Color.yellow;
  386. GUILayout.TextArea("Motion Blur only available in Offline Render mode");
  387. GUI.color = Color.white;
  388. }
  389. else
  390. {
  391. GUI_MotionBlur();
  392. }
  393. EditorGUI.EndDisabledGroup();
  394. }
  395. protected void GUI_VisualCodecs()
  396. {
  397. EditorGUILayout.PropertyField(_propUseMediaFoundationH264, new GUIContent("Use MF H.264 MP4 Codec"));
  398. if (!_propUseMediaFoundationH264.boolValue)
  399. {
  400. EditorGUILayout.PropertyField(_propVideoCodecPriority, new GUIContent("Codec Search Prority"), true);
  401. EditorGUILayout.PropertyField(_propForceVideoCodecIndex);
  402. }
  403. }
  404. protected void GUI_Audio()
  405. {
  406. EditorGUI.BeginDisabledGroup(!_propIsRealtime.boolValue || _propOutputType.enumValueIndex == (int)CaptureBase.OutputType.NamedPipe);
  407. if (!_propIsRealtime.boolValue)
  408. {
  409. GUI.color = Color.yellow;
  410. GUILayout.TextArea("Audio Capture only available in Realtime Capture mode");
  411. GUI.color = Color.white;
  412. }
  413. if (_propOutputType.enumValueIndex == (int)CaptureBase.OutputType.NamedPipe)
  414. {
  415. GUI.color = Color.yellow;
  416. GUILayout.TextArea("Audio Capture not available for named pipe output");
  417. GUI.color = Color.white;
  418. }
  419. if (GUI.enabled)
  420. {
  421. _propNoAudio.boolValue = !EditorGUILayout.Toggle("Capture Audio", !_propNoAudio.boolValue);
  422. if (!_propNoAudio.boolValue)
  423. {
  424. EditorUtils.IntAsDropdown("Source", _propForceAudioDeviceIndex, new string[] { "Unity", "System Recording Device" }, new int[] { -1, Mathf.Max(0, _propForceAudioDeviceIndex.intValue) });
  425. if (_propForceAudioDeviceIndex.intValue >= 0)
  426. {
  427. EditorGUILayout.PropertyField(_propForceAudioDeviceIndex);
  428. }
  429. else
  430. {
  431. EditorGUILayout.PropertyField(_propUnityAudioCapture);
  432. }
  433. EditorGUILayout.PropertyField(_propAudioCodecPriority, true);
  434. EditorGUILayout.PropertyField(_propForceAudioCodecIndex);
  435. }
  436. }
  437. EditorGUI.EndDisabledGroup();
  438. }
  439. protected void GUI_MotionBlur()
  440. {
  441. EditorGUILayout.PropertyField(_propUseMotionBlur);
  442. if (_propUseMotionBlur.boolValue)
  443. {
  444. EditorGUILayout.PropertyField(_propMotionBlurSamples, new GUIContent("Samples"));
  445. EditorGUILayout.PropertyField(_propMotionBlurCameras, new GUIContent("Cameras"), true);
  446. }
  447. }
  448. private void LoadSettings()
  449. {
  450. _isExpandedStartStop = EditorPrefs.GetBool(SettingsPrefix + "ExpandStartStop", _isExpandedStartStop);
  451. _isExpandedOutput = EditorPrefs.GetBool(SettingsPrefix + "ExpandOutput", _isExpandedOutput);
  452. _isExpandedVisual = EditorPrefs.GetBool(SettingsPrefix + "ExpandVisual", _isExpandedVisual);
  453. _isExpandedAudio = EditorPrefs.GetBool(SettingsPrefix + "ExpandAudio", _isExpandedAudio);
  454. _isExpandedMisc = EditorPrefs.GetBool(SettingsPrefix + "ExpandMisc", _isExpandedMisc);
  455. }
  456. private void SaveSettings()
  457. {
  458. EditorPrefs.SetBool(SettingsPrefix + "ExpandStartStop", _isExpandedStartStop);
  459. EditorPrefs.SetBool(SettingsPrefix + "ExpandOutput", _isExpandedOutput);
  460. EditorPrefs.SetBool(SettingsPrefix + "ExpandVisual", _isExpandedVisual);
  461. EditorPrefs.SetBool(SettingsPrefix + "ExpandAudio", _isExpandedAudio);
  462. EditorPrefs.SetBool(SettingsPrefix + "ExpandMisc", _isExpandedMisc);
  463. }
  464. protected virtual void OnEnable()
  465. {
  466. LoadSettings();
  467. _baseCapture = (CaptureBase)this.target;
  468. _propCaptureOnStart = serializedObject.FindProperty("_captureOnStart");
  469. _propCaptureKey = serializedObject.FindProperty("_captureKey");
  470. _propListCodecsOnStart = serializedObject.FindProperty("_listVideoCodecsOnStart");
  471. _propIsRealtime = serializedObject.FindProperty("_isRealTime");
  472. _propIsStartPaused = serializedObject.FindProperty("_startPaused");
  473. _propMinimumDiskSpaceMB = serializedObject.FindProperty("_minimumDiskSpaceMB");
  474. _propOutputType = serializedObject.FindProperty("_outputType");
  475. _propOutputFolderType = serializedObject.FindProperty("_outputFolderType");
  476. _propOutputFolderPath = serializedObject.FindProperty("_outputFolderPath");
  477. _propAutoGenerateFileName = serializedObject.FindProperty("_autoGenerateFilename");
  478. _propAutoFileNamePrefix = serializedObject.FindProperty("_autoFilenamePrefix");
  479. _propFileNameExtension = serializedObject.FindProperty("_autoFilenameExtension");
  480. _propForceFileName = serializedObject.FindProperty("_forceFilename");
  481. _propVideoCodecPriority = serializedObject.FindProperty("_videoCodecPriority");
  482. _propForceVideoCodecIndex = serializedObject.FindProperty("_forceVideoCodecIndex");
  483. _propUseMediaFoundationH264 = serializedObject.FindProperty("_useMediaFoundationH264");
  484. _propAudioCodecPriority = serializedObject.FindProperty("_audioCodecPriority");
  485. _propForceAudioCodecIndex = serializedObject.FindProperty("_forceAudioCodecIndex");
  486. _propForceAudioDeviceIndex = serializedObject.FindProperty("_forceAudioDeviceIndex");
  487. _propNoAudio = serializedObject.FindProperty("_noAudio");
  488. _propUnityAudioCapture = serializedObject.FindProperty("_audioCapture");
  489. _propDownScale = serializedObject.FindProperty("_downScale");
  490. _propMaxVideoSize = serializedObject.FindProperty("_maxVideoSize");
  491. _propFrameRate = serializedObject.FindProperty("_frameRate");
  492. _propFlipVertically = serializedObject.FindProperty("_flipVertically");
  493. _propSupportAlpha = serializedObject.FindProperty("_supportAlpha");
  494. _propUseMotionBlur = serializedObject.FindProperty("_useMotionBlur");
  495. _propMotionBlurSamples = serializedObject.FindProperty("_motionBlurSamples");
  496. _propMotionBlurCameras = serializedObject.FindProperty("_motionBlurCameras");
  497. _propStopMode = serializedObject.FindProperty("_stopMode");
  498. _propStopFrames = serializedObject.FindProperty("_stopFrames");
  499. _propStopSeconds = serializedObject.FindProperty("_stopSeconds");
  500. _propAllowVsyncDisable = serializedObject.FindProperty("_allowVSyncDisable");
  501. _propSupportTextureRecreate = serializedObject.FindProperty("_supportTextureRecreate");
  502. _isTrialVersion = false;
  503. if (Application.isPlaying)
  504. {
  505. _isTrialVersion = IsTrialVersion();
  506. }
  507. }
  508. private void OnDisable()
  509. {
  510. SaveSettings();
  511. }
  512. protected static bool IsTrialVersion()
  513. {
  514. bool result = false;
  515. try
  516. {
  517. result = NativePlugin.IsTrialVersion();
  518. }
  519. catch (System.DllNotFoundException)
  520. {
  521. // Silent catch as we report this error elsewhere
  522. }
  523. return result;
  524. }
  525. protected static void ShowNoticeBox(MessageType messageType, string message)
  526. {
  527. //GUI.backgroundColor = Color.yellow;
  528. //EditorGUILayout.HelpBox(message, messageType);
  529. switch (messageType)
  530. {
  531. case MessageType.Error:
  532. GUI.color = Color.red;
  533. message = "Error: " + message;
  534. break;
  535. case MessageType.Warning:
  536. GUI.color = Color.yellow;
  537. message = "Warning: " + message;
  538. break;
  539. }
  540. //GUI.color = Color.yellow;
  541. GUILayout.TextArea(message);
  542. GUI.color = Color.white;
  543. }
  544. public override bool RequiresConstantRepaint()
  545. {
  546. CaptureBase capture = (this.target) as CaptureBase;
  547. return (Application.isPlaying && capture.isActiveAndEnabled && capture.IsCapturing() && !capture.IsPaused());
  548. }
  549. }
  550. }
  551. #endif