Beispiel #1
0
    /// <summary>
    /// Shows a line of dialogue, gradually.
    /// </summary>
    /// <param name="dialogueLine">The line to deliver.</param>
    /// <param name="onDialogueLineFinished">A callback to invoke when
    /// the text has finished appearing.</param>
    /// <returns></returns>
    protected IEnumerator DoRunLine(LocalizedLine dialogueLine, System.Action onDialogueLineFinished)
    {
        finishCurrentLine = false;

        // First, potentially change DialogueGroups
        Yarn.Markup.MarkupParseResult markupResult = TryParseCharacter(dialogueLine);

        // Then, prepare dialogue group for tweening, markup, etc
        onLineParse?.Invoke();

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

        Sequence showAnimation = onLineStart.Invoke(text, textSpeed);
        var      frame         = new WaitForEndOfFrame();

        while (showAnimation != null && showAnimation.IsActive() && !showAnimation.IsComplete())
        {
            if (finishCurrentLine)
            {
                break;
            }
            yield return(frame);
        }

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

        // Indicate to the dialogue runner that we're done delivering
        // the line here
        onDialogueLineFinished();
    }
Beispiel #2
0
 private Yarn.Markup.MarkupParseResult TryParseCharacter(LocalizedLine dialogueLine)
 {
     Yarn.Markup.MarkupParseResult markupResult = dialogueLine.Text;
     if (markupResult.TryGetAttributeWithName("character", out var attribute))
     {
         TextAttributeHandler.HandleAttribute(attribute, this);
         return(markupResult.DeleteRange(attribute));
     }
     return(markupResult);
 }
Beispiel #3
0
 private string TryParseMarkup(Yarn.Markup.MarkupParseResult markupResult)
 {
     // Delete attributes
     foreach (KeyValuePair <string, bool> pair in TextAttributeHandler.attributes)
     {
         // If attribute is present, remove its text
         if (markupResult.TryGetAttributeWithName(pair.Key, out var attribute))
         {
             if (pair.Value == true)
             {
                 markupResult = markupResult.DeleteRange(attribute);
             }
             TextAttributeHandler.HandleAttribute(attribute, this);
         }
     }
     return(markupResult.Text);
 }