Пример #1
0
    public static void UMPGUI()
    {
        if (!_preloaded)
        {
            _preloadedSettings = PreloadedSettings.Instance;
            _preloaded         = true;
        }

        EditorGUILayout.LabelField("Editor/Desktop platforms:", EditorStyles.boldLabel);

        EditorGUILayout.Space();

        _preloadedSettings.UseAudioSource = EditorGUILayout.Toggle(new GUIContent("Use Unity 'Audio Source' component", "Will be using Unity 'Audio Source' component for audio output for all UMP instances (global) by default."), _preloadedSettings.UseAudioSource);

        EditorGUILayout.Space();

        _preloadedSettings.UseDebugMode = EditorGUILayout.Toggle(new GUIContent("Debug mode", "Allows you to use debug mode in your IDE with UMP asset in Unity Editor (it's still experimental and will work only in Unity Editor, also some default UMP functions will not work in this mode, because it's conflicting with IDE debug mode)."), _preloadedSettings.UseDebugMode);

        EditorGUILayout.Space();

        _preloadedSettings.UseExternalLibs = EditorGUILayout.Toggle(new GUIContent("Use installed VLC libraries", "Will be using external/installed VLC player libraries for all UMP instances (global). Path to install VLC directory will be obtained automatically (you can also setup your custom path)."), _preloadedSettings.UseExternalLibs);

        var chachedLabelColor = EditorStyles.label.normal.textColor;

        EditorStyles.label.wordWrap         = true;
        EditorStyles.label.normal.textColor = Color.red;

        if (MediaPlayerHelper.GetLibsPath(false).Equals(string.Empty))
        {
            EditorGUILayout.LabelField("Please correctly import UMP (Win, Mac, Linux) package to use internal VLC libraries.");
            _preloadedSettings.UseExternalLibs = true;
        }

        EditorGUILayout.Space();

        if (_preloadedSettings.UseExternalLibs)
        {
            string externalLibsPath = MediaPlayerHelper.GetLibsPath(true);
            if (externalLibsPath.Equals(string.Empty))
            {
                EditorGUILayout.LabelField("Did you install VLC player software correctly? Please make sure that:");
                EditorGUILayout.LabelField("1. Your installed VLC player bit application == Unity Editor bit application (VLC player 64-bit == Unity 64-bit Editor);");
                EditorGUILayout.LabelField("2. Use last version installer from official site: ");

                var link = "https://www.videolan.org/vlc/index.ru.html";
                EditorStyles.label.normal.textColor = Color.blue;
                EditorGUILayout.LabelField(link);

                Rect linkRect = GUILayoutUtility.GetLastRect();

                if (Event.current.type == EventType.MouseUp && linkRect.Contains(Event.current.mousePosition))
                {
                    Application.OpenURL(link);
                }

                EditorStyles.label.normal.textColor = Color.red;
                EditorGUILayout.LabelField("Or you can try to use custom additional path to your VLC libraries.");

                EditorGUILayout.Space();
            }

            EditorStyles.label.normal.textColor = chachedLabelColor;

            EditorGUILayout.LabelField(new GUIContent("External/installed VLC libraries path:", "Default path to installed VLC player libraries. Example: '" + @"C:\Program Files\VideoLAN\VLC'."));
            GUIStyle pathLabel = EditorStyles.textField;
            pathLabel.wordWrap = true;
            EditorGUILayout.LabelField(externalLibsPath, pathLabel);

            EditorGUILayout.Space();

            EditorGUILayout.LabelField(new GUIContent("Additional external/installed VLC libraries path:", "Additional path to installed VLC player libraries. Will be used if path to libraries can't be automatically obtained. Example: '" + @"C:\Program Files\VideoLAN\VLC'."));
            GUIStyle additionalLabel = EditorStyles.textField;
            additionalLabel.wordWrap = true;

            _preloadedSettings.AdditionalLibsPath = EditorGUILayout.TextField(_additionalLibsPath, _preloadedSettings.AdditionalLibsPath);
        }

        EditorStyles.label.normal.textColor = chachedLabelColor;

        EditorGUILayout.Space();

        EditorGUILayout.LabelField("Mobile platforms:", EditorStyles.boldLabel);

        EditorGUILayout.Space();

        _preloadedSettings.UseAndroidNative = EditorGUILayout.Toggle(new GUIContent("Use Android native player", "Will be using Android native media player for all UMP instances (global)."), _preloadedSettings.UseAndroidNative);

        if (_nativeLibraryPrepare != _preloadedSettings.UseAndroidNative)
        {
            List <string> libs = new List <string>();
            libs.AddRange(Directory.GetFiles(Application.dataPath + "/UniversalMediaPlayer/Plugins/Android/libs/armeabi-v7a"));
            libs.AddRange(Directory.GetFiles(Application.dataPath + "/UniversalMediaPlayer/Plugins/Android/libs/x86"));

            foreach (var lib in libs)
            {
                if (lib.Contains(".meta") && !lib.Contains("libUniversalMediaPlayer"))
                {
                    File.SetAttributes(lib, FileAttributes.Normal);
                    string metaData = File.ReadAllText(lib);
                    var    match    = Regex.Match(metaData, @"Android.*\s*enabled:.");

                    if (match.Success)
                    {
                        metaData = Regex.Replace(metaData, @"Android.*\s*enabled:." + (!_nativeLibraryPrepare ? 1 : 0), match.Value + (_nativeLibraryPrepare ? 1 : 0));
                        File.WriteAllText(lib, metaData);
                    }
                }
            }
            libs.Clear();
        }

        _nativeLibraryPrepare = _preloadedSettings.UseAndroidNative;

        if (GUI.changed)
        {
            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();
        }
    }
Пример #2
0
    public static void UMPGUI()
    {
        if (!_preloaded)
        {
            _preloadedSettings = PreloadedSettings.Instance;
            _preloaded         = true;
        }

        _preloadedSettings.UseExternalLibs = EditorGUILayout.Toggle(new GUIContent("Use installed VLC libraries", "Will be using external/installed VLC player libraries for all UMP instances (global). Path to install VLC directory will be automatically obtained, but you can also setup your custom path."), _preloadedSettings.UseExternalLibs);

        var chachedLabelColor = EditorStyles.label.normal.textColor;

        EditorStyles.label.wordWrap         = true;
        EditorStyles.label.normal.textColor = Color.red;

        if (MediaPlayerHelper.GetLibsPath(false).Equals(string.Empty))
        {
            EditorGUILayout.LabelField("Please correctly import UMP (Win, Mac, Linux) package to use internal VLC libraries.");
            _preloadedSettings.UseExternalLibs = true;
        }

        EditorGUILayout.Space();

        if (_preloadedSettings.UseExternalLibs)
        {
            string externalLibsPath = MediaPlayerHelper.GetLibsPath(true);
            if (externalLibsPath.Equals(string.Empty))
            {
                EditorGUILayout.LabelField("Did you install VLC player software correctly? Please make sure that:");
                EditorGUILayout.LabelField("1. Your installed VLC player bit application == Unity Editor bit application (VLC player 64-bit == Unity 64-bit Editor);");
                EditorGUILayout.LabelField("2. Use last version installer from official site: ");

                var link = "https://www.videolan.org/vlc/index.ru.html";
                EditorStyles.label.normal.textColor = Color.blue;
                EditorGUILayout.LabelField(link);

                Rect linkRect = GUILayoutUtility.GetLastRect();

                if (Event.current.type == EventType.MouseUp && linkRect.Contains(Event.current.mousePosition))
                {
                    Application.OpenURL(link);
                }

                EditorStyles.label.normal.textColor = Color.red;
                EditorGUILayout.LabelField("Or you can try to use custom additional path to your VLC libraries.");

                EditorGUILayout.Space();
            }

            EditorStyles.label.normal.textColor = chachedLabelColor;

            EditorGUILayout.LabelField(new GUIContent("External/installed VLC libraries path:", "Default path to installed VLC player libraries. Example: '" + @"C:\Program Files\VideoLAN\VLC'."));
            GUIStyle pathLabel = EditorStyles.textField;
            pathLabel.wordWrap = true;
            EditorGUILayout.LabelField(externalLibsPath, pathLabel);

            EditorGUILayout.Space();

            EditorGUILayout.LabelField(new GUIContent("Additional external/installed VLC libraries path:", "Additional path to installed VLC player libraries. Will be used if path to libraries can't be automatically obtained. Example: '" + @"C:\Program Files\VideoLAN\VLC'."));
            GUIStyle additionalLabel = EditorStyles.textField;
            additionalLabel.wordWrap = true;

            _preloadedSettings.AdditionalLibsPath = EditorGUILayout.TextField(_additionalLibsPath, _preloadedSettings.AdditionalLibsPath);
        }

        EditorStyles.label.normal.textColor = chachedLabelColor;

        EditorGUILayout.Space();
        _preloadedSettings.UseAndroidNative = EditorGUILayout.Toggle(new GUIContent("Use Android native player", "Will be using Android native media player for all UMP instances (global)."), _preloadedSettings.UseAndroidNative);

        if (GUI.changed)
        {
            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();
        }
    }
Пример #3
0
    public override void OnInspectorGUI()
    {
        serializedObject.Update();

        var umpEditor = (UniversalMediaPlayer)target;

        EditorGUIUtility.labelWidth = 0;
        EditorGUIUtility.fieldWidth = 0;

        EditorGUI.BeginChangeCheck();

        _savedFontStyle = EditorStyles.label.fontStyle;
        _savedTextColor = EditorStyles.textField.normal.textColor;

        #region Rendering Field
        EditorGUILayout.Space();
        EditorGUILayout.PropertyField(_renderingObjectsProp, new GUIContent("Rendering GameObjects:"), true);
        #endregion

        #region Audio Field
        EditorGUI.BeginDisabledGroup(Application.isPlaying);
        EditorGUILayout.Space();
        EditorGUILayout.PropertyField(_audioSourcesProp, new GUIContent("Audio Sources (only PC, Mac & Linux):"), true);
        EditorGUI.EndDisabledGroup();
        #endregion

        #region Path Field
        EditorGUILayout.Space();

        EditorStyles.label.fontStyle = FontStyle.Bold;
        EditorGUILayout.LabelField("Path to video file:");
        EditorStyles.label.fontStyle    = _savedFontStyle;
        EditorStyles.textField.wordWrap = true;
        _pathProp.stringValue           = EditorGUILayout.TextField(_pathProp.stringValue, GUILayout.Height(30));
        EditorStyles.textField.wordWrap = false;
        #endregion

        #region Additional Fields
        EditorGUILayout.Space();
        EditorStyles.label.fontStyle = FontStyle.Bold;
        EditorGUILayout.LabelField("Additional properties:");
        EditorStyles.label.fontStyle = _savedFontStyle;

        GUILayout.BeginVertical("Box");
        GUILayout.BeginHorizontal();
        AutoSizeLabelField("Auto play:");
        GUILayout.FlexibleSpace();
        _autoPlayProp.boolValue = EditorGUILayout.Toggle(_autoPlayProp.boolValue);
        AutoSizeLabelField("Loop:");
        GUILayout.FlexibleSpace();
        _loopProp.boolValue = EditorGUILayout.Toggle(_loopProp.boolValue);
        AutoSizeLabelField("Mute:");
        GUILayout.FlexibleSpace();
        _muteProp.boolValue = EditorGUILayout.Toggle(_muteProp.boolValue);
        GUILayout.EndHorizontal();

        GUILayout.BeginHorizontal();
        AutoSizeLabelField("Advanced:");
        _showAdvancedProperties.boolValue = EditorGUILayout.Toggle(_showAdvancedProperties.boolValue);
        GUILayout.EndHorizontal();

        if (_showAdvancedProperties.boolValue)
        {
            EditorStyles.label.normal.textColor = Color.black;
            EditorStyles.label.fontStyle        = FontStyle.Italic;
            EditorGUILayout.LabelField("Don't support on iOS/WebGL platforms", GUILayout.Width(240));
            EditorStyles.label.normal.textColor = _savedTextColor;
            EditorStyles.label.fontStyle        = _savedFontStyle;
            EditorGUILayout.Space();

            EditorGUI.BeginDisabledGroup(Application.isPlaying);

            float cachedLabelWidth = EditorGUIUtility.labelWidth;
            EditorGUIUtility.labelWidth = 170;
            _fileCachingProp.intValue   = EditorGUILayout.IntField("File caching (ms): ", _fileCachingProp.intValue);
            _fileCachingProp.intValue   = Mathf.Clamp(_fileCachingProp.intValue, 0, 60000);

            _liveCachingProp.intValue = EditorGUILayout.IntField("Live capture caching (ms): ", _liveCachingProp.intValue);
            _liveCachingProp.intValue = Mathf.Clamp(_liveCachingProp.intValue, 0, 60000);

            _diskCachingProp.intValue = EditorGUILayout.IntField("Disc caching (ms): ", _diskCachingProp.intValue);
            _diskCachingProp.intValue = Mathf.Clamp(_diskCachingProp.intValue, 0, 60000);

            _networkCachingProp.intValue = EditorGUILayout.IntField("Network caching (ms): ", _networkCachingProp.intValue);
            _networkCachingProp.intValue = Mathf.Clamp(_networkCachingProp.intValue, 0, 60000);

            EditorGUIUtility.labelWidth = cachedLabelWidth;

            EditorGUI.EndDisabledGroup();
        }
        else
        {
            _fileCachingProp.intValue    = PlayerArguments.ADVANCED_DEFAULT_CACHING;
            _liveCachingProp.intValue    = PlayerArguments.ADVANCED_DEFAULT_CACHING;
            _diskCachingProp.intValue    = PlayerArguments.ADVANCED_DEFAULT_CACHING;
            _networkCachingProp.intValue = PlayerArguments.ADVANCED_DEFAULT_CACHING;
        }

        if (PreloadedSettings.Instance.UseExternalLibs)
        {
            if (_externalPath.Equals(string.Empty))
            {
                _externalPath = MediaPlayerHelper.GetLibsPath(true);
            }

            if (_externalPath != string.Empty)
            {
                var wrapTextStyle = EditorStyles.textArea;
                wrapTextStyle.wordWrap = true;
                EditorGUILayout.LabelField("Path to external/installed libraries: '" + _externalPath + "'", wrapTextStyle);
            }
        }
        else
        {
            _externalPath = string.Empty;
        }

        GUILayout.EndVertical();
        #endregion

        #region Player Fields
        EditorGUILayout.Space();
        EditorStyles.label.fontStyle = FontStyle.Bold;
        EditorGUILayout.LabelField("Player properties:");
        EditorStyles.label.fontStyle = _savedFontStyle;
        GUILayout.BeginHorizontal();

        GUILayout.BeginVertical("Box");

        GUILayout.BeginHorizontal();
        var centeredStyle = GUI.skin.GetStyle("Label");
        centeredStyle.alignment = TextAnchor.MiddleCenter;
        EditorGUILayout.LabelField("Volume", centeredStyle, GUILayout.Width((Screen.width - 120) / 2f));
        if (GUILayout.Button("x", GUILayout.Width(15), GUILayout.Height(13)))
        {
            _volumeProp.intValue = 50;
        }
        GUILayout.EndHorizontal();

        _volumeProp.intValue = EditorGUILayout.IntSlider(_volumeProp.intValue, 0, 100);
        GUILayout.EndVertical();

        GUILayout.BeginVertical("Box");

        GUILayout.BeginHorizontal();
        EditorGUILayout.LabelField("Play rate", centeredStyle, GUILayout.Width((Screen.width - 120) / 2f));
        if (GUILayout.Button("x", GUILayout.Width(15), GUILayout.Height(13)))
        {
            _playRateProp.floatValue = 1f;
        }
        GUILayout.EndHorizontal();

        _playRateProp.floatValue = EditorGUILayout.Slider(_playRateProp.floatValue, 0.5f, 5f);
        GUILayout.EndVertical();

        GUILayout.EndHorizontal();

        EditorGUI.BeginDisabledGroup(!umpEditor.IsReady);
        EditorGUILayout.Space();
        GUILayout.BeginVertical("Box");
        EditorGUILayout.LabelField("Position", centeredStyle, GUILayout.ExpandWidth(true));
        _positionProp.floatValue = EditorGUILayout.Slider(_positionProp.floatValue, 0f, 1f);
        GUILayout.EndVertical();
        EditorGUI.EndDisabledGroup();

        EditorGUI.BeginDisabledGroup(!Application.isPlaying || !umpEditor.isActiveAndEnabled || umpEditor.IsParsing);
        GUILayout.BeginHorizontal("Box");
        if (GUILayout.Button("LOAD", GUILayout.Width(Screen.width / 6.5f)))
        {
            umpEditor.Prepare();
        }
        if (GUILayout.Button("PLAY", GUILayout.Width(Screen.width / 6.5f)))
        {
            umpEditor.Play();
        }
        if (GUILayout.Button("PAUSE", GUILayout.Width(Screen.width / 6.5f)))
        {
            umpEditor.Pause();
        }
        if (GUILayout.Button("STOP", GUILayout.Width(Screen.width / 6.5f)))
        {
            umpEditor.Stop();
        }
        if (GUILayout.Button("SHOT"))
        {
            umpEditor.Snapshot(Application.persistentDataPath);
        }
        GUILayout.EndHorizontal();
        EditorGUI.EndDisabledGroup();
        #endregion

        #region Events & Logging Fields
        EditorGUILayout.Space();
        EditorStyles.label.fontStyle = FontStyle.Bold;
        EditorGUILayout.LabelField("Events & Logging:", GUILayout.Width(150));
        EditorStyles.label.fontStyle = _savedFontStyle;

        if (Application.platform == RuntimePlatform.WindowsEditor || Application.platform == RuntimePlatform.OSXEditor)
        {
            GUILayout.BeginVertical("Box");
            EditorGUILayout.PropertyField(_logDetailProp);

            GUILayout.BeginHorizontal();
            AutoSizeLabelField("Last msg: ");
            _lastMsgScrollPos = GUILayout.BeginScrollView(_lastMsgScrollPos, GUILayout.Height(35));
            EditorStyles.label.normal.textColor = Color.black;
            EditorStyles.label.fontStyle        = FontStyle.Italic;
            EditorGUILayout.LabelField(_lastEventMsgProp.stringValue);
            EditorStyles.label.normal.textColor = _savedTextColor;
            EditorStyles.label.fontStyle        = _savedFontStyle;
            GUILayout.EndScrollView();
            GUILayout.EndHorizontal();
            GUILayout.EndVertical();
        }
        else
        {
            GUILayout.BeginVertical("Box");
            EditorGUILayout.LabelField("Not yet supported on this platform");
            GUILayout.EndVertical();
        }

        _showEventsListeners = EditorGUILayout.Foldout(_showEventsListeners, "Event Listeners");

        if (_showEventsListeners)
        {
            EditorGUILayout.PropertyField(_openingEventProp, true, GUILayout.Width(Screen.width - _barWidth));
            EditorGUILayout.PropertyField(_bufferingEventProp, true, GUILayout.Width(Screen.width - _barWidth));
            EditorGUILayout.PropertyField(_playingEventProp, true, GUILayout.Width(Screen.width - _barWidth));
            EditorGUILayout.PropertyField(_pausedEventProp, true, GUILayout.Width(Screen.width - _barWidth));
            EditorGUILayout.PropertyField(_stoppedEventProp, true, GUILayout.Width(Screen.width - _barWidth));
            EditorGUILayout.PropertyField(_endReachedEventProp, true, GUILayout.Width(Screen.width - _barWidth));
            EditorGUILayout.PropertyField(_encounteredErrorEventProp, true, GUILayout.Width(Screen.width - _barWidth));
            EditorGUILayout.PropertyField(_timeChangedEventProp, new GUIContent("Time Changed"), true, GUILayout.Width(Screen.width - _barWidth));
            EditorGUILayout.PropertyField(_positionChangedEventProp, new GUIContent("Position Changed"), true, GUILayout.Width(Screen.width - _barWidth));
            EditorGUILayout.PropertyField(_snapshotTakenEventProp, new GUIContent("Snapshot"), true, GUILayout.Width(Screen.width - _barWidth));
        }
        #endregion

        //EditorGUILayout.EndScrollView();
        Repaint();

        EditorStyles.label.normal.textColor = _savedTextColor;
        EditorStyles.label.fontStyle        = _savedFontStyle;

        if (EditorGUI.EndChangeCheck())
        {
            serializedObject.ApplyModifiedProperties();
        }
    }