SubtitleMovieManager.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using wf;
  5. public class SubtitleMovieManager : MonoBehaviour
  6. {
  7. public bool isPlaying { get; private set; }
  8. public static SubtitleMovieManager GetGlobalInstance(bool casinoType)
  9. {
  10. GameObject childObject = UTY.GetChildObject(GameObject.Find("__GameMain__"), "SystemUI Root", false);
  11. GameObject gameObject;
  12. if (!casinoType)
  13. {
  14. gameObject = UTY.GetChildObject(childObject, "GlobalSubtitleMovieManager", true);
  15. if (gameObject == null)
  16. {
  17. gameObject = Utility.CreatePrefab(childObject, "System/Prefab/SubtitleMovieManager", true);
  18. gameObject.name = "GlobalSubtitleMovieManager";
  19. }
  20. gameObject.transform.localPosition = new Vector3(-459f, -247f, 0f);
  21. }
  22. else
  23. {
  24. gameObject = UTY.GetChildObject(childObject, "GlobalSubtitleMovieManagerCasinoType", true);
  25. if (gameObject == null)
  26. {
  27. gameObject = Utility.CreatePrefab(childObject, "System/Prefab/SubtitleMovieManagerCasino", true);
  28. gameObject.name = "GlobalSubtitleMovieManagerCasinoType";
  29. }
  30. gameObject.transform.localPosition = new Vector3(228f, 375f, 0f);
  31. }
  32. return gameObject.GetComponent<SubtitleMovieManager>();
  33. }
  34. public static void DestroyGlobalInstance()
  35. {
  36. GameObject childObject = UTY.GetChildObject(GameObject.Find("__GameMain__"), "SystemUI Root", false);
  37. GameObject childObject2 = UTY.GetChildObject(childObject, "GlobalSubtitleMovieManager", true);
  38. if (childObject2 != null)
  39. {
  40. UnityEngine.Object.DestroyImmediate(childObject2);
  41. }
  42. childObject2 = UTY.GetChildObject(childObject, "GlobalSubtitleMovieManagerCasinoType", true);
  43. if (childObject2 != null)
  44. {
  45. UnityEngine.Object.DestroyImmediate(childObject2);
  46. }
  47. }
  48. public void Clear()
  49. {
  50. this.displayDatas.Clear();
  51. this.isPlaying = false;
  52. }
  53. public bool AddData(string text, int displayStartTime, int displayTime)
  54. {
  55. if (this.isPlaying)
  56. {
  57. return false;
  58. }
  59. SubtitleMovieManager.DisplayData displayData = new SubtitleMovieManager.DisplayData();
  60. displayData.displayStartTime = displayStartTime;
  61. displayData.displayEndTime = displayStartTime + displayTime;
  62. displayData.text = text;
  63. this.displayDatas.Add(displayData);
  64. return true;
  65. }
  66. public void LoadSubtitleScriptFile(string fileName)
  67. {
  68. if (!GameUty.FileSystem.IsExistentFile(fileName))
  69. {
  70. return;
  71. }
  72. byte[] array = null;
  73. try
  74. {
  75. using (AFileBase afileBase = GameUty.FileOpen(fileName, null))
  76. {
  77. if (!afileBase.IsValid())
  78. {
  79. return;
  80. }
  81. array = new byte[afileBase.GetSize()];
  82. afileBase.Read(ref array, afileBase.GetSize());
  83. }
  84. }
  85. catch (Exception)
  86. {
  87. return;
  88. }
  89. if (array == null)
  90. {
  91. return;
  92. }
  93. string[] array2 = NUty.SjisToUnicode(array).Split(new string[]
  94. {
  95. "\r\n",
  96. "\r",
  97. "\n"
  98. }, StringSplitOptions.RemoveEmptyEntries);
  99. int num = 0;
  100. int num2 = 0;
  101. bool flag = false;
  102. string text = string.Empty;
  103. foreach (string text2 in array2)
  104. {
  105. if (text2.IndexOf("@talk") == 0)
  106. {
  107. int num3 = text2.IndexOf("[") + 1;
  108. string[] array4 = text2.Substring(num3, text2.Length - num3 - 1).Split(new string[]
  109. {
  110. "-"
  111. }, StringSplitOptions.RemoveEmptyEntries);
  112. num = int.Parse(array4[0]);
  113. num2 = int.Parse(array4[1]);
  114. flag = true;
  115. text = string.Empty;
  116. }
  117. else if (text2.IndexOf("@hitret") == 0)
  118. {
  119. this.AddData(text, num, num2 - num);
  120. flag = false;
  121. }
  122. else if (flag)
  123. {
  124. text += text2;
  125. }
  126. }
  127. }
  128. public void Play(string text, int displayTime)
  129. {
  130. this.Clear();
  131. this.AddData(text, 0, displayTime);
  132. this.Play();
  133. }
  134. public void Play()
  135. {
  136. this.timeElapsed = 0;
  137. this.isPlaying = true;
  138. this.subtitleMgr.visible = false;
  139. }
  140. public void Stop()
  141. {
  142. if (this.subtitleMgr != null)
  143. {
  144. this.subtitleMgr.visible = false;
  145. }
  146. this.isPlaying = false;
  147. }
  148. public void Update()
  149. {
  150. if (!this.isPlaying || this.displayDatas.Count == 0 || this.subtitleMgr == null)
  151. {
  152. this.Stop();
  153. return;
  154. }
  155. this.timeElapsed += (int)(Time.deltaTime * 1000f);
  156. bool visible = false;
  157. List<SubtitleMovieManager.DisplayData> list = new List<SubtitleMovieManager.DisplayData>();
  158. for (int i = 0; i < this.displayDatas.Count; i++)
  159. {
  160. SubtitleMovieManager.DisplayData displayData = this.displayDatas[i];
  161. if (displayData.displayStartTime <= this.timeElapsed && this.timeElapsed <= displayData.displayEndTime)
  162. {
  163. visible = true;
  164. this.subtitleMgr.SetTextFromScriptStyle(displayData.text);
  165. }
  166. else if (displayData.displayEndTime < this.timeElapsed)
  167. {
  168. list.Add(displayData);
  169. }
  170. }
  171. this.subtitleMgr.visible = visible;
  172. for (int j = 0; j < list.Count; j++)
  173. {
  174. for (int k = 0; k < this.displayDatas.Count; k++)
  175. {
  176. if (list[j] == this.displayDatas[k])
  177. {
  178. this.displayDatas.RemoveAt(k);
  179. break;
  180. }
  181. }
  182. }
  183. if (this.displayDatas.Count == 0 && this.autoDestroy)
  184. {
  185. UnityEngine.Object.DestroyImmediate(base.gameObject);
  186. }
  187. }
  188. [SerializeField]
  189. private SubtitleDisplayManager subtitleMgr;
  190. public bool autoDestroy;
  191. private int timeElapsed;
  192. private List<SubtitleMovieManager.DisplayData> displayDatas = new List<SubtitleMovieManager.DisplayData>();
  193. private class DisplayData
  194. {
  195. public int displayStartTime;
  196. public int displayEndTime;
  197. public string text;
  198. }
  199. }