Exemplo n.º 1
0
        private async void PlayScriptAsync()
        {
            if (!string.IsNullOrEmpty(scriptName))
            {
                var player = Engine.GetService <IScriptPlayer>();
                if (player is null)
                {
                    throw new Exception($"Failed to play a script via `{nameof(PlayScript)}` component attached to `{gameObject.name}` game object: script player service is not available.");
                }
                await player.PreloadAndPlayAsync(scriptName);

                return;
            }

            if (!string.IsNullOrWhiteSpace(scriptText))
            {
                var text     = string.IsNullOrEmpty(argument) ? scriptText : scriptText.Replace("{arg}", argument);
                var script   = Script.FromScriptText($"`{name}` generated script", text);
                var playlist = new ScriptPlaylist(script);
                await playlist.ExecuteAsync();
            }
        }