AkiraPixelWind/Assets/Scripts/Main/UI/UIMgr/Tips/TipsUI.cs
2022-12-29 18:20:40 +08:00

183 lines
4.7 KiB
C#

// Author: whc
// Desc:
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TipsUI : UIBase
{
public Transform m_NodeHintTf;
public Transform m_NodeDialogTf;
public Transform m_NodeChoiceTf;
private UnitPool<TipHintUnit> m_HintPool;
public UnitPool<TipHintUnit> vHintPool {
get {
if (m_HintPool == null)
m_HintPool = new UnitPool<TipHintUnit>(m_NodeHintTf);
return m_HintPool;
}
}
private UnitPool<TipDialogUnit> m_DialogPool;
public UnitPool<TipDialogUnit> vDailogPool {
get {
if (m_DialogPool == null)
m_DialogPool = new UnitPool<TipDialogUnit>(m_NodeDialogTf);
return m_DialogPool;
}
}
private UnitPool<TipChoiceUnit> m_ChoicePool;
public UnitPool<TipChoiceUnit> vChoicePool {
get {
if (m_ChoicePool == null)
m_ChoicePool = new UnitPool<TipChoiceUnit>(m_NodeChoiceTf);
return m_ChoicePool;
}
}
private UnitPool<TipWaitUnit> m_WaitPool;
public UnitPool<TipWaitUnit> vWaitPool {
get {
if (m_WaitPool == null)
m_WaitPool = new UnitPool<TipWaitUnit>(m_NodeHintTf);
return m_WaitPool;
}
}
public override void Awake()
{
base.Awake();
m_NodeHintTf = transform.Find("NodeHint");
m_NodeDialogTf = transform.Find("NodeDialog");
m_NodeChoiceTf = transform.Find("NodeChoice");
}
private void OnEnable()
{
Inform<TipData>.Listen(eInformId.TipDialog, ShowDialog);
Inform<TipData>.Listen(eInformId.TipHint, ShowHint);
Inform<TipData>.Listen(eInformId.TipChoice, ShowChoice);
Inform<TipData>.Listen(eInformId.TipWait, ShowWait);
}
private void OnDisable()
{
Inform<TipData>.Cancel(eInformId.TipDialog, ShowDialog);
Inform<TipData>.Cancel(eInformId.TipHint, ShowHint);
Inform<TipData>.Cancel(eInformId.TipChoice, ShowChoice);
Inform<TipData>.Cancel(eInformId.TipWait, ShowWait);
}
//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 (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.Dialog:
ShowDialog(_Data);
break;
case eTipType.Choice:
ShowChoice(_Data);
break;
case eTipType.Wait:
ShowWait(_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);
}
public void ShowHint(TipData _Data)
{
TipHintUnit vUnit = vHintPool.GetAnyHide();
vUnit.Refresh(_Data);
}
public void ShowChoice(TipData _Data)
{
TipChoiceUnit vUnit = vChoicePool.GetAnyHide();
vUnit.Refresh(_Data);
}
public void ShowWait(TipData _Data)
{
TipWaitUnit vUnit = vWaitPool.GetAnyHide();
vUnit.Refresh(_Data);
}
}