| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- 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)
- {
- Debug.Log(text);
- // if (!ins) Instantiate(Resources.Load("Prefabs/Views/SideTipView"));
- // ins?._ShowTip(text, color);
- }
- }
|