Exemplo n.º 1
0
 /// Runs a line.
 /// <inheritdoc/>
 public override Dialogue.HandlerExecutionType RunLine(Yarn.Line line, ILineLocalisationProvider localisationProvider, System.Action onLineComplete)
 {
     // Start displaying the line; it will call onComplete later
     // which will tell the dialogue to continue
     StartCoroutine(DoRunLine(line, localisationProvider, onLineComplete));
     return(Dialogue.HandlerExecutionType.PauseExecution);
 }
    /// Show a list of options, and wait for the player to make a
    /// selection.
    private IEnumerator DoRunOptions(Yarn.OptionSet optionsCollection, ILineLocalisationProvider localisationProvider, System.Action <int> selectOption)
    {
        ds.ClearOptions();
        end = false;

        waitingForOptionSelection = true;

        currentOptionSelectionHandler = selectOption;

        foreach (var optionString in optionsCollection.Options)
        {
            string text = localisationProvider.GetLocalisedTextForLine(optionString.Line);
            ds.AddChoice(text, () => SelectOption(optionString.ID));
        }

        onOptionsStart?.Invoke();

        // Wait until the chooser has been used and then removed
        while (waitingForOptionSelection)
        {
            yield return(null);
        }

        onOptionsEnd?.Invoke();
    }
        private IEnumerator DoRunLine(Yarn.Line line, ILineLocalisationProvider localisationProvider, global::System.Action onComplete)
        {
            OnLineStart();

            string text = localisationProvider.GetLocalisedTextForLine(line);

            // Sanity check
            if (text == null)
            {
                Debug.LogWarning($"Line {line.ID} doesn't have any localised text.");
                text = line.ID;
            }

            SeparateNameAndDialogue(text, out string characterStyleName, out string characterName, out string characterDialogue);

            OnLineStyleUpdated(characterStyleName);
            OnNameLineUpdate(characterName);
            OnDialogueLineUpdate(characterDialogue);

            while (!RequestedNextLine)
            {
                yield return(null);
            }
            RequestedNextLine = false;

            yield return(new WaitForEndOfFrame());

            OnLineEnd();

            onComplete();
        }
Exemplo n.º 4
0
        /// Show a line of dialogue, gradually
        private IEnumerator DoRunLine(Yarn.Line line, ILineLocalisationProvider localisationProvider, Action onComplete)
        {
            onLineStart?.Invoke();

            // The final text we'll be showing for this line.
            string text = localisationProvider.GetLocalisedTextForLine(line);

            if (text == null)
            {
                Debug.LogWarning($"Line {line.ID} doesn't have any localised text.");
                text = line.ID;
            }
            else if (text[0] == LineStartPlaceHolder)
            {
                text = text.Remove(0, 1);
            }

            if (textSpeed > 0.0f && !proceedToNextLine)
            {
                IDialogueText completeText = ComplexDialogueText.AnalyzeText(text, RunLineLogger);

                foreach (string currentText in completeText.Parse())
                {
                    LineUpdate(currentText);
                    if (proceedToNextLine)
                    {
                        // We've requested a skip of the entire line.
                        // Display all of the text immediately.
                        LineUpdate(text);
                        break;
                    }
                    yield return(new WaitForSeconds(textSpeed));
                }
            }
            else
            {
                // Display the entire line immediately if textSpeed <= 0
                LineUpdate(text);
            }

            // We're now waiting for the player to move on to the next line
            proceedToNextLine = false;

            // Indicate to the rest of the game that the line has finished being delivered
            LineFinishDisplaying();

            while (!proceedToNextLine)
            {
                yield return(CheckContinue());
            }

            // Avoid skipping lines if textSpeed == 0
            yield return(new WaitForEndOfFrame());

            // Hide the text and prompt
            LineEnd();

            onComplete();
        }
Exemplo n.º 5
0
        /// Show a line of dialogue, gradually
        private IEnumerator DoRunLine(Yarn.Line line, ILineLocalisationProvider localisationProvider, System.Action onComplete)
        {
            onLineStart?.Invoke();

            userRequestedNextLine = false;

            // The final text we'll be showing for this line.
            string text = localisationProvider.GetLocalisedTextForLine(line);

            if (text == null)
            {
                Debug.LogWarning($"Line {line.ID} doesn't have any localised text.");
                text = line.ID;
            }

            if (textSpeed > 0.0f)
            {
                // Display the line one character at a time
                var stringBuilder = new StringBuilder();

                foreach (char c in text)
                {
                    stringBuilder.Append(c);
                    onLineUpdate?.Invoke(stringBuilder.ToString());
                    if (userRequestedNextLine)
                    {
                        // We've requested a skip of the entire line.
                        // Display all of the text immediately.
                        onLineUpdate?.Invoke(text);
                        break;
                    }
                    yield return(new WaitForSeconds(textSpeed));
                }
            }
            else
            {
                // Display the entire line immediately if textSpeed <= 0
                onLineUpdate?.Invoke(text);
            }

            // We're now waiting for the player to move on to the next line
            userRequestedNextLine = false;

            // Indicate to the rest of the game that the line has finished being delivered
            onLineFinishDisplaying?.Invoke();

            while (userRequestedNextLine == false)
            {
                yield return(null);
            }

            // Avoid skipping lines if textSpeed == 0
            yield return(new WaitForEndOfFrame());

            // Hide the text and prompt
            onLineEnd?.Invoke();

            onComplete();
        }
Exemplo n.º 6
0
    /// Show a line of dialogue, gradually
    private IEnumerator DoRunLine(Yarn.Line line, ILineLocalisationProvider localisationProvider, System.Action onComplete)
    {
        onLineStart?.Invoke();

        userRequestedNextLine = false;

        // The final text we'll be showing for this line.
        string text = localisationProvider.GetLocalisedTextForLine(line);

        if (text == null)
        {
            Debug.LogWarning($"Line {line.ID} doesn't have any localised text.");
            text = line.ID;
        }


        string[] split = text.Split('^');

        bool eventualEnd = end;

        end = false;

        for (int i = 0; i < split.Length; i++)
        {
            if (split[i][0] == '&')
            {
                ds.AddImage(split[i].Remove(0, 1));
            }
            else
            {
                ds.AddToDialogText(currentSpeakerName, split[i], textAlign);
            }


            if (i == split.Length - 1)
            {
                end = eventualEnd;
            }

            // We're now waiting for the player to move on to the next line
            userRequestedNextLine = false;

            // Indicate to the rest of the game that the line has finished being delivered
            onLineFinishDisplaying?.Invoke();

            while (userRequestedNextLine == false)
            {
                yield return(null);
            }
        }

        // Hide the text and prompt
        onLineEnd?.Invoke();

        onComplete();
    }
    /// EDITED FOR SAILING WITH THE GODS
    /// Designed for our dialog system to fill in a dialog object
    private IEnumerator DoRunLine(Yarn.Line line, ILineLocalisationProvider localisationProvider, System.Action onComplete)
    {
        onLineStart?.Invoke();

        userRequestedNextLine = false;

        string text = localisationProvider.GetLocalisedTextForLine(line);

        if (text == null)
        {
            Debug.LogWarning($"Line {line.ID} doesn't have any localised text.");
            text = line.ID;
        }

        //Split one block of text into multiple sections
        string[] split = text.Split('^');

        //If we need to end after the split, we have to save that for later
        //Otherwise, we'll end between the split, which isn't right
        bool eventualEnd = end;

        end = false;

        for (int i = 0; i < split.Length; i++)
        {
            if (split[i][0] == '&')
            {
                ds.AddImage(split[i].Remove(0, 1));
            }
            else
            {
                ds.AddToDialogText(currentSpeakerName, split[i], textAlign);
            }

            //If this is the final part of the split text, remember if this is the end or not
            if (i == split.Length - 1)
            {
                end = eventualEnd;
            }

            // We're now waiting for the player to move on to the next line
            userRequestedNextLine = false;

            // Indicate to the rest of the game that the line has finished being delivered
            onLineFinishDisplaying?.Invoke();

            while (userRequestedNextLine == false)
            {
                yield return(null);
            }
        }

        onLineEnd?.Invoke();

        onComplete();
    }
Exemplo n.º 8
0
        private Action <int> currentOptionSelectionHandler;     // Action supplied but RunOptions to be triggered later

        /// <summary>
        /// Runs a line supplied by the DialogueRunner. Refer to YarnSpinner docs for more information.
        /// </summary>
        public override Dialogue.HandlerExecutionType RunLine(Line line, ILineLocalisationProvider localisationProvider, Action onLineComplete)
        {
            isRunningLine       = true;
            lineCompleteHandler = onLineComplete;
            string text = localisationProvider.GetLocalisedTextForLine(line);

            // Trigger Bolt event with line information so it can be used in Bolt graphs.
            CustomEvent.Trigger(this.gameObject, "RUN_LINE", text);

            return(Dialogue.HandlerExecutionType.PauseExecution);
        }
        public override void RunOptions(Yarn.OptionSet optionSet, ILineLocalisationProvider localisationProvider, Action <int> onOptionSelected)
        {
            if (_options.IsNull())
            {
                _options = new List <IDialogueOptions>();
            }

            if (_poolOptions.IsNull())
            {
                _poolOptions = new Queue <IDialogueOptions>();
            }

            //pool
            for (int i = 0; i < optionSet.Options.Length; i++)
            {
                var option       = optionSet.Options[i];
                var id           = option.ID;
                var localizeText = localisationProvider.GetLocalisedTextForLine(option.Line);
                var text         = localizeText;

                if (_options.Count - 1 < i)
                {
                    var newValue = _poolOptions.Count > 0? _poolOptions.Dequeue() : new YarnSpinnerDialogueOptions(id, text, localizeText);
                    _options.Add(newValue);
                }

                var current = _options[i] as YarnSpinnerDialogueOptions;
                current.id           = id;
                current.text         = text;
                current.localizeText = localizeText;
                current.RemoveAllListener();
                current.AddListener(val =>
                {
                    onOptionSelected?.Invoke(val.id);
                    _ui?.OnOptionsSelected(val.id);
                    _ui?.OnOptionsEnd();
                });
            }

            if (_options.Count > optionSet.Options.Length)
            {
                var count = _options.Count - optionSet.Options.Length;
                for (int i = 0; i < count; i++)
                {
                    var option = _options.Last() as YarnSpinnerDialogueOptions;
                    option.RemoveAllListener();

                    _poolOptions.Enqueue(option);
                    _options.Remove(option);
                }
            }

            _ui?.OnOptionsStart(_options);
        }
Exemplo n.º 10
0
        public override Dialogue.HandlerExecutionType RunLine(Yarn.Line line, ILineLocalisationProvider localisationProvider, System.Action onLineComplete)
        {
            string text = localisationProvider.GetLocalisedTextForLine(line);

            speakerName = Regex.Match(text, @"^.*?(?=:)").Value;

            lastLine    = currentLine;
            currentLine = line;

            // Start displaying the line; it will call onComplete later
            // which will tell the dialogue to continue
            StartCoroutine(DoRunLine(line, localisationProvider, onLineComplete));
            return(Dialogue.HandlerExecutionType.PauseExecution);
        }
Exemplo n.º 11
0
    private IEnumerator DoRunOptions(Yarn.OptionSet optionsCollection, ILineLocalisationProvider localisationProvider, System.Action <int> selectOption)
    {
        if (optionsCollection.Options.Length > optionButtons.Count)
        {
            Debug.LogWarning("There arent enough buttons for the amount of choices we need to display. This will cause problems");
        }

        int i = 0;

        ds = DialogState.Choices;

        speaker.portraitUI.SetActive(true);
        foreach (var optionString in optionsCollection.Options)
        {
            optionButtons[i].gameObject.SetActive(true);

            optionButtons[i].onClick.RemoveAllListeners();
            optionButtons[i].onClick.AddListener(() => SelectOption(optionString.ID, selectOption));

            var optionText = localisationProvider.GetLocalisedTextForLine(optionString.Line);

            if (optionText == null)
            {
                Debug.LogWarning($"Option {optionString.Line.ID} doesn't have any localised text");
                optionText = optionString.Line.ID;
            }

            var unityText = optionButtons [i].GetComponentInChildren <TextMeshProUGUI> ();
            if (unityText != null)
            {
                unityText.text = optionText;
            }
            i++;
        }

        while (ds == DialogState.Choices)
        {
            yield return(null);
        }
        Debug.Log("Alpha");

        // TODO: THIS SEEMS KINDA SKETCH
        // speaker.portraitUI.SetActive(false);

        // Hide all the buttons
        foreach (var button in optionButtons)
        {
            button.gameObject.SetActive(false);
        }
    }
Exemplo n.º 12
0
        /// <summary>
        /// Runs Options supplied by the DialogueRunner. Refer to YarnSpinner docs for more information.
        /// </summary>
        public override void RunOptions(OptionSet optionSet, ILineLocalisationProvider localisationProvider, Action <int> onOptionSelected)
        {
            isRunningOptions = true;
            currentOptionSelectionHandler = onOptionSelected;

            List <string> OptionsText = new List <string>();

            optionsCount = 0;

            // Convert the options into a String List and count the number of options.
            foreach (var optionString in optionSet.Options)
            {
                var optionText = localisationProvider.GetLocalisedTextForLine(optionString.Line);
                OptionsText.Add(optionText);
                optionsCount++;
            }

            // Trigger Bolt event with Options information
            CustomEvent.Trigger(this.gameObject, "RUN_OPTIONS", OptionsText, optionsCount);
        }
Exemplo n.º 13
0
        public override Yarn.Dialogue.HandlerExecutionType RunLine(Yarn.Line line, ILineLocalisationProvider localisationProvider, Action onComplete)
        {
            proceedToNextLine = false;

            if (skipDialogue)
            {
                if (AllowSkip)
                {
                    return(Yarn.Dialogue.HandlerExecutionType.ContinueExecution);
                }
                else
                {
                    SkipDialogueEnd();
                }
            }

            // Start displaying the line; it will call onComplete later
            // which will tell the dialogue to continue
            StartCoroutine(DoRunLine(line, localisationProvider, onComplete));
            return(Yarn.Dialogue.HandlerExecutionType.PauseExecution);
        }
        public override Yarn.Dialogue.HandlerExecutionType RunLine(Yarn.Line line, ILineLocalisationProvider localisationProvider, System.Action onLineComplete)
        {
            var text = localisationProvider.GetLocalisedTextForLine(line);

            if (text.IsNullOrEmpty())
            {
                text = line.ID;
                $"Line {line.ID} doesn't have any localised text".Log();
            }

            if (_line.IsNull())
            {
                _line = new YarnSpinnerDialogueLine();
            }

            _line.text = text;
            _line.RemoveAllListener();
            _line.AddListener(onLineComplete);
            _line.AddListener(_ui.OnLineEnd);
            _ui?.OnLineStart(_line);

            return(Yarn.Dialogue.HandlerExecutionType.PauseExecution);
        }
Exemplo n.º 15
0
        public void OnChoicesStarted(Yarn.OptionSet.Option[] options, ILineLocalisationProvider localisationProvider)
        {
            IEnumerable <DialogueChoice> dialogueChoices = options.Select((option) => {
                string text = localisationProvider.GetLocalisedTextForLine(option.Line);

                // Sanity check
                if (text == null)
                {
                    Debug.LogWarning($"Line {option.Line.ID} doesn't have any localised text.");
                    text = option.Line.ID;
                }

                DialogueChoice dialogueChoice = new DialogueChoice()
                {
                    Text = text,
                    ID   = option.ID
                };

                return(dialogueChoice);
            });

            DialogueManager.OnChoicesStarted(dialogueChoices);
        }
Exemplo n.º 16
0
        /// Show a list of options, and wait for the player to make a
        /// selection.
        private IEnumerator DoRunOptions(Yarn.OptionSet optionsCollection, ILineLocalisationProvider localisationProvider, System.Action <int> selectOption)
        {
            // Do a little bit of safety checking
            if (optionsCollection.Options.Length > optionButtons.Count)
            {
                Debug.LogWarning("There are more options to present than there are" +
                                 "buttons to present them in. This will cause problems.");
            }

            // Display each option in a button, and make it visible
            int i = 0;

            waitingForOptionSelection = true;

            currentOptionSelectionHandler = selectOption;

            foreach (var optionString in optionsCollection.Options)
            {
                optionButtons [i].gameObject.SetActive(true);

                // When the button is selected, tell the dialogue about it
                optionButtons [i].onClick.RemoveAllListeners();
                optionButtons [i].onClick.AddListener(() => SelectOption(optionString.ID));

                var optionText = localisationProvider.GetLocalisedTextForLine(optionString.Line);

                if (optionText == null)
                {
                    Debug.LogWarning($"Option {optionString.Line.ID} doesn't have any localised text");
                    optionText = optionString.Line.ID;
                }

                var unityText = optionButtons [i].GetComponentInChildren <Text> ();
                if (unityText != null)
                {
                    if (optionText[0] == '#')
                    {
                        unityText.fontStyle = FontStyle.Bold;
                        optionText          = optionText.Substring(1);
                    }
                    else
                    {
                        unityText.fontStyle = FontStyle.Normal;
                    }
                    unityText.text = optionText;
                }

                var textMeshProText = optionButtons [i].GetComponentInChildren <TMPro.TMP_Text> ();
                if (textMeshProText != null)
                {
                    textMeshProText.text = optionText;
                }

                i++;
            }

            onOptionsStart?.Invoke();

            // Wait until the chooser has been used and then removed
            while (waitingForOptionSelection)
            {
                yield return(null);
            }


            // Hide all the buttons
            foreach (var button in optionButtons)
            {
                button.gameObject.SetActive(false);
            }

            onOptionsEnd?.Invoke();
        }
Exemplo n.º 17
0
        /// Show a line of dialogue, gradually
        private IEnumerator DoRunLine(Yarn.Line line, ILineLocalisationProvider localisationProvider, System.Action onComplete)
        {
            onLineStart?.Invoke();

            userRequestedNextLine = false;

            // The final text we'll be showing for this line.
            string text = localisationProvider.GetLocalisedTextForLine(line);

            if (text == null)
            {
                Debug.LogWarning($"Line {line.ID} doesn't have any localised text.");
                text = line.ID;
            }

            if (parseCharacterNames && text.Contains(":"))
            {
                string[] splitText = text.Split(':');
                string   name      = splitText[0];

                onLineCharacterStart?.Invoke(name);

                text = text.Remove(0, name.Length + 2); // remove + 2 to account for the : and the space
            }

            // regardless of speed, call this function.
            onLineStringStart?.Invoke(text);

            if (textSpeed > 0.0f)
            {
                // Display the line one character at a time
                var stringBuilder = new StringBuilder();

                int i = 0;

                foreach (char c in text)
                {
                    stringBuilder.Append(c);
                    onLineUpdate?.Invoke(stringBuilder.ToString());
                    if (userRequestedNextLine)
                    {
                        // We've requested a skip of the entire line.
                        // Display all of the text immediately.
                        onLineUpdate?.Invoke(text);
                        onPositionUpdate?.Invoke(text.Length);
                        break;
                    }

                    float waitTime = textSpeed;

                    if (i != text.Length - 1)
                    {
                        if (c == ',')
                        {
                            waitTime *= commaSpeedMultiplier;
                        }
                        else if (c == '.')
                        {
                            waitTime *= periodSpeedMultiplier;
                        }
                    }

                    i++;
                    onPositionUpdate?.Invoke(i);
                    yield return(new WaitForSeconds(waitTime));
                }
            }
            else
            {
                // Display the entire line immediately if textSpeed <= 0
                onLineUpdate?.Invoke(text);
                onPositionUpdate?.Invoke(text.Length);
            }

            // We're now waiting for the player to move on to the next line
            userRequestedNextLine = false;

            // Indicate to the rest of the game that the line has finished being delivered
            onLineFinishDisplaying?.Invoke();

            while (userRequestedNextLine == false)
            {
                yield return(null);
            }

            // Avoid skipping lines if textSpeed == 0
            yield return(new WaitForEndOfFrame());

            // Hide the text and prompt
            onLineEnd?.Invoke();

            onComplete();
        }
Exemplo n.º 18
0
 /// Runs a set of options.
 /// <inheritdoc/>
 public override void RunOptions(Yarn.OptionSet optionSet, ILineLocalisationProvider localisationProvider, System.Action <int> onOptionSelected)
 {
     StartCoroutine(DoRunOptions(optionSet, localisationProvider, onOptionSelected));
 }
Exemplo n.º 19
0
 public override void RunOptions(OptionSet optionSet, ILineLocalisationProvider localisationProvider, Action <int> onOptionSelected)
 {
     // Do nothing
 }
Exemplo n.º 20
0
 public override Dialogue.HandlerExecutionType RunLine(Line line, ILineLocalisationProvider localisationProvider, Action onLineComplete)
 {
     CurrentLine = localisationProvider.GetLocalisedTextForLine(line);
     onComplete  = onLineComplete;
     return(Dialogue.HandlerExecutionType.PauseExecution);
 }
Exemplo n.º 21
0
    private IEnumerator DoRunLine(Yarn.Line line, ILineLocalisationProvider localisationProvider, System.Action onComplete)
    {
        Debug.Log("Beta");
        dialogueContainer.SetActive(true);
        ds = DialogState.Rolling;
        string text = localisationProvider.GetLocalisedTextForLine(line);

        // Yarn Spinner doesnt let you escape certain characters so we need to do workarounds like this :/
        text = Regex.Replace(text, "&", "#");

        textDisplay.text = "";
        int i                  = -1;
        int tagStartIndex      = -1;
        int styleTagStartIndex = -1;
        var match              = Regex.Match(text, "([A-z ]+): ");

        // Disable previous speaker's portrait.
        if (speaker != null)
        {
            speaker.portraitUI.SetActive(false);
        }

        // Get portrait with the captured group
        if (characterDatas.TryGetValue(match.Groups[1].Value, out speaker))
        {
            speaker.portraitUI.SetActive(true);
        }
        else
        {
            Debug.LogWarning("Couldnt find portrait for character named " + match.Groups[1].Value);
        }

        // Chop off the front of text
        text = text.Substring(match.Length);

        if (match.Groups[1].Value == "Notebook")
        {
            Notebook.instance.TakeNote(text);
        }
        typingSpeed = DEFAULT_TYPING_SPEED;
        foreach (char letter in text)
        {
            i++;
            if (letter == '<')
            {
                styleTagStartIndex = i;
            }
            if (letter == '>')
            {
                styleTagStartIndex = -1;
            }
            if (letter == '~')             // We're looking at
            {
                tagStartIndex = i;
            }
            if (tagStartIndex != -1)
            {
                if (letter == '`')
                {
                    tagHelper(text.Substring(tagStartIndex + 1, i - tagStartIndex - 1));
                    tagStartIndex = -1;
                }
                continue;
            }
            textDisplay.text += letter;
            if ("aeiouyAEIOUY".IndexOf(letter) == -1)
            {
                //play a voice synthesis sound
            }
            if (!skipRolling)
            {
                if (letter != ' ' && styleTagStartIndex == -1)
                {
                    yield return(new WaitForSeconds(typingSpeed));
                }
            }
        }
        skipRolling = false;
        ds          = DialogState.Rolled;

        // Show the continue prompt, if we have one
        // TODO: continue prompt

        Debug.Log(Time.time - timeSinceSkipRolling);
        // Wait while they arent clicking or they are locked out
        while (!Input.GetMouseButtonDown(0) || MouseNearNotebook() || (Notebook.instance.leaveNotebookFrame == Time.frameCount) || (Time.time - timeSinceSkipRolling < TEXT_ADVANCE_LOCKOUT))
        {
            yield return(null);
        }

        yield return(new WaitForEndOfFrame());

        speaker.portraitUI.SetActive(false);
        // Remove the continue prompt if we have one


        onComplete();
    }
Exemplo n.º 22
0
        /// Show a line of dialogue, gradually
        private IEnumerator DoRunLine(Yarn.Line line, ILineLocalisationProvider localisationProvider, System.Action onComplete)
        {
            onLineStart?.Invoke();

            userRequestedNextLine = false;

            // Break apart the text into speaker and text. This is big MOD
            string rawText = localisationProvider.GetLocalisedTextForLine(line);

            string[] splitText = rawText.Split(new[] { ':' }, 2);

            string speaker = "";
            string text    = "";

            if (splitText.Length >= 2)
            {
                speaker = splitText[0].Trim();
                text    = splitText[1].Trim();
            }
            else
            {
                text = splitText[0].Trim();
            }
            // End MOD

            if (currentSpeaker != speaker)
            {
                currentSpeaker = speaker;

                if (string.IsNullOrWhiteSpace(speaker))
                {
                    onNoSpeaker?.Invoke();
                }
                else
                {
                    onSpeakerUpdate?.Invoke(speaker);
                }
            }


            if (text == null)
            {
                Debug.LogWarning($"Line {line.ID} doesn't have any localised text.");
                text = line.ID;
            }

            if (textSpeed > 0.0f)
            {
                // Display the line one character at a time
                var stringBuilder = new StringBuilder();

                foreach (char c in text)
                {
                    stringBuilder.Append(c);
                    onLineUpdate?.Invoke(stringBuilder.ToString());
                    if (userRequestedNextLine)
                    {
                        // We've requested a skip of the entire line.
                        // Display all of the text immediately.
                        onLineUpdate?.Invoke(text);
                        break;
                    }
                    yield return(new WaitForSeconds(textSpeed));
                }
            }
            else
            {
                // Display the entire line immediately if textSpeed <= 0
                onLineUpdate?.Invoke(text);
            }

            // We're now waiting for the player to move on to the next line
            userRequestedNextLine = false;

            // Indicate to the rest of the game that the line has finished being delivered
            onLineFinishDisplaying?.Invoke();

            while (userRequestedNextLine == false)
            {
                yield return(null);
            }

            // Avoid skipping lines if textSpeed == 0
            yield return(new WaitForEndOfFrame());

            // Hide the text and prompt
            onLineEnd?.Invoke();

            onComplete();
        }
Exemplo n.º 23
0
        /// Show a line of dialogue, gradually
        private IEnumerator DoRunLine(Yarn.Line line, ILineLocalisationProvider localisationProvider, System.Action onComplete)
        {
            userRequestedNextLine = false;

            // The final text we'll be showing for this line.
            string text = localisationProvider.GetLocalisedTextForLine(line);

            if (text == null)
            {
                Debug.LogWarning($"Line {line.ID} doesn't have any localised text.");
                text = line.ID;
            }

            // Announce the line start for listeners
            onLineStart?.Invoke(text);

            string[] keys = text.Split(new char[] { ':' }, 2);

            text = keys.Length != 1 ? keys[1].Trim() : keys[0].Trim();

            dialogueText.text = text;
            dialogueText.maxVisibleCharacters = 0;

            if (textSpeed > 0.0f)
            {
                // Fade in the text
                DOTween.To(() => dialogueText.color, color => dialogueText.color = color, new Color(dialogueText.color.r, dialogueText.color.g, dialogueText.color.b, 1f), _fadeInTime).SetId(0);

                // Display the line one character at a time
                for (int i = 0; i < dialogueText.text.Length; i++)
                {
                    dialogueText.maxVisibleCharacters++;
                    if (userRequestedNextLine)
                    {
                        onLineUpdate?.Invoke(text);
                        dialogueText.maxVisibleCharacters = text.Length;
                        break;
                    }
                    yield return(new WaitForSeconds(textSpeed));
                }
            }
            else
            {
                // Display the entire line immediately if textSpeed <= 0
                onLineUpdate?.Invoke(text);
            }

            // We're now waiting for the player to move on to the next line
            userRequestedNextLine = false;

            // Indicate to the rest of the game that the line has finished being delivered
            onLineFinishDisplaying?.Invoke();

            // Show the ContinueIndicator
            DOTween.To(() => continueIndicator.color, color => continueIndicator.color = color, new Color(continueIndicator.color.r, continueIndicator.color.g, continueIndicator.color.b, 1f), _fadeInTime / 2);

            // Auto advancing when auto mode is on
            StartCoroutine(nameof(AutoAdvance));

            // Wait for the user to request the next line
            while (userRequestedNextLine == false)
            {
                yield return(null);
            }

            StopCoroutine(nameof(AutoAdvance));

            if (!isSkipModeEnabled)
            {
                // Complete the text fade-in
                DOTween.Complete(0);

                // Hide the ContinueIndicator
                DOTween.To(() => continueIndicator.color, color => continueIndicator.color = color, new Color(continueIndicator.color.r, continueIndicator.color.g, continueIndicator.color.b, 0), _fadeInTime / 2);

                // Fade out the text
                DOTween.To(() => dialogueText.color, color => dialogueText.color = color, new Color(dialogueText.color.r, dialogueText.color.g, dialogueText.color.b, 0), _fadeOutTime / 2);

                yield return(new WaitForSecondsRealtime(_fadeOutTime));
            }
            else
            {
                // Complete all the tweens in order to not get tween conflicts
                DOTween.CompleteAll();

                // A bit of a delay to not make the skip too fast
                yield return(new WaitForSecondsRealtime(0.05f));
            }

            // Hide the text and prompt
            onLineEnd?.Invoke();

            onComplete();
        }
        public override void RunOptions(Yarn.OptionSet optionSet, ILineLocalisationProvider localisationProvider, global::System.Action <int> onOptionSelected)
        {
            DialogueSystem.OnChoicesStarted(optionSet.Options, localisationProvider);

            OptionSelectionHandler = onOptionSelected;
        }
 public override Yarn.Dialogue.HandlerExecutionType RunLine(Yarn.Line line, ILineLocalisationProvider localisationProvider, global::System.Action onLineComplete)
 {
     StartCoroutine(DoRunLine(line, localisationProvider, onLineComplete));
     return(Yarn.Dialogue.HandlerExecutionType.PauseExecution);
 }