public void OnRecorderSelected()
        {
            if (m_Editor != null)
            {
                UnityHelpers.Destroy(m_Editor);
                m_Editor = null;
            }

            if (m_recorderSelector.selectedRecorder == null)
            {
                return;
            }

            m_Category = m_recorderSelector.category;

            if (m_WindowSettingsAsset.m_Settings != null &&
                RecordersInventory.GetRecorderInfo(m_recorderSelector.selectedRecorder).settingsClass != m_WindowSettingsAsset.m_Settings.GetType())
            {
                CleanupSettingsAsset();
            }

            if (m_WindowSettingsAsset.m_Settings == null)
            {
                m_WindowSettingsAsset.m_Settings = RecordersInventory.GenerateRecorderInitialSettings(m_WindowSettingsAsset, m_recorderSelector.selectedRecorder);
            }
            m_Editor = Editor.CreateEditor(m_WindowSettingsAsset.m_Settings) as RecorderEditor;
            AssetDatabase.Refresh();
        }
        void ResetSettings()
        {
            UnityHelpers.Destroy(m_Editor);
            m_Editor           = null;
            m_recorderSelector = null;
            var path = AssetDatabase.GetAssetPath(m_WindowSettingsAsset);

            UnityHelpers.Destroy(m_WindowSettingsAsset, true);
            AssetDatabase.DeleteAsset(path);
            AssetDatabase.Refresh(ImportAssetOptions.Default);
            m_WindowSettingsAsset = null;
        }
        public void OnGUI()
        {
            try
            {
                m_ScrollPos = EditorGUILayout.BeginScrollView(m_ScrollPos);
                try
                {
                    m_LastRepaint = DateTime.Now;

                    // Bug? work arround: on Stop play, Enable is not called.
                    if (m_Editor != null && m_Editor.target == null)
                    {
                        UnityHelpers.Destroy(m_Editor);
                        m_Editor           = null;
                        m_recorderSelector = null;
                    }

                    if (m_recorderSelector == null)
                    {
                        if (m_WindowSettingsAsset == null)
                        {
                            var candidates = AssetDatabase.FindAssets("t:RecorderWindowSettings");
                            if (candidates.Length > 0)
                            {
                                var path = AssetDatabase.GUIDToAssetPath(candidates[0]);
                                m_WindowSettingsAsset = AssetDatabase.LoadAssetAtPath <RecorderWindowSettings>(path);
                                if (m_WindowSettingsAsset == null)
                                {
                                    AssetDatabase.DeleteAsset(path);
                                }
                            }
                            if (m_WindowSettingsAsset == null)
                            {
                                m_WindowSettingsAsset = ScriptableObject.CreateInstance <RecorderWindowSettings>();
                                AssetDatabase.CreateAsset(m_WindowSettingsAsset, FRPackagerPaths.GetRecorderRootPath() + "/RecorderWindowSettings.asset");
                                AssetDatabase.Refresh();
                            }
                        }

                        m_recorderSelector = new RecorderSelector(OnRecorderSelected, false);
                        m_recorderSelector.Init(m_WindowSettingsAsset.m_Settings, m_Category);
                    }

                    if (m_State == EState.WaitingForPlayModeToStartRecording && EditorApplication.isPlaying)
                    {
                        DelayedStartRecording();
                    }

                    using (new EditorGUI.DisabledScope(EditorApplication.isPlaying))
                        m_recorderSelector.OnGui();

                    if (m_Editor != null)
                    {
                        m_Editor.showBounds = true;
                        using (new EditorGUI.DisabledScope(EditorApplication.isPlaying))
                        {
                            EditorGUILayout.Separator();
                            m_Editor.OnInspectorGUI();
                            EditorGUILayout.Separator();
                        }
                        RecordButtonOnGui();
                        GUILayout.Space(50);
                    }
                }
                finally
                {
                    EditorGUILayout.EndScrollView();
                }
            }
            catch (ExitGUIException)
            {
            }
            catch (Exception ex)
            {
                if (m_State == EState.Recording)
                {
                    try
                    {
                        Debug.LogError("Aborting recording due to an exception!\n" + ex.ToString());
                        StopRecording();
                    }
                    catch (Exception) {}
                }
                else
                {
                    EditorGUILayout.HelpBox("An exception was raised while editing the settings. This can be indicative of corrupted settings.", MessageType.Warning);

                    if (GUILayout.Button("Reset settings to default"))
                    {
                        ResetSettings();
                    }
                }
            }
        }
 public void OnDestroy()
 {
     StopRecording();
     UnityHelpers.Destroy(m_Editor);
     m_Editor = null;
 }