先修复一下,错误的场景 删除不必要的钓场资产 修复into场景 update:更新meta文件,修复报错 update:修复资源 修复第一章节建造 修复建造第三章 update:删除多余内容 update:更新README.md update:还原图标 update:更新README update:更新配置
222 lines
6.2 KiB
C#
222 lines
6.2 KiB
C#
using asap.core;
|
|
using GameCore;
|
|
using System;
|
|
using System.Collections;
|
|
using UniRx;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
/// <summary>
|
|
/// 转场结束事件,用于播放关闭转场动画
|
|
/// </summary>
|
|
public class EndTransition
|
|
{
|
|
}
|
|
/// <summary>
|
|
/// 转场结束后事件,用于通知外部转场关闭动画已结束
|
|
/// </summary>
|
|
public class OnTransitioned
|
|
{
|
|
}
|
|
public class CloudTransitionPanel : MonoBehaviour
|
|
{
|
|
Animation ani;
|
|
IDisposable disposable;
|
|
|
|
Button btn_close;
|
|
ILoadResourceService loadResourceService;
|
|
Image bar;
|
|
GameObject bg_bar;
|
|
//TMP_Text text_info;
|
|
public Action OnConfrim;
|
|
public Action OnCloseClick;
|
|
bool externalClose;
|
|
bool failedClose;
|
|
IDisposable load;
|
|
float progress = 0;
|
|
string curName;
|
|
int showCount = 0;
|
|
private void Awake()
|
|
{
|
|
ani = GetComponent<Animation>();
|
|
disposable = GContext.OnEvent<EndTransition>().Subscribe(EndTransition);
|
|
|
|
loadResourceService = GContext.container.Resolve<ILoadResourceService>();
|
|
btn_close = transform.Find("btn_close").GetComponent<Button>();
|
|
bar = transform.Find("root/bg_bar/bar").GetComponent<Image>();
|
|
bg_bar = transform.Find("root/bg_bar").gameObject;
|
|
//text_info = transform.Find("root/text_info").GetComponent<TMP_Text>();
|
|
}
|
|
|
|
public void Start()
|
|
{
|
|
btn_close.onClick.AddListener(OnClickClose);
|
|
}
|
|
/// <summary>
|
|
/// externalClose == true (下载成功不自动关闭界面)
|
|
/// failedClose == false (下载失败不自动关闭界面,建造成败都需要转场)
|
|
/// 需要手动调用 EndTransition 关闭面板;
|
|
/// 如果紧接着 changeAct 会在OnActLoaded 里调用 EndTransition
|
|
/// </summary>
|
|
/// <param name="OnConfrim"></param>
|
|
/// <param name="OnCloseClick"></param>
|
|
/// <param name="curName"> 需要检查的资源进度 默认 loadResourceService.curName</param>
|
|
public void SetBtn(bool externalClose, Action OnConfrim, Action OnCloseClick = null, bool failedClose = true)
|
|
{
|
|
this.externalClose = externalClose;
|
|
this.failedClose = failedClose;
|
|
this.OnConfrim = OnConfrim;
|
|
this.OnCloseClick = OnCloseClick;
|
|
this.curName = "";
|
|
if (!externalClose)
|
|
{
|
|
showCount++;
|
|
}
|
|
StartCoroutine(StartShowBar());
|
|
}
|
|
IEnumerator StartShowBar()
|
|
{
|
|
yield return new WaitForSeconds(0.5f);
|
|
ShowLoad();
|
|
}
|
|
void ShowLoad()
|
|
{
|
|
if (string.IsNullOrEmpty(curName))
|
|
{
|
|
if (string.IsNullOrEmpty(loadResourceService.oldName))
|
|
{
|
|
Debug.LogError("当前没有需要下载的资源; 请使用 loadResourceService.Load 或 .Loads 下载资源");
|
|
StartCoroutine(End());
|
|
return;
|
|
}
|
|
if (string.IsNullOrEmpty(loadResourceService.curName))
|
|
{
|
|
curName = loadResourceService.oldName;
|
|
Debug.LogWarning("当前没有需要下载的资源; 传入 curName 检查是否已下载");
|
|
}
|
|
else
|
|
{
|
|
curName = loadResourceService.curName;
|
|
}
|
|
}
|
|
Init();
|
|
}
|
|
async void Init()
|
|
{
|
|
bool isCanEnter = await loadResourceService.Load(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();
|
|
showCount--;
|
|
OnConfrim = null;
|
|
if (OnCloseClick != null)
|
|
{
|
|
OnCloseClick?.Invoke();
|
|
OnCloseClick = null;
|
|
}
|
|
if (failedClose)
|
|
{
|
|
StartCoroutine(End());
|
|
}
|
|
}
|
|
//private const long byte2mb = 1024 * 1024;
|
|
void OnLoadProgress(LoadProgressEvent e)
|
|
{
|
|
if (e.name == loadResourceService.curName)
|
|
{
|
|
//float progress = e.progress;
|
|
//if (progress > 1)
|
|
//{
|
|
// progress = 1;
|
|
//}
|
|
//var progressStr = $"\n{(progress * e.totalDownloadSize / byte2mb).ToString("0.0")}MB/{(e.totalDownloadSize / byte2mb).ToString("0.0")}MB ({progress.ToPercentageString()})";
|
|
//text_info.text = LocalizationMgr.GetFormatTextValue("UI_FishingDownLoadPopupPanel_1", progressStr);
|
|
if (progress < e.progress)
|
|
{
|
|
progress = e.progress;
|
|
bar.fillAmount = progress;
|
|
}
|
|
|
|
if (e.isSucceeded)
|
|
{
|
|
OnClickConfrim();
|
|
}
|
|
else if (e.isFailed)
|
|
{
|
|
OnClickClose();
|
|
}
|
|
}
|
|
}
|
|
async void OnClickConfrim()
|
|
{
|
|
EndLoad();
|
|
if (!externalClose)
|
|
{
|
|
externalClose = true;
|
|
_ = StartCoroutine(End());
|
|
}
|
|
await Awaiters.NextFrame;
|
|
showCount--;
|
|
OnConfrim?.Invoke();
|
|
OnConfrim = null;
|
|
OnCloseClick = null;
|
|
}
|
|
void EndLoad()
|
|
{
|
|
load?.Dispose();
|
|
load = null;
|
|
btn_close.onClick.RemoveAllListeners();
|
|
btn_close.gameObject.SetActive(false);
|
|
bg_bar.SetActive(false);
|
|
}
|
|
public void EndTransition(EndTransition endTransition)
|
|
{
|
|
if (showCount <= 0)
|
|
{
|
|
EndLoad();
|
|
showCount--;
|
|
OnConfrim = null;
|
|
OnCloseClick = null;
|
|
StartCoroutine(End());
|
|
}
|
|
}
|
|
private void OnDisable()
|
|
{
|
|
Dispose();
|
|
}
|
|
IEnumerator End()
|
|
{
|
|
ani.Play("cloud_out");
|
|
Dispose();
|
|
yield return new WaitForSeconds(0.6f);
|
|
UIManager.Instance.DestroyUI(gameObject.name);
|
|
GContext.Publish(new OnTransitioned());
|
|
}
|
|
void Dispose()
|
|
{
|
|
load?.Dispose();
|
|
load = null;
|
|
disposable?.Dispose();
|
|
disposable = null;
|
|
}
|
|
}
|