示例#1
0
        /// <summary>
        /// Plays a movie with the provided name; returns when the playback finishes.
        /// </summary>
        public async Task PlayAsync(string movieName, CancellationToken cancellationToken = default)
        {
            if (IsPlaying)
            {
                Stop();
            }

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

            OnMoviePlay?.Invoke();
            await waitForFade;

            if (cancellationToken.IsCancellationRequested)
            {
                return;
            }

            #if UNITY_WEBGL && !UNITY_EDITOR
            Player.url = PathUtils.Combine(Application.streamingAssetsPath, videoLoader.BuildFullPath(movieName)) + ".mp4";
            #else
            var videoClipResource = await videoLoader.LoadAsync(movieName);

            if (cancellationToken.IsCancellationRequested)
            {
                return;
            }
            if (!videoClipResource.IsValid)
            {
                Debug.LogError($"Failed to load `{movieName}` movie."); Stop(); return;
            }
            Player.clip = videoClipResource;
            videoClipResource.Hold(this);
            #endif

            Player.Prepare();
            while (!Player.isPrepared)
            {
                await waitForEndOfFrame;
            }
            if (cancellationToken.IsCancellationRequested)
            {
                return;
            }
            OnMovieTextureReady?.Invoke(Player.texture);

            Player.Play();
            while (IsPlaying)
            {
                await waitForEndOfFrame;
            }
        }
示例#2
0
        public virtual async UniTask <Texture2D> LoadCGTextureAsync()
        {
            Texture2D cgTexture;

            if (textureLoader.IsLoaded(textureLocalPath))
            {
                cgTexture = textureLoader.GetLoadedOrNull(textureLocalPath);
            }
            else
            {
                thumbnailImage.texture = loadingTexture;
                cgTexture = await textureLoader.LoadAsync(textureLocalPath);
            }

            thumbnailImage.texture = unlockableManager.ItemUnlocked(UnlockableId) ? cgTexture : lockedTexture;

            return(cgTexture);
        }