using System; using UnityEngine; using UnityEngine.UI; using System.Text; using System.Collections; using System.Collections.Generic; public class InfoBoxManager : Regist { public class InfoBox { public class InfoText { public float Timer; public Text Text; } #region Config public int MaxCount; public bool Lock; public bool Reverse; 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; #endregion public InfoBox(int maxCount, float duration, string infoItemName, bool reverse, ObjType objType, Transform grid) { Grid = grid; Reverse = reverse; 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, Color color, Sprite atlas) { if (CanvasGroup != null) CanvasGroup.TweenForCG(); if (TextList.Count == MaxCount) { ResourceManager.Save(TextList[0].Text); TextList.RemoveAt(0); } TextPlus text = ResourceManager.GetInfoItem(InfoItemName, Grid, ObjType); text.ImagePlus.sprite = atlas; text.SetParent(Grid); if (Reverse) { text.rectTransform.SetAsLastSibling(); } else { text.rectTransform.SetAsFirstSibling(); } if (VerticalLayoutGroup != null) { Auxiliary.Instance.DelayCall ( () => { LayoutRebuilder.MarkLayoutForRebuild(VerticalLayoutGroup.GetComponent()); //VerticalLayoutGroup.SetLayoutVertical(); }, 1 ); } InfoText infoText = new InfoText(); text.text = str; text.SetAlpha(1); text.color = color; infoText.Timer = DurationTime; infoText.Text = text; TextList.Add(infoText); Lock = true; DurationTimer = time; } } #region Config private const int MaxGardenInfoCount = 4; private const int MaxPlazaRoomCount = 300; public static InfoBox GardenInfoBox; public static InfoBox PlazaRoomInfoBox; #endregion public override void FirstInit() { GardenInfoBox = new InfoBox(MaxGardenInfoCount, 45f, ResourceLabel.GardenInfoItem, true, ObjType.C_InfoItem, ResourceManager.Get(ObjectLabel.C_Info)); PlazaRoomInfoBox = new InfoBox(MaxPlazaRoomCount, Mathf.Infinity, ResourceLabel.PlazaInfoItem, true, ObjType.X_InfoItem, ResourceManager.Get(ObjectLabel.X_Info)); } public void Update() { GardenInfoBox.Update(); PlazaRoomInfoBox.Update(); } }