ManaNotify.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. ManaReso.Get("R_Notify").TweenForCG();
  48. }
  49. public static void Initialize(string language)
  50. {
  51. Initialized = true;
  52. List<Content> contents = ContentsDic[language];
  53. for (int i = 0; i < contents.Count; i++)
  54. {
  55. Transform transform = ManaReso.Get("NotifyItem", Folder.UI, false, ManaReso.Get("R_Grid"), false);
  56. if (contents[i].IsImage)
  57. {
  58. transform.GetComponent<Text>().fontSize = 300;
  59. transform.GetComponent<Text>().verticalOverflow = VerticalWrapMode.Overflow;
  60. transform.GetComponent<Text>().horizontalOverflow = HorizontalWrapMode.Overflow;
  61. transform.GetComponent<Text>().resizeTextForBestFit = false;
  62. transform.GetComponent<ContentSizeFitter>().enabled = true;
  63. transform.GetChild(0).GetComponent<Image>().sprite = ManaServer.NotificationSprite;
  64. }
  65. transform.GetComponent<Text>().text = contents[i].text;
  66. transform.GetComponent<Text>().alignment = contents[i].Alignment;
  67. TextList.Add(transform.GetComponent<Text>());
  68. }
  69. Auxiliary.Instance.DelayCall
  70. (
  71. () =>
  72. {
  73. ManaReso.Get<VerticalLayoutGroup>("R_Grid").enabled = true;
  74. },
  75. 1
  76. );
  77. }
  78. public static void SwitchLanguage(string language)
  79. {
  80. for (int i = 0; i < TextList.Count; i++)
  81. {
  82. TextList[i].text = ContentsDic[language][i].text;
  83. }
  84. }
  85. public static string GetLanguage()
  86. {
  87. if (ManaLan.CurrentLan == Lan.ChineseSimplified)
  88. {
  89. return "Chinese";
  90. }
  91. else if (ManaLan.CurrentLan == Lan.ChineseTraditional)
  92. {
  93. return "ChineseTraditional";
  94. }
  95. else if (ManaLan.CurrentLan == Lan.English)
  96. {
  97. return "English";
  98. }
  99. else
  100. {
  101. throw new Exception();
  102. }
  103. }
  104. }