MediaPlayerEditor_Network.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. using UnityEngine;
  2. using UnityEditor;
  3. //-----------------------------------------------------------------------------
  4. // Copyright 2015-2021 RenderHeads Ltd. All rights reserved.
  5. //-----------------------------------------------------------------------------
  6. namespace RenderHeads.Media.AVProVideo.Editor
  7. {
  8. /// <summary>
  9. /// Editor for the MediaPlayer component
  10. /// </summary>
  11. public partial class MediaPlayerEditor : UnityEditor.Editor
  12. {
  13. private void OnInspectorGUI_Network()
  14. {
  15. if (_showUltraOptions)
  16. {
  17. SerializedProperty httpHeadersProp = serializedObject.FindProperty("_httpHeaders.httpHeaders");
  18. OnInspectorGUI_HttpHeaders(httpHeadersProp);
  19. SerializedProperty keyAuthProp = serializedObject.FindProperty("_keyAuth");
  20. OnInspectorGUI_HlsDecryption(keyAuthProp);
  21. }
  22. }
  23. private void OnInspectorGUI_HlsDecryption(SerializedProperty keyAuthProp)
  24. {
  25. if (keyAuthProp == null) return;
  26. EditorGUILayout.BeginVertical(GUI.skin.box);
  27. GUILayout.Label("HLS Decryption", EditorStyles.boldLabel);
  28. // Key server auth token
  29. SerializedProperty prop = keyAuthProp.FindPropertyRelative("keyServerToken");
  30. if (prop != null)
  31. {
  32. EditorGUILayout.PropertyField(prop, new GUIContent("Auth Token", "Token to pass to the key server in the 'Authorization' HTTP header field"));
  33. }
  34. //GUILayout.Label("Overrides");
  35. //EditorGUI.indentLevel++;
  36. // Key server override
  37. /*prop = serializedObject.FindProperty(optionsVarName + ".keyServerURLOverride");
  38. if (prop != null)
  39. {
  40. EditorGUILayout.PropertyField(prop, new GUIContent("Key Server URL", "Overrides the key server URL if present in a HLS manifest."));
  41. }*/
  42. // Key data blob override
  43. prop = keyAuthProp.FindPropertyRelative("overrideDecryptionKeyBase64");
  44. if (prop != null)
  45. {
  46. EditorGUILayout.PropertyField(prop, new GUIContent("Key Override (Base64)", "Override key to use for decoding encrypted HLS streams (in Base64 format)."));
  47. }
  48. //EditorGUI.indentLevel--;
  49. EditorGUILayout.EndVertical();
  50. }
  51. private void OnInspectorGUI_HttpHeaders(SerializedProperty httpHeadersProp)
  52. {
  53. if (httpHeadersProp == null) return;
  54. //GUILayout.Space(8f);
  55. bool isExpanded = _HTTPHeadersToggle;
  56. if (isExpanded)
  57. {
  58. EditorGUILayout.BeginVertical(GUI.skin.box);
  59. }
  60. bool hasHeaders = (httpHeadersProp.arraySize > 0);
  61. Color tintColor = hasHeaders?Color.yellow:Color.white;
  62. if (AnimCollapseSection.BeginShow("Custom HTTP Headers", ref _HTTPHeadersToggle, tintColor))
  63. {
  64. {
  65. if (httpHeadersProp.arraySize > 0)
  66. {
  67. int deleteIndex = -1;
  68. for (int i = 0; i < httpHeadersProp.arraySize; ++i)
  69. {
  70. SerializedProperty httpHeaderProp = httpHeadersProp.GetArrayElementAtIndex(i);
  71. SerializedProperty headerProp = httpHeaderProp.FindPropertyRelative("name");
  72. GUILayout.BeginVertical(GUI.skin.box);
  73. GUILayout.BeginHorizontal();
  74. GUI.color = HttpHeader.IsValid(headerProp.stringValue)?Color.white:Color.red;
  75. EditorGUILayout.PropertyField(headerProp, GUIContent.none);
  76. headerProp.stringValue = headerProp.stringValue.Trim();
  77. GUI.color = Color.white;
  78. if (GUILayout.Button("-", GUILayout.ExpandWidth(false)))
  79. {
  80. deleteIndex = i;
  81. }
  82. GUILayout.EndHorizontal();
  83. SerializedProperty valueProp = httpHeaderProp.FindPropertyRelative("value");
  84. GUI.color = HttpHeader.IsValid(valueProp.stringValue)?Color.white:Color.red;
  85. valueProp.stringValue = EditorGUILayout.TextArea(valueProp.stringValue, EditorHelper.IMGUI.GetWordWrappedTextAreaStyle());
  86. GUI.color = Color.white;
  87. valueProp.stringValue = valueProp.stringValue.Trim();
  88. GUILayout.EndVertical();
  89. GUILayout.Space(4f);
  90. }
  91. if (deleteIndex >= 0)
  92. {
  93. httpHeadersProp.DeleteArrayElementAtIndex(deleteIndex);
  94. }
  95. }
  96. if (GUILayout.Button("+"))
  97. {
  98. httpHeadersProp.InsertArrayElementAtIndex(httpHeadersProp.arraySize);
  99. }
  100. }
  101. }
  102. AnimCollapseSection.EndShow();
  103. if (isExpanded)
  104. {
  105. EditorGUILayout.EndVertical();
  106. }
  107. //GUILayout.Space(8f);
  108. }
  109. }
  110. }