// Author: whc // Desc: using CaoCao; using CaoCao.Event; using Game; using Game.HotFix; using System; using System.Collections; using System.Collections.Generic; using UnityEngine; public class TipsUI : UIBase { public static TipsUI Instance; public Transform m_NodeHintTf; public Transform m_NodeLeftHintTf; public Transform m_NodeWaitTf; public Transform m_NodeDialogTf; public Transform m_NodeChoiceTf; public Transform m_NodeNRATF; private UnitPool m_HintPool; public UnitPool vHintPool { get { if (m_HintPool == null) m_HintPool = new UnitPool(null,m_NodeHintTf); return m_HintPool; } } private UnitPool m_LeftHintPool; public UnitPool vLeftHintPool { get { if (m_LeftHintPool == null) m_LeftHintPool = new UnitPool(null, m_NodeLeftHintTf); return m_LeftHintPool; } } private UnitPool m_DialogPool; public UnitPool vDailogPool { get { if (m_DialogPool == null) m_DialogPool = new UnitPool(null, m_NodeDialogTf); return m_DialogPool; } } private UnitPool m_ChoicePool; public UnitPool vChoicePool { get { if (m_ChoicePool == null) m_ChoicePool = new UnitPool(null, m_NodeChoiceTf); return m_ChoicePool; } } private UnitPool m_WaitPool; public UnitPool vWaitPool { get { if (m_WaitPool == null) m_WaitPool = new UnitPool(null, m_NodeWaitTf); return m_WaitPool; } } private UnitPool m_NotRemindAgainPool; public UnitPool vNotRemindAgainPool { get { if (m_NotRemindAgainPool == null) m_NotRemindAgainPool = new UnitPool(null, m_NodeNRATF); return m_NotRemindAgainPool; } } #region TipHintUnit 专属 /// /// 显示队列 /// private Queue mHintTipsQue; /// /// 左侧显示队列 /// private Queue mLeftHintTipsQue; /// /// 最大等待条数 /// const int mMaxWaitNum = 4; /// /// 最大显示条数 /// const int mMaxShowNum = 4; /// /// 当前显示条数 /// private int mNowShowNum = 0; /// /// 当前显示条数 /// private int mNowLeftShowNum = 0; public void ReduceShowNum(bool isLeft) { if (isLeft) { --mNowLeftShowNum; } else { --mNowShowNum; } } #endregion public override void Awake() { base.Awake(); Instance = this; m_NodeHintTf = transform.Find("NodeHint"); m_NodeLeftHintTf = transform.Find("NodeLeftHint"); m_NodeWaitTf = transform.Find("NodeWait"); m_NodeDialogTf = transform.Find("NodeDialog"); m_NodeChoiceTf = transform.Find("NodeChoice"); m_NodeNRATF = transform.Find("NodeNRA"); mHintTipsQue = new Queue(); mLeftHintTipsQue = new Queue(); } private void OnEnable() { Inform.Listen(eInformId.TipDialog, ShowDialog); Inform.Listen(eInformId.TipHint, ShowHint); Inform.Listen(eInformId.TipLeftHint, ShowLeftHint); Inform.Listen(eInformId.TipChoice, ShowChoice); Inform.Listen(eInformId.TipWait, ShowWait); Inform.Listen(eInformId.TipActivityStart, ShowActivityStart); Inform.Listen(eInformId.TipNotRemindAgain, ShowNotRemindAgain); //AppEntry.Event.Subscribe(Listen.EventId, RefreshPanel); Inform.Listen(eInformId.ReduceTipHintEventArgs, RefreshPanel2); } private void OnDisable() { Inform.Cancel(eInformId.TipDialog, ShowDialog); Inform.Cancel(eInformId.TipHint, ShowHint); Inform.Cancel(eInformId.TipLeftHint, ShowLeftHint); Inform.Cancel(eInformId.TipChoice, ShowChoice); Inform.Cancel(eInformId.TipWait, ShowWait); Inform.Cancel(eInformId.TipActivityStart, ShowActivityStart); Inform.Cancel(eInformId.TipNotRemindAgain, ShowNotRemindAgain); //AppEntry.Event.Unsubscribe(ReduceTipHintEventArgs.EventId, RefreshPanel); Inform.Cancel(eInformId.ReduceTipHintEventArgs, RefreshPanel2); } //bool isShowOutGame = false; //bool isCheckWhenBack = false; //void OnApplicationFocus(bool _focus) //{ // //Debug.Log("OnApplicationFocus _focus:"+ _focus.ToString()); // if(_focus) // { // if (!isCheckWhenBack) // return; // isCheckWhenBack = false; // isShowOutGame = true; // if (!Game.Instance.GetNet().IsLoop()) // return; // if (!Game.Instance.GetNet().IsConnected()) // { // Game.Instance.GetNet().ShowReconnectTips(); // //Tips.Instance.SafeShowChoice("失去网络链接, 是否重连?", ReConnect, ExitWork); // } // } // else // { // isCheckWhenBack = true; // if (!isShowOutGame) // return; // Debug.Log("请不要离开太久, 否则会中断服务器链接."); // //Tips.Instance.ShowHint("请不要离开太久, 否则会中断服务器链接."); // } //} public void GameExit() { Application.Quit(); } int m_lastFrame = 0; private void Update() { if (m_lastFrame < 8) { m_lastFrame++; return; } m_lastFrame = 0; if (mHintTipsQue.Count > 0 && mNowShowNum < mMaxShowNum) { TipHintUnit vUnit = vHintPool.GetAnyHide(); vUnit.Refresh(mHintTipsQue.Dequeue()); ++mNowShowNum; } if (mLeftHintTipsQue.Count > 0 && mNowLeftShowNum < mMaxShowNum) { TipLeftHintUnit vUnit = vLeftHintPool.GetAnyHide(); vUnit.Refresh(mLeftHintTipsQue.Dequeue()); ++mNowLeftShowNum; } if (Tips.Instance.SafeTipQue.Count <= 0) return; SwitchTipDataShow(Tips.Instance.SafeTipQue.Dequeue()); } public void SwitchTipDataShow(TipData _Data) { switch (_Data.m_type) { case eTipType.Hint: ShowHint(_Data); break; case eTipType.LeftHint: ShowLeftHint(_Data); break; case eTipType.Dialog: ShowDialog(_Data); break; case eTipType.Choice: ShowChoice(_Data); break; case eTipType.Wait: ShowWait(_Data); break; case eTipType.ActivityStart: ShowActivityStart(_Data); break; default: Debug.LogError("not switch (_Data.m_type). type:" + _Data.m_type.ToString()); break; } } public void ShowDialog(TipData _Data) { TipDialogUnit vUnit = vDailogPool.GetAnyHide(); vUnit.Refresh(_Data); Setlen(); } public void ShowHint(TipData _Data) { if(mHintTipsQue.Count < mMaxWaitNum) { mHintTipsQue.Enqueue(_Data); } Setlen(); } public void ShowLeftHint(TipData _Data) { //TipHintUnit vUnit = vHintPool.GetAnyHide(); //vUnit.Refresh(_Data); if (mLeftHintTipsQue.Count < mMaxWaitNum) { mLeftHintTipsQue.Enqueue(_Data); } Setlen(); } public void ShowChoice(TipData _Data) { TipChoiceUnit vUnit = vChoicePool.GetAnyHide(); vUnit.Refresh(_Data); Setlen(); } public void ShowNotRemindAgain(TipData _Data, NotRemindAgainType pType) { TipNotRemindAgainUnit vUnit = vNotRemindAgainPool.GetAnyHide(); vUnit.Refresh(_Data, pType); Setlen(); } public void ShowWait(TipData _Data) { TipWaitUnit vUnit = vWaitPool.GetObj(0);//.GetAnyHide(); vUnit.Refresh(_Data); Setlen(); } public void ShowActivityStart(TipData _Data) { //TipActivityStartUnit vUnit = vActivityStartPool.GetAnyHide(); //vUnit.Refresh(_Data); Setlen(); } //private void RefreshPanel(object sender, LogicEventArgs e) //{ // ReduceTipHintEventArgs roleListEvent = (ReduceTipHintEventArgs)e; // if (roleListEvent == null) // throw new GameException("ShowHint 显示更新失败"); // ReduceShowNum(roleListEvent.isLeft); //} private void RefreshPanel2(bool pValue) { ReduceShowNum(pValue); } public void Clean() { mHintTipsQue.Clear(); mLeftHintTipsQue.Clear(); mNowShowNum = 0; mNowLeftShowNum = 0; vChoicePool.Destory(); vDailogPool.Destory(); vHintPool.Destory(); vLeftHintPool.Destory(); vNotRemindAgainPool.Destory(); vWaitPool.Destory(); } void Setlen() { transform.SetAsLastSibling(); } }