VideoStreamSenderEditor.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. #if UNITY_EDITOR
  2. using System;
  3. using UnityEngine;
  4. using UnityEditor;
  5. using UnityEditor.AnimatedValues;
  6. namespace Unity.RenderStreaming.Editor
  7. {
  8. [CustomEditor(typeof(VideoStreamSender))]
  9. [CanEditMultipleObjects]
  10. internal class VideoStreamSenderEditor : UnityEditor.Editor
  11. {
  12. class Styles
  13. {
  14. public readonly GUIContent sourceContent =
  15. EditorGUIUtility.TrTextContent("Video Source Type", "Type of source the video will be streamed.");
  16. public readonly GUIContent frameRateContent =
  17. EditorGUIUtility.TrTextContent("Frame rate", "A value affects loads on the encoding thread.");
  18. public readonly GUIContent bitrateContent =
  19. EditorGUIUtility.TrTextContent("Bitrate (kbits/sec)", "A range of bitrate of video streaming.");
  20. public readonly GUIContent scaleFactorContent =
  21. EditorGUIUtility.TrTextContent("Scale Resolution Down", "A factor of downscale resolution.");
  22. }
  23. static Styles s_Styles;
  24. SerializedProperty m_source;
  25. SerializedProperty m_camera;
  26. SerializedProperty m_texture;
  27. SerializedProperty m_frameRate;
  28. SerializedProperty m_bitrate;
  29. SerializedProperty m_scaleFactor;
  30. SerializedProperty m_depth;
  31. SerializedProperty m_antiAliasing;
  32. SerializedProperty m_codec;
  33. SerializedProperty m_textureSize;
  34. SerializedProperty m_webCamDeviceIndex;
  35. SerializedProperty m_autoRequestUserAuthorization;
  36. static AnimBool[] m_sourceFade;
  37. void OnEnable()
  38. {
  39. m_source = serializedObject.FindProperty("m_Source");
  40. m_camera = serializedObject.FindProperty("m_Camera");
  41. m_texture = serializedObject.FindProperty("m_Texture");
  42. m_webCamDeviceIndex = serializedObject.FindProperty("m_WebCamDeviceIndex");
  43. m_codec = serializedObject.FindProperty("m_Codec");
  44. m_textureSize = serializedObject.FindProperty("m_TextureSize");
  45. m_frameRate = serializedObject.FindProperty("m_FrameRate");
  46. m_bitrate = serializedObject.FindProperty("m_Bitrate");
  47. m_scaleFactor = serializedObject.FindProperty("m_ScaleFactor");
  48. m_depth = serializedObject.FindProperty("m_Depth");
  49. m_antiAliasing = serializedObject.FindProperty("m_AntiAliasing");
  50. m_autoRequestUserAuthorization = serializedObject.FindProperty("m_AutoRequestUserAuthorization");
  51. if (m_sourceFade == null)
  52. {
  53. m_sourceFade = new AnimBool[Enum.GetValues(typeof(VideoStreamSource)).Length];
  54. for (int i = 0; i < m_sourceFade.Length; i++)
  55. m_sourceFade[i] = new AnimBool(i == m_source.intValue);
  56. }
  57. Array.ForEach(m_sourceFade, anim => anim.valueChanged.AddListener(Repaint));
  58. }
  59. void OnDisable()
  60. {
  61. Array.ForEach(m_sourceFade, anim => anim.valueChanged.RemoveListener(Repaint));
  62. }
  63. public override void OnInspectorGUI()
  64. {
  65. if (s_Styles == null)
  66. s_Styles = new Styles();
  67. serializedObject.Update();
  68. bool disableEditMediaSource = Application.isPlaying;
  69. /// todo(kazuki): Make available to change video source parameters in runtime.
  70. using (new EditorGUI.DisabledScope(disableEditMediaSource))
  71. {
  72. EditorGUILayout.PropertyField(m_source, s_Styles.sourceContent);
  73. HandleDataSourceField();
  74. EditorGUILayout.Space();
  75. EditorGUILayout.PropertyField(m_codec);
  76. }
  77. EditorGUILayout.Space();
  78. EditorGUILayout.PropertyField(m_frameRate, s_Styles.frameRateContent);
  79. EditorGUILayout.PropertyField(m_bitrate, s_Styles.bitrateContent);
  80. EditorGUILayout.PropertyField(m_scaleFactor, s_Styles.scaleFactorContent);
  81. serializedObject.ApplyModifiedProperties();
  82. }
  83. private void HandleDataSourceField()
  84. {
  85. for (var i = 0; i < m_sourceFade.Length; i++)
  86. m_sourceFade[i].target = m_source.intValue == i;
  87. if (EditorGUILayout.BeginFadeGroup(m_sourceFade[(int)VideoStreamSource.Camera].faded))
  88. {
  89. EditorGUILayout.PropertyField(m_camera);
  90. EditorGUILayout.PropertyField(m_depth);
  91. EditorGUILayout.PropertyField(m_antiAliasing);
  92. EditorGUILayout.PropertyField(m_textureSize);
  93. }
  94. EditorGUILayout.EndFadeGroup();
  95. if (EditorGUILayout.BeginFadeGroup(m_sourceFade[(int)VideoStreamSource.Screen].faded))
  96. {
  97. EditorGUILayout.PropertyField(m_depth);
  98. EditorGUILayout.PropertyField(m_antiAliasing);
  99. EditorGUILayout.PropertyField(m_textureSize);
  100. }
  101. EditorGUILayout.EndFadeGroup();
  102. if (EditorGUILayout.BeginFadeGroup(m_sourceFade[(int)VideoStreamSource.Texture].faded))
  103. {
  104. EditorGUILayout.PropertyField(m_texture);
  105. EditorGUILayout.PropertyField(m_textureSize);
  106. }
  107. EditorGUILayout.EndFadeGroup();
  108. if (EditorGUILayout.BeginFadeGroup(m_sourceFade[(int)VideoStreamSource.WebCamera].faded))
  109. {
  110. EditorGUILayout.PropertyField(m_webCamDeviceIndex);
  111. EditorGUILayout.PropertyField(m_autoRequestUserAuthorization);
  112. EditorGUILayout.PropertyField(m_textureSize);
  113. }
  114. EditorGUILayout.EndFadeGroup();
  115. }
  116. }
  117. }
  118. #endif