ManaNotify.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. using System;
  2. using UnityEngine;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using UnityEngine.UI;
  6. public class ManaNotify
  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. public static bool Initialized;
  21. private static List<Text> TextList = new List<Text>();
  22. private static Dictionary<string, List<Content>> ContentsDic = new Dictionary<string, List<Content>>();
  23. public static void AddLine(bool isImage, string language, string content, TextAnchor alignment)
  24. {
  25. if (language == "null")
  26. {
  27. AddLine(isImage, "English", content, alignment);
  28. AddLine(isImage, "Chinese", content, alignment);
  29. AddLine(isImage, "ChineseTraditional", content, alignment);
  30. }
  31. if (!ContentsDic.ContainsKey(language))
  32. {
  33. ContentsDic.Add(language, new List<Content>());
  34. }
  35. ContentsDic[language].Add(new Content(isImage, content, alignment));
  36. }
  37. public static void Show()
  38. {
  39. if (!Initialized)
  40. {
  41. Initialize(GetLanguage());
  42. }
  43. else
  44. {
  45. SwitchLanguage(GetLanguage());
  46. }
  47. ManaAudio.PlayClip(Clip.BubbleClip);
  48. ManaReso.Get("R_Notify").TweenForCG();
  49. }
  50. public static void Initialize(string language)
  51. {
  52. Initialized = true;
  53. List<Content> contents = ContentsDic[language];
  54. for (int i = 0; i < contents.Count; i++)
  55. {
  56. Transform transform = ManaReso.Get("NotifyItem", Folder.UI, false, ManaReso.Get("R_Grid"), false);
  57. if (contents[i].IsImage)
  58. {
  59. transform.GetComponent<Text>().fontSize = 300;
  60. transform.GetComponent<Text>().verticalOverflow = VerticalWrapMode.Overflow;
  61. transform.GetComponent<Text>().horizontalOverflow = HorizontalWrapMode.Overflow;
  62. transform.GetComponent<Text>().resizeTextForBestFit = false;
  63. transform.GetComponent<ContentSizeFitter>().enabled = true;
  64. transform.GetChild(0).GetComponent<Image>().sprite = ManaServer.NotificationSprite;
  65. }
  66. transform.GetComponent<Text>().text = contents[i].text;
  67. transform.GetComponent<Text>().alignment = contents[i].Alignment;
  68. TextList.Add(transform.GetComponent<Text>());
  69. }
  70. Auxiliary.Instance.DelayCall
  71. (
  72. () =>
  73. {
  74. ManaReso.Get<VerticalLayoutGroup>("R_Grid").enabled = true;
  75. },
  76. 1
  77. );
  78. }
  79. public static void SwitchLanguage(string language)
  80. {
  81. for (int i = 0; i < TextList.Count; i++)
  82. {
  83. TextList[i].text = ContentsDic[language][i].text;
  84. }
  85. }
  86. public static string GetLanguage()
  87. {
  88. if (ManaLan.CurrentLan == Lan.ChineseSimplified)
  89. {
  90. return "Chinese";
  91. }
  92. else if (ManaLan.CurrentLan == Lan.ChineseTraditional)
  93. {
  94. return "ChineseTraditional";
  95. }
  96. else if (ManaLan.CurrentLan == Lan.English)
  97. {
  98. return "English";
  99. }
  100. else
  101. {
  102. throw new Exception();
  103. }
  104. }
  105. }