RecorderControllerSettingsPresetEditor.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. using System.Collections.Generic;
  2. namespace UnityEditor.Recorder
  3. {
  4. [CustomEditor(typeof(RecorderControllerSettingsPreset))]
  5. class RecorderControllerSettingsPresetEditor : Editor
  6. {
  7. Editor m_Editor;
  8. class PresetEditorState
  9. {
  10. public bool expanded;
  11. public Editor presetEditor;
  12. }
  13. readonly List<PresetEditorState> m_RecordersEditors = new List<PresetEditorState>();
  14. void OnEnable()
  15. {
  16. if (target == null)
  17. return;
  18. var preset = (RecorderControllerSettingsPreset) target;
  19. m_Editor = CreateEditor(preset.model);
  20. m_RecordersEditors.Clear();
  21. var recorderPresets = preset.recorderPresets;
  22. foreach (var p in recorderPresets)
  23. {
  24. var state = new PresetEditorState
  25. {
  26. presetEditor = CreateEditor(p),
  27. expanded = false
  28. };
  29. m_RecordersEditors.Add(state);
  30. }
  31. }
  32. public override void OnInspectorGUI()
  33. {
  34. if (target == null)
  35. return;
  36. m_Editor.OnInspectorGUI();
  37. EditorGUILayout.Separator();
  38. foreach (var state in m_RecordersEditors)
  39. {
  40. if (FoldoutPresetEditorStateHeader(state))
  41. {
  42. EditorGUILayout.Separator();
  43. state.presetEditor.OnInspectorGUI();
  44. }
  45. }
  46. }
  47. static bool FoldoutPresetEditorStateHeader(PresetEditorState state)
  48. {
  49. var r = EditorGUILayout.GetControlRect();
  50. state.expanded = EditorGUI.Foldout(r, state.expanded, state.presetEditor.target.name);
  51. return state.expanded;
  52. }
  53. void OnDestroy()
  54. {
  55. if (m_Editor != null)
  56. {
  57. DestroyImmediate(m_Editor);
  58. m_Editor = null;
  59. }
  60. foreach (var state in m_RecordersEditors)
  61. DestroyImmediate(state.presetEditor);
  62. m_RecordersEditors.Clear();
  63. }
  64. }
  65. }