MediaPlayerEditor_Platforms.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  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 static int _platformIndex = -1;
  14. private static bool _HTTPHeadersToggle = false;
  15. private static GUIContent[] _platformNames = null;
  16. private void OnInspectorGUI_SelectPlatform()
  17. {
  18. // TODO: support multiple targets?
  19. MediaPlayer media = (this.target) as MediaPlayer;
  20. int i = 0;
  21. int platformIndex = _platformIndex;
  22. foreach (GUIContent platformText in _platformNames)
  23. {
  24. MediaPlayer.PlatformOptions options = media.GetPlatformOptions((Platform)i);
  25. Color hilight = Color.yellow;
  26. if (i == _platformIndex)
  27. {
  28. // Selected, unmodified
  29. if (!options.IsModified())
  30. {
  31. GUI.contentColor = Color.white;
  32. }
  33. else
  34. {
  35. // Selected, modified
  36. GUI.color = hilight;
  37. GUI.contentColor = Color.white;
  38. }
  39. }
  40. else if (options.IsModified())
  41. {
  42. // Unselected, modified
  43. GUI.backgroundColor = Color.grey* hilight;
  44. GUI.contentColor = hilight;
  45. }
  46. else
  47. {
  48. // Unselected, unmodified
  49. if (EditorGUIUtility.isProSkin)
  50. {
  51. GUI.backgroundColor = Color.grey;
  52. GUI.color = new Color(0.65f, 0.66f, 0.65f);// Color.grey;
  53. }
  54. }
  55. if (i == _platformIndex)
  56. {
  57. if (!GUILayout.Toggle(true, _platformNames[i], GUI.skin.button))
  58. {
  59. platformIndex = -1;
  60. }
  61. }
  62. else
  63. {
  64. GUI.skin.button.imagePosition = ImagePosition.ImageOnly;
  65. if (GUILayout.Toggle(false, _platformNames[i], GUI.skin.button))
  66. {
  67. platformIndex = i;
  68. }
  69. GUI.skin.button.imagePosition = ImagePosition.ImageLeft;
  70. }
  71. GUI.backgroundColor = Color.white;
  72. GUI.contentColor = Color.white;
  73. GUI.color = Color.white;
  74. i++;
  75. }
  76. //_platformIndex = GUILayout.SelectionGrid(_platformIndex, _platformNames, 3);
  77. //return;
  78. #if false
  79. int rowCount = 0;
  80. int platformIndex = _platformIndex;
  81. const int itemsPerLine = 4;
  82. for (int i = 0; i < _platformNames.Length; i++)
  83. {
  84. if (i % itemsPerLine == 0)
  85. {
  86. GUILayout.BeginHorizontal();
  87. rowCount++;
  88. }
  89. MediaPlayer.PlatformOptions options = media.GetPlatformOptions((Platform)i);
  90. Color hilight = Color.yellow;
  91. if (i == _platformIndex)
  92. {
  93. // Selected, unmodified
  94. if (!options.IsModified())
  95. {
  96. GUI.contentColor = Color.white;
  97. }
  98. else
  99. {
  100. // Selected, modified
  101. GUI.color = hilight;
  102. GUI.contentColor = Color.white;
  103. }
  104. }
  105. else if (options.IsModified())
  106. {
  107. // Unselected, modified
  108. GUI.backgroundColor = Color.grey* hilight;
  109. GUI.contentColor = hilight;
  110. }
  111. else
  112. {
  113. // Unselected, unmodified
  114. if (EditorGUIUtility.isProSkin)
  115. {
  116. GUI.backgroundColor = Color.grey;
  117. GUI.color = new Color(0.65f, 0.66f, 0.65f);// Color.grey;
  118. }
  119. }
  120. if (i == _platformIndex)
  121. {
  122. if (!GUILayout.Toggle(true, _platformNames[i], GUI.skin.button))
  123. {
  124. platformIndex = -1;
  125. }
  126. }
  127. else
  128. {
  129. GUI.skin.button.imagePosition = ImagePosition.ImageOnly;
  130. if (GUILayout.Toggle(false, _platformNames[i], GUI.skin.button))
  131. {
  132. platformIndex = i;
  133. }
  134. GUI.skin.button.imagePosition = ImagePosition.ImageLeft;
  135. }
  136. if ((i+1) % itemsPerLine == 0)
  137. {
  138. rowCount--;
  139. GUILayout.EndHorizontal();
  140. }
  141. GUI.backgroundColor = Color.white;
  142. GUI.contentColor = Color.white;
  143. GUI.color = Color.white;
  144. }
  145. if (rowCount > 0)
  146. {
  147. GUILayout.EndHorizontal();
  148. }
  149. #endif
  150. //platformIndex = GUILayout.SelectionGrid(_platformIndex, Helper.GetPlatformNames(), 3);
  151. //int platformIndex = GUILayout.Toolbar(_platformIndex, Helper.GetPlatformNames());
  152. if (platformIndex != _platformIndex)
  153. {
  154. _platformIndex = platformIndex;
  155. // We do this to clear the focus, otherwise a focused text field will not change when the Toolbar index changes
  156. EditorGUI.FocusTextInControl("ClearFocus");
  157. }
  158. }
  159. private void OnInspectorGUI_PlatformOverrides()
  160. {
  161. foreach (AnimCollapseSection section in _platformSections)
  162. {
  163. AnimCollapseSection.Show(section, indentLevel:2);
  164. }
  165. }
  166. private readonly static GUIContent[] _audio360ChannelMapGuiNames =
  167. {
  168. new GUIContent("(TBE_8_2) 8 channels of hybrid TBE ambisonics and 2 channels of head-locked stereo audio"),
  169. new GUIContent("(TBE_8) 8 channels of hybrid TBE ambisonics. NO head-locked stereo audio"),
  170. new GUIContent("(TBE_6_2) 6 channels of hybrid TBE ambisonics and 2 channels of head-locked stereo audio"),
  171. new GUIContent("(TBE_6) 6 channels of hybrid TBE ambisonics. NO head-locked stereo audio"),
  172. new GUIContent("(TBE_4_2) 4 channels of hybrid TBE ambisonics and 2 channels of head-locked stereo audio"),
  173. new GUIContent("(TBE_4) 4 channels of hybrid TBE ambisonics. NO head-locked stereo audio"),
  174. new GUIContent("(TBE_8_PAIR0) Channels 1 and 2 of TBE hybrid ambisonics"),
  175. new GUIContent("(TBE_8_PAIR1) Channels 3 and 4 of TBE hybrid ambisonics"),
  176. new GUIContent("(TBE_8_PAIR2) Channels 5 and 6 of TBE hybrid ambisonics"),
  177. new GUIContent("(TBE_8_PAIR3) Channels 7 and 8 of TBE hybrid ambisonics"),
  178. new GUIContent("(TBE_CHANNEL0) Channels 1 of TBE hybrid ambisonics"),
  179. new GUIContent("(TBE_CHANNEL1) Channels 2 of TBE hybrid ambisonics"),
  180. new GUIContent("(TBE_CHANNEL2) Channels 3 of TBE hybrid ambisonics"),
  181. new GUIContent("(TBE_CHANNEL3) Channels 4 of TBE hybrid ambisonics"),
  182. new GUIContent("(TBE_CHANNEL4) Channels 5 of TBE hybrid ambisonics"),
  183. new GUIContent("(TBE_CHANNEL5) Channels 6 of TBE hybrid ambisonics"),
  184. new GUIContent("(TBE_CHANNEL6) Channels 7 of TBE hybrid ambisonics"),
  185. new GUIContent("(TBE_CHANNEL7) Channels 8 of TBE hybrid ambisonics"),
  186. new GUIContent("(HEADLOCKED_STEREO) Head-locked stereo audio"),
  187. new GUIContent("(HEADLOCKED_CHANNEL0) Channels 1 or left of head-locked stereo audio"),
  188. new GUIContent("(HEADLOCKED_CHANNEL1) Channels 2 or right of head-locked stereo audio"),
  189. new GUIContent("(AMBIX_4) 4 channels of first order ambiX"),
  190. new GUIContent("(AMBIX_4_2) 4 channels of first order ambiX with 2 channels of head-locked audio"),
  191. new GUIContent("(AMBIX_9) 9 channels of second order ambiX"),
  192. new GUIContent("(AMBIX_9_2) 9 channels of second order ambiX with 2 channels of head-locked audio"),
  193. new GUIContent("(AMBIX_16) 16 channels of third order ambiX"),
  194. new GUIContent("(AMBIX_16_2) 16 channels of third order ambiX with 2 channels of head-locked audio"),
  195. new GUIContent("(MONO) Mono audio"),
  196. new GUIContent("(STEREO) Stereo audio"),
  197. };
  198. private struct FieldDescription
  199. {
  200. public FieldDescription(string fieldName, GUIContent description)
  201. {
  202. this.fieldName = fieldName;
  203. this.description = description;
  204. }
  205. public string fieldName;
  206. public GUIContent description;
  207. }
  208. private SerializedProperty DisplayPlatformOption(string platformOptionsFieldName, FieldDescription option)
  209. {
  210. return DisplayPlatformOption(this.serializedObject, platformOptionsFieldName + option.fieldName, option.description);
  211. }
  212. private static SerializedProperty DisplayPlatformOption(SerializedObject so, string fieldName, GUIContent description)
  213. {
  214. SerializedProperty prop = so.FindProperty(fieldName);
  215. if (prop != null)
  216. {
  217. if (description == GUIContent.none)
  218. {
  219. EditorGUILayout.PropertyField(prop, true);
  220. }
  221. else
  222. {
  223. EditorGUILayout.PropertyField(prop, description, true);
  224. }
  225. }
  226. else
  227. {
  228. Debug.LogWarning("Can't find property `" + fieldName + "`");
  229. }
  230. return prop;
  231. }
  232. private SerializedProperty DisplayPlatformOptionEnum(string platformOptionsFieldName, FieldDescription option, GUIContent[] enumNames)
  233. {
  234. return DisplayPlatformOptionEnum(this.serializedObject, platformOptionsFieldName + option.fieldName, option.description, enumNames);
  235. }
  236. private static SerializedProperty DisplayPlatformOptionEnum(SerializedObject so, string fieldName, GUIContent description, GUIContent[] enumNames)
  237. {
  238. SerializedProperty prop = so.FindProperty(fieldName);
  239. if (prop != null)
  240. {
  241. prop.enumValueIndex = EditorGUILayout.Popup(description, prop.enumValueIndex, enumNames);
  242. }
  243. else
  244. {
  245. Debug.LogWarning("Can't find property `" + fieldName + "`");
  246. }
  247. return prop;
  248. }
  249. #if false
  250. private void OnInspectorGUI_HlsDecryption(string optionsVarName)
  251. {
  252. EditorGUILayout.BeginVertical(GUI.skin.box);
  253. GUILayout.Label("HLS Decryption", EditorStyles.boldLabel);
  254. // Key server auth token
  255. SerializedProperty prop = serializedObject.FindProperty(optionsVarName + ".keyAuth.keyServerToken");
  256. if (prop != null)
  257. {
  258. EditorGUILayout.PropertyField(prop, new GUIContent("Key Server Auth Token", "Token to pass to the key server in the 'Authorization' HTTP header field"));
  259. }
  260. GUILayout.Label("Overrides");
  261. EditorGUI.indentLevel++;
  262. // Key server override
  263. /*prop = serializedObject.FindProperty(optionsVarName + ".keyServerURLOverride");
  264. if (prop != null)
  265. {
  266. EditorGUILayout.PropertyField(prop, new GUIContent("Key Server URL", "Overrides the key server URL if present in a HLS manifest."));
  267. }*/
  268. // Key data blob override
  269. prop = serializedObject.FindProperty(optionsVarName + ".keyAuth.overrideDecryptionKeyBase64");
  270. if (prop != null)
  271. {
  272. EditorGUILayout.PropertyField(prop, new GUIContent("Key (Base64)", "Override key to use for decoding encrypted HLS streams (in Base64 format)."));
  273. }
  274. EditorGUI.indentLevel--;
  275. EditorGUILayout.EndVertical();
  276. }
  277. private void OnInspectorGUI_HttpHeaders(string platformOptionsVarName)
  278. {
  279. SerializedProperty httpHeadersProp = serializedObject.FindProperty(platformOptionsVarName + ".httpHeaders.httpHeaders");
  280. if (httpHeadersProp != null)
  281. {
  282. if (BeginCollapsableSection("Custom HTTP Headers", ref _HTTPHeadersToggle))
  283. {
  284. {
  285. if (httpHeadersProp.arraySize > 0)
  286. {
  287. int deleteIndex = -1;
  288. for (int i = 0; i < httpHeadersProp.arraySize; ++i)
  289. {
  290. SerializedProperty httpHeaderProp = httpHeadersProp.GetArrayElementAtIndex(i);
  291. SerializedProperty headerProp = httpHeaderProp.FindPropertyRelative("name");
  292. GUILayout.BeginVertical(GUI.skin.box);
  293. GUILayout.BeginHorizontal();
  294. GUI.color = HttpHeader.IsValid(headerProp.stringValue)?Color.white:Color.red;
  295. EditorGUILayout.PropertyField(headerProp, GUIContent.none);
  296. headerProp.stringValue = headerProp.stringValue.Trim();
  297. GUI.color = Color.white;
  298. if (GUILayout.Button("-", GUILayout.ExpandWidth(false)))
  299. {
  300. deleteIndex = i;
  301. }
  302. GUILayout.EndHorizontal();
  303. SerializedProperty valueProp = httpHeaderProp.FindPropertyRelative("value");
  304. GUI.color = HttpHeader.IsValid(valueProp.stringValue)?Color.white:Color.red;
  305. valueProp.stringValue = EditorGUILayout.TextArea(valueProp.stringValue, EditorHelper.IMGUI.GetWordWrappedTextAreaStyle());
  306. GUI.color = Color.white;
  307. valueProp.stringValue = valueProp.stringValue.Trim();
  308. GUILayout.EndVertical();
  309. GUILayout.Space(4f);
  310. }
  311. if (deleteIndex >= 0)
  312. {
  313. httpHeadersProp.DeleteArrayElementAtIndex(deleteIndex);
  314. }
  315. }
  316. if (GUILayout.Button("+"))
  317. {
  318. httpHeadersProp.InsertArrayElementAtIndex(httpHeadersProp.arraySize);
  319. }
  320. }
  321. }
  322. EndCollapsableSection();
  323. }
  324. }
  325. #endif
  326. }
  327. }