mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-07 16:45:10 +00:00
新增GetUIAsync,ShowUIAsyncAwait
新增GetUIAsync,ShowUIAsyncAwait
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using Cysharp.Threading.Tasks;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
using YooAsset;
|
using YooAsset;
|
||||||
@@ -267,6 +268,16 @@ namespace TEngine
|
|||||||
{
|
{
|
||||||
ShowUIImp(typeof(T), false, userDatas);
|
ShowUIImp(typeof(T), false, userDatas);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 异步打开窗口。
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="userDatas">用户自定义数据。</param>
|
||||||
|
/// <returns>打开窗口操作句柄。</returns>
|
||||||
|
public async UniTask<UIWindow> ShowUIAsyncAwait<T>(params System.Object[] userDatas) where T : UIWindow
|
||||||
|
{
|
||||||
|
return await ShowUIAwaitImp(typeof(T), true, userDatas);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 同步打开窗口。
|
/// 同步打开窗口。
|
||||||
@@ -298,6 +309,38 @@ namespace TEngine
|
|||||||
window.InternalLoad(window.AssetName, OnWindowPrepare, isAsync, userDatas).Forget();
|
window.InternalLoad(window.AssetName, OnWindowPrepare, isAsync, userDatas).Forget();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async UniTask<UIWindow> ShowUIAwaitImp(Type type, bool isAsync, params System.Object[] userDatas)
|
||||||
|
{
|
||||||
|
string windowName = type.FullName;
|
||||||
|
|
||||||
|
// 如果窗口已经存在
|
||||||
|
if (IsContains(windowName))
|
||||||
|
{
|
||||||
|
UIWindow window = GetWindow(windowName);
|
||||||
|
Pop(window); //弹出窗口
|
||||||
|
Push(window); //重新压入
|
||||||
|
window.TryInvoke(OnWindowPrepare, userDatas);
|
||||||
|
return window;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
UIWindow window = CreateInstance(type);
|
||||||
|
Push(window); //首次压入
|
||||||
|
window.InternalLoad(window.AssetName, OnWindowPrepare, isAsync, userDatas).Forget();
|
||||||
|
float time = 0f;
|
||||||
|
while (!window.IsLoadDone)
|
||||||
|
{
|
||||||
|
time += Time.time;
|
||||||
|
if (time > 60f)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
await UniTask.Yield();
|
||||||
|
}
|
||||||
|
return window;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 关闭窗口
|
/// 关闭窗口
|
||||||
@@ -459,6 +502,88 @@ namespace TEngine
|
|||||||
|
|
||||||
return window;
|
return window;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 异步获取窗口。
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>打开窗口操作句柄。</returns>
|
||||||
|
public async UniTask<T> GetUIAsyncAwait<T>() where T : UIWindow
|
||||||
|
{
|
||||||
|
string windowName = typeof(T).FullName;
|
||||||
|
var window = GetWindow(windowName);
|
||||||
|
if (window == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
var ret = window as T;
|
||||||
|
|
||||||
|
if (ret == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ret.IsLoadDone)
|
||||||
|
{
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
float time = 0f;
|
||||||
|
while (!ret.IsLoadDone)
|
||||||
|
{
|
||||||
|
time += Time.time;
|
||||||
|
if (time > 60f)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
await UniTask.Yield();
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 异步获取窗口。
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="callback">回调。</param>
|
||||||
|
/// <returns>打开窗口操作句柄。</returns>
|
||||||
|
public void GetUIAsync<T>(Action<T> callback) where T : UIWindow
|
||||||
|
{
|
||||||
|
string windowName = typeof(T).FullName;
|
||||||
|
var window = GetWindow(windowName);
|
||||||
|
if (window == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var ret = window as T;
|
||||||
|
|
||||||
|
if (ret == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ret.IsLoadDone)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
GetUIAsyncImp(callback).Forget();
|
||||||
|
|
||||||
|
async UniTaskVoid GetUIAsyncImp(Action<T> ctx)
|
||||||
|
{
|
||||||
|
float time = 0f;
|
||||||
|
while (!ret.IsLoadDone)
|
||||||
|
{
|
||||||
|
time += Time.time;
|
||||||
|
if (time > 60f)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
await UniTask.Yield();
|
||||||
|
}
|
||||||
|
ctx?.Invoke(ret);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private UIWindow GetWindow(string windowName)
|
private UIWindow GetWindow(string windowName)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user