AnnounceManager.cs 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. using System;
  2. using UnityEngine;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using UnityEngine.UI;
  6. using Object = UnityEngine.Object;
  7. public class NotifyItem
  8. {
  9. public virtual GameObject Create()
  10. {
  11. throw new Exception();
  12. }
  13. }
  14. public class NotifyTitle : NotifyItem
  15. {
  16. public string text;
  17. public NotifyTitle(string text)
  18. {
  19. this.text = text;
  20. }
  21. public override GameObject Create()
  22. {
  23. Transform parent = ResourceManager.Get(CanvasLabel.R_Grid);
  24. Transform trans = ResourceManager.Get(ResourceLabel.NotifyTitle, Folder.UI, false, parent, false);
  25. Text text = trans.GetComponent<Text>();
  26. text.text = this.text;
  27. return trans.gameObject;
  28. }
  29. }
  30. public class NotifyDate : NotifyItem
  31. {
  32. public string text;
  33. public NotifyDate(string text)
  34. {
  35. this.text = text;
  36. }
  37. public override GameObject Create()
  38. {
  39. Transform parent = ResourceManager.Get(CanvasLabel.R_Grid);
  40. Transform trans = ResourceManager.Get(ResourceLabel.NotifyDate, Folder.UI, false, parent, false);
  41. Text text = trans.GetComponent<Text>();
  42. text.text = this.text;
  43. return trans.gameObject;
  44. }
  45. }
  46. public class NotifyContent : NotifyItem
  47. {
  48. public string text;
  49. public NotifyContent(string text)
  50. {
  51. this.text = text;
  52. }
  53. public override GameObject Create()
  54. {
  55. Transform parent = ResourceManager.Get(CanvasLabel.R_Grid);
  56. Transform trans = ResourceManager.Get(ResourceLabel.NotifyContent, Folder.UI, false, parent, false);
  57. Text text = trans.GetComponent<Text>();
  58. text.text = this.text;
  59. return trans.gameObject;
  60. }
  61. }
  62. public class NotifyImage : NotifyItem
  63. {
  64. public string spriteName;
  65. public NotifyImage(string spriteName)
  66. {
  67. this.spriteName = spriteName;
  68. }
  69. public override GameObject Create()
  70. {
  71. Transform parent = ResourceManager.Get(CanvasLabel.R_Grid);
  72. Transform trans = ResourceManager.Get(ResourceLabel.NotifyImage, Folder.UI, false, parent, false);
  73. Image image = trans.GetComponent<Image>();
  74. image.sprite = HttpManager.AnnounceSpiteDict[spriteName];
  75. image.SetNativeSize();
  76. if (image.rectTransform.rect.width > 580)
  77. {
  78. Vector2 newSize = new Vector2();
  79. newSize.x = 580;
  80. newSize.y = image.rectTransform.rect.height*580/image.rectTransform.rect.width;
  81. image.rectTransform.sizeDelta = newSize;
  82. }
  83. return trans.gameObject;
  84. }
  85. }
  86. public class NotifySplit : NotifyItem
  87. {
  88. public override GameObject Create()
  89. {
  90. Transform parent = ResourceManager.Get(CanvasLabel.R_Grid);
  91. Transform trans = ResourceManager.Get(ResourceLabel.NotifySplit, Folder.UI, false, parent, false);
  92. //Debug.Log(0, trans.gameObject);
  93. return trans.gameObject;
  94. }
  95. }
  96. public class AnnounceManager
  97. {
  98. #region Config
  99. public static string DefaultLanguage = "null";
  100. public static string Hans = "Chinese";
  101. public static string Hant = "ChineseTraditional";
  102. public static string En = "English";
  103. public static bool Inited;
  104. //private static List<Text> Textes = new List<Text>();
  105. private static List<GameObject> itemGos = new List<GameObject>();
  106. private static Dictionary<string, List<NotifyItem>> ItemDict = new Dictionary<string, List<NotifyItem>>();
  107. #endregion
  108. //private static int SpriteSize = 300;
  109. public static void Init(string language)
  110. {
  111. foreach (var item in itemGos)
  112. {
  113. Object.DestroyImmediate(item);
  114. }
  115. itemGos = new List<GameObject>();
  116. List<NotifyItem> notifyItems = ItemDict[language];
  117. foreach (var notifyItem in notifyItems)
  118. {
  119. GameObject itemGo = notifyItem.Create();
  120. itemGos.Add(itemGo);
  121. }
  122. //Inited = true;
  123. //List<Content> contents = ContentDictionary[language];
  124. //for (int i = 0; i < contents.Count; i++)
  125. //{
  126. // Transform transform = ResourceManager.Get(ResourceLabel.NotifyItem, Folder.UI, false, ResourceManager.Get(CanvasLabel.R_Grid), false);
  127. // if (contents[i].IsSprite)
  128. // {
  129. // transform.GetComponent<Text>().fontSize = SpriteSize;
  130. // transform.GetComponent<Text>().verticalOverflow = VerticalWrapMode.Overflow;
  131. // transform.GetComponent<Text>().horizontalOverflow = HorizontalWrapMode.Overflow;
  132. // transform.GetComponent<Text>().resizeTextForBestFit = false;
  133. // transform.GetComponent<ContentSizeFitter>().enabled = true;
  134. // transform.GetChild(0).GetComponent<Image>().sprite = HttpManager.AnnounceSpite;
  135. // }
  136. // transform.GetComponent<Text>().text = contents[i].content;
  137. // transform.GetComponent<Text>().alignment = contents[i].Alignment;
  138. // Textes.Add(transform.GetComponent<Text>());
  139. //}
  140. }
  141. public static void ShowAnnouncePanel()
  142. {
  143. if (!Inited)
  144. {
  145. Init(GetLanguage());
  146. }
  147. else
  148. {
  149. //SwitchLanguage(GetLanguage());
  150. }
  151. AudioManager.PlayClip(AudioLabel.Bubble);
  152. ResourceManager.Get(CanvasLabel.R_Notify).TweenForCG();
  153. Auxiliary.Instance.DelayCall
  154. (
  155. () =>
  156. {
  157. LayoutRebuilder.MarkLayoutForRebuild(ResourceManager.Get<RectTransform>(CanvasLabel.R_Grid));
  158. },
  159. 1
  160. );
  161. }
  162. public static void AddItem(string language, NotifyItem item)
  163. {
  164. if (language == DefaultLanguage)
  165. {
  166. AddItem(En, item);
  167. AddItem(Hans, item);
  168. AddItem(Hant, item);
  169. }
  170. if (!ItemDict.ContainsKey(language))
  171. {
  172. ItemDict.Add(language, new List<NotifyItem>());
  173. }
  174. ItemDict[language].Add(item);
  175. }
  176. //public static void AddContent(bool isImage, string language, string content, TextAnchor alignment)
  177. //{
  178. // if (language == DefaultLanguage)
  179. // {
  180. // AddContent(isImage, En, content, alignment);
  181. // AddContent(isImage, Hans, content, alignment);
  182. // AddContent(isImage, Hant, content, alignment);
  183. // }
  184. // if (!ItemDict.ContainsKey(language))
  185. // {
  186. // ItemDict.Add(language, new List<Content>());
  187. // }
  188. // ItemDict[language].Add(new Content(isImage, content, alignment));
  189. //}
  190. //public static void SwitchLanguage(string language)
  191. //{
  192. // for (int i = 0; i < Textes.Count; i++)
  193. // {
  194. // Textes[i].text = ContentDictionary[language][i].content;
  195. // }
  196. //}
  197. public static string GetLanguage()
  198. {
  199. if (LanguageManager.CurrentLanguage == CurrentLanguage.ChineseSimplified)
  200. {
  201. return Hans;
  202. }
  203. else if (LanguageManager.CurrentLanguage == CurrentLanguage.ChineseTraditional)
  204. {
  205. return Hant;
  206. }
  207. else if (LanguageManager.CurrentLanguage == CurrentLanguage.English)
  208. {
  209. return En;
  210. }
  211. else
  212. {
  213. throw new Exception();
  214. }
  215. }
  216. }