AnnounceManager.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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(ObjectLabel.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.NotificationSprite;
  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(ObjectLabel.R_Notify).TweenForCG();
  63. Auxiliary.Instance.DelayCall
  64. (
  65. () =>
  66. {
  67. ResourceManager.Get<VerticalLayoutGroup>(ObjectLabel.R_Grid).CalculateLayoutInputVertical();
  68. ResourceManager.Get<VerticalLayoutGroup>(ObjectLabel.R_Grid).SetLayoutVertical();
  69. },
  70. 1
  71. );
  72. }
  73. public static void AddContent(bool isImage, string language, string content, TextAnchor alignment)
  74. {
  75. if (language == DefaultLanguage)
  76. {
  77. AddContent(isImage, En, content, alignment);
  78. AddContent(isImage, Hants, content, alignment);
  79. AddContent(isImage, Hant, content, alignment);
  80. }
  81. if (!ContentDictionary.ContainsKey(language))
  82. {
  83. ContentDictionary.Add(language, new List<Content>());
  84. }
  85. ContentDictionary[language].Add(new Content(isImage, content, alignment));
  86. }
  87. public static void SwitchLanguage(string language)
  88. {
  89. for (int i = 0; i < Textes.Count; i++)
  90. {
  91. Textes[i].text = ContentDictionary[language][i].content;
  92. }
  93. }
  94. public static string GetLanguage()
  95. {
  96. if (LanguageManager.CurrentLanguage == CurrentLanguage.ChineseSimplified)
  97. {
  98. return Hants;
  99. }
  100. else if (LanguageManager.CurrentLanguage == CurrentLanguage.ChineseTraditional)
  101. {
  102. return Hant;
  103. }
  104. else if (LanguageManager.CurrentLanguage == CurrentLanguage.English)
  105. {
  106. return En;
  107. }
  108. else
  109. {
  110. throw new Exception();
  111. }
  112. }
  113. }