CameraSelectorEditor.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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(CameraSelector))]
  14. public class CameraSelectorEditor : UnityEditor.Editor
  15. {
  16. private SerializedProperty _propSelectBy;
  17. private SerializedProperty _propScanFrequency;
  18. private SerializedProperty _propScanHiddenCameras;
  19. private SerializedProperty _propTag;
  20. private SerializedProperty _propName;
  21. private SerializedProperty _propCamera;
  22. void OnEnable()
  23. {
  24. _propSelectBy = serializedObject.AssertFindProperty("_selectBy");
  25. _propScanFrequency = serializedObject.AssertFindProperty("_scanFrequency");
  26. _propScanHiddenCameras = serializedObject.AssertFindProperty("_scanHiddenCameras");
  27. _propTag = serializedObject.AssertFindProperty("_tag");
  28. _propName = serializedObject.AssertFindProperty("_name");
  29. _propCamera = serializedObject.AssertFindProperty("_camera");
  30. }
  31. public override void OnInspectorGUI()
  32. {
  33. serializedObject.Update();
  34. EditorGUILayout.PropertyField(_propScanFrequency);
  35. EditorGUILayout.PropertyField(_propScanHiddenCameras);
  36. EditorGUILayout.PropertyField(_propSelectBy);
  37. if (_propSelectBy.enumValueIndex == (int)CameraSelector.SelectByMode.Name)
  38. {
  39. EditorGUILayout.PropertyField(_propName);
  40. }
  41. else if (_propSelectBy.enumValueIndex == (int)CameraSelector.SelectByMode.Tag)
  42. {
  43. EditorGUILayout.PropertyField(_propTag);
  44. }
  45. else if (_propSelectBy.enumValueIndex == (int)CameraSelector.SelectByMode.Manual)
  46. {
  47. EditorGUILayout.PropertyField(_propCamera);
  48. }
  49. #if !SUPPORT_SCENE_VIEW_GIZMOS_CAPTURE
  50. else if (_propSelectBy.enumValueIndex == (int)CameraSelector.SelectByMode.EditorSceneView)
  51. {
  52. GUI.color = Color.yellow;
  53. GUILayout.TextArea("Warning: Scene View capture only currently supports gizmo capture up to Unity 2018.2.x");
  54. GUI.color = Color.white;
  55. }
  56. #endif
  57. if (Application.isPlaying)
  58. {
  59. EditorGUILayout.Separator();
  60. GUILayout.Label("Cameras:");
  61. CameraSelector selector = (this.target) as CameraSelector;
  62. // Display buttons for all possible cameras
  63. for (int i = 0; i < selector.CameraCacheCount; i++)
  64. {
  65. if (selector.Camera != selector.CameraCache[i])
  66. {
  67. if (GUILayout.Button(selector.CameraCache[i].name))
  68. {
  69. selector.Camera = selector.CameraCache[i];
  70. }
  71. }
  72. else
  73. {
  74. GUI.color = Color.green;
  75. GUILayout.Button(selector.Camera.name);
  76. GUI.color = Color.white;
  77. }
  78. }
  79. EditorGUILayout.Separator();
  80. if (_propScanFrequency.enumValueIndex != (int)CameraSelector.ScanFrequencyMode.Frame)
  81. {
  82. if (GUILayout.Button("Update Camera List"))
  83. {
  84. selector.UpdateCameraCache();
  85. }
  86. }
  87. }
  88. serializedObject.ApplyModifiedProperties();
  89. }
  90. }
  91. }
  92. #endif