| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using JCUnityLib;
- public class SideTipView : ViewBase
- {
- Transform container;
- GameObject sideTipPrefab;
- static SideTipView ins;
- void Awake()
- {
- ins = this;
- container = transform.Find("Container");
- sideTipPrefab = container.Find("SideTip").gameObject;
- sideTipPrefab.SetActive(false);
- }
- void OnDestroy()
- {
- if (ins == this) ins = null;
- }
- void _ShowTip(string text, Color color)
- {
- var o = Instantiate(sideTipPrefab);
- var t = o.GetComponentInChildren<Text>();
- t.text = text;
- t.color = color;
- o.transform.SetParent(container);
- o.SetActive(true);
- StartCoroutine(AutoDestroy(o));
- }
- IEnumerator AutoDestroy(GameObject o)
- {
- yield return new WaitForSeconds(5.0f);
- Destroy(o);
- }
- public static void ShowTip(string text, Color color)
- {
- if (!ins) Instantiate(Resources.Load("Prefabs/Views/SideTipView"));
- ins?._ShowTip(text, color);
- }
- }
|