/// <summary> /// 解析颜色值。 /// </summary> /// <returns>解析后的字符串。</returns> public string ParseColor(string text) { Color def = GetComponent <Text>().color; int index = 0; m_ColorInfos.Clear(); CacheSB.Length = 0; CacheSB.Append(UnderLineChar); //首个解析函数要加下划线占位符 foreach (Match match in ColorRegex.Matches(text)) { string colorstr = match.Groups[1].Value.Trim(); string innertext = match.Groups[2].Value; ColorInfo info = new ColorInfo(); CacheSB.Append(text.Substring(index, match.Index - index)); //匹配目标前的那一部分 info.StartIndex = CacheSB.Length; info.EndIndex = info.StartIndex + innertext.Length; info.TextColor = UiUtil.ToColor(colorstr, def); m_ColorInfos.Add(info); CacheSB.Append(innertext); index = match.Index + match.Length; } CacheSB.Append(text.Substring(index, text.Length - index)); return(CacheSB.ToString()); }