コード例 #1
0
    private IEnumerator populateSpeechBubble(string text, DialogueHandler dialogueHandler, GameObject dialogueObject)
    {
        if (talking)
        {
            yield break;
        }
        talking = true;
        dialogueObject.SetActive(true);
        foreach (char c in text)
        {
            if (audioSource != null && !audioSource.isPlaying && Char.IsLetter(c))
            {
                int randomClip = UnityEngine.Random.Range(0, 3);
                if (randomClip == 0)
                {
                    audioSource.clip = talkSound1;
                }
                if (randomClip == 1)
                {
                    audioSource.clip = talkSound2;
                }
                if (randomClip == 2)
                {
                    audioSource.clip = talkSound3;
                }
                audioSource.Play();
            }
            dialogueHandler.SetDialogue(dialogueHandler.GetDialogue() + c);
            yield return(new WaitForSeconds(0.08f));

            if (c.Equals('.') || c.Equals('?') || c.Equals('!'))
            {
                yield return(new WaitForSeconds(0.7f));
            }
            audioSource.Stop();
        }
        var wt = (float)System.Math.Ceiling(text.Length / 60f);

        yield return(new WaitForSeconds(wt));

        dialogueHandler.SetDialogue("");
        talking = false;
        dialogueObject.SetActive(false);
        yield return(new WaitForSeconds(0.6f));
    }
コード例 #2
0
        public async Task Dialogue(CommandContext ctx)
        {
            var thirdStep  = new TextStep("Enter something sad!", null);
            var secondStep = new TextStep("Enter something boring!", thirdStep);
            var inputStep  = new TextStep("Enter something interesting!", secondStep);
            var funnyStep  = new IntStep("Haha funny", null, 4, 10);

            string input = string.Empty;
            int    value = 0;


            funnyStep.OnValidResult += (result) => value = result;

            var userChannel = await ctx.Member.CreateDmChannelAsync().ConfigureAwait(false);

            var inputDialogueHandler = new DialogueHandler(ctx.Client, userChannel, ctx.User, inputStep);

            List <DiscordMessage> dialogue = inputDialogueHandler.GetDialogue();

            bool succeded = await inputDialogueHandler.ProcessDialogue().ConfigureAwait(false);

            StringBuilder inputDialogue = new StringBuilder();


            foreach (var message in dialogue)
            {
                inputDialogue.Append($"** {message.Content} ** \n");
            }

            var finalEmbed = new DiscordEmbedBuilder
            {
                Description = inputDialogue.ToString(),
                Color       = DiscordColor.DarkBlue,
                Title       = "Dialogue"
            };

            if (!succeded)
            {
                return;
            }

            await ctx.Channel.SendMessageAsync(embed : finalEmbed).ConfigureAwait(false);

            await ctx.Channel.SendMessageAsync(value.ToString()).ConfigureAwait(false);
        }