| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using JCUnityLib;
- public class SideTipView : ViewBase
- {
- GameObject sideTip;
- Text sideTipText;
- List<string> tipStrList = new List<string>();
- static SideTipView ins;
- void Awake()
- {
- ins = this;
- sideTip = transform.Find("SideTip").gameObject;
- sideTipText = sideTip.GetComponentInChildren<Text>();
- }
- void OnDestroy()
- {
- if (ins == this) ins = null;
- }
- void _ShowTip(string text, Color color)
- {
- string c = "white";
- if (color == Color.yellow) c = "yellow";
- string s =
- $"<color=#BBFFFF>{System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}</color>\n" +
- $"<color={c}>{text}</color>";
- tipStrList.Add(s);
- sideTipText.text = string.Join("\n", tipStrList);
- if (tipStrList.Count == 1) sideTip.SetActive(true);
- StartCoroutine(AutoDestroy());
- }
- IEnumerator AutoDestroy()
- {
- yield return new WaitForSeconds(10.0f);
- tipStrList.RemoveAt(0);
- sideTipText.text = string.Join("\n", tipStrList);
- if (tipStrList.Count == 0) sideTip.SetActive(false);
- }
- public static void ShowTip(string text, Color color)
- {
- if (!ins) Instantiate(Resources.Load("Prefabs/Views/SideTipView"));
- ins?._ShowTip(text, color);
- }
- }
|