示例#1
0
        public void GivenChar_SetTarget_SetsParsedValue()
        {
            var targetObject   = new MockStruct();
            var uut            = new StringSetter();
            var mappingDetails = new TagMapLeaf(targetObject.GetType().GetProperty(nameof(targetObject.Tag1)), uut);
            var messageContext = new FixMessageContext();

            uut.SetTarget <MockStruct>("ab", mappingDetails, messageContext, ref targetObject);
            Assert.Equal("ab", targetObject.Tag1);
        }
        /// <summary>
        /// A Function that allows you to fill up text gradually over time
        /// </summary>
        /// <param name="text">The text that you eventually want to be displayed on screen</param>
        /// <param name="textSetter">The function that sets the text you want displayed (its a long story)</param>
        /// <param name="charactersPerSecond">The amount of characters displayed every second</param>
        /// <param name="OnDialogueEvent">The event trigged when the Dialogue ends</param>
        public static IEnumerator FillText(string text, StringSetter textSetter, float charactersPerSecond, UnityEvent OnDialogueEvent = null)
        {
            textSetter("");
            List <string> activeTags = new List <string>();

            for (int i = 0; i < text.Length; i++)
            {
                string outputText = "";
                if (text[i] == '<')
                {
                    int j = i;
                    while (text[i] != '>')
                    {
                        i++;
                    }

                    if (i < text.Length - 1)
                    {
                        i++;
                        if (text[j + 1] == '/')
                        {
                            activeTags.Remove(text.Substring(j + 2, i - j - 2));
                        }
                        else
                        {
                            activeTags.Add(text.Substring(j + 1, i - j - 2));
                        }
                    }
                    else
                    {
                        textSetter(text);
                        if (OnDialogueEvent != null)
                        {
                            OnDialogueEvent.Invoke();
                        }
                        yield break;
                    }
                }
                outputText = text.Substring(0, i + 1);
                for (int j = 0; j < activeTags.Count; j++)
                {
                    outputText += "</" + activeTags[j] + ">";
                }
                textSetter(outputText);
                yield return(new WaitForSeconds(1f / charactersPerSecond));
            }
            if (OnDialogueEvent != null)
            {
                OnDialogueEvent.Invoke();
            }
            yield break;
        }