public void TextWriterStyles_CanEvaluateStyleWithWackyExtraArgs()
        {
            MockTextWriterStyleFactory mockFactory = new MockTextWriterStyleFactory();

            TextWriterStyleBase command = mockFactory.Create("helloworld:asdf=123");
            string result = command.Evaluate(null, null, null, -1, null);

            Assert.AreEqual(result, "HELLO WORLD!");
        }
        public void TextWriterStyles_CanEvaluateStyleWithRequiredArgs()
        {
            MockTextWriterStyleFactory mockFactory = new MockTextWriterStyleFactory();

            TextWriterStyleBase command = mockFactory.Create("helloWorldArgs:firstName=Jordan,lastName=Bleu");
            string result = command.Evaluate(null, null, null, -1, null);

            Assert.AreEqual(result, "Hello Jordan Bleu!");
        }
        public void EndColorStyle_Works()
        {
            MockTextWriterStyleFactory mockFactory = new MockTextWriterStyleFactory();

            TextWriterStyleBase command = mockFactory.Create("endcolor");

            StringBuilder sb = new StringBuilder();

            string result = command.Evaluate(null, null, sb, -1, null);

            Assert.AreEqual(sb.ToString(), "</color>");
        }
        public void ColorStyle_Works()
        {
            MockTextWriterStyleFactory mockFactory = new MockTextWriterStyleFactory();

            string hex = "#AABBCC";

            TextWriterStyleBase command = mockFactory.Create($"color:hex={hex}");

            // This style should append to the builder not the text
            StringBuilder builder = new StringBuilder();

            string result = command.Evaluate(null, null, builder, -1, null);

            Assert.AreEqual(builder.ToString(), $"<{hex}>");
        }
        public override void DelayedUpdate()
        {
            if (isAnimationReady)
            {
                if (!string.IsNullOrEmpty(text) && !IsDoneTyping)
                {
                    IsDoneTyping = (charIndex >= text.Length);

                    if (!IsDoneTyping)
                    {
                        char nextChar = text[charIndex];

                        if (nextChar.Equals('{'))
                        {
                            // Begin reading the remaining text as a command until we reach the }
                            StringBuilder command     = new StringBuilder();
                            bool          foundEndTag = false;

                            while (charIndex < text.Length)
                            {
                                charIndex++;
                                char commandChar = text[charIndex];

                                if (commandChar.Equals('}'))
                                {
                                    foundEndTag = true;
                                    break;
                                }
                                else if (commandChar.Equals('{'))
                                {
                                    throw new UnityException("Unable to parse command string.  Expected ending } but found another opening {");
                                }
                                else
                                {
                                    command.Append(text[charIndex]);
                                }
                            }

                            if (!foundEndTag)
                            {
                                throw new UnityException("Unable to parse command string.  Expected ending }");
                            }
                            else
                            {
                                // Execute the command
                                TextWriterStyleBase commandObject = styleFactory.Create(command.ToString());
                                string result = commandObject.Evaluate(this, textMeshComponent, chars, charIndex + 1, text);

                                if (!string.IsNullOrEmpty(result))
                                {
                                    SpliceResult(result, charIndex);
                                }
                            }
                        }
                        else // Just a normal character
                        {
                            chars.Append(nextChar);
                        }
                    }

                    if (beep != null)
                    {
                        audioSource.PlayOneShot(beep);
                    }
                    charIndex++;
                }
            }
        }