ManaInfoBox.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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 ObjType ObjType;
  28. public Transform Grid;
  29. public CanvasGroup CanvasGroup;
  30. public InfoBox(int maxCount, float duration, string infoItemName, ObjType objType, Transform grid)
  31. {
  32. Grid = grid;
  33. ObjType = objType;
  34. DurationTime = duration;
  35. MaxCount = maxCount;
  36. InfoItemName = infoItemName;
  37. CanvasGroup = Grid.GetComponent<CanvasGroup>();
  38. }
  39. public void Update()
  40. {
  41. DurationTimer -= Time.deltaTime;
  42. if (DurationTimer <= 0 && Lock)
  43. {
  44. Lock = false;
  45. CanvasGroup.TweenBacCG();
  46. }
  47. for (int i = 0; i < TextList.Count; i++)
  48. {
  49. InfoText infoText = TextList[i];
  50. infoText.Timer -= Time.deltaTime;
  51. if (infoText.Timer < 0)
  52. {
  53. infoText.Text.TweenBacGra();
  54. TextList.RemoveAt(i--);
  55. }
  56. }
  57. }
  58. public void Show(string str, float time, Sprite atlas)
  59. {
  60. CanvasGroup.TweenForCG();
  61. if (TextList.Count == MaxCount)
  62. {
  63. ManaReso.Save(TextList[0].Text);
  64. TextList.RemoveAt(0);
  65. }
  66. TextPlus text = ManaReso.GetInfoItem(InfoItemName, ObjType);
  67. text.ImagePlus.sprite = atlas;
  68. text.SetParent(Grid);
  69. text.rectTransform.SetAsFirstSibling();
  70. InfoText infoText = new InfoText();
  71. text.text = str;
  72. text.SetAlpha(1);
  73. infoText.Timer = DurationTime;
  74. infoText.Text = text;
  75. TextList.Add(infoText);
  76. Lock = true;
  77. DurationTimer = time;
  78. }
  79. }
  80. #region Config
  81. private const int MaxGardenInfoCount = 4;
  82. private const int MaxPlazaRoomCount = 50;
  83. private static InfoBox GardenInfoBox;
  84. private static InfoBox PlazaRoomInfoBox;
  85. #endregion
  86. public override void RegistValueA()
  87. {
  88. GardenInfoBox = new InfoBox(MaxGardenInfoCount, 45f, "C_InfoItem", ObjType.C_InfoItem, ManaReso.Get("C_Info"));
  89. PlazaRoomInfoBox = new InfoBox(MaxPlazaRoomCount, Mathf.Infinity, "X_InfoItem", ObjType.X_InfoItem, ManaReso.Get("X_Info"));
  90. }
  91. public void Update()
  92. {
  93. GardenInfoBox.Update();
  94. PlazaRoomInfoBox.Update();
  95. }
  96. public static void Show(InfoCategory infoCategory, string str, float time, Sprite atlas = null)
  97. {
  98. if (infoCategory == InfoCategory.Garden)
  99. {
  100. GardenInfoBox.Show(str, time, atlas);
  101. }
  102. else if (infoCategory == InfoCategory.PlazaRoom)
  103. {
  104. PlazaRoomInfoBox.Show(str, time, atlas);
  105. }
  106. else
  107. {
  108. throw new Exception();
  109. }
  110. }
  111. }