using System.Text.RegularExpressions; using System.Collections; using System; using FairyGUI; using UnityEngine; namespace GFGGame { public class StoryUtil { public static ArrayList GetLettersList(string words) { Regex regex = new Regex("\\u005Bcolor.*?/color]"); MatchCollection mc = regex.Matches(words); string[] splitResult = regex.Split(words); ArrayList colorList = HandleColorTextList(mc); ArrayList result = new ArrayList(); for(int i = 0; i < splitResult.Length; i++) { string text = splitResult[i]; char[] charArr = text.ToCharArray(); foreach(char a in charArr) { result.Add(a.ToString()); } if(i < colorList.Count) { string[] colorTextArr = (string[])colorList[i]; foreach(string b in colorTextArr) { result.Add(b); } } } return result; } private static ArrayList HandleColorTextList(MatchCollection mc) { ArrayList colorList = new ArrayList(); for(int i = 0; i < mc.Count; i++) { Match m = mc[i]; string[] result = HandleColorText(m); colorList.Add(result); } return colorList; } private static string[] HandleColorText(Match m) { string value = m.Value; Regex regexColor = new Regex("\\u005B.*?]"); string text = regexColor.Replace(value, ""); string[] result = new string[text.Length]; Regex regexText = new Regex(text); string colorTemp = regexText.Replace(value, "xx"); Regex regexLetter = new Regex("xx"); for(int i = 0; i < text.Length; i++) { string letter = text.Substring(i, 1); string colorLetter = regexLetter.Replace(colorTemp, letter); result[i] = colorLetter; } return result; } public static string GetChapterOrderText(int chapterID) { int order = GetChapterOrder(chapterID); return "第" + NumberUtil.GetChiniseNumberText(order) + "章"; } /// /// 获得章节显示的序号 /// /// /// public static int GetChapterOrder(int chapterCfgId) { StoryChapterCfg storyChapterCfg = StoryChapterCfgArray.Instance.GetCfg(chapterCfgId); return storyChapterCfg.order; } public static void UpdateStar(int starCount, GComponent component) { if(component != null) { int num = component.numChildren; for(int i = 1; i <= 3; i++) { GObject obj = component.GetChild("f" +i); if(obj != null) { obj.visible = i <= starCount; } } } } public static void UpdateStar(int starCount, GComponent component ,int currentIndex) { if (component != null) { int num = component.numChildren; for (int i = 1; i <= 3; i++) { GObject obj = component.GetChild("f" + i); if (obj != null) { obj.visible = i <= starCount; if (currentIndex == 1) { (obj as GLoader).url = "ui://Main/tb_zx_jy_star"; } else { (obj as GLoader).url = "ui://Main/tb_zx_pt_star"; } } } } } } }