using System; using UnityEngine; using UnityEngine.UI; using System.Text; using System.Collections; using System.Collections.Generic; public enum InfoCategory { Garden, PlazaRoom, } public class ManaInfoBox : Regist { public class InfoBox { public class InfoText { public float Timer; public Text Text; } public int MaxCount; public bool Lock; public float DurationTime; public float DurationTimer; public string InfoItemName; public List TextList = new List(); public ObjType ObjType; public Transform Grid; public CanvasGroup CanvasGroup; public VerticalLayoutGroup VerticalLayoutGroup; public InfoBox(int maxCount, float duration, string infoItemName, ObjType objType, Transform grid) { Grid = grid; ObjType = objType; DurationTime = duration; MaxCount = maxCount; InfoItemName = infoItemName; CanvasGroup = Grid.GetComponent(); VerticalLayoutGroup = Grid.GetComponent(); } public void Update() { DurationTimer -= Time.deltaTime; if (DurationTimer <= 0 && Lock) { Lock = false; if (CanvasGroup != null) CanvasGroup.TweenBacCG(); } for (int i = 0; i < TextList.Count; i++) { InfoText infoText = TextList[i]; if (infoText.Timer == Mathf.Infinity) { continue; } infoText.Timer -= Time.deltaTime; if (infoText.Timer < 0) { infoText.Text.TweenBacGra(); TextList.RemoveAt(i--); } } } public void Show(string str, float time, Sprite atlas) { if (CanvasGroup != null) CanvasGroup.TweenForCG(); if (TextList.Count == MaxCount) { ManaReso.Save(TextList[0].Text); TextList.RemoveAt(0); } TextPlus text = ManaReso.GetInfoItem(InfoItemName, Grid, ObjType); text.ImagePlus.sprite = atlas; text.SetParent(Grid); text.rectTransform.SetAsFirstSibling(); if (VerticalLayoutGroup != null) { Auxiliary.Instance.DelayCall( () => { VerticalLayoutGroup.SetLayoutVertical(); }, 1 ); } InfoText infoText = new InfoText(); text.text = str; text.SetAlpha(1); infoText.Timer = DurationTime; infoText.Text = text; TextList.Add(infoText); Lock = true; DurationTimer = time; } } #region Config private const int MaxGardenInfoCount = 4; private const int MaxPlazaRoomCount = 19; private static InfoBox GardenInfoBox; private static InfoBox PlazaRoomInfoBox; #endregion public override void RegistValueA() { GardenInfoBox = new InfoBox(MaxGardenInfoCount, 45f, "C_InfoItem", ObjType.C_InfoItem, ManaReso.Get("C_Info")); PlazaRoomInfoBox = new InfoBox(MaxPlazaRoomCount, Mathf.Infinity, "X_InfoItem", ObjType.X_InfoItem, ManaReso.Get("X_Info")); } public void Update() { GardenInfoBox.Update(); PlazaRoomInfoBox.Update(); } public static void Show(InfoCategory infoCategory, string str, float time, Sprite atlas = null) { if (infoCategory == InfoCategory.Garden) { GardenInfoBox.Show(str, time, atlas); } else if (infoCategory == InfoCategory.PlazaRoom) { PlazaRoomInfoBox.Show(str, time, atlas); } else { throw new Exception(); } } }