// Author: whc // Desc: 各种提示 using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using Axibug.Runtime; public enum eTipType { None, Dialog, // 弹窗 Hint, // 飘字 Choice, // 选择框 Wait, // 等待框 } public class Tips : GameComponent { //public static readonly Tips Instance= new Tips(); public static Tips Instance = null; protected override void Awake() { base.Awake(); Instance = this; } private Queue m_SafeTipQue; // 用于线程安全的提示队列 public Queue SafeTipQue { get { if (m_SafeTipQue == null) m_SafeTipQue = new Queue(); return m_SafeTipQue; } } // 提示框 public void ShowDialog(string _text, string _title = "提示") { DialogData vData = new DialogData(_text, _title); Inform.Dispatch(eInformId.TipDialog, vData); } // 提示文字 public void ShowHint(string _text, eHintType _type = eHintType.Info) { HintData vData = new HintData(_text, _type); Inform.Dispatch(eInformId.TipHint, vData); } public void ShowHint(string _text, int _type) { ShowHint(_text, (eHintType)_type); } // 提示选择框 public void ShowChoice(string _text, Action _Call, Action _NoCall = null, string _title = "提示") { ChoiceData vData = new ChoiceData(_text, _Call, _NoCall, _title); Inform.Dispatch(eInformId.TipChoice, vData); } // 提示等待 public void ShowWait(string _text, float _waitTimeMax = 15f) { WaitData vData = new WaitData(_text, _waitTimeMax); Inform.Dispatch(eInformId.TipWait, vData); } // 主线程安全 提示框 public void SafeShowDialog(string _text, string _title = "提示") { DialogData vData = new DialogData(_text, _title); SafeTipQue.Enqueue(vData); } // 主线程安全 提示文字 public void SafeShowHint(string _text, eHintType _type = eHintType.Info) { HintData vData = new HintData(_text, _type); SafeTipQue.Enqueue(vData); } public void SafeShowHint(string _text, int _type) { ShowHint(_text, (eHintType)_type); } // 主线程安全 提示选择框 public void SafeShowChoice(string _text, Action _Call, Action _NoCall = null, string _title = "提示") { ChoiceData vData = new ChoiceData(_text, _Call, _NoCall, _title); SafeTipQue.Enqueue(vData); } // 主线程安全 提示等待 public void SafeShowWait(string _text, float _waitTimeMax = 15f) { WaitData vData = new WaitData(_text, _waitTimeMax); SafeTipQue.Enqueue(vData); } public void HideChoice() { Inform.Dispatch(eInformId.TipChoiceClose); // 关闭选择框 } // 关闭等待界面 public void HideWait() { Inform.Dispatch(eInformId.TipWaitClose); } } public class TipData { public eTipType m_type = eTipType.None; public string m_text = string.Empty; public TipData(string _str) { m_text = _str; } } public class DialogData : TipData { public string m_title = string.Empty; public DialogData(string _str, string _title = "提示") : base(_str) { m_type = eTipType.Dialog; m_title = _title; } } public enum eHintType { Info = 1, // 普通 绿色 Warn, // 警告 黄色 Error, // 错误 红色 } public class HintData : TipData { private eHintType m_HintType; public eHintType p_HintType { get { return m_HintType; } } public HintData(string _str, eHintType _type = eHintType.Info):base(_str) { m_type = eTipType.Hint; m_HintType = _type; } } public class ChoiceData : DialogData { public Action m_YesCall; public Action m_NoCall; public ChoiceData(string _str, Action _Call, Action _NoCall = null, string _title = "提示") : base(_str, _title) { m_type = eTipType.Choice; m_YesCall += _Call; if (_NoCall != null) m_NoCall += _NoCall; } } public class WaitData:TipData { public float m_waitTimeMax; public WaitData(string _str, float _waitTimeMax = 15f):base(_str) { m_type = eTipType.Wait; m_waitTimeMax = _waitTimeMax; } }