备份CatanBuilding瘦身独立工程
This commit is contained in:
10
Assets/Scripts/UI/DownLoad/BgDownload.cs
Normal file
10
Assets/Scripts/UI/DownLoad/BgDownload.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class BgDownload : MonoBehaviour
|
||||
{
|
||||
public Animation ani;
|
||||
public void OnLoadSucceed()
|
||||
{
|
||||
ani.Play();
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/UI/DownLoad/BgDownload.cs.meta
Normal file
11
Assets/Scripts/UI/DownLoad/BgDownload.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fcad58631a627304f895eff987c36d9b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
204
Assets/Scripts/UI/DownLoad/CloudTransitionPanel.cs
Normal file
204
Assets/Scripts/UI/DownLoad/CloudTransitionPanel.cs
Normal file
@@ -0,0 +1,204 @@
|
||||
using asap.core;
|
||||
using GameCore;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using UniRx;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
public class EndTransition
|
||||
{
|
||||
}
|
||||
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;
|
||||
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 需要手动调用 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, string curName = "")
|
||||
{
|
||||
this.externalClose = externalClose;
|
||||
this.OnConfrim = OnConfrim;
|
||||
this.OnCloseClick = OnCloseClick;
|
||||
this.curName = 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;
|
||||
}
|
||||
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);
|
||||
}
|
||||
void Dispose()
|
||||
{
|
||||
load?.Dispose();
|
||||
load = null;
|
||||
disposable?.Dispose();
|
||||
disposable = null;
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/UI/DownLoad/CloudTransitionPanel.cs.meta
Normal file
11
Assets/Scripts/UI/DownLoad/CloudTransitionPanel.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6c903e17e7b5dc449a842b92af9f55a8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
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;
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/UI/DownLoad/DownLoadPopupPanel.cs.meta
Normal file
11
Assets/Scripts/UI/DownLoad/DownLoadPopupPanel.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 89d5e0f18b473b946baca6594b46b2a8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user