VideoStreamReceiverEditor.cs 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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(VideoStreamReceiver))]
  9. [CanEditMultipleObjects]
  10. internal class VideoStreamSenderReceiver : UnityEditor.Editor
  11. {
  12. SerializedProperty m_codec;
  13. SerializedProperty m_renderMode;
  14. SerializedProperty m_targetTexture;
  15. static AnimBool[] m_renderModeFade;
  16. void OnEnable()
  17. {
  18. m_codec = serializedObject.FindProperty("m_Codec");
  19. m_renderMode = serializedObject.FindProperty("m_RenderMode");
  20. m_targetTexture = serializedObject.FindProperty("m_TargetTexture");
  21. if (m_renderModeFade == null)
  22. {
  23. m_renderModeFade = new AnimBool[Enum.GetValues(typeof(VideoRenderMode)).Length];
  24. for (int i = 0; i < m_renderModeFade.Length; i++)
  25. m_renderModeFade[i] = new AnimBool(i == m_renderMode.intValue);
  26. }
  27. Array.ForEach(m_renderModeFade, anim => anim.valueChanged.AddListener(Repaint));
  28. }
  29. void OnDisable()
  30. {
  31. Array.ForEach(m_renderModeFade, anim => anim.valueChanged.RemoveListener(Repaint));
  32. }
  33. public override void OnInspectorGUI()
  34. {
  35. serializedObject.Update();
  36. bool disableEditMediaSource = Application.isPlaying;
  37. /// todo(kazuki): Make available to change video source parameters in runtime.
  38. using (new EditorGUI.DisabledScope(disableEditMediaSource))
  39. {
  40. EditorGUILayout.PropertyField(m_renderMode);
  41. HandleDataSourceField();
  42. EditorGUILayout.Space();
  43. EditorGUILayout.PropertyField(m_codec);
  44. }
  45. serializedObject.ApplyModifiedProperties();
  46. }
  47. private void HandleDataSourceField()
  48. {
  49. for (var i = 0; i < m_renderModeFade.Length; i++)
  50. m_renderModeFade[i].target = m_renderMode.intValue == i;
  51. if (EditorGUILayout.BeginFadeGroup(m_renderModeFade[(int)VideoRenderMode.APIOnly].faded))
  52. {
  53. }
  54. EditorGUILayout.EndFadeGroup();
  55. if (EditorGUILayout.BeginFadeGroup(m_renderModeFade[(int)VideoRenderMode.RenderTexture].faded))
  56. {
  57. EditorGUILayout.PropertyField(m_targetTexture);
  58. }
  59. EditorGUILayout.EndFadeGroup();
  60. }
  61. }
  62. }
  63. #endif