using DG.Tweening; namespace FlowerPower { using System.Collections; using FairyGUI; using UnityEngine; using Object = UnityEngine.Object; public class LoadingUI : BaseUI { private LoadingUICtrl ctrl; private LoadingModel model; private FGUI.PLoading.com_loading ui; protected GProgressBar pb_loading; private Tweener tweener; private bool loading = false; protected int currValue; public LoadingUI(LoadingUICtrl ctrl) : base(ctrl) { uiName = UIConst.LoadingUI; this.ctrl = ctrl; } protected override void SetUIInfo(UIInfo uiInfo) { uiInfo.packageName = "PLoading"; uiInfo.assetName = "com_loading"; uiInfo.layerType = UILayerType.Loading; uiInfo.isNeedOpenAnim = false; uiInfo.isNeedCloseAnim = false; uiInfo.isNeedUIMask = false; } #region 生命周期 protected override void OnInit() { } protected override void OnClose() { } protected override void OnBind() { ui = baseUI as FGUI.PLoading.com_loading; } protected override void OnOpenBefore(object args) { UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.OpenBgUI_Open); ui.com_pb.max = 100; ui.com_pb.value = 0; // if (!GameHelper.IsConnect()) // { // return; // } CrazyAsyKit.StartCoroutine(SetProgress()); // var splashCanvas = GameObject.Find("SplashCanvas"); // if (splashCanvas != null) // { // splashCanvas.SetActive(false); // Object.Destroy(splashCanvas); // } } public IEnumerator SetProgress() { tweener = DOTween.To(() => ui.com_pb.value, x => ui.com_pb.value = x, 97, 12.0f); yield return tweener; } private void Reconnection(object obj = null) { CrazyAsyKit.StartCoroutine(SetProgress()); } protected override void OnOpen(object args) { } #endregion #region 消息 protected override void AddListener() { GameDispatcher.Instance.AddListener(GameMsg.UpdateHotFixMax, OnUpdateHotFixMax); GameDispatcher.Instance.AddListener(GameMsg.UpdateHotFixProgress, OnUpdateHotFixProgress); GameDispatcher.Instance.AddListener(GameMsg.Network_reconnection, Reconnection); GameDispatcher.Instance.AddListener(GameMsg.CloseMask, closeMask); } protected override void RemoveListener() { GameDispatcher.Instance.RemoveListener(GameMsg.UpdateHotFixMax, OnUpdateHotFixMax); GameDispatcher.Instance.RemoveListener(GameMsg.UpdateHotFixProgress, OnUpdateHotFixProgress); GameDispatcher.Instance.RemoveListener(GameMsg.Network_reconnection, Reconnection); GameDispatcher.Instance.RemoveListener(GameMsg.CloseMask, closeMask); } #endregion private void closeMask(object a = null) { ui.com_pb.visible = true; OnUpdateHotFixProgress(97); } private bool isAgree = true; public void CheckAgree() { if (!isAgree) return; ctrl.CloseUI(); } private void OnUpdateHotFixMax(object obj) { if (obj != null) { var max = (int)obj; } } private void OnUpdateHotFixProgress(object obj) { if (loading) return; if (obj != null) { loading = true; tweener.Kill(); var value = (int)obj; tweener = DOTween.To(() => ui.com_pb.value, x => ui.com_pb.value = x, value, 12f) .OnUpdate(() => { ui.com_pb.title.text = (int)(ui.com_pb.value) + "%"; }); } } } }