CaptureFromCameraEditor.cs 4.3 KB

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