AnnounceManager.cs 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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 AnnounceManager
  87. {
  88. #region Config
  89. public static string DefaultLanguage = "null";
  90. public static string Hans = "Chinese";
  91. public static string Hant = "ChineseTraditional";
  92. public static string En = "English";
  93. public static bool Inited;
  94. //private static List<Text> Textes = new List<Text>();
  95. private static List<GameObject> itemGos = new List<GameObject>();
  96. private static Dictionary<string, List<NotifyItem>> ItemDict = new Dictionary<string, List<NotifyItem>>();
  97. #endregion
  98. private static int SpriteSize = 300;
  99. public static void Init(string language)
  100. {
  101. foreach (var item in itemGos)
  102. {
  103. Object.DestroyImmediate(item);
  104. }
  105. itemGos = new List<GameObject>();
  106. List<NotifyItem> notifyItems = ItemDict[language];
  107. foreach (var notifyItem in notifyItems)
  108. {
  109. GameObject itemGo = notifyItem.Create();
  110. itemGos.Add(itemGo);
  111. }
  112. //Inited = true;
  113. //List<Content> contents = ContentDictionary[language];
  114. //for (int i = 0; i < contents.Count; i++)
  115. //{
  116. // Transform transform = ResourceManager.Get(ResourceLabel.NotifyItem, Folder.UI, false, ResourceManager.Get(CanvasLabel.R_Grid), false);
  117. // if (contents[i].IsSprite)
  118. // {
  119. // transform.GetComponent<Text>().fontSize = SpriteSize;
  120. // transform.GetComponent<Text>().verticalOverflow = VerticalWrapMode.Overflow;
  121. // transform.GetComponent<Text>().horizontalOverflow = HorizontalWrapMode.Overflow;
  122. // transform.GetComponent<Text>().resizeTextForBestFit = false;
  123. // transform.GetComponent<ContentSizeFitter>().enabled = true;
  124. // transform.GetChild(0).GetComponent<Image>().sprite = HttpManager.AnnounceSpite;
  125. // }
  126. // transform.GetComponent<Text>().text = contents[i].content;
  127. // transform.GetComponent<Text>().alignment = contents[i].Alignment;
  128. // Textes.Add(transform.GetComponent<Text>());
  129. //}
  130. }
  131. public static void ShowAnnouncePanel()
  132. {
  133. if (!Inited)
  134. {
  135. Init(GetLanguage());
  136. }
  137. else
  138. {
  139. //SwitchLanguage(GetLanguage());
  140. }
  141. AudioManager.PlayClip(AudioLabel.Bubble);
  142. ResourceManager.Get(CanvasLabel.R_Notify).TweenForCG();
  143. Auxiliary.Instance.DelayCall
  144. (
  145. () =>
  146. {
  147. LayoutRebuilder.MarkLayoutForRebuild(ResourceManager.Get<RectTransform>(CanvasLabel.R_Grid));
  148. },
  149. 1
  150. );
  151. }
  152. public static void AddItem(string language, NotifyItem item)
  153. {
  154. if (language == DefaultLanguage)
  155. {
  156. AddItem(En, item);
  157. AddItem(Hans, item);
  158. AddItem(Hant, item);
  159. }
  160. if (!ItemDict.ContainsKey(language))
  161. {
  162. ItemDict.Add(language, new List<NotifyItem>());
  163. }
  164. ItemDict[language].Add(item);
  165. }
  166. //public static void AddContent(bool isImage, string language, string content, TextAnchor alignment)
  167. //{
  168. // if (language == DefaultLanguage)
  169. // {
  170. // AddContent(isImage, En, content, alignment);
  171. // AddContent(isImage, Hans, content, alignment);
  172. // AddContent(isImage, Hant, content, alignment);
  173. // }
  174. // if (!ItemDict.ContainsKey(language))
  175. // {
  176. // ItemDict.Add(language, new List<Content>());
  177. // }
  178. // ItemDict[language].Add(new Content(isImage, content, alignment));
  179. //}
  180. //public static void SwitchLanguage(string language)
  181. //{
  182. // for (int i = 0; i < Textes.Count; i++)
  183. // {
  184. // Textes[i].text = ContentDictionary[language][i].content;
  185. // }
  186. //}
  187. public static string GetLanguage()
  188. {
  189. if (LanguageManager.CurrentLanguage == CurrentLanguage.ChineseSimplified)
  190. {
  191. return Hans;
  192. }
  193. else if (LanguageManager.CurrentLanguage == CurrentLanguage.ChineseTraditional)
  194. {
  195. return Hant;
  196. }
  197. else if (LanguageManager.CurrentLanguage == CurrentLanguage.English)
  198. {
  199. return En;
  200. }
  201. else
  202. {
  203. throw new Exception();
  204. }
  205. }
  206. }