| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 | using UnityEngine;using UnityEditor;using System.Collections.Generic;//-----------------------------------------------------------------------------// Copyright 2015-2021 RenderHeads Ltd.  All rights reserved.//-----------------------------------------------------------------------------namespace RenderHeads.Media.AVProVideo.Editor{	/// <summary>	/// Editor for the MediaPlayer component	/// </summary>	public partial class MediaPlayerEditor : UnityEditor.Editor	{		private readonly static FieldDescription _optionAudioMode = new FieldDescription("._audioMode", new GUIContent("Audio Mode", "Unity mode does not work with HLS video"));		private readonly static FieldDescription _optionTextureFormat = new FieldDescription(".textureFormat", new GUIContent("Texture Format", "BGRA32 is the most compatible.\nYCbCr420_OES requires less memory and processing however it does require shader support."));		private readonly static FieldDescription _optionPreferredForwardBufferDuration = new FieldDescription("._preferredForwardBufferDuration", new GUIContent("Preferred Forward Buffer Duration", "The duration in seconds the player should buffer ahead of the playhead to prevent stalling. Set to 0 to let the system decide."));		private readonly static FieldDescription _optionCustomPreferredPeakBitRateApple = new FieldDescription("._preferredPeakBitRate", new GUIContent("Preferred Peak BitRate", "The desired limit of network bandwidth consumption for playback, set to 0 for no preference."));		private readonly static FieldDescription _optionCustomPreferredPeakBitRateUnitsApple = new FieldDescription("._preferredPeakBitRateUnits", new GUIContent());		private void OnInspectorGUI_Override_Apple(Platform platform)		{			GUILayout.Space(8f);			string optionsVarName = MediaPlayer.GetPlatformOptionsVariable(platform);			EditorGUILayout.BeginVertical(GUI.skin.box);			DisplayPlatformOption(optionsVarName, _optionTextureFormat);			SerializedProperty flagsProp = serializedObject.FindProperty(optionsVarName + "._flags");			MediaPlayer.OptionsApple.Flags flags = flagsProp != null ? (MediaPlayer.OptionsApple.Flags)flagsProp.intValue : 0;			// Texture flags			if (flagsProp != null)			{				bool generateMipmaps = flags.GenerateMipmaps();				generateMipmaps = EditorGUILayout.Toggle(new GUIContent("Generate Mipmaps"), generateMipmaps);				flags = flags.SetGenerateMipMaps(generateMipmaps);			}			// Audio			DisplayPlatformOption(optionsVarName, _optionAudioMode);			// Platform specific flags			if (flagsProp != null)			{				if (platform == Platform.macOS || platform == Platform.iOS)				{					bool b = flags.AllowExternalPlayback();					b = EditorGUILayout.Toggle(new GUIContent("Allow External Playback", "Enables support for playback on external devices via AirPlay."), b);					flags = flags.SetAllowExternalPlayback(b);				}				if (platform == Platform.iOS)				{					bool b = flags.ResumePlaybackAfterAudioSessionRouteChange();					b = EditorGUILayout.Toggle(new GUIContent("Resume playback after audio route change", "The default behaviour is for playback to pause when the audio route changes, for instance when disconnecting headphones."), b);					flags = flags.SetResumePlaybackAfterAudioSessionRouteChange(b);				}				bool playWithoutBuffering = flags.PlayWithoutBuffering();				playWithoutBuffering = EditorGUILayout.Toggle(new GUIContent("Play without buffering"), playWithoutBuffering);				flags = flags.SetPlayWithoutBuffering(playWithoutBuffering);				bool useSinglePlayerItem = flags.UseSinglePlayerItem();				useSinglePlayerItem = EditorGUILayout.Toggle(new GUIContent("Use single player item", "Restricts the media player to using only one player item. This can help reduce network usage for remote videos but will cause a stall when looping."), useSinglePlayerItem);				flags = flags.SetUseSinglePlayerItem(useSinglePlayerItem);			}			SerializedProperty maximumPlaybackRateProp = serializedObject.FindProperty(optionsVarName + ".maximumPlaybackRate");			if (maximumPlaybackRateProp != null)			{				EditorGUILayout.Slider(maximumPlaybackRateProp, 2.0f, 10.0f, new GUIContent("Max Playback Rate", "Increase the maximum playback rate before which playback switches to key-frames only."));			}			GUILayout.Space(8f);			EditorGUILayout.BeginVertical();			EditorGUILayout.LabelField("Network", EditorStyles.boldLabel);			SerializedProperty preferredMaximumResolutionProp = DisplayPlatformOption(optionsVarName, _optionPreferredMaximumResolution);			if ((MediaPlayer.OptionsApple.Resolution)preferredMaximumResolutionProp.intValue == MediaPlayer.OptionsApple.Resolution.Custom)			{				#if UNITY_2017_2_OR_NEWER				DisplayPlatformOption(optionsVarName, _optionCustomPreferredMaxResolution);				#endif			}			EditorGUILayout.BeginHorizontal();			DisplayPlatformOption(optionsVarName, _optionCustomPreferredPeakBitRateApple);			DisplayPlatformOption(optionsVarName, _optionCustomPreferredPeakBitRateUnitsApple);			EditorGUILayout.EndHorizontal();			DisplayPlatformOption(optionsVarName, _optionPreferredForwardBufferDuration);			EditorGUILayout.EndVertical();			EditorGUILayout.EndVertical();			// Set the flags			if (flagsProp != null)			{				flagsProp.intValue = (int)flags;			}			if (_showUltraOptions)			{				SerializedProperty keyAuthProp = serializedObject.FindProperty(optionsVarName + ".keyAuth");				if (keyAuthProp != null)				{					OnInspectorGUI_HlsDecryption(keyAuthProp);				}				SerializedProperty httpHeadersProp = serializedObject.FindProperty(optionsVarName + ".httpHeaders.httpHeaders");				if (httpHeadersProp != null)				{					OnInspectorGUI_HttpHeaders(httpHeadersProp);				}			}		}		private void OnInspectorGUI_Override_MacOSX()		{			OnInspectorGUI_Override_Apple(Platform.macOS);		}		private void OnInspectorGUI_Override_iOS()		{			OnInspectorGUI_Override_Apple(Platform.iOS);		}		private void OnInspectorGUI_Override_tvOS()		{			OnInspectorGUI_Override_Apple(Platform.tvOS);		}		private void OnInspectorGUI_Override_visionOS()		{			OnInspectorGUI_Override_Apple(Platform.visionOS);		}	}}
 |