备份CatanBuilding瘦身独立工程
This commit is contained in:
151
Assets/Scripts/UI/DownLoad/DownLoadPopupPanel.cs
Normal file
151
Assets/Scripts/UI/DownLoad/DownLoadPopupPanel.cs
Normal file
@@ -0,0 +1,151 @@
|
||||
using asap.core;
|
||||
using GameCore;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using UniRx;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class DownLoadPopupPanel : MonoBehaviour
|
||||
{
|
||||
Animator ani;
|
||||
Button btn_close;
|
||||
ILoadResourceService loadResourceService;
|
||||
Image bar;
|
||||
GameObject bg_bar;
|
||||
public Action OnConfrim;
|
||||
public Action OnCloseClick;
|
||||
IDisposable load;
|
||||
float progress = 0;
|
||||
GameObject root;
|
||||
public int showTime = 3;
|
||||
private void Awake()
|
||||
{
|
||||
root = transform.Find("root").gameObject;
|
||||
ani = GetComponent<Animator>();
|
||||
ani.Play("popup_common_show", 0, 0);
|
||||
ani.speed = 0;
|
||||
root.SetActive(false);
|
||||
loadResourceService = GContext.container.Resolve<ILoadResourceService>();
|
||||
btn_close = transform.Find("root/btn_close").GetComponent<Button>();
|
||||
bar = transform.Find("root/mask_bg2/root/bg_bar/bar").GetComponent<Image>();
|
||||
bg_bar = transform.Find("root/mask_bg2/root/bg_bar").gameObject;
|
||||
}
|
||||
|
||||
public void Start()
|
||||
{
|
||||
btn_close.onClick.AddListener(OnClickClose);
|
||||
}
|
||||
/// <summary>
|
||||
/// 下载资源 时的按钮回调 OnConfrim 如果没有Act的切换 需要退场
|
||||
/// </summary>
|
||||
/// <param name="OnConfrim"></param>
|
||||
/// <param name="OnCloseClick"></param>
|
||||
public void SetBtn(Action OnConfrim, Action OnCloseClick)
|
||||
{
|
||||
this.OnConfrim = OnConfrim;
|
||||
this.OnCloseClick = OnCloseClick;
|
||||
StartCoroutine(StartShowBar());
|
||||
StartCoroutine(StartShowPanel());
|
||||
}
|
||||
IEnumerator StartShowPanel()
|
||||
{
|
||||
yield return new WaitForSeconds(showTime);
|
||||
ani.speed = 1;
|
||||
root.SetActive(true);
|
||||
}
|
||||
IEnumerator StartShowBar()
|
||||
{
|
||||
yield return new WaitForSeconds(0.5f);
|
||||
Init();
|
||||
}
|
||||
async void Init()
|
||||
{
|
||||
if (string.IsNullOrEmpty(loadResourceService.curName))
|
||||
{
|
||||
Debug.LogError("当前没有需要下载的资源; 请检查是否已下载 或 使用 loadResourceService.Load 或 .Loads 下载资源");
|
||||
return;
|
||||
}
|
||||
bool isCanEnter = await loadResourceService.Load(loadResourceService.curName);
|
||||
//text_info.text = LocalizationMgr.GetFormatTextValue("UI_FishingDownLoadPopupPanel_1", 0);
|
||||
if (OnConfrim == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
progress = 0;
|
||||
if (isCanEnter)
|
||||
{
|
||||
bar.fillAmount = 1;
|
||||
OnClickConfrim();
|
||||
}
|
||||
else
|
||||
{
|
||||
btn_close.gameObject.SetActive(true);
|
||||
bg_bar.SetActive(true);
|
||||
bar.fillAmount = 0;
|
||||
load = GContext.OnEvent<LoadProgressEvent>().Subscribe(OnLoadProgress);
|
||||
}
|
||||
}
|
||||
|
||||
void OnClickClose()
|
||||
{
|
||||
EndLoad();
|
||||
OnConfrim = null;
|
||||
if (OnCloseClick != null)
|
||||
{
|
||||
OnCloseClick?.Invoke();
|
||||
OnCloseClick = null;
|
||||
}
|
||||
UIManager.Instance.DestroyUI(UITypes.DownLoadPopupPanel);
|
||||
}
|
||||
//private const long byte2mb = 1024 * 1024;
|
||||
void OnLoadProgress(LoadProgressEvent e)
|
||||
{
|
||||
if (e.name == loadResourceService.curName)
|
||||
{
|
||||
if (progress < e.progress)
|
||||
{
|
||||
progress = e.progress;
|
||||
bar.fillAmount = progress;
|
||||
}
|
||||
|
||||
if (e.isSucceeded)
|
||||
{
|
||||
OnClickConfrim();
|
||||
}
|
||||
else if (e.isFailed)
|
||||
{
|
||||
OnClickClose();
|
||||
}
|
||||
}
|
||||
}
|
||||
async void OnClickConfrim()
|
||||
{
|
||||
EndLoad();
|
||||
await Awaiters.NextFrame;
|
||||
OnConfrim?.Invoke();
|
||||
OnConfrim = null;
|
||||
OnCloseClick = null;
|
||||
await Awaiters.NextFrame;
|
||||
UIManager.Instance.DestroyUI(UITypes.DownLoadPopupPanel);
|
||||
}
|
||||
void EndLoad()
|
||||
{
|
||||
load?.Dispose();
|
||||
load = null;
|
||||
btn_close.onClick.RemoveAllListeners();
|
||||
btn_close.gameObject.SetActive(false);
|
||||
bg_bar.SetActive(false);
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
Dispose();
|
||||
}
|
||||
|
||||
void Dispose()
|
||||
{
|
||||
load?.Dispose();
|
||||
load = null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user