Beispiel #1
0
        public override void Dispose()
        {
            Settings.i.OnGeneralSettingsChanged           -= OnSettingsChanged;
            CommonScriptableObjects.playerCoords.OnChange -= OnPlayerCoordsChanged;
            if (scene != null)
            {
                scene.OnEntityRemoved -= OnEntityRemoved;
            }
            if (texturePlayerUpdateRoutine != null)
            {
                CoroutineStarter.Stop(texturePlayerUpdateRoutine);
                texturePlayerUpdateRoutine = null;
            }

            if (texturePlayer != null)
            {
                texturePlayer.Dispose();
                texturePlayer = null;
            }

            if (isTest && texture != null)
            {
                UnityEngine.Object.Destroy(texture);
            }

            texture = null;
            base.Dispose();
        }
Beispiel #2
0
        public override IEnumerator ApplyChanges(string newJson)
        {
            yield return(new WaitUntil(() => CommonScriptableObjects.rendererState.Get()));

            model = SceneController.i.SafeFromJson <Model>(newJson);

            unitySamplingMode = model.samplingMode;

            switch (model.wrap)
            {
            case BabylonWrapMode.CLAMP:
                unityWrap = TextureWrapMode.Clamp;
                break;

            case BabylonWrapMode.WRAP:
                unityWrap = TextureWrapMode.Repeat;
                break;

            case BabylonWrapMode.MIRROR:
                unityWrap = TextureWrapMode.Mirror;
                break;
            }

            if (texturePlayer == null)
            {
                DCLVideoClip dclVideoClip = scene.GetSharedComponent(model.videoClipId) as DCLVideoClip;
                if (dclVideoClip == null)
                {
                    Debug.LogError("Wrong video clip type when playing VideoTexture!!");
                    yield break;
                }

                string videoId = (!string.IsNullOrEmpty(scene.sceneData.id)) ? scene.sceneData.id + id : scene.GetHashCode().ToString() + id;
                texturePlayer = new WebVideoPlayer(videoId, dclVideoClip.GetUrl(), dclVideoClip.isStream);
                texturePlayerUpdateRoutine = CoroutineStarter.Start(VideoTextureUpdate());
                CommonScriptableObjects.playerCoords.OnChange += OnPlayerCoordsChanged;
                scene.OnEntityRemoved += OnEntityRemoved;
                Settings.i.OnGeneralSettingsChanged += OnSettingsChanged;
            }

            // NOTE: create texture for testing cause real texture will only be created on web platform
            if (isTest)
            {
                if (texture == null)
                {
                    texture = new Texture2D(1, 1);
                }
            }

            if (texture == null)
            {
                while (texturePlayer.texture == null && !texturePlayer.isError)
                {
                    yield return(null);
                }

                if (texturePlayer.isError)
                {
                    if (texturePlayerUpdateRoutine != null)
                    {
                        CoroutineStarter.Stop(texturePlayerUpdateRoutine);
                        texturePlayerUpdateRoutine = null;
                    }

                    yield break;
                }

                texture          = texturePlayer.texture;
                isPlayStateDirty = true;
            }

            if (texturePlayer != null)
            {
                if (texturePlayer.playing && !model.playing)
                {
                    texturePlayer.Pause();
                }
                else if (model.playing)
                {
                    texturePlayer.Play();
                }

                if (baseVolume != model.volume)
                {
                    baseVolume = model.volume;
                    UpdateVolume();
                }

                if (model.seek >= 0)
                {
                    texturePlayer.SetTime(model.seek);
                    model.seek = -1;
                }

                texturePlayer.SetPlaybackRate(model.playbackRate);
                texturePlayer.SetLoop(model.loop);
            }
        }
        public override IEnumerator ApplyChanges(BaseModel newModel)
        {
            yield return(new WaitUntil(() => CommonScriptableObjects.rendererState.Get()));

            //If the scene creates and destroy the component before our renderer has been turned on bad things happen!
            //TODO: Analyze if we can catch this upstream and stop the IEnumerator
            if (isDisposed)
            {
                yield break;
            }

            var model = (Model)newModel;

            unitySamplingMode = model.samplingMode;

            switch (model.wrap)
            {
            case BabylonWrapMode.CLAMP:
                unityWrap = TextureWrapMode.Clamp;
                break;

            case BabylonWrapMode.WRAP:
                unityWrap = TextureWrapMode.Repeat;
                break;

            case BabylonWrapMode.MIRROR:
                unityWrap = TextureWrapMode.Mirror;
                break;
            }

            if (texturePlayer == null)
            {
                DCLVideoClip dclVideoClip = scene.GetSharedComponent(model.videoClipId) as DCLVideoClip;

                if (dclVideoClip == null)
                {
                    Debug.LogError("Wrong video clip type when playing VideoTexture!!");
                    yield break;
                }

                string videoId = (!string.IsNullOrEmpty(scene.sceneData.id)) ? scene.sceneData.id + id : scene.GetHashCode().ToString() + id;
                texturePlayer = new WebVideoPlayer(videoId, dclVideoClip.GetUrl(), dclVideoClip.isStream);
                texturePlayerUpdateRoutine = CoroutineStarter.Start(VideoTextureUpdate());
                CommonScriptableObjects.playerCoords.OnChange += OnPlayerCoordsChanged;
                CommonScriptableObjects.sceneID.OnChange      += OnSceneIDChanged;
                scene.OnEntityRemoved += OnEntityRemoved;
                Settings.i.OnGeneralSettingsChanged += OnSettingsChanged;

                OnSceneIDChanged(CommonScriptableObjects.sceneID.Get(), null);
            }

            // NOTE: create texture for testing cause real texture will only be created on web platform
            if (isTest)
            {
                if (texture == null)
                {
                    texture = new Texture2D(1, 1);
                }
            }

            if (texture == null)
            {
                while (texturePlayer.texture == null && !texturePlayer.isError)
                {
                    yield return(null);
                }

                if (texturePlayer.isError)
                {
                    if (texturePlayerUpdateRoutine != null)
                    {
                        CoroutineStarter.Stop(texturePlayerUpdateRoutine);
                        texturePlayerUpdateRoutine = null;
                    }

                    yield break;
                }

                texture          = texturePlayer.texture;
                isPlayStateDirty = true;
            }

            if (texturePlayer != null)
            {
                if (model.seek >= 0)
                {
                    texturePlayer.SetTime(model.seek);
                    model.seek = -1;

                    // Applying seek is not immediate
                    yield return(null);
                }

                if (model.playing)
                {
                    texturePlayer.Play();
                }
                else
                {
                    texturePlayer.Pause();
                }

                if (baseVolume != model.volume)
                {
                    baseVolume = model.volume;
                    UpdateVolume();
                }

                texturePlayer.SetPlaybackRate(model.playbackRate);
                texturePlayer.SetLoop(model.loop);
            }
        }