AnnounceManager.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. using System;
  2. using UnityEngine;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using UnityEngine.UI;
  6. public class AnnounceManager
  7. {
  8. private class Content
  9. {
  10. public bool IsSprite;
  11. public string content;
  12. public TextAnchor Alignment;
  13. public Content(bool isSprite, string content, TextAnchor alignment)
  14. {
  15. this.content = content;
  16. IsSprite = isSprite;
  17. Alignment = alignment;
  18. }
  19. }
  20. #region Config
  21. public static string DefaultLanguage = "null";
  22. public static string Hants = "Chinese";
  23. public static string Hant = "ChineseTraditional";
  24. public static string En = "English";
  25. public static bool Inited;
  26. private static List<Text> Textes = new List<Text>();
  27. private static Dictionary<string, List<Content>> ContentDictionary = new Dictionary<string, List<Content>>();
  28. #endregion
  29. private static int SpriteSize = 300;
  30. public static void Init(string language)
  31. {
  32. Inited = true;
  33. List<Content> contents = ContentDictionary[language];
  34. for (int i = 0; i < contents.Count; i++)
  35. {
  36. Transform transform = ResourceManager.Get(ResourceLabel.NotifyItem, Folder.UI, false, ResourceManager.Get(CanvasLabel.R_Grid), false);
  37. if (contents[i].IsSprite)
  38. {
  39. transform.GetComponent<Text>().fontSize = SpriteSize;
  40. transform.GetComponent<Text>().verticalOverflow = VerticalWrapMode.Overflow;
  41. transform.GetComponent<Text>().horizontalOverflow = HorizontalWrapMode.Overflow;
  42. transform.GetComponent<Text>().resizeTextForBestFit = false;
  43. transform.GetComponent<ContentSizeFitter>().enabled = true;
  44. transform.GetChild(0).GetComponent<Image>().sprite = HttpManager.AnnounceSpite;
  45. }
  46. transform.GetComponent<Text>().text = contents[i].content;
  47. transform.GetComponent<Text>().alignment = contents[i].Alignment;
  48. Textes.Add(transform.GetComponent<Text>());
  49. }
  50. }
  51. public static void ShowAnnouncePanel()
  52. {
  53. if (!Inited)
  54. {
  55. Init(GetLanguage());
  56. }
  57. else
  58. {
  59. SwitchLanguage(GetLanguage());
  60. }
  61. AudioManager.PlayClip(AudioLabel.Bubble);
  62. ResourceManager.Get(CanvasLabel.R_Notify).TweenForCG();
  63. Auxiliary.Instance.DelayCall
  64. (
  65. () =>
  66. {
  67. LayoutRebuilder.MarkLayoutForRebuild(ResourceManager.Get<RectTransform>(CanvasLabel.R_Grid));
  68. },
  69. 1
  70. );
  71. }
  72. public static void AddContent(bool isImage, string language, string content, TextAnchor alignment)
  73. {
  74. if (language == DefaultLanguage)
  75. {
  76. AddContent(isImage, En, content, alignment);
  77. AddContent(isImage, Hants, content, alignment);
  78. AddContent(isImage, Hant, content, alignment);
  79. }
  80. if (!ContentDictionary.ContainsKey(language))
  81. {
  82. ContentDictionary.Add(language, new List<Content>());
  83. }
  84. ContentDictionary[language].Add(new Content(isImage, content, alignment));
  85. }
  86. public static void SwitchLanguage(string language)
  87. {
  88. for (int i = 0; i < Textes.Count; i++)
  89. {
  90. Textes[i].text = ContentDictionary[language][i].content;
  91. }
  92. }
  93. public static string GetLanguage()
  94. {
  95. if (LanguageManager.CurrentLanguage == CurrentLanguage.ChineseSimplified)
  96. {
  97. return Hants;
  98. }
  99. else if (LanguageManager.CurrentLanguage == CurrentLanguage.ChineseTraditional)
  100. {
  101. return Hant;
  102. }
  103. else if (LanguageManager.CurrentLanguage == CurrentLanguage.English)
  104. {
  105. return En;
  106. }
  107. else
  108. {
  109. throw new Exception();
  110. }
  111. }
  112. }