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 LiveTimer; public Text Text; } #region Config public int MaxTextCount; public bool Lock; public bool ReverseDirection; public float DisplayTime; public float DisplayTimer; public string InfoItemName; public List TextList = new List(); public ObjType ObjType; public Transform Grid; public CanvasGroup CanvasGroup; public VerticalLayoutGroup VerticalLayoutGroup; #endregion public InfoBox(int maxTextCount, float displayTime, string infoItemName, bool reverseDirection, ObjType objType, Transform grid) { Grid = grid; ReverseDirection = reverseDirection; ObjType = objType; DisplayTime = displayTime; MaxTextCount = maxTextCount; InfoItemName = infoItemName; CanvasGroup = Grid.GetComponent(); VerticalLayoutGroup = Grid.GetComponent(); } public void Update() { DisplayTimer -= Time.deltaTime; if (DisplayTimer <= 0 && Lock) { Lock = false; if (CanvasGroup != null) CanvasGroup.TweenBacCG(); } for (int i = 0; i < TextList.Count; i++) { InfoText infoText = TextList[i]; if (infoText.LiveTimer == Mathf.Infinity) { continue; } infoText.LiveTimer -= Time.deltaTime; if (infoText.LiveTimer < 0) { infoText.Text.TweenBacGra(); TextList.RemoveAt(i--); } } } public void Display(string str, float time, Color color, Sprite atlas) { if (CanvasGroup != null) CanvasGroup.TweenForCG(); if (TextList.Count == MaxTextCount) { ResourceManager.Save(TextList[0].Text); TextList.RemoveAt(0); } TextPlus text = ResourceManager.GetInfoItem(InfoItemName, Grid, ObjType); text.ImagePlus.sprite = atlas; text.SetParent(Grid); if (ReverseDirection) { text.rectTransform.SetAsLastSibling(); } else { text.rectTransform.SetAsFirstSibling(); } if (VerticalLayoutGroup != null) { Auxiliary.Instance.DelayCall ( () => { LayoutRebuilder.MarkLayoutForRebuild(VerticalLayoutGroup.GetComponent()); }, 1 ); } InfoText infoText = new InfoText(); text.text = str; text.SetAlpha(1); text.color = color; infoText.LiveTimer = DisplayTime; infoText.Text = text; TextList.Add(infoText); Lock = true; DisplayTimer = time; } } #region Config private const int MaxGardenInfoItemCount = 4; private const int MaxPlazaRoomItemCount = 300; public static float GardenInfoBoxDisplayTime = 45f; public static float PlazaRoomInfoBoxDisplayTime = Mathf.Infinity; public static InfoBox GardenInfoBox; public static InfoBox PlazaRoomInfoBox; #endregion public override void FirstInit() { GardenInfoBox = new InfoBox(MaxGardenInfoItemCount, GardenInfoBoxDisplayTime, ResourceLabel.GardenInfoItem, true, ObjType.GardenInfoItem, ResourceManager.Get(CanvasLabel.C_Info)); PlazaRoomInfoBox = new InfoBox(MaxPlazaRoomItemCount, PlazaRoomInfoBoxDisplayTime, ResourceLabel.PlazaInfoItem, true, ObjType.PlazaroomInfoItem, ResourceManager.Get(CanvasLabel.X_Info)); } public void Update() { GardenInfoBox.Update(); PlazaRoomInfoBox.Update(); } }