CaptureFromCameraEditor.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. #if UNITY_EDITOR
  2. #if !UNITY_2018_3_OR_NEWER
  3. #define SUPPORT_SCENE_VIEW_GIZMOS_CAPTURE
  4. #endif
  5. using UnityEngine;
  6. using UnityEditor;
  7. //-----------------------------------------------------------------------------
  8. // Copyright 2012-2022 RenderHeads Ltd. All rights reserved.
  9. //-----------------------------------------------------------------------------
  10. namespace RenderHeads.Media.AVProMovieCapture.Editor
  11. {
  12. [CanEditMultipleObjects]
  13. [CustomEditor(typeof(CaptureFromCamera))]
  14. public class CaptureFromCameraEditor : CaptureBaseEditor
  15. {
  16. //private CaptureFromCamera _capture;
  17. private SerializedProperty _propCameraSelector;
  18. private SerializedProperty _propLastCamera;
  19. private SerializedProperty _propContribCameras;
  20. private SerializedProperty _propUseContribCameras;
  21. #if SUPPORT_SCENE_VIEW_GIZMOS_CAPTURE
  22. private SerializedProperty _propIncludeSceneViewGizmos;
  23. #endif
  24. private SerializedProperty _propRenderResolution;
  25. private SerializedProperty _propRenderSize;
  26. private SerializedProperty _propAntiAliasing;
  27. private static readonly GUIContent _guiItemCamera = new GUIContent("Camera", "The top level camera you want to capture");
  28. private static readonly GUIContent _guiItemContribCamera = new GUIContent("Contributing Cameras", "Cameras in render order from first to last that contribute to the rendering of the main camera above");
  29. protected override void OnEnable()
  30. {
  31. base.OnEnable();
  32. //_capture = (this.target) as CaptureFromCamera;
  33. _propCameraSelector = serializedObject.AssertFindProperty("_cameraSelector");
  34. _propLastCamera = serializedObject.AssertFindProperty("_lastCamera");
  35. _propContribCameras = serializedObject.AssertFindProperty("_contribCameras");
  36. _propContribCameras.isExpanded = true;
  37. _propUseContribCameras = serializedObject.AssertFindProperty("_useContributingCameras");
  38. #if SUPPORT_SCENE_VIEW_GIZMOS_CAPTURE
  39. _propIncludeSceneViewGizmos = serializedObject.AssertFindProperty("_includeSceneViewGizmos");
  40. #endif
  41. _propRenderResolution = serializedObject.AssertFindProperty("_renderResolution");
  42. _propRenderSize = serializedObject.AssertFindProperty("_renderSize");
  43. _propAntiAliasing = serializedObject.AssertFindProperty("_renderAntiAliasing");
  44. }
  45. protected void GUI_Camera()
  46. {
  47. Camera prevLastCamera = null, lastCamera = null;
  48. EditorGUILayout.PropertyField(_propCameraSelector);
  49. if (null == _propCameraSelector.objectReferenceValue)
  50. {
  51. prevLastCamera = (Camera)_propLastCamera.objectReferenceValue;
  52. EditorGUILayout.PropertyField(_propLastCamera, _guiItemCamera);
  53. lastCamera = (Camera)_propLastCamera.objectReferenceValue;
  54. }
  55. // If the user has changed the camera, reset the contributing cameras
  56. if (lastCamera != prevLastCamera)
  57. {
  58. _propContribCameras.arraySize = 0;
  59. if (lastCamera == null)
  60. {
  61. _propUseContribCameras.boolValue = false;
  62. }
  63. }
  64. _propUseContribCameras.boolValue = EditorGUILayout.ToggleLeft("Use Contributing Cameras", _propUseContribCameras.boolValue);
  65. if (lastCamera != null)
  66. {
  67. if (_propUseContribCameras.boolValue)
  68. {
  69. if (GUILayout.Button("Find Contributing Cameras", EditorStyles.miniButtonRight, GUILayout.ExpandWidth(false)))
  70. {
  71. bool hasContribCameras = false;
  72. if (Utils.HasContributingCameras(lastCamera))
  73. {
  74. Camera[] cameras = Utils.FindContributingCameras(lastCamera);
  75. if (cameras != null && cameras.Length > 0)
  76. {
  77. hasContribCameras = true;
  78. _propContribCameras.arraySize = cameras.Length;
  79. for (int slotIndex = 0; slotIndex < cameras.Length; slotIndex++)
  80. {
  81. _propContribCameras.GetArrayElementAtIndex(slotIndex).objectReferenceValue = cameras[slotIndex];
  82. }
  83. }
  84. }
  85. if (!hasContribCameras)
  86. {
  87. _propContribCameras.arraySize = 0;
  88. _propUseContribCameras.boolValue = false;
  89. }
  90. }
  91. EditorGUILayout.PropertyField(_propContribCameras, _guiItemContribCamera, true);
  92. EditorGUILayout.Space();
  93. }
  94. }
  95. EditorUtils.EnumAsDropdown("Resolution", _propRenderResolution, CaptureBaseEditor.ResolutionStrings);
  96. if (_propRenderResolution.enumValueIndex == (int)CaptureBase.Resolution.Custom)
  97. {
  98. EditorGUILayout.PropertyField(_propRenderSize, new GUIContent("Size"));
  99. _propRenderSize.vector2Value = new Vector2(Mathf.Clamp((int)_propRenderSize.vector2Value.x, 1, NativePlugin.MaxRenderWidth), Mathf.Clamp((int)_propRenderSize.vector2Value.y, 1, NativePlugin.MaxRenderHeight));
  100. }
  101. {
  102. string currentAA = "None";
  103. if (QualitySettings.antiAliasing > 1)
  104. {
  105. currentAA = QualitySettings.antiAliasing.ToString() + "x";
  106. }
  107. EditorUtils.IntAsDropdown("Anti-aliasing", _propAntiAliasing, new string[] { "Current (" + currentAA + ")", "None", "2x", "4x", "8x" }, new int[] { -1, 1, 2, 4, 8 });
  108. }
  109. #if SUPPORT_SCENE_VIEW_GIZMOS_CAPTURE
  110. EditorGUILayout.PropertyField(_propIncludeSceneViewGizmos);
  111. #endif
  112. }
  113. protected override void GUI_User()
  114. {
  115. if (_baseCapture != null && !_baseCapture.IsCapturing())
  116. {
  117. serializedObject.Update();
  118. bool boolTrue = true;
  119. EditorUtils.DrawSection("Capture From Camera", ref boolTrue, GUI_Camera);
  120. if (serializedObject.ApplyModifiedProperties())
  121. {
  122. EditorUtility.SetDirty(target);
  123. }
  124. }
  125. }
  126. /*
  127. public override void OnInspectorGUI()
  128. {
  129. GUI_Header();
  130. GUI_BaseOptions();
  131. }*/
  132. }
  133. }
  134. #endif