using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using JCUnityLib; public class SideTipView : ViewBase { GameObject sideTip; Text sideTipText; List tipStrList = new List(); static SideTipView ins; void Awake() { ins = this; sideTip = transform.Find("SideTip").gameObject; sideTipText = sideTip.GetComponentInChildren(); } void OnDestroy() { if (ins == this) ins = null; } void _ShowTip(string text, Color color) { string c = "white"; if (color == Color.yellow) c = "yellow"; string s = $"{System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}\n" + $"{text}"; 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) { Debug.Log(text); // if (!ins) Instantiate(Resources.Load("Prefabs/Views/SideTipView")); // ins?._ShowTip(text, color); } }