AnnounceManager.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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 IsImage;
  11. public string text;
  12. public TextAnchor Alignment;
  13. public Content(bool isImage, string text, TextAnchor alignment)
  14. {
  15. this.text = text;
  16. this.IsImage = isImage;
  17. this.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. #endregion
  26. public static bool Initialized;
  27. private static List<Text> TextList = new List<Text>();
  28. private static Dictionary<string, List<Content>> ContentsDic = new Dictionary<string, List<Content>>();
  29. public static void AddLine(bool isImage, string language, string content, TextAnchor alignment)
  30. {
  31. if (language == DefaultLanguage)
  32. {
  33. AddLine(isImage, En, content, alignment);
  34. AddLine(isImage, Hants, content, alignment);
  35. AddLine(isImage, Hant, content, alignment);
  36. }
  37. if (!ContentsDic.ContainsKey(language))
  38. {
  39. ContentsDic.Add(language, new List<Content>());
  40. }
  41. ContentsDic[language].Add(new Content(isImage, content, alignment));
  42. }
  43. public static void Show()
  44. {
  45. if (!Initialized)
  46. {
  47. Initialize(GetLanguage());
  48. }
  49. else
  50. {
  51. SwitchLanguage(GetLanguage());
  52. }
  53. AudioManager.PlayClip(Clip.BubbleClip);
  54. ResourceManager.Get(ObjectLabel.R_Notify).TweenForCG();
  55. Auxiliary.Instance.DelayCall
  56. (
  57. () =>
  58. {
  59. ResourceManager.Get<VerticalLayoutGroup>(ObjectLabel.R_Grid).CalculateLayoutInputVertical();
  60. ResourceManager.Get<VerticalLayoutGroup>(ObjectLabel.R_Grid).SetLayoutVertical();
  61. },
  62. 1
  63. );
  64. }
  65. public static void Initialize(string language)
  66. {
  67. Initialized = true;
  68. List<Content> contents = ContentsDic[language];
  69. for (int i = 0; i < contents.Count; i++)
  70. {
  71. Transform transform = ResourceManager.Get("NotifyItem", Folder.UI, false, ResourceManager.Get(ObjectLabel.R_Grid), false);
  72. if (contents[i].IsImage)
  73. {
  74. transform.GetComponent<Text>().fontSize = 300;
  75. transform.GetComponent<Text>().verticalOverflow = VerticalWrapMode.Overflow;
  76. transform.GetComponent<Text>().horizontalOverflow = HorizontalWrapMode.Overflow;
  77. transform.GetComponent<Text>().resizeTextForBestFit = false;
  78. transform.GetComponent<ContentSizeFitter>().enabled = true;
  79. transform.GetChild(0).GetComponent<Image>().sprite = HttpManager.NotificationSprite;
  80. }
  81. transform.GetComponent<Text>().text = contents[i].text;
  82. transform.GetComponent<Text>().alignment = contents[i].Alignment;
  83. TextList.Add(transform.GetComponent<Text>());
  84. }
  85. }
  86. public static void SwitchLanguage(string language)
  87. {
  88. for (int i = 0; i < TextList.Count; i++)
  89. {
  90. TextList[i].text = ContentsDic[language][i].text;
  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. }