Ejemplo n.º 1
0
 private void LogTag(RichTextTag tag)
 {
     if (tag != null)
     {
         Debug.Log("Tag: " + tag.ToString());
     }
 }
Ejemplo n.º 2
0
        public static List <TextSymbol> CreateSymbolListFromText(string text)
        {
            var symbolList       = new List <TextSymbol>();
            int parsedCharacters = 0;

            while (parsedCharacters < text.Length)
            {
                TextSymbol symbol = null;

                // Check for tags
                var remainingText = text.Substring(parsedCharacters, text.Length - parsedCharacters);
                if (RichTextTag.StringStartsWithTag(remainingText))
                {
                    var tag = RichTextTag.ParseNext(remainingText);
                    symbol = new TextSymbol(tag);
                }
                else
                {
                    symbol = new TextSymbol(remainingText.Substring(0, 1));
                }

                parsedCharacters += symbol.Length;
                symbolList.Add(symbol);
            }

            return(symbolList);
        }
Ejemplo n.º 3
0
        public TextSymbol Initialize(RichTextTag tag)
        {
            this.Character = null;
            this.Tag       = tag;

            return(this);
        }
        private static string RemoveTags(string textWithTags, params string[] tags)
        {
            string textWithoutTags = textWithTags;
            foreach (var tag in tags)
            {
                textWithoutTags = RichTextTag.RemoveTagsFromString(textWithoutTags, tag);
            }

            return textWithoutTags;
        }
Ejemplo n.º 5
0
        private static string RemoveUnityTags(string textWithTags)
        {
            string textWithoutTags = textWithTags;

            foreach (var unityTag in UnityTagTypes)
            {
                textWithoutTags = RichTextTag.RemoveTagsFromString(textWithoutTags, unityTag);
            }

            return(textWithoutTags);
        }
Ejemplo n.º 6
0
        private static string RemoveCustomTags(string textWithTags)
        {
            string textWithoutTags = textWithTags;

            foreach (var customTag in CustomTagTypes)
            {
                textWithoutTags = RichTextTag.RemoveTagsFromString(textWithoutTags, customTag);
            }

            return(textWithoutTags);
        }
Ejemplo n.º 7
0
 public void Update()
 {
     if (Input.GetKeyDown(KeyCode.Space))
     {
         var tag = RichTextTag.ParseNext("blah<color=red>boo</color");
         LogTag(tag);
         tag = RichTextTag.ParseNext("<color=blue>blue</color");
         LogTag(tag);
         tag = RichTextTag.ParseNext("No tag in here");
         LogTag(tag);
         tag = RichTextTag.ParseNext("No <color=blueblue</color tag here either");
         LogTag(tag);
         tag = RichTextTag.ParseNext("This tag is a closing tag </bold>");
         LogTag(tag);
     }
 }
Ejemplo n.º 8
0
        public void Update()
        {
            UnityEngine.Time.timeScale = this.pauseGameToggle.isOn ? 0.0f : 1.0f;

            if (Input.GetKeyDown(KeyCode.Space))
            {
                var tag = RichTextTag.ParseNext("blah<color=red>boo</color");
                LogTag(tag);
                tag = RichTextTag.ParseNext("<color=blue>blue</color");
                LogTag(tag);
                tag = RichTextTag.ParseNext("No tag in here");
                LogTag(tag);
                tag = RichTextTag.ParseNext("No <color=blueblue</color tag here either");
                LogTag(tag);
                tag = RichTextTag.ParseNext("This tag is a closing tag </bold>");
                LogTag(tag);
            }
        }
Ejemplo n.º 9
0
        private static List <TypedTextSymbol> CreateSymbolListFromText(string text)
        {
            var symbolList       = new List <TypedTextSymbol>();
            int parsedCharacters = 0;

            while (parsedCharacters < text.Length)
            {
                TypedTextSymbol symbol = null;

                // Check for tags
                var remainingText = text.Substring(parsedCharacters, text.Length - parsedCharacters);

                if (RichTextTag.StringStartsWithTag(remainingText))
                {
                    var tag = RichTextTag.ParseNext(remainingText);
                    symbol = new TypedTextSymbol(tag);
                }
                else if (RichTextTag.StringStartsWithMarkup(remainingText))
                {
                    var tag = RichTextTag.ParseMarkup(remainingText);
                    symbol = new TypedTextSymbol(tag);
                    if (tag == "{{player}}")
                    {
                        foreach (var letter in Player.Instance.entityName)
                        {
                            symbolList.Add(new TypedTextSymbol(letter.ToString()));
                        }
                        parsedCharacters += symbol.Length;
                        continue;
                    }
                }
                else
                {
                    symbol = new TypedTextSymbol(remainingText.Substring(0, 1));
                }

                parsedCharacters += symbol.Length;
                symbolList.Add(symbol);
            }

            return(symbolList);
        }
Ejemplo n.º 10
0
 public TextSymbol(RichTextTag tag)
 {
     this.Tag = tag;
 }
Ejemplo n.º 11
0
        /// <summary>
        /// Gets the typed text at the specified visibleCharacterIndex. This is the text that should be written
        /// to the Text component.
        /// </summary>
        /// <returns>The <see cref="TypedText"/> generated at the specified visible character index.</returns>
        /// <param name="text">Text to parse.</param>
        /// <param name="visibleCharacterIndex">Visible character index (ignores tags).</param>
        public TypedText GetTypedTextAt(string text, int visibleCharacterIndex)
        {
            var textAsSymbolList = CreateSymbolListFromText(text);

            // Split the text into shown and hide strings based on the actual visible characters
            int printedCharCount     = 0;
            var shownText            = string.Empty;
            var hiddenText           = string.Empty;
            var lastVisibleCharacter = char.MinValue;

            foreach (var symbol in textAsSymbolList)
            {
                if (printedCharCount <= visibleCharacterIndex)
                {
                    shownText += symbol.Text;

                    // Keep track of the visible characters that have been printed
                    if (!symbol.IsTag)
                    {
                        lastVisibleCharacter = symbol.Character.ToCharArray()[0];
                    }
                }
                else
                {
                    hiddenText += symbol.Text;
                }

                if (!symbol.IsTag)
                {
                    printedCharCount++;
                }
            }

            var activeTags = GetActiveTagsInSymbolList(textAsSymbolList, visibleCharacterIndex);

            // Remove closing tags for active tags from hidden text (move to before color hide tag)
            foreach (var activeTag in activeTags)
            {
                hiddenText = RemoveFirstOccurance(hiddenText, activeTag.ClosingTagText);
            }

            // Remove all color tags from hidden text so that they don't cause it to be shown
            // ex: <color=clear>This should <color=red>be clear</color></color> will show 'be clear" in red
            hiddenText = RichTextTag.RemoveTagsFromString(hiddenText, "color");

            // Add the hidden text, provided there is text to hide
            if (!string.IsNullOrEmpty(hiddenText))
            {
                var hiddenTag = RichTextTag.ClearColorTag;
                hiddenText = hiddenText.Insert(0, hiddenTag.TagText);
                hiddenText = hiddenText.Insert(hiddenText.Length, hiddenTag.ClosingTagText);
            }

            // Add back in closing tags in reverse order
            for (int i = 0; i < activeTags.Count; ++i)
            {
                hiddenText = hiddenText.Insert(0, activeTags[i].ClosingTagText);
            }

            // Remove all custom tags since Unity will display them when printed (it doesn't recognize them as rich text tags)
            var printText = shownText + hiddenText;

            foreach (var customTag in CustomTagTypes)
            {
                printText = RichTextTag.RemoveTagsFromString(printText, customTag);
            }

            // Calculate Delay, if active
            var delay = 0.0f;

            foreach (var activeTag in activeTags)
            {
                if (activeTag.TagType == "delay")
                {
                    try
                    {
                        delay = activeTag.IsOpeningTag ? float.Parse(activeTag.Parameter) : 0.0f;
                    }
                    catch (System.FormatException e)
                    {
                        var warning = string.Format(
                            "TypedTextGenerator found Invalid paramter format in tag [{0}]. " +
                            "Parameter [{1}] does not parse to a float. Exception: {2}",
                            activeTag,
                            activeTag.Parameter,
                            e);
                        Debug.Log(warning);
                        delay = 0.0f;
                    }
                }
            }

            var typedText = new TypedText();

            typedText.TextToPrint     = printText;
            typedText.Delay           = delay;
            typedText.LastPrintedChar = lastVisibleCharacter;
            typedText.IsComplete      = string.IsNullOrEmpty(hiddenText);

            return(typedText);
        }