StoryUtil.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 = GetNormalChapterId(chapterID);
  67. return "第" + NumberUtil.GetChiniseNumberText(order) + "章";
  68. }
  69. /// <summary>
  70. /// 获得章节显示的序号
  71. /// </summary>
  72. /// <param name="chapterId"></param>
  73. /// <returns></returns>
  74. public static int GetNormalChapterId(int chapterId)
  75. {
  76. if(CalculateHelper.CheckChapterIsHard(chapterId))
  77. {
  78. return chapterId - GameConst.START_ID_OF_HARD;
  79. }
  80. return chapterId;
  81. }
  82. public static void UpdateStar(int starCount, GComponent component)
  83. {
  84. if(component != null)
  85. {
  86. int num = component.numChildren;
  87. for(int i = 1; i <= 3; i++)
  88. {
  89. GObject obj = component.GetChild("f" +i);
  90. if(obj != null)
  91. {
  92. obj.visible = i <= starCount;
  93. }
  94. }
  95. }
  96. }
  97. }
  98. }