Ejemplo n.º 1
0
        public override async UniTask ChangeVisibilityAsync(bool visible, float?duration = null)
        {
            if (visible && !string.IsNullOrEmpty(titleScriptName))
            {
                await scriptPlayer.PreloadAndPlayAsync(titleScriptName);

                while (scriptPlayer.Playing)
                {
                    await AsyncUtils.WaitEndOfFrame;
                }
            }

            var changeVisibilityTask = base.ChangeVisibilityAsync(visible, duration);

            // Save title menu visibility state; otherwise it's lost when changing language,
            // while a title or initialization scripts are used (the game is save-loaded in those cases).
            var stateMap = stateManager.PeekRollbackStack();

            if (stateMap != null && stateMap.GetState <GameState>(name) is GameState state)
            {
                state.Visible = visible;
            }

            await changeVisibilityTask;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Loads the provided script, preloads the script's commands and starts playing at the provided line and inline indexes or a label;
        /// when <paramref name="label"/> is provided, will ignore line and inline indexes.
        /// </summary>
        /// <param name="scriptName">Name (resource path) of the script to load and play.</param>
        /// <param name="startLineIndex">Line index to start playback from.</param>
        /// <param name="startInlineIndex">Command inline index to start playback from.</param>
        /// <param name="label">Name of a label within the script to start playback from.</param>
        public static async UniTask PreloadAndPlayAsync(this IScriptPlayer scriptPlayer, string scriptName, int startLineIndex = 0, int startInlineIndex = 0, string label = null)
        {
            var script = await Engine.GetService <IScriptManager>().LoadScriptAsync(scriptName);

            if (script is null)
            {
                throw new Exception($"Script player failed to start: script with name `{scriptName}` wasn't able to load.");
            }
            await scriptPlayer.PreloadAndPlayAsync(script, startLineIndex, startInlineIndex, label);
        }
Ejemplo n.º 3
0
        protected override async void OnButtonClick()
        {
            if (string.IsNullOrEmpty(startScriptName))
            {
                Debug.LogError("Can't start new game: specify start script name in the settings.");
                return;
            }

            if (!string.IsNullOrEmpty(titleScriptName) &&
                await scriptManager.LoadScriptAsync(titleScriptName) is Script titleScript &&
                titleScript.LabelExists(titleLabel))
            {
                await scriptPlayer.PreloadAndPlayAsync(titleScriptName, label : titleLabel);

                await UniTask.WaitWhile(() => scriptPlayer.Playing);
            }

            titleMenu.Hide();
            StartNewGameAsync();
        }
Ejemplo n.º 4
0
        protected override async void OnButtonClick ()
        {
            if (!string.IsNullOrEmpty(titleScriptName) &&
                await scriptManager.LoadScriptAsync(titleScriptName) is Script titleScript &&
                titleScript.LabelExists(titleLabel))
            {
                await scriptPlayer.PreloadAndPlayAsync(titleScriptName, label: titleLabel);
                await UniTask.WaitWhile(() => scriptPlayer.Playing);
            }

            if (Application.platform == RuntimePlatform.WebGLPlayer)
                Application.OpenURL("about:blank");
            else Application.Quit();
        }
Ejemplo n.º 5
0
        public override async UniTask ChangeVisibilityAsync(bool visible, float?duration = null, CancellationToken cancellationToken = default)
        {
            if (visible && !string.IsNullOrEmpty(titleScriptName))
            {
                await scriptPlayer.PreloadAndPlayAsync(titleScriptName);

                if (cancellationToken.CancelASAP)
                {
                    return;
                }
                await UniTask.WaitWhile(() => scriptPlayer.Playing);

                if (cancellationToken.CancelASAP)
                {
                    return;
                }
            }

            await base.ChangeVisibilityAsync(visible, duration, cancellationToken);
        }
 private async void PlayScriptAsync()
 {
     await stateManager.ResetStateAsync(null, () => player.PreloadAndPlayAsync(script.Name));
 }
Ejemplo n.º 7
0
 private async void StartNewGameAsync()
 {
     await stateManager.ResetStateAsync(null, () => player.PreloadAndPlayAsync(startScriptName));
 }