Exemple #1
0
        public override void OnInspectorGUI()
        {
            UAVP uavpEditor = (UAVP)target;

            EditorGUI.BeginChangeCheck();

            // Additional Fields
            EditorGUILayout.Space();
            EditorStyles.label.fontStyle = FontStyle.Bold;
            EditorGUILayout.LabelField("Additional Properties:");

            GUILayout.BeginVertical("Box");

            GUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Auto Play:", GUILayout.MinWidth(10));
            _autoPlay.boolValue = EditorGUILayout.Toggle(_autoPlay.boolValue, EditorStyles.radioButton);
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Loop:", GUILayout.MinWidth(10));
            _loop.boolValue = EditorGUILayout.Toggle(_loop.boolValue, EditorStyles.radioButton);
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Mute:", GUILayout.MinWidth(10));
            _mute.boolValue = EditorGUILayout.Toggle(_mute.boolValue, EditorStyles.radioButton);
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            int[]    logOptions     = { 0, 1, 2, 3 };
            string[] logOptionsText = { "Debug", "Source", "Porting", "System" };
            _logLevel.intValue = EditorGUILayout.IntPopup("LogLevel", _logLevel.intValue, logOptionsText, logOptions);
            GUILayout.EndHorizontal();

            GUILayout.EndVertical();

            _playType = new string[] { "Media Streaming", "Local", "Asset" };
            _mediaPlayType.intValue = GUILayout.SelectionGrid(_mediaPlayType.intValue, _playType, _playType.Length, EditorStyles.miniButton);
            _mediaPlayType.intValue = Mathf.Clamp(_mediaPlayType.intValue, 0, _playType.Length);

            // Streaming Video Field
            if (_mediaPlayType.intValue == 0)
            {
                EditorGUILayout.Space();
                EditorGUILayout.LabelField("URL : ");
                EditorStyles.textField.wordWrap = true;

                _mediaURI.stringValue           = EditorGUILayout.TextField(_mediaURI.stringValue, GUILayout.Height(30));
                EditorStyles.textField.wordWrap = false;
            }

            // Local Video Field
            if (_mediaPlayType.intValue == 1)
            {
                EditorGUILayout.Space();
                EditorGUILayout.LabelField("Local File Path(Please Input the whole absolute path): ");
                EditorStyles.textField.wordWrap = true;

                _localURI.stringValue           = EditorGUILayout.TextField(_localURI.stringValue, GUILayout.Height(30));
                EditorStyles.textField.wordWrap = false;
            }

            // Asset Video Path Field
            if (_mediaPlayType.intValue == 2)
            {
                EditorGUILayout.Space();
                EditorGUILayout.LabelField("Asset video file : ");
                EditorStyles.textField.wordWrap = true;

                string[] filesArray = UAVPUtility.GetStreamingAssetVideoFiles();
                if (filesArray != null)
                {
                    _assetFileIndex.intValue = EditorGUILayout.Popup(_assetFileIndex.intValue, filesArray);
                    if (_assetFileIndex.intValue < filesArray.Length)
                    {
                        _assetFileURI.stringValue = filesArray[_assetFileIndex.intValue];
                    }
                    else
                    {
                        _assetFileURI.stringValue = filesArray[0];
                    }
                }
                else
                {
                    EditorGUILayout.Space();
                    EditorGUILayout.LabelField("Please Add Video File in StreamingAsseets Directory \n" + Application.streamingAssetsPath);
                    EditorStyles.textField.wordWrap = true;
                }
            }

            // Rendering Field
            EditorGUILayout.Space();
            EditorGUILayout.LabelField("Objects for which video will be Rendered");
            GUILayout.BeginVertical("Box");
            EditorGUILayout.PropertyField(_videoMat, new GUIContent("Material"), true);
            EditorGUILayout.PropertyField(_videoRawImage, new GUIContent("RawImage"), true);
            GUILayout.EndVertical();

            EditorGUILayout.Space();
            EditorGUILayout.LabelField("Media Control UI");
            GUILayout.BeginVertical("Box");
            EditorGUILayout.PropertyField(_elapsedTime, new GUIContent("Current Time"), true);
            EditorGUILayout.PropertyField(_totalTime, new GUIContent("Media TotalTime"), true);
            EditorGUILayout.PropertyField(_seekbar, new GUIContent("Media SeekBar"), true);
            GUILayout.EndVertical();

            // Events
            _eventListeners = EditorGUILayout.Foldout(_eventListeners, "Event Listeners");
            if (_eventListeners)
            {
                EditorGUILayout.PropertyField(_openEvent, new GUIContent("Media Open Callback Event"), true, GUILayout.MinWidth(50));
                EditorGUILayout.PropertyField(_playEvent, new GUIContent("Media Play Callback Event"), true, GUILayout.MinWidth(50));
                EditorGUILayout.PropertyField(_pauseEvent, new GUIContent("Media Pause Callback Event"), true, GUILayout.MinWidth(50));
                EditorGUILayout.PropertyField(_endEvent, new GUIContent("Media End Callback Event"), true, GUILayout.MinWidth(50));
            }

            if (EditorGUI.EndChangeCheck())
            {
                serializedObject.ApplyModifiedProperties();
            }
        }
Exemple #2
0
        // Start is called before the first frame update
        void Start()
        {
            Debug.Log("UAVP Version: " + uavp_version);
            // Initialize the property
            if (seekbar != null)
            {
                EventTrigger eventTrigger = seekbar.gameObject.AddComponent <EventTrigger>();

                // When Click the Slider
                EventTrigger.Entry entry_PointerDown = new EventTrigger.Entry();
                entry_PointerDown.eventID = EventTriggerType.PointerDown;
                entry_PointerDown.callback.AddListener((data) => { OnPointerDown((PointerEventData)data); });
                eventTrigger.triggers.Add(entry_PointerDown);

                // When Touch Up the Slider
                EventTrigger.Entry entry_EndDrag = new EventTrigger.Entry();
                entry_EndDrag.eventID = EventTriggerType.EndDrag;
                entry_EndDrag.callback.AddListener((data) => { OnEndDrag((PointerEventData)data); });
                eventTrigger.triggers.Add(entry_EndDrag);
            }
            if (player != null)
            {
                if (autoPlay)
                {
                    player.setProperty(UAVPProperty.UAVP_AUTOPLAY, 1);
                }
                else
                {
                    player.setProperty(UAVPProperty.UAVP_AUTOPLAY, 0);
                }

                if (loop)
                {
                    player.setProperty(UAVPProperty.UAVP_LOOP, 1);
                }
                else
                {
                    player.setProperty(UAVPProperty.UAVP_LOOP, 0);
                }

                if (mute)
                {
                    player.setProperty(UAVPProperty.UAVP_MUTE, 1);
                }
                else
                {
                    player.setProperty(UAVPProperty.UAVP_MUTE, 0);
                }
            }

            if (seekbar != null)
            {
                seekbar.minValue = 0;
            }

            if (videoMat != null)
            {
                videoMat.mainTexture = null;
            }

            if (player != null)
            {
                // Register the Event
                UAVPlayerSource.onEvent += EventNotify;

                UAVPError error = player.InitPlayer(logLevel);
                if (error == UAVPError.UAVP_ERROR_NONE)
                {
                    if (mediaPlayType == UAVPMediaType.UAVP_Streaming_Media)            // Streaming
                    {
                        Debug.Log("Play Streaming");
                        URI = mediaURI;
                    }
                    else if (mediaPlayType == UAVPMediaType.UAVP_StreamingAsset_Media)  // StreamingAsset
                    {
                        if (Application.platform == RuntimePlatform.OSXEditor)
                        {
                            Debug.Log("Play StreamingAsset Media");
                            if (assetFileURI != null)
                            {
                                URI = UAVPUtility.GetLocalURI(Application.dataPath + "/StreamingAssets/" + assetFileURI);
                            }
                            else
                            {
                                URI = null;
                            }
                        }
                        else if (Application.platform == RuntimePlatform.IPhonePlayer)
                        {
                            URI = assetFileURI;
                        }
                    }
                    else if (mediaPlayType == UAVPMediaType.UAVP_Local_Media)           // Local
                    {
                        if (Application.platform == RuntimePlatform.OSXEditor)
                        {
                            Debug.Log("Play Local Media");
                            if (localURI != null)
                            {
                                URI = UAVPUtility.GetLocalURI(localURI);
                            }
                            else
                            {
                                URI = null;
                            }
                        }
                        else if (Application.platform == RuntimePlatform.IPhonePlayer)
                        {
                            URI = localURI;
                        }
                    }

                    if (URI != null)
                    {
                        Debug.Log("Start to play [" + URI + "]");
                        player.OpenMedia(URI, mediaPlayType);
                    }
                    else
                    {
                        Debug.Log("URI is null");
                    }

                    openEvent.Invoke();
                }
                else
                {
                    player = null;
                }
            }
            else
            {
                Debug.Log("Player is null");
            }
        }