Ejemplo n.º 1
0
        public virtual async UniTask PlayAsync(string movieName, CancellationToken cancellationToken = default)
        {
            if (Playing)
            {
                Stop();
            }

            playedMovieName = movieName;
            playCTS         = cancellationToken.CreateLinkedTokenSource();

            OnMoviePlay?.Invoke();
            await UniTask.Delay(TimeSpan.FromSeconds(Configuration.FadeDuration));

            if (cancellationToken.CancelASAP)
            {
                return;
            }

            #if UNITY_WEBGL && !UNITY_EDITOR
            Player.url = PathUtils.Combine(Application.streamingAssetsPath, $"{Configuration.Loader.PathPrefix}/{movieName}") + streamExtension;
            #else
            var videoClipResource = await videoLoader.LoadAndHoldAsync(movieName, this);

            if (cancellationToken.CancelASAP)
            {
                return;
            }
            if (!videoClipResource.Valid)
            {
                throw new Exception($"Failed to load `{movieName}` movie.");
            }
            Player.clip = videoClipResource;
            #endif

            Player.Prepare();
            while (!Player.isPrepared)
            {
                await AsyncUtils.WaitEndOfFrame;
            }
            if (cancellationToken.CancelASAP)
            {
                return;
            }
            OnMovieTextureReady?.Invoke(Player.texture);

            Player.Play();
            while (Playing)
            {
                await AsyncUtils.WaitEndOfFrame;
            }
        }
Ejemplo n.º 2
0
        public virtual async UniTask <Texture2D> LoadCGTextureAsync()
        {
            Texture2D cgTexture;

            if (textureLoader.IsLoaded(textureLocalPath))
            {
                cgTexture = textureLoader.GetLoadedOrNull(textureLocalPath);
            }
            else
            {
                thumbnailImage.texture = loadingTexture;
                var resource = await textureLoader.LoadAndHoldAsync(textureLocalPath, this);

                cgTexture = resource;
            }

            return(cgTexture);
        }