123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- 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<InfoText> TextList = new List<InfoText>();
- 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<CanvasGroup>();
- VerticalLayoutGroup = Grid.GetComponent<VerticalLayoutGroup>();
- }
- 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<RectTransform>());
- },
- 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();
- }
- }
|