Files
JJBB/Assets/Project/Script/GUI/Other/LoadingTips.cs
2024-08-23 15:49:34 +08:00

168 lines
4.0 KiB
C#

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using GCGame.Table;
using System;
using Games.GlobeDefine;
public class LoadingTips : UIControllerBase<LoadingTips>
{
public enum LoadTipType
{
Reconnect,
ResDownloading,
}
private void OnEnable()
{
SetInstance(this);
}
private void OnDisable()
{
SetInstance(null);
}
private void Update()
{
LoadUIUpdate();
}
public void Close()
{
UIManager.CloseUI(UIInfo.LoadingTips);
}
public static void ShowLoadingTips(LoadTipType loadTipType)
{
_DefaultShowUI = true;
if (LoadingTips.Instance())
{
LoadingTips.Instance().InitLoadTips(loadTipType);
return;
}
UIManager.ShowUI(UIInfo.LoadingTips, delegate (bool bSucess, object param) {
if (bSucess)
{
if (!_DefaultShowUI)
{
HideLoadingTips();
}
else
{
LoadingTips.Instance().InitLoadTips(loadTipType);
}
}
});
}
public static void HideLoadingTips()
{
_DefaultShowUI = false;
if (!LoadingTips.Instance())
{
return;
}
LoadingTips.Instance().Close();
}
#region
public static bool _DefaultShowUI = false;
public GameObject _EffectReconnectPrefab;
public GameObject _EffectResLoadingPrefab;
private GameObject _EffectReconnectInstance;
private GameObject _EffectResLoadingInstance;
private void InitEffect()
{
if (_EffectReconnectInstance == null)
{
_EffectReconnectInstance = GameObject.Instantiate(_EffectReconnectPrefab);
_EffectReconnectInstance.transform.SetParent(transform);
_EffectReconnectInstance.transform.localScale = Vector3.one;
_EffectReconnectInstance.AddComponent<UIParticleSystem>();
}
if (_EffectResLoadingInstance == null)
{
_EffectResLoadingInstance = GameObject.Instantiate(_EffectResLoadingPrefab);
_EffectResLoadingInstance.transform.SetParent(transform);
_EffectResLoadingInstance.transform.localScale = Vector3.one;
_EffectResLoadingInstance.AddComponent<UIParticleSystem>();
}
}
public void InitLoadTips(LoadTipType loadTipType)
{
InitEffect();
if (loadTipType == LoadTipType.Reconnect)
{
_EffectReconnectInstance.gameObject.SetActive(true);
_EffectResLoadingInstance.gameObject.SetActive(false);
}
else if (loadTipType == LoadTipType.ResDownloading)
{
_EffectReconnectInstance.gameObject.SetActive(false);
_EffectResLoadingInstance.gameObject.SetActive(true);
}
}
#endregion
#region loading ui
public class LoadingUIInfo
{
public string UIName;
public float StartTime;
}
static LoadingUIInfo _LoadingUI = null;
public static float _LoadingTimeLimit = 5.0f;
public static void LoadingUI(string uiName)
{
GuiTextDebug.debug("LoadingUI:" + uiName);
if (_LoadingUI != null)
return;
_LoadingUI = new LoadingUIInfo();
_LoadingUI.UIName = uiName;
_LoadingUI.StartTime = Time.time;
if (_LoadingTimeLimit < 0)
{
_LoadingTimeLimit = SystemParam.GetSystemParam_FLOAT(39);
}
ShowLoadingTips(LoadTipType.ResDownloading);
}
public static void LoadingUIFinish(string uiName)
{
_LoadingUI = null;
HideLoadingTips();
}
private void LoadUIUpdate()
{
if (_LoadingUI == null)
return;
if (Time.time - _LoadingUI.StartTime > _LoadingTimeLimit)
{
GUIData.AddNotifyData("#{23007}");
_LoadingUI = null;
HideLoadingTips();
}
}
#endregion
}