RecorderEditor.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using UnityEngine;
  4. namespace UnityEditor.Recorder
  5. {
  6. public abstract class RecorderEditor : Editor
  7. {
  8. SerializedProperty m_CaptureEveryNthFrame;
  9. SerializedProperty m_FileNameGenerator;
  10. SerializedProperty m_Take;
  11. static Texture2D s_SeparatorTexture;
  12. static readonly Color s_SeparatorColor = new Color(1.0f, 1.0f, 1.0f, 0.1f);
  13. static class Styles
  14. {
  15. internal static readonly GUIContent FileNameLabel = new GUIContent("File Name");
  16. internal static readonly GUIContent CaptureLabel = new GUIContent("Capture");
  17. internal static readonly GUIContent TakeNumberLabel = new GUIContent("Take Number");
  18. internal static readonly GUIContent RenderStepFrameLabel = new GUIContent("Render Step Frame");
  19. }
  20. protected virtual void OnEnable()
  21. {
  22. if (target != null)
  23. {
  24. var pf = new PropertyFinder<RecorderSettings>(serializedObject);
  25. m_CaptureEveryNthFrame = pf.Find(w => w.captureEveryNthFrame);
  26. m_FileNameGenerator = pf.Find(w => w.fileNameGenerator);
  27. m_Take = pf.Find(w => w.take);
  28. s_SeparatorTexture = Resources.Load<Texture2D>("vertical_gradient");
  29. }
  30. }
  31. protected static void DrawSeparator()
  32. {
  33. EditorGUILayout.Separator();
  34. var r = EditorGUILayout.GetControlRect();
  35. r.xMin -= 10.0f;
  36. r.xMax += 10.0f;
  37. r.yMin += 5.0f;
  38. r.height = 10;
  39. var orgColor = GUI.color;
  40. GUI.color = s_SeparatorColor;
  41. GUI.DrawTexture(r, s_SeparatorTexture);
  42. GUI.color = orgColor;
  43. EditorGUILayout.Separator();
  44. }
  45. public override void OnInspectorGUI()
  46. {
  47. if (target == null)
  48. return;
  49. EditorGUI.BeginChangeCheck();
  50. serializedObject.Update();
  51. FileTypeAndFormatGUI();
  52. DrawSeparator();
  53. AOVGUI();
  54. NameAndPathGUI();
  55. ImageRenderOptionsGUI();
  56. EditorGUILayout.Separator();
  57. ExtraOptionsGUI();
  58. EditorGUILayout.Separator();
  59. OnEncodingGui();
  60. serializedObject.ApplyModifiedProperties();
  61. EditorGUI.EndChangeCheck();
  62. if (GUI.changed)
  63. ((RecorderSettings) target).SelfAdjustSettings();
  64. OnValidateSettingsGUI();
  65. }
  66. protected virtual void OnValidateSettingsGUI()
  67. {
  68. var errors = new List<string>();
  69. if (!((RecorderSettings) target).ValidityCheck(errors))
  70. {
  71. foreach (var error in errors)
  72. EditorGUILayout.HelpBox(error, MessageType.Warning);
  73. }
  74. }
  75. protected virtual void NameAndPathGUI()
  76. {
  77. EditorGUILayout.PropertyField(m_FileNameGenerator, Styles.FileNameLabel);
  78. EditorGUILayout.Space();
  79. EditorGUI.BeginChangeCheck();
  80. EditorGUILayout.PropertyField(m_Take, Styles.TakeNumberLabel);
  81. if (EditorGUI.EndChangeCheck())
  82. m_Take.intValue = Mathf.Max(0, m_Take.intValue);
  83. }
  84. protected virtual void ImageRenderOptionsGUI()
  85. {
  86. var recorder = (RecorderSettings) target;
  87. foreach (var inputsSetting in recorder.InputsSettings)
  88. {
  89. var p = GetInputSerializedProperty(serializedObject, inputsSetting);
  90. EditorGUILayout.Separator();
  91. EditorGUILayout.PropertyField(p, Styles.CaptureLabel);
  92. }
  93. }
  94. static SerializedProperty GetInputSerializedProperty(SerializedObject owner, object fieldValue)
  95. {
  96. var targetObject = (object)owner.targetObject;
  97. var type = targetObject.GetType();
  98. foreach (var info in InputSettingsSelector.GetInputFields(type))
  99. {
  100. if (info.GetValue(targetObject) == fieldValue)
  101. {
  102. return owner.FindProperty(info.Name);
  103. }
  104. if (typeof(InputSettingsSelector).IsAssignableFrom(info.FieldType))
  105. {
  106. var selector = info.GetValue(targetObject);
  107. var fields = InputSettingsSelector.GetInputFields(selector.GetType());
  108. var selectorInput = fields.FirstOrDefault(i => i.GetValue(selector) == fieldValue);
  109. if (selectorInput != null)
  110. {
  111. return owner.FindProperty(info.Name);
  112. }
  113. }
  114. }
  115. return null;
  116. }
  117. protected virtual void ExtraOptionsGUI()
  118. {
  119. if (((RecorderSettings)target).FrameRatePlayback == FrameRatePlayback.Variable)
  120. EditorGUILayout.PropertyField(m_CaptureEveryNthFrame, Styles.RenderStepFrameLabel);
  121. }
  122. protected virtual void FileTypeAndFormatGUI()
  123. {
  124. }
  125. protected virtual void OnEncodingGui()
  126. {
  127. }
  128. protected virtual void AOVGUI()
  129. {
  130. }
  131. }
  132. }