Example #1
0
 /// <summary>
 /// Sets the character name to display on the Say Dialog.
 /// Supports variable substitution e.g. John {$surname}
 /// </summary>
 public virtual void SetCharacterName(string name, Color color)
 {
     if (nameText != null)
     {
         var subbedName = stringSubstituter.SubstituteStrings(name);
         nameText.text  = subbedName;
         nameText.color = color;
     }
 }
Example #2
0
 /// <summary>
 /// Sets the character name to display on the Say Dialog.
 /// Supports variable substitution e.g. John {$surname}
 /// </summary>
 public virtual void SetCharacterName(string name, Color color)
 {
     if (NameText != null)
     {
         var subbedName = stringSubstituter.SubstituteStrings(name);
         NameText = subbedName;
         nameTextAdapter.SetTextColor(color);
     }
 }
Example #3
0
        public virtual string SubstituteVariables(string input)
        {
            if (stringSubstituer == null)
            {
                stringSubstituer = new StringSubstituter();
                stringSubstituer.CacheSubstitutionHandlers();
            }

            // Use the string builder from StringSubstituter for efficiency.
            StringBuilder sb = stringSubstituer._StringBuilder;

            sb.Length = 0;
            sb.Append(input);

            // Instantiate the regular expression object.
            Regex r = new Regex("{\\$.*?}");

            bool changed = false;

            // Match the regular expression pattern against a text string.
            var results = r.Matches(input);

            foreach (Match match in results)
            {
                string key = match.Value.Substring(2, match.Value.Length - 3);

                // Look for any matching private variables in this Flowchart first
                foreach (Variable variable in variables)
                {
                    if (variable == null)
                    {
                        continue;
                    }

                    if (variable.Scope == VariableScope.Private &&
                        variable.Key == key)
                    {
                        string value = variable.ToString();
                        sb.Replace(match.Value, value);
                        changed = true;
                    }
                }
            }

            // Now do all other substitutions in the scene
            changed |= stringSubstituer.SubstituteStrings(sb);

            if (changed)
            {
                return(sb.ToString());
            }
            else
            {
                return(input);
            }
        }
Example #4
0
 /// <summary>
 /// Performs string substitution on the input string, replacing tokens of the form {$VarName} with
 /// matching variables, localised strings, etc. in the scene.
 /// </summary>
 public virtual string Substitute(string input)
 {
     return(stringSubstituter.SubstituteStrings(input));
 }
Example #5
0
        /// <summary>
        /// Substitute variables in the input text with the format {$VarName}
        /// This will first match with private variables in this Flowchart, and then
        /// with public variables in all Flowcharts in the scene (and any component
        /// in the scene that implements StringSubstituter.ISubstitutionHandler).
        /// </summary>

        // 进行变量替换
        // 先使用本Flowcharts上的私有变量
        // 然后使用ISubstitutionHandler,可以找到全局的Flowchart
        public virtual string SubstituteVariables(string input)
        {
            // 创建StringSubstituter实例
            if (stringSubstituer == null)
            {
                stringSubstituer = new StringSubstituter();
            }

            // Use the string builder from StringSubstituter for efficiency.
            StringBuilder sb = stringSubstituer._StringBuilder;

            sb.Length = 0;
            sb.Append(input);

            // 变量格式匹配
            // {$变量名}
            // Instantiate the regular expression object.
            Regex r = new Regex(SubstituteVariableRegexString);

            bool changed = false;

            // 匹配到句子中
            // 所有变量
            // Match the regular expression pattern against a text string.
            var results = r.Matches(input);

            for (int i = 0; i < results.Count; i++)
            {
                Match match = results[i];

                // 提取到变量名
                string key = match.Value.Substring(2, match.Value.Length - 3);

                // 匹配私有变量
                // Look for any matching private variables in this Flowchart first
                for (int j = 0; j < variables.Count; j++)
                {
                    var variable = variables[j];
                    if (variable == null)
                    {
                        continue;
                    }
                    if (variable.Scope == VariableScope.Private && variable.Key == key)
                    {
                        string value = variable.ToString();
                        sb.Replace(match.Value, value);
                        changed = true;
                    }
                }
            }

            // 使用ISubstitutionHandler
            // 进行变量替换
            // (这里会调用到,全局的Flowchart)

            // Now do all other substitutions in the scene
            changed |= stringSubstituer.SubstituteStrings(sb);

            if (changed)
            {
                return(sb.ToString());
            }
            else
            {
                return(input);
            }
        }