ManaInfoBox.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. using System;
  2. using UnityEngine;
  3. using UnityEngine.UI;
  4. using System.Text;
  5. using System.Collections;
  6. using System.Collections.Generic;
  7. public enum InfoCategory
  8. {
  9. Garden,
  10. PlazaRoom,
  11. }
  12. public class ManaInfoBox : Regist
  13. {
  14. public class InfoBox
  15. {
  16. public class InfoText
  17. {
  18. public float Timer;
  19. public Text Text;
  20. }
  21. public int MaxCount;
  22. public bool Lock;
  23. public float DurationTime;
  24. public float DurationTimer;
  25. public string InfoItemName;
  26. public List<InfoText> TextList = new List<InfoText>();
  27. public Transform Grid;
  28. public CanvasGroup CanvasGroup;
  29. public InfoBox(int maxCount, float duration, string infoItemName, Transform grid)
  30. {
  31. Grid = grid;
  32. DurationTime = duration;
  33. MaxCount = maxCount;
  34. InfoItemName = infoItemName;
  35. CanvasGroup = Grid.GetComponent<CanvasGroup>();
  36. }
  37. public void Update()
  38. {
  39. DurationTimer -= Time.deltaTime;
  40. if (DurationTimer <= 0 && Lock)
  41. {
  42. Lock = false;
  43. CanvasGroup.TweenBacCG();
  44. }
  45. for (int i = 0; i < TextList.Count; i++)
  46. {
  47. InfoText infoText = TextList[i];
  48. infoText.Timer -= Time.deltaTime;
  49. if (infoText.Timer < 0)
  50. {
  51. infoText.Text.TweenBacGra();
  52. TextList.RemoveAt(i--);
  53. }
  54. }
  55. }
  56. public void Show(string str, float time, Sprite atlas)
  57. {
  58. CanvasGroup.TweenForCG();
  59. if (TextList.Count == MaxCount)
  60. {
  61. ManaReso.Save(TextList[0].Text);
  62. TextList.RemoveAt(0);
  63. }
  64. TextPlus text = ManaReso.GetInfoItem(InfoItemName);
  65. text.ImagePlus.sprite = atlas;
  66. text.SetParent(Grid);
  67. text.rectTransform.SetAsFirstSibling();
  68. InfoText infoText = new InfoText();
  69. text.text = str;
  70. text.SetAlpha(1);
  71. infoText.Timer = DurationTime;
  72. infoText.Text = text;
  73. TextList.Add(infoText);
  74. Lock = true;
  75. DurationTimer = time;
  76. }
  77. }
  78. #region Config
  79. private const int MaxGardenInfoCount = 4;
  80. private const int MaxPlazaRoomCount = 50;
  81. private static InfoBox GardenInfoBox;
  82. private static InfoBox PlazaRoomInfoBox;
  83. #endregion
  84. public override void RegistValueA()
  85. {
  86. GardenInfoBox = new InfoBox(MaxGardenInfoCount, 45f, "C_InfoItem", ManaReso.Get("C_Info"));
  87. PlazaRoomInfoBox = new InfoBox(MaxPlazaRoomCount, Mathf.Infinity, "X_InfoItem", ManaReso.Get("X_Info"));
  88. }
  89. public void Update()
  90. {
  91. GardenInfoBox.Update();
  92. PlazaRoomInfoBox.Update();
  93. }
  94. public static void Show(InfoCategory infoCategory, string str, float time, Sprite atlas = null)
  95. {
  96. if (infoCategory == InfoCategory.Garden)
  97. {
  98. GardenInfoBox.Show(str, time, atlas);
  99. }
  100. else if (infoCategory == InfoCategory.PlazaRoom)
  101. {
  102. PlazaRoomInfoBox.Show(str, time, atlas);
  103. }
  104. else
  105. {
  106. throw new Exception();
  107. }
  108. }
  109. }