AudioStreamSenderEditor.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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(AudioStreamSender))]
  9. [CanEditMultipleObjects]
  10. internal class AudioStreamSenderEditor : UnityEditor.Editor
  11. {
  12. class Styles
  13. {
  14. public readonly GUIContent sourceContent =
  15. EditorGUIUtility.TrTextContent("Audio Source Type", "Type of source the audio will be streamed.");
  16. public readonly GUIContent bitrateContent =
  17. EditorGUIUtility.TrTextContent("Bitrate (kbits/sec)", "A range of bitrate of audio streaming.");
  18. }
  19. static Styles s_Styles;
  20. SerializedProperty m_source;
  21. SerializedProperty m_codec;
  22. SerializedProperty m_audioSource;
  23. SerializedProperty m_audioListener;
  24. SerializedProperty m_microphoneDeviceIndex;
  25. SerializedProperty m_autoRequestUserAuthorization;
  26. SerializedProperty m_bitrate;
  27. static AnimBool[] m_sourceFade;
  28. void OnEnable()
  29. {
  30. m_source = serializedObject.FindProperty("m_Source");
  31. m_audioSource = serializedObject.FindProperty("m_AudioSource");
  32. m_audioListener = serializedObject.FindProperty("m_AudioListener");
  33. m_microphoneDeviceIndex = serializedObject.FindProperty("m_MicrophoneDeviceIndex");
  34. m_autoRequestUserAuthorization = serializedObject.FindProperty("m_AutoRequestUserAuthorization");
  35. m_codec = serializedObject.FindProperty("m_Codec");
  36. m_bitrate = serializedObject.FindProperty("m_Bitrate");
  37. if (m_sourceFade == null)
  38. {
  39. m_sourceFade = new AnimBool[Enum.GetValues(typeof(AudioStreamSource)).Length];
  40. for (int i = 0; i < m_sourceFade.Length; i++)
  41. m_sourceFade[i] = new AnimBool(i == m_source.intValue);
  42. }
  43. Array.ForEach(m_sourceFade, anim => anim.valueChanged.AddListener(Repaint));
  44. }
  45. void OnDisable()
  46. {
  47. Array.ForEach(m_sourceFade, anim => anim.valueChanged.RemoveListener(Repaint));
  48. }
  49. public override void OnInspectorGUI()
  50. {
  51. if (s_Styles == null)
  52. s_Styles = new Styles();
  53. serializedObject.Update();
  54. bool disableEditMediaSource = Application.isPlaying;
  55. /// todo(kazuki): Make available to change video source parameters in runtime.
  56. using (new EditorGUI.DisabledScope(disableEditMediaSource))
  57. {
  58. EditorGUILayout.PropertyField(m_source, s_Styles.sourceContent);
  59. HandleSourceField();
  60. EditorGUILayout.Space();
  61. EditorGUILayout.PropertyField(m_codec);
  62. }
  63. EditorGUILayout.Space();
  64. EditorGUILayout.PropertyField(m_bitrate, s_Styles.bitrateContent);
  65. serializedObject.ApplyModifiedProperties();
  66. }
  67. private void HandleSourceField()
  68. {
  69. for (var i = 0; i < m_sourceFade.Length; i++)
  70. m_sourceFade[i].target = m_source.intValue == i;
  71. if (EditorGUILayout.BeginFadeGroup(m_sourceFade[(int)AudioStreamSource.AudioListener].faded))
  72. {
  73. EditorGUILayout.PropertyField(m_audioListener);
  74. }
  75. EditorGUILayout.EndFadeGroup();
  76. if (EditorGUILayout.BeginFadeGroup(m_sourceFade[(int)AudioStreamSource.AudioSource].faded))
  77. {
  78. EditorGUILayout.PropertyField(m_audioSource);
  79. }
  80. EditorGUILayout.EndFadeGroup();
  81. if (EditorGUILayout.BeginFadeGroup(m_sourceFade[(int)AudioStreamSource.Microphone].faded))
  82. {
  83. EditorGUILayout.PropertyField(m_microphoneDeviceIndex);
  84. EditorGUILayout.PropertyField(m_autoRequestUserAuthorization);
  85. }
  86. EditorGUILayout.EndFadeGroup();
  87. }
  88. }
  89. }
  90. #endif