RecorderSettingsPrefsEditor.cs 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. using UnityEngine;
  2. namespace UnityEditor.Recorder
  3. {
  4. [CustomEditor(typeof(RecorderControllerSettings))]
  5. class RecorderSettingsPrefsEditor : Editor
  6. {
  7. SerializedProperty m_RecordModeProperty;
  8. SerializedProperty m_PlaybackProperty;
  9. SerializedProperty m_FrameRateTypeProperty;
  10. SerializedProperty m_CustomFrameRateValueProperty;
  11. SerializedProperty m_StartFrameProperty;
  12. SerializedProperty m_EndFrameProperty;
  13. SerializedProperty m_StartTimeProperty;
  14. SerializedProperty m_EndTimeProperty;
  15. SerializedProperty m_CapFrameRateProperty;
  16. GenericMenu m_FrameRateMenu;
  17. static class Styles
  18. {
  19. internal static readonly GUIContent RecordModeLabel = new GUIContent("Record Mode");
  20. internal static readonly GUIContent SingleFrameLabel = new GUIContent("Frame");
  21. internal static readonly GUIContent StartLabel = new GUIContent("Start");
  22. internal static readonly GUIContent EndLabel = new GUIContent("End");
  23. internal static readonly GUIContent FrameRateTitle = new GUIContent("Frame Rate");
  24. internal static readonly GUIContent PlaybackLabel = new GUIContent("Playback");
  25. internal static readonly GUIContent TargetFPSLabel = new GUIContent("Target");
  26. internal static readonly GUIContent MaxFPSLabel = new GUIContent("Max");
  27. internal static readonly GUIContent CapFPSLabel = new GUIContent("Cap");
  28. internal static readonly GUIContent ValueLabel = new GUIContent("Value");
  29. }
  30. void OnEnable()
  31. {
  32. if (target == null)
  33. return;
  34. m_RecordModeProperty = serializedObject.FindProperty("m_RecordMode");
  35. m_PlaybackProperty = serializedObject.FindProperty("m_FrameRatePlayback");
  36. m_FrameRateTypeProperty = serializedObject.FindProperty("m_FrameRateType");
  37. m_CustomFrameRateValueProperty = serializedObject.FindProperty("m_CustomFrameRateValue");
  38. m_StartFrameProperty = serializedObject.FindProperty("m_StartFrame");
  39. m_EndFrameProperty = serializedObject.FindProperty("m_EndFrame");
  40. m_StartTimeProperty = serializedObject.FindProperty("m_StartTime");
  41. m_EndTimeProperty = serializedObject.FindProperty("m_EndTime");
  42. m_CapFrameRateProperty = serializedObject.FindProperty("m_CapFrameRate");
  43. }
  44. public override void OnInspectorGUI()
  45. {
  46. RecordModeGUI();
  47. EditorGUILayout.Separator();
  48. FrameRateGUI();
  49. }
  50. internal bool RecordModeGUI()
  51. {
  52. serializedObject.Update();
  53. EditorGUILayout.PropertyField(m_RecordModeProperty, Styles.RecordModeLabel);
  54. ++EditorGUI.indentLevel;
  55. switch ((RecordMode)m_RecordModeProperty.enumValueIndex)
  56. {
  57. case RecordMode.Manual:
  58. {
  59. // Nothing
  60. break;
  61. }
  62. case RecordMode.SingleFrame:
  63. {
  64. var value = EditorGUILayout.IntField(Styles.SingleFrameLabel, m_StartFrameProperty.intValue);
  65. m_StartFrameProperty.intValue = Mathf.Max(value, 0);
  66. break;
  67. }
  68. case RecordMode.FrameInterval:
  69. {
  70. var outputDimensions = new int[2];
  71. outputDimensions[0] = m_StartFrameProperty.intValue;
  72. outputDimensions[1] = m_EndFrameProperty.intValue;
  73. if (UIElementHelper.MultiIntField(GUIContent.none, new [] { Styles.StartLabel, Styles.EndLabel },
  74. outputDimensions))
  75. {
  76. m_StartFrameProperty.intValue = Mathf.Max(outputDimensions[0], 0);
  77. m_EndFrameProperty.intValue = Mathf.Max(outputDimensions[1], m_StartFrameProperty.intValue);
  78. }
  79. break;
  80. }
  81. case RecordMode.TimeInterval:
  82. {
  83. var outputDimensions = new float[2];
  84. outputDimensions[0] = m_StartTimeProperty.floatValue;
  85. outputDimensions[1] = m_EndTimeProperty.floatValue;
  86. if (UIElementHelper.MultiFloatField(GUIContent.none, new [] { Styles.StartLabel, Styles.EndLabel },
  87. outputDimensions))
  88. {
  89. m_StartTimeProperty.floatValue = Mathf.Max(outputDimensions[0], 0);
  90. m_EndTimeProperty.floatValue = Mathf.Max(outputDimensions[1], m_StartTimeProperty.floatValue);
  91. }
  92. break;
  93. }
  94. }
  95. --EditorGUI.indentLevel;
  96. serializedObject.ApplyModifiedProperties();
  97. return GUI.changed;
  98. }
  99. internal bool FrameRateGUI()
  100. {
  101. serializedObject.Update();
  102. EditorGUILayout.LabelField(Styles.FrameRateTitle);
  103. ++EditorGUI.indentLevel;
  104. EditorGUILayout.PropertyField(m_PlaybackProperty, Styles.PlaybackLabel);
  105. var variableFPS = m_PlaybackProperty.enumValueIndex == (int) FrameRatePlayback.Variable;
  106. EditorGUILayout.PropertyField(m_FrameRateTypeProperty, variableFPS ? Styles.MaxFPSLabel : Styles.TargetFPSLabel);
  107. if (m_FrameRateTypeProperty.enumValueIndex == (int) FrameRateType.FR_CUSTOM)
  108. {
  109. ++EditorGUI.indentLevel;
  110. EditorGUILayout.PropertyField(m_CustomFrameRateValueProperty, Styles.ValueLabel);
  111. --EditorGUI.indentLevel;
  112. }
  113. if (!variableFPS)
  114. {
  115. EditorGUILayout.PropertyField(m_CapFrameRateProperty, Styles.CapFPSLabel);
  116. }
  117. --EditorGUI.indentLevel;
  118. serializedObject.ApplyModifiedProperties();
  119. return GUI.changed;
  120. }
  121. }
  122. }