StoryUtil.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. using System.Text.RegularExpressions;
  2. using System.Collections;
  3. using System;
  4. using FairyGUI;
  5. using UnityEngine;
  6. namespace GFGGame
  7. {
  8. public class StoryUtil
  9. {
  10. public static ArrayList GetLettersList(string words)
  11. {
  12. Regex regex = new Regex("\\u005Bcolor.*?/color]");
  13. MatchCollection mc = regex.Matches(words);
  14. string[] splitResult = regex.Split(words);
  15. ArrayList colorList = HandleColorTextList(mc);
  16. ArrayList result = new ArrayList();
  17. for(int i = 0; i < splitResult.Length; i++)
  18. {
  19. string text = splitResult[i];
  20. char[] charArr = text.ToCharArray();
  21. foreach(char a in charArr)
  22. {
  23. result.Add(a.ToString());
  24. }
  25. if(i < colorList.Count)
  26. {
  27. string[] colorTextArr = (string[])colorList[i];
  28. foreach(string b in colorTextArr)
  29. {
  30. result.Add(b);
  31. }
  32. }
  33. }
  34. return result;
  35. }
  36. private static ArrayList HandleColorTextList(MatchCollection mc)
  37. {
  38. ArrayList colorList = new ArrayList();
  39. for(int i = 0; i < mc.Count; i++)
  40. {
  41. Match m = mc[i];
  42. string[] result = HandleColorText(m);
  43. colorList.Add(result);
  44. }
  45. return colorList;
  46. }
  47. private static string[] HandleColorText(Match m)
  48. {
  49. string value = m.Value;
  50. Regex regexColor = new Regex("\\u005B.*?]");
  51. string text = regexColor.Replace(value, "");
  52. string[] result = new string[text.Length];
  53. Regex regexText = new Regex(text);
  54. string colorTemp = regexText.Replace(value, "xx");
  55. Regex regexLetter = new Regex("xx");
  56. for(int i = 0; i < text.Length; i++)
  57. {
  58. string letter = text.Substring(i, 1);
  59. string colorLetter = regexLetter.Replace(colorTemp, letter);
  60. result[i] = colorLetter;
  61. }
  62. return result;
  63. }
  64. public static string GetChapterOrderText(int chapterID)
  65. {
  66. int order = GetChapterOrder(chapterID);
  67. return "第" + NumberUtil.GetChiniseNumberText(order) + "章";
  68. }
  69. /// <summary>
  70. /// 获得章节显示的序号
  71. /// </summary>
  72. /// <param name="chapterCfgId"></param>
  73. /// <returns></returns>
  74. public static int GetChapterOrder(int chapterCfgId)
  75. {
  76. StoryChapterCfg storyChapterCfg = StoryChapterCfgArray.Instance.GetCfg(chapterCfgId);
  77. return storyChapterCfg.order;
  78. }
  79. public static void UpdateStar(int starCount, GComponent component)
  80. {
  81. if(component != null)
  82. {
  83. int num = component.numChildren;
  84. for(int i = 1; i <= 3; i++)
  85. {
  86. GObject obj = component.GetChild("f" +i);
  87. if(obj != null)
  88. {
  89. obj.visible = i <= starCount;
  90. }
  91. }
  92. }
  93. }
  94. public static void UpdateStar(int starCount, GComponent component ,int currentIndex)
  95. {
  96. if (component != null)
  97. {
  98. int num = component.numChildren;
  99. for (int i = 1; i <= 3; i++)
  100. {
  101. GObject obj = component.GetChild("f" + i);
  102. if (obj != null)
  103. {
  104. obj.visible = i <= starCount;
  105. if (currentIndex == 0)
  106. {
  107. (obj as GLoader).url = "ui://Main/tb_zx_pt_star";
  108. }
  109. else
  110. {
  111. (obj as GLoader).url = "ui://Main/tb_zx_jy_star";
  112. }
  113. }
  114. }
  115. }
  116. }
  117. }
  118. }