AnnounceManager.cs 3.9 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 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. private static int AnnounceImageSize = 300;
  66. public static void Initialize(string language)
  67. {
  68. Initialized = true;
  69. List<Content> contents = ContentsDic[language];
  70. for (int i = 0; i < contents.Count; i++)
  71. {
  72. Transform transform = ResourceManager.Get(ResourceLabel.NotifyItem, Folder.UI, false, ResourceManager.Get(ObjectLabel.R_Grid), false);
  73. if (contents[i].IsImage)
  74. {
  75. transform.GetComponent<Text>().fontSize = AnnounceImageSize;
  76. transform.GetComponent<Text>().verticalOverflow = VerticalWrapMode.Overflow;
  77. transform.GetComponent<Text>().horizontalOverflow = HorizontalWrapMode.Overflow;
  78. transform.GetComponent<Text>().resizeTextForBestFit = false;
  79. transform.GetComponent<ContentSizeFitter>().enabled = true;
  80. transform.GetChild(0).GetComponent<Image>().sprite = HttpManager.NotificationSprite;
  81. }
  82. transform.GetComponent<Text>().text = contents[i].text;
  83. transform.GetComponent<Text>().alignment = contents[i].Alignment;
  84. TextList.Add(transform.GetComponent<Text>());
  85. }
  86. }
  87. public static void SwitchLanguage(string language)
  88. {
  89. for (int i = 0; i < TextList.Count; i++)
  90. {
  91. TextList[i].text = ContentsDic[language][i].text;
  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. }