继续重构调整(UI)

- 引入 UniTask 和异步版本的 UIModule
- 调整 Runtime/UIBase 和 Presentation 下的脚本命名空间到 SepCore.UI
- 将原来的 5 层 UI 迁移到异步实现
- 规范各层的 UI 脚本命名
This commit is contained in:
SepComet
2026-06-03 09:58:37 +08:00
parent 6b8a6a8789
commit 7bba8bbb80
552 changed files with 83648 additions and 2726 deletions
@@ -0,0 +1,127 @@
using System;
using System.Threading;
using Cysharp.Threading.Tasks;
using GameFramework.Event;
namespace UnityGameFramework.Runtime.AsyncTask
{
/// <summary>
/// 异步任务辅助类,用于将事件回调转换为 UniTask
/// </summary>
public static class AsyncTaskHelper
{
/// <summary>
/// 等待指定事件触发
/// </summary>
/// <typeparam name="T">事件参数类型</typeparam>
/// <param name="eventId">事件ID</param>
/// <param name="predicate">事件过滤条件</param>
/// <param name="timeout">超时时间(秒),0表示不超时</param>
/// <returns>事件参数</returns>
public static UniTask<T> WaitEventAsync<T>(int eventId, Func<T, bool> predicate = null, float timeout = 0f) where T : GameEventArgs
{
var tcs = new UniTaskCompletionSource<T>();
var eventComponent = global::GameEntry.Event;
EventHandler<GameEventArgs> handler = null;
handler = (_, e) =>
{
var args = e as T;
if (args == null) return;
if (predicate != null && !predicate(args)) return;
eventComponent.Unsubscribe(eventId, handler);
tcs.TrySetResult(args);
};
eventComponent.Subscribe(eventId, handler);
// 超时处理
if (timeout > 0f)
{
UniTask.Delay(TimeSpan.FromSeconds(timeout), cancellationToken: CancellationToken.None)
.ContinueWith(() =>
{
if (tcs.TrySetException(new TimeoutException($"等待事件超时: {timeout}秒")))
{
eventComponent.Unsubscribe(eventId, handler);
}
});
}
return tcs.Task;
}
/// <summary>
/// 等待成功或失败事件
/// </summary>
/// <typeparam name="TSuccess">成功事件参数类型</typeparam>
/// <typeparam name="TFailure">失败事件参数类型</typeparam>
/// <param name="successEventId">成功事件ID</param>
/// <param name="failureEventId">失败事件ID</param>
/// <param name="successPredicate">成功事件过滤条件</param>
/// <param name="failurePredicate">失败事件过滤条件</param>
/// <param name="timeout">超时时间(秒),0表示不超时</param>
/// <returns>成功事件参数</returns>
public static UniTask<TSuccess> WaitSuccessOrFailureAsync<TSuccess, TFailure>(
int successEventId,
int failureEventId,
Func<TSuccess, bool> successPredicate = null,
Func<TFailure, bool> failurePredicate = null,
float timeout = 0f)
where TSuccess : GameEventArgs
where TFailure : GameEventArgs
{
var tcs = new UniTaskCompletionSource<TSuccess>();
var eventComponent = global::GameEntry.Event;
// 先声明两个 handler,再赋值 lambda,避免前向引用
EventHandler<GameEventArgs> successHandler = null;
EventHandler<GameEventArgs> failureHandler = null;
successHandler = (_, e) =>
{
var args = e as TSuccess;
if (args == null) return;
if (successPredicate != null && !successPredicate(args)) return;
eventComponent.Unsubscribe(successEventId, successHandler);
eventComponent.Unsubscribe(failureEventId, failureHandler);
tcs.TrySetResult(args);
};
failureHandler = (_, e) =>
{
var args = e as TFailure;
if (args == null) return;
if (failurePredicate != null && !failurePredicate(args)) return;
eventComponent.Unsubscribe(successEventId, successHandler);
eventComponent.Unsubscribe(failureEventId, failureHandler);
tcs.TrySetException(new Exception($"操作失败: {args}"));
};
eventComponent.Subscribe(successEventId, successHandler);
eventComponent.Subscribe(failureEventId, failureHandler);
// 超时处理
if (timeout > 0f)
{
UniTask.Delay(TimeSpan.FromSeconds(timeout), cancellationToken: CancellationToken.None)
.ContinueWith(() =>
{
if (tcs.TrySetException(new TimeoutException($"等待事件超时: {timeout}秒")))
{
eventComponent.Unsubscribe(successEventId, successHandler);
eventComponent.Unsubscribe(failureEventId, failureHandler);
}
});
}
return tcs.Task;
}
}
}
@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 7e46538e3d51b6b4ca463fa6080ad335
guid: 2a0640fd52beabf479281c111c9e861f
MonoImporter:
externalObjects: {}
serializedVersion: 2
@@ -1,18 +1,10 @@
//------------------------------------------------------------
// Game Framework
// Copyright © 2013-2021 Jiang Yin. All rights reserved.
// Homepage: https://gameframework.cn/
// Feedback: mailto:ellan@gameframework.cn
//------------------------------------------------------------
using UnityEngine;
using UnityGameFramework.Runtime;
using UnityGameFramework.Runtime;
/// <summary>
/// 游戏入口。
/// </summary>
public partial class GameEntry : MonoBehaviour
public partial class GameEntry
{
/// <summary>
/// 获取游戏基础组件。
@@ -137,4 +129,4 @@ public partial class GameEntry : MonoBehaviour
UI = UnityGameFramework.Runtime.GameEntry.GetComponent<UIComponent>();
WebRequest = UnityGameFramework.Runtime.GameEntry.GetComponent<WebRequestComponent>();
}
}
}
@@ -1,11 +1,12 @@
using CustomComponent;
using SepCore.CustomComponent;
using Simulation;
using UnityEngine;
/// <summary>
/// 游戏入口。
/// </summary>
public partial class GameEntry : MonoBehaviour
public partial class GameEntry
{
public static BuiltinDataComponent BuiltinData { get; private set; }
@@ -1,11 +1,4 @@
//------------------------------------------------------------
// Game Framework
// Copyright © 2013-2021 Jiang Yin. All rights reserved.
// Homepage: https://gameframework.cn/
// Feedback: mailto:ellan@gameframework.cn
//------------------------------------------------------------
using UnityEngine;
using UnityEngine;
/// <summary>
/// 游戏入口。
@@ -17,4 +10,4 @@ public partial class GameEntry : MonoBehaviour
InitBuiltinComponents();
InitCustomComponents();
}
}
}
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 207c87580b7a7a44384221e758baac1c
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,64 @@
using System;
using Cysharp.Threading.Tasks;
using GameFramework;
using GameFramework.Config;
using UnityGameFramework.Runtime;
namespace UnityGameFramework.Runtime.AsyncTask
{
/// <summary>
/// Config 异步扩展方法
/// </summary>
public static class ConfigAsyncExtension
{
/// <summary>
/// 异步加载配置
/// </summary>
/// <param name="configComponent">配置组件</param>
/// <param name="configAssetName">配置资源名称</param>
/// <param name="userData">用户自定义数据</param>
/// <param name="timeout">超时时间(秒),0表示不超时</param>
/// <returns>加载成功事件</returns>
public static UniTask<LoadConfigSuccessEventArgs> LoadConfigAsync(this ConfigComponent configComponent,
string configAssetName,
object userData = null,
float timeout = 30f)
{
UniTask<LoadConfigSuccessEventArgs> waitTask = AsyncTaskHelper.WaitSuccessOrFailureAsync<LoadConfigSuccessEventArgs, LoadConfigFailureEventArgs>(
LoadConfigSuccessEventArgs.EventId,
LoadConfigFailureEventArgs.EventId,
successArgs => successArgs.ConfigAssetName == configAssetName && ReferenceEquals(successArgs.UserData, userData),
failureArgs => failureArgs.ConfigAssetName == configAssetName && ReferenceEquals(failureArgs.UserData, userData),
timeout
);
configComponent.ReadData(configAssetName, userData);
return waitTask;
}
/// <summary>
/// 异步加载配置(通过字典加载)
/// </summary>
/// <param name="configComponent">配置组件</param>
/// <param name="dictionaryName">字典名称</param>
/// <param name="userData">用户自定义数据</param>
/// <param name="timeout">超时时间(秒),0表示不超时</param>
/// <returns>加载成功事件</returns>
public static UniTask<LoadConfigSuccessEventArgs> LoadConfigFromDictionaryAsync(this ConfigComponent configComponent,
string dictionaryName,
object userData = null,
float timeout = 30f)
{
UniTask<LoadConfigSuccessEventArgs> waitTask = AsyncTaskHelper.WaitSuccessOrFailureAsync<LoadConfigSuccessEventArgs, LoadConfigFailureEventArgs>(
LoadConfigSuccessEventArgs.EventId,
LoadConfigFailureEventArgs.EventId,
successArgs => successArgs.ConfigAssetName == dictionaryName && ReferenceEquals(successArgs.UserData, userData),
failureArgs => failureArgs.ConfigAssetName == dictionaryName && ReferenceEquals(failureArgs.UserData, userData),
timeout
);
configComponent.ReadData(dictionaryName, userData);
return waitTask;
}
}
}
@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 692b282b1ecbf5a44839d5bf4a03a937
guid: c268d17be2de9c242939823c820012e4
MonoImporter:
externalObjects: {}
serializedVersion: 2
@@ -0,0 +1,64 @@
using System;
using Cysharp.Threading.Tasks;
using GameFramework;
using GameFramework.DataTable;
using SepCore.DataTable;
using UnityGameFramework.Runtime;
namespace UnityGameFramework.Runtime.AsyncTask
{
/// <summary>
/// DataTable 异步扩展方法
/// </summary>
public static class DataTableAsyncExtension
{
/// <summary>
/// 异步加载数据表
/// </summary>
/// <param name="dataTableComponent">数据表组件</param>
/// <param name="dataTableAssetName">数据表资源名称</param>
/// <param name="userData">用户自定义数据</param>
/// <param name="timeout">超时时间(秒),0表示不超时</param>
/// <returns>加载成功事件</returns>
public static UniTask<LoadDataTableSuccessEventArgs> LoadDataTableAsync(this DataTableComponent dataTableComponent,
string dataTableAssetName,
object userData = null,
float timeout = 30f)
{
UniTask<LoadDataTableSuccessEventArgs> waitTask = AsyncTaskHelper.WaitSuccessOrFailureAsync<LoadDataTableSuccessEventArgs, LoadDataTableFailureEventArgs>(
LoadDataTableSuccessEventArgs.EventId,
LoadDataTableFailureEventArgs.EventId,
successArgs => successArgs.DataTableAssetName == dataTableAssetName && ReferenceEquals(successArgs.UserData, userData),
failureArgs => failureArgs.DataTableAssetName == dataTableAssetName && ReferenceEquals(failureArgs.UserData, userData),
timeout
);
string dataTableName = System.IO.Path.GetFileNameWithoutExtension(dataTableAssetName);
dataTableComponent.LoadDataTable(dataTableName, dataTableAssetName, userData);
return waitTask;
}
/// <summary>
/// 异步加载数据表(泛型版本)
/// </summary>
/// <typeparam name="T">数据行类型</typeparam>
/// <param name="dataTableComponent">数据表组件</param>
/// <param name="dataTableAssetName">数据表资源名称</param>
/// <param name="userData">用户自定义数据</param>
/// <param name="timeout">超时时间(秒),0表示不超时</param>
/// <returns>加载的数据表</returns>
public static UniTask<IDataTable<T>> LoadDataTableAsync<T>(this DataTableComponent dataTableComponent,
string dataTableAssetName,
object userData = null,
float timeout = 30f) where T : IDataRow
{
return LoadDataTableAsync(dataTableComponent, dataTableAssetName, userData, timeout)
.ContinueWith(successArgs =>
{
// 获取数据表名称(去掉路径和扩展名)
string dataTableName = System.IO.Path.GetFileNameWithoutExtension(dataTableAssetName);
return dataTableComponent.GetDataTable<T>(dataTableName);
});
}
}
}
@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: e8bc5e59a2be3094798c8c46d1a4999f
guid: fd425f3318ddacb44a9c9468dcd434bf
MonoImporter:
externalObjects: {}
serializedVersion: 2
@@ -0,0 +1,58 @@
using System;
using Cysharp.Threading.Tasks;
using GameFramework;
using GameFramework.Download;
using UnityGameFramework.Runtime;
namespace UnityGameFramework.Runtime.AsyncTask
{
/// <summary>
/// Download 异步扩展方法
/// </summary>
public static class DownloadAsyncExtension
{
/// <summary>
/// 异步下载文件
/// </summary>
/// <param name="downloadComponent">下载组件</param>
/// <param name="downloadUri">下载地址</param>
/// <param name="downloadPath">下载后存放路径</param>
/// <param name="userData">用户自定义数据</param>
/// <param name="timeout">超时时间(秒),0表示不超时</param>
/// <returns>下载成功事件</returns>
public static UniTask<DownloadSuccessEventArgs> DownloadFileAsync(this DownloadComponent downloadComponent,
string downloadUri,
string downloadPath,
object userData = null,
float timeout = 300f)
{
int serialId = 0;
UniTask<DownloadSuccessEventArgs> waitTask = AsyncTaskHelper.WaitSuccessOrFailureAsync<DownloadSuccessEventArgs, DownloadFailureEventArgs>(
DownloadSuccessEventArgs.EventId,
DownloadFailureEventArgs.EventId,
successArgs => successArgs.SerialId == serialId,
failureArgs => failureArgs.SerialId == serialId,
timeout
);
serialId = downloadComponent.AddDownload(downloadPath, downloadUri, userData);
return waitTask;
}
/// <summary>
/// 异步下载文件(简化版本)
/// </summary>
/// <param name="downloadComponent">下载组件</param>
/// <param name="downloadUri">下载地址</param>
/// <param name="downloadPath">下载后存放路径</param>
/// <param name="timeout">超时时间(秒),0表示不超时</param>
/// <returns>下载成功事件</returns>
public static UniTask<DownloadSuccessEventArgs> DownloadFileAsync(this DownloadComponent downloadComponent,
string downloadUri,
string downloadPath,
float timeout = 300f)
{
return DownloadFileAsync(downloadComponent, downloadUri, downloadPath, null, timeout);
}
}
}
@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 696c0314286f89c4082c2aa2eddaec2d
guid: cfc5e4ff432a8564a99f65529449b370
MonoImporter:
externalObjects: {}
serializedVersion: 2
@@ -0,0 +1,114 @@
using System;
using Cysharp.Threading.Tasks;
using GameFramework;
using GameFramework.Entity;
using UnityGameFramework.Runtime;
namespace UnityGameFramework.Runtime.AsyncTask
{
/// <summary>
/// Entity 异步扩展方法
/// </summary>
public static class EntityAsyncExtension
{
/// <summary>
/// 异步显示实体
/// </summary>
/// <param name="entityComponent">实体组件</param>
/// <param name="entityId">实体编号</param>
/// <param name="entityLogicType">实体逻辑类型</param>
/// <param name="entityAssetName">实体资源名称</param>
/// <param name="entityGroupName">实体组名称</param>
/// <param name="userData">用户自定义数据</param>
/// <param name="timeout">超时时间(秒),0表示不超时</param>
/// <returns>显示的实体</returns>
public static UniTask<Entity> ShowEntityAsync(this EntityComponent entityComponent,
int entityId,
Type entityLogicType,
string entityAssetName,
string entityGroupName,
object userData = null,
float timeout = 30f)
{
UniTask<Entity> waitTask = AsyncTaskHelper.WaitSuccessOrFailureAsync<ShowEntitySuccessEventArgs, ShowEntityFailureEventArgs>(
ShowEntitySuccessEventArgs.EventId,
ShowEntityFailureEventArgs.EventId,
successArgs => successArgs.Entity.Id == entityId && ReferenceEquals(successArgs.UserData, userData),
failureArgs => failureArgs.EntityId == entityId && ReferenceEquals(failureArgs.UserData, userData),
timeout
).ContinueWith(successArgs => successArgs.Entity);
entityComponent.ShowEntity(entityId, entityLogicType, entityAssetName, entityGroupName, userData);
return waitTask;
}
/// <summary>
/// 异步显示实体(泛型版本)
/// </summary>
/// <typeparam name="T">实体逻辑类型</typeparam>
/// <param name="entityComponent">实体组件</param>
/// <param name="entityId">实体编号</param>
/// <param name="entityAssetName">实体资源名称</param>
/// <param name="entityGroupName">实体组名称</param>
/// <param name="userData">用户自定义数据</param>
/// <param name="timeout">超时时间(秒),0表示不超时</param>
/// <returns>显示的实体</returns>
public static UniTask<T> ShowEntityAsync<T>(this EntityComponent entityComponent,
int entityId,
string entityAssetName,
string entityGroupName,
object userData = null,
float timeout = 30f) where T : EntityLogic
{
UniTask<T> waitTask = AsyncTaskHelper.WaitSuccessOrFailureAsync<ShowEntitySuccessEventArgs, ShowEntityFailureEventArgs>(
ShowEntitySuccessEventArgs.EventId,
ShowEntityFailureEventArgs.EventId,
successArgs => successArgs.Entity.Id == entityId && ReferenceEquals(successArgs.UserData, userData),
failureArgs => failureArgs.EntityId == entityId && ReferenceEquals(failureArgs.UserData, userData),
timeout
).ContinueWith(successArgs => (T)successArgs.Entity.Logic);
entityComponent.ShowEntity<T>(entityId, entityAssetName, entityGroupName, userData);
return waitTask;
}
/// <summary>
/// 异步隐藏实体
/// </summary>
/// <param name="entityComponent">实体组件</param>
/// <param name="entityId">实体编号</param>
/// <param name="userData">用户自定义数据</param>
/// <param name="timeout">超时时间(秒),0表示不超时</param>
/// <returns>隐藏完成事件</returns>
public static UniTask<HideEntityCompleteEventArgs> HideEntityAsync(this EntityComponent entityComponent,
int entityId,
object userData = null,
float timeout = 30f)
{
UniTask<HideEntityCompleteEventArgs> waitTask = AsyncTaskHelper.WaitEventAsync<HideEntityCompleteEventArgs>(
HideEntityCompleteEventArgs.EventId,
args => args.EntityId == entityId,
timeout
);
entityComponent.HideEntity(entityId, userData);
return waitTask;
}
/// <summary>
/// 异步隐藏实体(通过实体对象)
/// </summary>
/// <param name="entityComponent">实体组件</param>
/// <param name="entity">要隐藏的实体</param>
/// <param name="userData">用户自定义数据</param>
/// <param name="timeout">超时时间(秒),0表示不超时</param>
/// <returns>隐藏完成事件</returns>
public static UniTask<HideEntityCompleteEventArgs> HideEntityAsync(this EntityComponent entityComponent,
Entity entity,
object userData = null,
float timeout = 30f)
{
return HideEntityAsync(entityComponent, entity.Id, userData, timeout);
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 0049c1a3ff0446246b18d6b2ab0f29c6
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,39 @@
using System;
using Cysharp.Threading.Tasks;
using GameFramework;
using GameFramework.Localization;
using UnityGameFramework.Runtime;
namespace UnityGameFramework.Runtime.AsyncTask
{
/// <summary>
/// Localization 异步扩展方法
/// </summary>
public static class LocalizationAsyncExtension
{
/// <summary>
/// 异步加载字典
/// </summary>
/// <param name="localizationComponent">本地化组件</param>
/// <param name="dictionaryAssetName">字典资源名称</param>
/// <param name="userData">用户自定义数据</param>
/// <param name="timeout">超时时间(秒),0表示不超时</param>
/// <returns>加载成功事件</returns>
public static UniTask<LoadDictionarySuccessEventArgs> LoadDictionaryAsync(this LocalizationComponent localizationComponent,
string dictionaryAssetName,
object userData = null,
float timeout = 30f)
{
UniTask<LoadDictionarySuccessEventArgs> waitTask = AsyncTaskHelper.WaitSuccessOrFailureAsync<LoadDictionarySuccessEventArgs, LoadDictionaryFailureEventArgs>(
LoadDictionarySuccessEventArgs.EventId,
LoadDictionaryFailureEventArgs.EventId,
successArgs => successArgs.DictionaryAssetName == dictionaryAssetName && ReferenceEquals(successArgs.UserData, userData),
failureArgs => failureArgs.DictionaryAssetName == dictionaryAssetName && ReferenceEquals(failureArgs.UserData, userData),
timeout
);
localizationComponent.ReadData(dictionaryAssetName, userData);
return waitTask;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 2d8cd831d31f1e746bbc65c5591dc930
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,76 @@
using System;
using Cysharp.Threading.Tasks;
using GameFramework;
using GameFramework.Network;
using UnityGameFramework.Runtime;
namespace UnityGameFramework.Runtime.AsyncTask
{
/// <summary>
/// Network 异步扩展方法
/// </summary>
public static class NetworkAsyncExtension
{
/// <summary>
/// 异步连接网络
/// </summary>
/// <param name="networkComponent">网络组件</param>
/// <param name="networkChannelName">网络频道名称</param>
/// <param name="address">连接地址</param>
/// <param name="userData">用户自定义数据</param>
/// <param name="timeout">超时时间(秒),0表示不超时</param>
/// <returns>连接成功事件</returns>
public static UniTask<NetworkConnectedEventArgs> ConnectAsync(this NetworkComponent networkComponent,
string networkChannelName,
string address,
object userData = null,
float timeout = 30f)
{
return AsyncTaskHelper.WaitEventAsync<NetworkConnectedEventArgs>(
NetworkConnectedEventArgs.EventId,
args => args.NetworkChannel.Name == networkChannelName,
timeout
);
}
/// <summary>
/// 异步连接网络(带端口)
/// </summary>
/// <param name="networkComponent">网络组件</param>
/// <param name="networkChannelName">网络频道名称</param>
/// <param name="address">连接地址</param>
/// <param name="port">端口号</param>
/// <param name="userData">用户自定义数据</param>
/// <param name="timeout">超时时间(秒),0表示不超时</param>
/// <returns>连接成功事件</returns>
public static UniTask<NetworkConnectedEventArgs> ConnectAsync(this NetworkComponent networkComponent,
string networkChannelName,
string address,
int port,
object userData = null,
float timeout = 30f)
{
return ConnectAsync(networkComponent, networkChannelName, $"{address}:{port}", userData, timeout);
}
/// <summary>
/// 异步断开网络连接
/// </summary>
/// <param name="networkComponent">网络组件</param>
/// <param name="networkChannelName">网络频道名称</param>
/// <param name="userData">用户自定义数据</param>
/// <param name="timeout">超时时间(秒),0表示不超时</param>
/// <returns>关闭事件</returns>
public static UniTask<NetworkClosedEventArgs> DisconnectAsync(this NetworkComponent networkComponent,
string networkChannelName,
object userData = null,
float timeout = 30f)
{
return AsyncTaskHelper.WaitEventAsync<NetworkClosedEventArgs>(
NetworkClosedEventArgs.EventId,
args => args.NetworkChannel.Name == networkChannelName,
timeout
);
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: cc307b69189670d499c75d8c4cb5553a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,62 @@
using System;
using Cysharp.Threading.Tasks;
using GameFramework;
using GameFramework.Resource;
using UnityGameFramework.Runtime;
namespace UnityGameFramework.Runtime.AsyncTask
{
/// <summary>
/// Resource 异步扩展方法
/// </summary>
public static class ResourceAsyncExtension
{
/// <summary>
/// 异步等待资源更新完成
/// </summary>
/// <param name="resourceComponent">资源组件</param>
/// <param name="timeout">超时时间(秒),0表示不超时</param>
/// <returns>更新完成事件</returns>
public static UniTask<ResourceUpdateAllCompleteEventArgs> WaitForResourceUpdateCompleteAsync(this ResourceComponent resourceComponent,
float timeout = 0f)
{
return AsyncTaskHelper.WaitEventAsync<ResourceUpdateAllCompleteEventArgs>(
ResourceUpdateAllCompleteEventArgs.EventId,
null,
timeout
);
}
/// <summary>
/// 异步等待资源验证完成
/// </summary>
/// <param name="resourceComponent">资源组件</param>
/// <param name="timeout">超时时间(秒),0表示不超时</param>
/// <returns>验证成功事件</returns>
public static UniTask<ResourceVerifySuccessEventArgs> WaitForResourceVerifyCompleteAsync(this ResourceComponent resourceComponent,
float timeout = 0f)
{
return AsyncTaskHelper.WaitEventAsync<ResourceVerifySuccessEventArgs>(
ResourceVerifySuccessEventArgs.EventId,
null,
timeout
);
}
/// <summary>
/// 异步等待资源应用完成
/// </summary>
/// <param name="resourceComponent">资源组件</param>
/// <param name="timeout">超时时间(秒),0表示不超时</param>
/// <returns>应用成功事件</returns>
public static UniTask<ResourceApplySuccessEventArgs> WaitForResourceApplyCompleteAsync(this ResourceComponent resourceComponent,
float timeout = 0f)
{
return AsyncTaskHelper.WaitEventAsync<ResourceApplySuccessEventArgs>(
ResourceApplySuccessEventArgs.EventId,
null,
timeout
);
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e1e5440eb71427c42a16164ab6a664e2
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,64 @@
using System;
using Cysharp.Threading.Tasks;
using GameFramework;
using GameFramework.Scene;
using UnityGameFramework.Runtime;
namespace UnityGameFramework.Runtime.AsyncTask
{
/// <summary>
/// Scene 异步扩展方法
/// </summary>
public static class SceneAsyncExtension
{
/// <summary>
/// 异步加载场景
/// </summary>
/// <param name="sceneComponent">场景组件</param>
/// <param name="sceneAssetName">场景资源名称</param>
/// <param name="userData">用户自定义数据</param>
/// <param name="timeout">超时时间(秒),0表示不超时</param>
/// <returns>加载成功事件</returns>
public static UniTask<LoadSceneSuccessEventArgs> LoadSceneAsync(this SceneComponent sceneComponent,
string sceneAssetName,
object userData = null,
float timeout = 60f)
{
UniTask<LoadSceneSuccessEventArgs> waitTask = AsyncTaskHelper.WaitSuccessOrFailureAsync<LoadSceneSuccessEventArgs, LoadSceneFailureEventArgs>(
LoadSceneSuccessEventArgs.EventId,
LoadSceneFailureEventArgs.EventId,
successArgs => successArgs.SceneAssetName == sceneAssetName && ReferenceEquals(successArgs.UserData, userData),
failureArgs => failureArgs.SceneAssetName == sceneAssetName && ReferenceEquals(failureArgs.UserData, userData),
timeout
);
sceneComponent.LoadScene(sceneAssetName, userData);
return waitTask;
}
/// <summary>
/// 异步卸载场景
/// </summary>
/// <param name="sceneComponent">场景组件</param>
/// <param name="sceneAssetName">场景资源名称</param>
/// <param name="userData">用户自定义数据</param>
/// <param name="timeout">超时时间(秒),0表示不超时</param>
/// <returns>卸载成功事件</returns>
public static UniTask<UnloadSceneSuccessEventArgs> UnloadSceneAsync(this SceneComponent sceneComponent,
string sceneAssetName,
object userData = null,
float timeout = 60f)
{
UniTask<UnloadSceneSuccessEventArgs> waitTask = AsyncTaskHelper.WaitSuccessOrFailureAsync<UnloadSceneSuccessEventArgs, UnloadSceneFailureEventArgs>(
UnloadSceneSuccessEventArgs.EventId,
UnloadSceneFailureEventArgs.EventId,
successArgs => successArgs.SceneAssetName == sceneAssetName && ReferenceEquals(successArgs.UserData, userData),
failureArgs => failureArgs.SceneAssetName == sceneAssetName && ReferenceEquals(failureArgs.UserData, userData),
timeout
);
sceneComponent.UnloadScene(sceneAssetName, userData);
return waitTask;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b140d86ecd745fd48b99bdc70b28b6e1
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,45 @@
using System;
using Cysharp.Threading.Tasks;
using GameFramework;
using GameFramework.Sound;
using UnityGameFramework.Runtime;
namespace UnityGameFramework.Runtime.AsyncTask
{
/// <summary>
/// Sound 异步扩展方法
/// </summary>
public static class SoundAsyncExtension
{
/// <summary>
/// 异步播放声音
/// </summary>
/// <param name="soundComponent">声音组件</param>
/// <param name="soundAssetName">声音资源名称</param>
/// <param name="soundGroupName">声音组名称</param>
/// <param name="playSoundParams">播放声音参数</param>
/// <param name="userData">用户自定义数据</param>
/// <param name="timeout">超时时间(秒),0表示不超时</param>
/// <returns>播放成功事件</returns>
public static UniTask<PlaySoundSuccessEventArgs> PlaySoundAsync(this SoundComponent soundComponent,
string soundAssetName,
string soundGroupName,
PlaySoundParams playSoundParams = null,
object userData = null,
float timeout = 30f)
{
int serialId = 0;
UniTask<PlaySoundSuccessEventArgs> waitTask = AsyncTaskHelper.WaitSuccessOrFailureAsync<PlaySoundSuccessEventArgs, PlaySoundFailureEventArgs>(
PlaySoundSuccessEventArgs.EventId,
PlaySoundFailureEventArgs.EventId,
successArgs => successArgs.SerialId == serialId,
failureArgs => failureArgs.SerialId == serialId,
timeout
);
serialId = soundComponent.PlaySound(soundAssetName, soundGroupName, 0, playSoundParams, userData);
return waitTask;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: cfb0decbe226b9d4895ed53603d37c29
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,124 @@
using Cysharp.Threading.Tasks;
using SepCore.Definition;
using SepCore.UI;
using UnityGameFramework.Runtime;
namespace UnityGameFramework.Runtime.AsyncTask
{
/// <summary>
/// UI 异步扩展方法
/// </summary>
public static class UIAsyncExtension
{
/// <summary>
/// 等待界面打开完成
/// </summary>
/// <param name="uiComponent">UI组件</param>
/// <param name="serialId">界面序列编号</param>
/// <param name="timeout">超时时间(秒),0表示不超时</param>
/// <returns>打开的界面</returns>
public static UniTask<UIForm> WaitOpenUIFormAsync(this UIComponent uiComponent,
int serialId,
float timeout = 30f)
{
return AsyncTaskHelper.WaitSuccessOrFailureAsync<OpenUIFormSuccessEventArgs, OpenUIFormFailureEventArgs>(
OpenUIFormSuccessEventArgs.EventId,
OpenUIFormFailureEventArgs.EventId,
successArgs => successArgs.UIForm.SerialId == serialId,
failureArgs => failureArgs.SerialId == serialId,
timeout
).ContinueWith(successArgs => successArgs.UIForm);
}
/// <summary>
/// 异步打开界面
/// </summary>
/// <param name="uiComponent">UI组件</param>
/// <param name="uiFormAssetName">界面资源名称</param>
/// <param name="uiGroupName">界面组名称</param>
/// <param name="pauseCoveredUIForm">是否暂停被覆盖的界面</param>
/// <param name="userData">用户自定义数据</param>
/// <param name="timeout">超时时间(秒),0表示不超时</param>
/// <returns>打开的界面</returns>
public static UniTask<UIForm> OpenUIFormAsync(this UIComponent uiComponent,
string uiFormAssetName,
string uiGroupName,
bool pauseCoveredUIForm = true,
object userData = null,
float timeout = 30f)
{
int serialId = 0;
UniTask<UIForm> waitTask = AsyncTaskHelper.WaitSuccessOrFailureAsync<OpenUIFormSuccessEventArgs, OpenUIFormFailureEventArgs>(
OpenUIFormSuccessEventArgs.EventId,
OpenUIFormFailureEventArgs.EventId,
successArgs => successArgs.UIForm.SerialId == serialId,
failureArgs => failureArgs.SerialId == serialId,
timeout
).ContinueWith(successArgs => successArgs.UIForm);
serialId = uiComponent.OpenUIForm(uiFormAssetName, uiGroupName, pauseCoveredUIForm, userData);
return waitTask;
}
/// <summary>
/// 异步打开界面(通过界面编号)
/// </summary>
/// <param name="uiComponent">UI组件</param>
/// <param name="uiType">界面类型</param>
/// <param name="userData">用户自定义数据</param>
/// <param name="timeout">超时时间(秒),0表示不超时</param>
/// <returns>打开的界面</returns>
public static UniTask<UIForm> OpenUIFormAsync(this UIComponent uiComponent,
UIFormType uiType,
object userData = null,
float timeout = 30f)
{
int? serialId = uiComponent.OpenUIForm(uiType, userData);
if (!serialId.HasValue)
{
return UniTask.FromResult<UIForm>(null);
}
return uiComponent.WaitOpenUIFormAsync(serialId.Value, timeout);
}
/// <summary>
/// 异步关闭界面
/// </summary>
/// <param name="uiComponent">UI组件</param>
/// <param name="serialId">界面序列编号</param>
/// <param name="userData">用户自定义数据</param>
/// <param name="timeout">超时时间(秒),0表示不超时</param>
/// <returns>关闭完成事件</returns>
public static UniTask<CloseUIFormCompleteEventArgs> CloseUIFormAsync(this UIComponent uiComponent,
int serialId,
object userData = null,
float timeout = 30f)
{
UniTask<CloseUIFormCompleteEventArgs> waitTask = AsyncTaskHelper.WaitEventAsync<CloseUIFormCompleteEventArgs>(
CloseUIFormCompleteEventArgs.EventId,
args => args.SerialId == serialId,
timeout
);
uiComponent.CloseUIForm(serialId, userData);
return waitTask;
}
/// <summary>
/// 异步关闭界面(通过界面对象)
/// </summary>
/// <param name="uiComponent">UI组件</param>
/// <param name="uiForm">要关闭的界面</param>
/// <param name="userData">用户自定义数据</param>
/// <param name="timeout">超时时间(秒),0表示不超时</param>
/// <returns>关闭完成事件</returns>
public static UniTask<CloseUIFormCompleteEventArgs> CloseUIFormAsync(this UIComponent uiComponent,
UIForm uiForm,
object userData = null,
float timeout = 30f)
{
return CloseUIFormAsync(uiComponent, uiForm.SerialId, userData, timeout);
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 9ceba48ef9e814a40a88f96bf1fbf14c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,102 @@
using System;
using Cysharp.Threading.Tasks;
using GameFramework;
using GameFramework.WebRequest;
using UnityGameFramework.Runtime;
namespace UnityGameFramework.Runtime.AsyncTask
{
/// <summary>
/// WebRequest 异步扩展方法
/// </summary>
public static class WebRequestAsyncExtension
{
/// <summary>
/// 异步发送Web请求
/// </summary>
/// <param name="webRequestComponent">WebRequest组件</param>
/// <param name="webRequestUri">请求地址</param>
/// <param name="userData">用户自定义数据</param>
/// <param name="timeout">超时时间(秒),0表示不超时</param>
/// <returns>请求成功事件</returns>
public static UniTask<WebRequestSuccessEventArgs> GetWebRequestAsync(this WebRequestComponent webRequestComponent,
string webRequestUri,
object userData = null,
float timeout = 30f)
{
int serialId = 0;
UniTask<WebRequestSuccessEventArgs> waitTask = AsyncTaskHelper.WaitSuccessOrFailureAsync<WebRequestSuccessEventArgs, WebRequestFailureEventArgs>(
WebRequestSuccessEventArgs.EventId,
WebRequestFailureEventArgs.EventId,
successArgs => successArgs.SerialId == serialId,
failureArgs => failureArgs.SerialId == serialId,
timeout
);
serialId = webRequestComponent.AddWebRequest(webRequestUri, userData);
return waitTask;
}
/// <summary>
/// 异步发送Web请求并获取字节数据
/// </summary>
/// <param name="webRequestComponent">WebRequest组件</param>
/// <param name="webRequestUri">请求地址</param>
/// <param name="userData">用户自定义数据</param>
/// <param name="timeout">超时时间(秒),0表示不超时</param>
/// <returns>响应字节数据</returns>
public static UniTask<byte[]> GetWebRequestBytesAsync(this WebRequestComponent webRequestComponent,
string webRequestUri,
object userData = null,
float timeout = 30f)
{
return GetWebRequestAsync(webRequestComponent, webRequestUri, userData, timeout)
.ContinueWith(successArgs => successArgs.GetWebResponseBytes());
}
/// <summary>
/// 异步发送Web请求并获取字符串数据
/// </summary>
/// <param name="webRequestComponent">WebRequest组件</param>
/// <param name="webRequestUri">请求地址</param>
/// <param name="userData">用户自定义数据</param>
/// <param name="timeout">超时时间(秒),0表示不超时</param>
/// <returns>响应字符串数据</returns>
public static UniTask<string> GetWebRequestStringAsync(this WebRequestComponent webRequestComponent,
string webRequestUri,
object userData = null,
float timeout = 30f)
{
return GetWebRequestBytesAsync(webRequestComponent, webRequestUri, userData, timeout)
.ContinueWith(bytes => System.Text.Encoding.UTF8.GetString(bytes));
}
/// <summary>
/// 异步发送POST请求
/// </summary>
/// <param name="webRequestComponent">WebRequest组件</param>
/// <param name="webRequestUri">请求地址</param>
/// <param name="postData">POST数据</param>
/// <param name="userData">用户自定义数据</param>
/// <param name="timeout">超时时间(秒),0表示不超时</param>
/// <returns>请求成功事件</returns>
public static UniTask<WebRequestSuccessEventArgs> PostWebRequestAsync(this WebRequestComponent webRequestComponent,
string webRequestUri,
byte[] postData,
object userData = null,
float timeout = 30f)
{
int serialId = 0;
UniTask<WebRequestSuccessEventArgs> waitTask = AsyncTaskHelper.WaitSuccessOrFailureAsync<WebRequestSuccessEventArgs, WebRequestFailureEventArgs>(
WebRequestSuccessEventArgs.EventId,
WebRequestFailureEventArgs.EventId,
successArgs => successArgs.SerialId == serialId,
failureArgs => failureArgs.SerialId == serialId,
timeout
);
serialId = webRequestComponent.AddWebRequest(webRequestUri, postData, userData);
return waitTask;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 579cf8ed8a820d34d9e7e46f60a3f176
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,121 @@
using GameFramework.DataTable;
using GameFramework.UI;
using SepCore.DataTable;
using SepCore.Definition;
using CustomUtility;
using UnityGameFramework.Runtime;
namespace SepCore.UI
{
public static class UIComponentExtension
{
public static bool HasUIForm(this UIComponent uiComponent, UIFormType uiFormType, string uiGroupName = null)
{
return uiComponent.HasUIForm((int)uiFormType, uiGroupName);
}
public static bool HasUIForm(this UIComponent uiComponent, int uiFormId, string uiGroupName = null)
{
IDataTable<DRUIForm> dtUIForm = GameEntry.DataTable.GetDataTable<DRUIForm>();
DRUIForm drUIForm = dtUIForm.GetDataRow(uiFormId);
if (drUIForm == null)
{
return false;
}
string assetName = AssetUtility.GetUIFormAsset(drUIForm.AssetName);
if (string.IsNullOrEmpty(uiGroupName))
{
return uiComponent.HasUIForm(assetName);
}
IUIGroup uiGroup = uiComponent.GetUIGroup(uiGroupName);
if (uiGroup == null)
{
return false;
}
return uiGroup.HasUIForm(assetName);
}
public static UGuiForm GetUIForm(this UIComponent uiComponent, UIFormType uiFormType, string uiGroupName = null)
{
return uiComponent.GetUIForm((int)uiFormType, uiGroupName);
}
public static UGuiForm GetUIForm(this UIComponent uiComponent, int uiFormId, string uiGroupName = null)
{
IDataTable<DRUIForm> dtUIForm = GameEntry.DataTable.GetDataTable<DRUIForm>();
DRUIForm drUIForm = dtUIForm.GetDataRow(uiFormId);
if (drUIForm == null)
{
return null;
}
string assetName = AssetUtility.GetUIFormAsset(drUIForm.AssetName);
UIForm uiForm = null;
if (string.IsNullOrEmpty(uiGroupName))
{
uiForm = uiComponent.GetUIForm(assetName);
if (uiForm == null)
{
return null;
}
return (UGuiForm)uiForm.Logic;
}
IUIGroup uiGroup = uiComponent.GetUIGroup(uiGroupName);
if (uiGroup == null)
{
return null;
}
uiForm = (UIForm)uiGroup.GetUIForm(assetName);
if (uiForm == null)
{
return null;
}
return (UGuiForm)uiForm.Logic;
}
public static void CloseUIForm(this UIComponent uiComponent, UGuiForm uiForm)
{
uiComponent.CloseUIForm(uiForm.UIForm);
}
public static int? OpenUIForm(this UIComponent uiComponent, UIFormType uiFormType, object userData = null)
{
return uiComponent.OpenUIForm((int)uiFormType, userData);
}
public static int? OpenUIForm(this UIComponent uiComponent, int uiFormId, object userData = null)
{
IDataTable<DRUIForm> dtUIForm = GameEntry.DataTable.GetDataTable<DRUIForm>();
DRUIForm drUIForm = dtUIForm.GetDataRow(uiFormId);
if (drUIForm == null)
{
Log.Warning("Can not load UI form '{0}' from data table.", uiFormId.ToString());
return null;
}
string assetName = AssetUtility.GetUIFormAsset(drUIForm.AssetName);
if (!drUIForm.AllowMultiInstance)
{
if (uiComponent.IsLoadingUIForm(assetName))
{
return null;
}
if (uiComponent.HasUIForm(assetName))
{
return null;
}
}
return uiComponent.OpenUIForm(assetName, drUIForm.UIGroupName, Constant.AssetPriority.UIFormAsset,
drUIForm.PauseCoveredUIForm, userData);
}
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 08ddcb062d3388c459474bc44e247523
timeCreated: 1528026162
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -8,7 +8,7 @@
using SepCore.Definition;
using GameFramework;
using StarForce;
using UI;
using SepCore.UI;
using UnityEngine;
using UnityEngine.Serialization;
using UnityGameFramework.Runtime;
@@ -1,9 +1,6 @@
using System;
using System.Collections.Generic;
using GameFramework.ObjectPool;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
using UnityGameFramework.Runtime;
namespace CustomComponent
@@ -78,4 +75,4 @@ namespace CustomComponent
_damageTextItemPool = null;
}
}
}
}
@@ -1,16 +1,8 @@
//------------------------------------------------------------
// Game Framework
// Copyright © 2013-2021 Jiang Yin. All rights reserved.
// Homepage: https://gameframework.cn/
// Feedback: mailto:ellan@gameframework.cn
//------------------------------------------------------------
using GameFramework.ObjectPool;
using GameFramework.ObjectPool;
using System.Collections.Generic;
using Entity;
using StarForce;
using UnityEngine;
using UnityEngine.Serialization;
using UnityGameFramework.Runtime;
namespace CustomComponent
@@ -122,4 +114,4 @@ namespace CustomComponent
return hpBarItem;
}
}
}
}
@@ -1,14 +1,8 @@
//------------------------------------------------------------
// Game Framework
// Copyright © 2013-2021 Jiang Yin. All rights reserved.
// Homepage: https://gameframework.cn/
// Feedback: mailto:ellan@gameframework.cn
//------------------------------------------------------------
using System.Collections;
using System.Collections;
using Entity;
using UI;
using SepCore.UI;
using UnityEngine;
using UnityEngine.Serialization;
using UnityEngine.UI;
using UnityGameFramework.Runtime;
@@ -20,22 +14,15 @@ namespace StarForce
private const float KeepSeconds = 0.4f;
private const float FadeOutSeconds = 0.3f;
[SerializeField]
private Slider m_HPBar = null;
[FormerlySerializedAs("m_HPBar")] [SerializeField] private Slider _hPBar = null;
private Canvas m_ParentCanvas = null;
private RectTransform m_CachedTransform = null;
private CanvasGroup m_CachedCanvasGroup = null;
private EntityBase m_Owner = null;
private Canvas _parentCanvas = null;
private RectTransform _cachedTransform = null;
private CanvasGroup _cachedCanvasGroup = null;
private EntityBase _owner = null;
private int m_OwnerId = 0;
public EntityBase Owner
{
get
{
return m_Owner;
}
}
public EntityBase Owner => _owner;
public void Init(EntityBase owner, Canvas parentCanvas, float fromHPRatio, float toHPRatio)
{
@@ -45,16 +32,16 @@ namespace StarForce
return;
}
m_ParentCanvas = parentCanvas;
_parentCanvas = parentCanvas;
gameObject.SetActive(true);
StopAllCoroutines();
m_CachedCanvasGroup.alpha = 1f;
if (m_Owner != owner || m_OwnerId != owner.Id)
_cachedCanvasGroup.alpha = 1f;
if (_owner != owner || m_OwnerId != owner.Id)
{
m_HPBar.value = fromHPRatio;
m_Owner = owner;
_hPBar.value = fromHPRatio;
_owner = owner;
m_OwnerId = owner.Id;
}
@@ -65,21 +52,22 @@ namespace StarForce
public bool Refresh()
{
if (m_CachedCanvasGroup.alpha <= 0f)
if (_cachedCanvasGroup.alpha <= 0f)
{
return false;
}
if (m_Owner != null && Owner.Available && Owner.Id == m_OwnerId)
if (_owner != null && Owner.Available && Owner.Id == m_OwnerId)
{
Vector3 worldPosition = m_Owner.CachedTransform.position + Vector3.forward;
Vector3 worldPosition = _owner.CachedTransform.position + Vector3.forward;
Vector3 screenPosition = GameEntry.Scene.MainCamera.WorldToScreenPoint(worldPosition);
Vector2 position;
if (RectTransformUtility.ScreenPointToLocalPointInRectangle((RectTransform)m_ParentCanvas.transform, screenPosition,
m_ParentCanvas.worldCamera, out position))
if (RectTransformUtility.ScreenPointToLocalPointInRectangle((RectTransform)_parentCanvas.transform,
screenPosition,
_parentCanvas.worldCamera, out position))
{
m_CachedTransform.localPosition = position;
_cachedTransform.localPosition = position;
}
}
@@ -89,23 +77,23 @@ namespace StarForce
public void Reset()
{
StopAllCoroutines();
m_CachedCanvasGroup.alpha = 1f;
m_HPBar.value = 1f;
m_Owner = null;
_cachedCanvasGroup.alpha = 1f;
_hPBar.value = 1f;
_owner = null;
gameObject.SetActive(false);
}
private void Awake()
{
m_CachedTransform = GetComponent<RectTransform>();
if (m_CachedTransform == null)
_cachedTransform = GetComponent<RectTransform>();
if (_cachedTransform == null)
{
Log.Error("RectTransform is invalid.");
return;
}
m_CachedCanvasGroup = GetComponent<CanvasGroup>();
if (m_CachedCanvasGroup == null)
_cachedCanvasGroup = GetComponent<CanvasGroup>();
if (_cachedCanvasGroup == null)
{
Log.Error("CanvasGroup is invalid.");
return;
@@ -114,9 +102,9 @@ namespace StarForce
private IEnumerator HPBarCo(float value, float animationDuration, float keepDuration, float fadeOutDuration)
{
yield return m_HPBar.SmoothValue(value, animationDuration);
yield return _hPBar.SmoothValue(value, animationDuration);
yield return new WaitForSeconds(keepDuration);
yield return m_CachedCanvasGroup.FadeToAlpha(0f, fadeOutDuration);
yield return _cachedCanvasGroup.FadeToAlpha(0f, fadeOutDuration);
}
}
}
@@ -1,31 +1,91 @@
using System;
using System.Collections.Generic;
using Cysharp.Threading.Tasks;
using SepCore.Definition;
using SepCore.UI;
using UnityEngine;
using UnityGameFramework.Runtime;
using UI;
namespace CustomComponent
namespace SepCore.CustomComponent
{
public class UIRouterComponent : GameFrameworkComponent
{
[Serializable]
public class ControllerBinding
{
[SerializeField] private UIFormType _uiFormType = UIFormType.Undefined;
[SerializeField] private string _controllerTypeName;
public UIFormType UIFormType => _uiFormType;
public string ControllerTypeName => _controllerTypeName;
}
[SerializeField] private List<ControllerBinding> _controllerBindings = new();
private readonly Dictionary<UIFormType, IUIFormController> _routeControllers = new();
private readonly Dictionary<UIFormType, Func<IUIFormController>> _controllerFactories = new();
protected override void Awake()
{
base.Awake();
RegisterSerializedBindings();
}
public void RegisterController(UIFormType uiFormType, Func<IUIFormController> controllerFactory)
{
if (controllerFactory == null)
{
Log.Error("UIRouterComponent.RegisterController() controllerFactory is invalid.");
return;
}
if (_routeControllers.TryGetValue(uiFormType, out IUIFormController controller))
{
controller.CloseUIAsync().Forget();
_routeControllers.Remove(uiFormType);
}
_controllerFactories[uiFormType] = controllerFactory;
}
public void RegisterController<TController>(UIFormType uiFormType)
where TController : IUIFormController, new()
{
RegisterController(uiFormType, () => new TController());
}
public void BindUIUseCase(UIFormType uiFormType, IUIUseCase useCase)
{
IUIFormController controller = GetOrCreateController(uiFormType);
if (controller == null)
{
return;
}
controller.BindUseCase(useCase);
}
public int? OpenUI(UIFormType uiFormType, object userData = null)
public UniTask<int?> OpenUIAsync(UIFormType uiFormType, object userData = null, float timeout = 30f)
{
IUIFormController controller = GetOrCreateController(uiFormType);
return controller.OpenUI(userData);
if (controller == null)
{
return UniTask.FromResult<int?>(null);
}
return controller.OpenUIAsync(userData, timeout);
}
public void CloseUI(UIFormType uiFormType)
public UniTask CloseUIAsync(UIFormType uiFormType, object userData = null, float timeout = 30f)
{
IUIFormController controller = GetOrCreateController(uiFormType);
controller.CloseUI();
if (controller == null)
{
return UniTask.CompletedTask;
}
return controller.CloseUIAsync(userData, timeout);
}
private IUIFormController GetOrCreateController(UIFormType uiFormType)
@@ -35,67 +95,82 @@ namespace CustomComponent
return controller;
}
string typename = $"UI.{uiFormType}Controller";
Type controllerType = Type.GetType(typename);
if (controllerType == null)
if (!_controllerFactories.TryGetValue(uiFormType, out Func<IUIFormController> controllerFactory))
{
controller = new DefaultUIFormController(uiFormType);
Log.Error("UIRouterComponent requires a controller binding for '{0}'.", uiFormType.ToString());
return null;
}
else
controller = controllerFactory();
if (controller == null)
{
controller = (IUIFormController)Activator.CreateInstance(controllerType);
Log.Error("UIRouterComponent controller factory for '{0}' returned null.", uiFormType.ToString());
return null;
}
_routeControllers.Add(uiFormType, controller);
return controller;
}
private void RegisterSerializedBindings()
{
if (_controllerBindings == null || _controllerBindings.Count == 0)
{
return;
}
HashSet<UIFormType> seen = new();
foreach (ControllerBinding binding in _controllerBindings)
{
if (binding == null || binding.UIFormType == UIFormType.Undefined ||
string.IsNullOrWhiteSpace(binding.ControllerTypeName))
{
continue;
}
if (!seen.Add(binding.UIFormType))
{
Log.Warning("UIRouter duplicate binding for '{0}', later one overrides earlier one.",
binding.UIFormType.ToString());
}
Type controllerType = Type.GetType(binding.ControllerTypeName);
if (controllerType == null)
{
Log.Warning("UIRouter binding type not found: {0}", binding.ControllerTypeName);
continue;
}
if (!typeof(IUIFormController).IsAssignableFrom(controllerType))
{
Log.Warning("UIRouter binding type '{0}' does not implement IUIFormController.",
binding.ControllerTypeName);
continue;
}
RegisterController(binding.UIFormType, () => CreateController(controllerType));
}
}
private static IUIFormController CreateController(Type controllerType)
{
object instance = Activator.CreateInstance(controllerType);
if (instance is IUIFormController controller)
{
return controller;
}
return null;
}
private void OnDestroy()
{
foreach (KeyValuePair<UIFormType, IUIFormController> pair in _routeControllers)
{
pair.Value.CloseUI();
pair.Value.CloseUIAsync().Forget();
}
_routeControllers.Clear();
}
private class DefaultUIFormController : IUIFormController
{
private readonly UIFormType _uiFormType;
private int? _lastSerialId;
public DefaultUIFormController(UIFormType uiFormType)
{
_uiFormType = uiFormType;
}
public int? OpenUI(object userData = null)
{
_lastSerialId = GameEntry.UI.OpenUIForm(_uiFormType, userData);
return _lastSerialId;
}
public void CloseUI()
{
if (_lastSerialId.HasValue)
{
GameEntry.UI.CloseUIForm(_lastSerialId.Value);
_lastSerialId = null;
return;
}
UGuiForm uiForm = GameEntry.UI.GetUIForm(_uiFormType);
if (uiForm != null)
{
GameEntry.UI.CloseUIForm(uiForm);
}
}
public void BindUseCase(IUIUseCase useCase)
{
}
}
}
}
@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: b3695ff420be99d44ab812d7e1863044
guid: 8e8c4ca7b7a670745a789c67ac6c8e40
MonoImporter:
externalObjects: {}
serializedVersion: 2
@@ -1,9 +1,13 @@
namespace UI
using Cysharp.Threading.Tasks;
namespace SepCore.UI
{
public interface IUIFormController
{
int? OpenUI(object userData = null);
void CloseUI();
UniTask<int?> OpenUIAsync(object userData = null, float timeout = 30f);
UniTask CloseUIAsync(object userData = null, float timeout = 30f);
void BindUseCase(IUIUseCase useCase);
}
}
@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 08145adf06b2b2c4b9d61d3ef6d39cfc
guid: 66fa704224e65f54584adec043702f21
MonoImporter:
externalObjects: {}
serializedVersion: 2
@@ -1,10 +1,6 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace UI
namespace SepCore.UI
{
public interface IUIUseCase
{
}
}
}
@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 8b527e4ad6d6207418137211caa179d5
guid: 277ebfa2eef59b448b093625c15ecaad
MonoImporter:
externalObjects: {}
serializedVersion: 2
@@ -1,11 +1,4 @@
//------------------------------------------------------------
// Game Framework
// Copyright © 2013-2021 Jiang Yin. All rights reserved.
// Homepage: https://gameframework.cn/
// Feedback: mailto:ellan@gameframework.cn
//------------------------------------------------------------
using System.Collections;
using System.Collections;
using System.Collections.Generic;
using StarForce;
using TMPro;
@@ -13,7 +6,7 @@ using UnityEngine;
using UnityEngine.UI;
using UnityGameFramework.Runtime;
namespace UI
namespace SepCore.UI
{
public abstract class UGuiForm : UIFormLogic
{
@@ -9,7 +9,7 @@ using UnityEngine;
using UnityEngine.UI;
using UnityGameFramework.Runtime;
namespace UI
namespace SepCore.UI
{
/// <summary>
/// uGUI 界面组辅助器。
@@ -1,10 +1,6 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace UI
namespace SepCore.UI
{
public class UIContext
{
}
}
}
@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 7ac4a8b30b5b7684ca58f70386314a4b
guid: aacfc86c69a60264b82af0d0b457eb96
MonoImporter:
externalObjects: {}
serializedVersion: 2
@@ -0,0 +1,112 @@
using Cysharp.Threading.Tasks;
using SepCore.Definition;
using UnityGameFramework.Runtime;
using UnityGameFramework.Runtime.AsyncTask;
namespace SepCore.UI
{
public abstract class UIControllerBase<TContext, TForm> : IUIFormController
where TContext : UIContext
where TForm : UGuiForm
{
private TContext _context;
private TForm _form;
private int? _formSerialId;
protected TContext Context => _context;
protected TForm Form => _form;
protected abstract UIFormType UIFormType { get; }
protected abstract void RefreshUI(TForm form, TContext context);
protected virtual void SubscribeCustomEvents()
{
}
protected virtual void UnsubscribeCustomEvents()
{
}
protected virtual void CloseLoadedFormDirect(TForm form)
{
form.Close();
}
protected async UniTask<int?> OpenFormAsync(TContext context, float timeout = 30f)
{
if (context == null)
{
Log.Warning("{0}.OpenFormAsync() context is null.", GetType().Name);
return null;
}
if (_form != null)
{
_context = context;
RefreshUI(_form, _context);
return _formSerialId;
}
_context = context;
UIForm uiForm = await GameEntry.UI.OpenUIFormAsync(UIFormType, _context, timeout);
if (uiForm == null)
{
Log.Warning("{0}.OpenFormAsync() failed to open form '{1}'.", GetType().Name, UIFormType.ToString());
return null;
}
_formSerialId = uiForm.SerialId;
_form = uiForm.Logic as TForm;
if (_form == null)
{
Log.Warning("{0} open success but form logic is invalid.", GetType().Name);
_context = null;
_formSerialId = null;
return null;
}
SubscribeCustomEvents();
RefreshUI(_form, _context);
return _formSerialId;
}
protected virtual async UniTask CloseFormAsync(object userData = null, float timeout = 30f)
{
UnsubscribeCustomEvents();
int? serialId = _formSerialId;
TForm form = _form;
_context = null;
_form = null;
_formSerialId = null;
if (serialId.HasValue)
{
if (GameEntry.UI.HasUIForm(serialId.Value))
{
await GameEntry.UI.CloseUIFormAsync(serialId.Value, userData, timeout);
}
return;
}
if (form != null)
{
CloseLoadedFormDirect(form);
}
}
public abstract UniTask<int?> OpenUIAsync(object userData = null, float timeout = 30f);
public virtual UniTask CloseUIAsync(object userData = null, float timeout = 30f)
{
return CloseFormAsync(userData, timeout);
}
public abstract void BindUseCase(IUIUseCase useCase);
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d69abc928823685498bed2fd356128be
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -1,14 +1,8 @@
using GameFramework.DataTable;
using GameFramework.UI;
using System.Collections;
using SepCore.DataTable;
using SepCore.Definition;
using CustomUtility;
using System.Collections;
using UnityEngine;
using UnityEngine.UI;
using UnityGameFramework.Runtime;
namespace UI
namespace SepCore.UI
{
public static class UIExtension
{
@@ -39,122 +33,5 @@ namespace UI
slider.value = value;
}
public static bool HasUIForm(this UIComponent uiComponent, UIFormType uiFormType, string uiGroupName = null)
{
return uiComponent.HasUIForm((int)uiFormType, uiGroupName);
}
public static bool HasUIForm(this UIComponent uiComponent, int uiFormId, string uiGroupName = null)
{
IDataTable<DRUIForm> dtUIForm = GameEntry.DataTable.GetDataTable<DRUIForm>();
DRUIForm drUIForm = dtUIForm.GetDataRow(uiFormId);
if (drUIForm == null)
{
return false;
}
string assetName = AssetUtility.GetUIFormAsset(drUIForm.AssetName);
if (string.IsNullOrEmpty(uiGroupName))
{
return uiComponent.HasUIForm(assetName);
}
IUIGroup uiGroup = uiComponent.GetUIGroup(uiGroupName);
if (uiGroup == null)
{
return false;
}
return uiGroup.HasUIForm(assetName);
}
public static UGuiForm GetUIForm(this UIComponent uiComponent, UIFormType uiFormType, string uiGroupName = null)
{
return uiComponent.GetUIForm((int)uiFormType, uiGroupName);
}
public static UGuiForm GetUIForm(this UIComponent uiComponent, int uiFormId, string uiGroupName = null)
{
IDataTable<DRUIForm> dtUIForm = GameEntry.DataTable.GetDataTable<DRUIForm>();
DRUIForm drUIForm = dtUIForm.GetDataRow(uiFormId);
if (drUIForm == null)
{
return null;
}
string assetName = AssetUtility.GetUIFormAsset(drUIForm.AssetName);
UIForm uiForm = null;
if (string.IsNullOrEmpty(uiGroupName))
{
uiForm = uiComponent.GetUIForm(assetName);
if (uiForm == null)
{
return null;
}
return (UGuiForm)uiForm.Logic;
}
IUIGroup uiGroup = uiComponent.GetUIGroup(uiGroupName);
if (uiGroup == null)
{
return null;
}
uiForm = (UIForm)uiGroup.GetUIForm(assetName);
if (uiForm == null)
{
return null;
}
return (UGuiForm)uiForm.Logic;
}
public static void CloseUIForm(this UIComponent uiComponent, UGuiForm uiForm)
{
uiComponent.CloseUIForm(uiForm.UIForm);
}
public static int? OpenUIForm(this UIComponent uiComponent, UIFormType uiFormType, object userData = null)
{
return uiComponent.OpenUIForm((int)uiFormType, userData);
}
public static int? OpenUIForm(this UIComponent uiComponent, int uiFormId, object userData = null)
{
IDataTable<DRUIForm> dtUIForm = GameEntry.DataTable.GetDataTable<DRUIForm>();
DRUIForm drUIForm = dtUIForm.GetDataRow(uiFormId);
if (drUIForm == null)
{
Log.Warning("Can not load UI form '{0}' from data table.", uiFormId.ToString());
return null;
}
string assetName = AssetUtility.GetUIFormAsset(drUIForm.AssetName);
if (!drUIForm.AllowMultiInstance)
{
if (uiComponent.IsLoadingUIForm(assetName))
{
return null;
}
if (uiComponent.HasUIForm(assetName))
{
return null;
}
}
return uiComponent.OpenUIForm(assetName, drUIForm.UIGroupName, Constant.AssetPriority.UIFormAsset, drUIForm.PauseCoveredUIForm, userData);
}
private static void OpenNativeDialog(DialogFormRawData rawData)
{
// TODO:这里应该弹出原生对话框,先简化实现为直接按确认按钮
if (rawData != null && rawData.OnClickConfirm != null)
{
rawData.OnClickConfirm(rawData.UserData);
}
}
}
}
@@ -1,10 +0,0 @@
namespace UI
{
public abstract class UIFormControllerBase<TContext> : IUIFormController where TContext : UIContext
{
protected abstract int? OpenUIInternal(TContext context);
public abstract int? OpenUI(object userData = null);
public abstract void CloseUI();
public abstract void BindUseCase(IUIUseCase useCase);
}
}
@@ -1,183 +0,0 @@
using SepCore.Definition;
using GameFramework.Event;
using UnityGameFramework.Runtime;
namespace UI
{
public abstract class UIFormControllerCommonBase<TContext, TForm> : UIFormControllerBase<TContext>
where TContext : UIContext
where TForm : UGuiForm
{
private TContext _context;
private TForm _form;
private int? _formSerialId;
private bool _pendingRefresh;
private bool _isBindEvent;
protected TContext Context => _context;
protected TForm Form => _form;
protected int? FormSerialId => _formSerialId;
protected abstract UIFormType UIFormTypeId { get; }
protected abstract void RefreshUI(TForm form, TContext context);
protected virtual void SubscribeCustomEvents()
{
}
protected virtual void UnsubscribeCustomEvents()
{
}
protected virtual void CloseLoadedFormDirect(TForm form)
{
form.Close();
}
protected void SetContext(TContext context)
{
_context = context;
}
protected void RefreshCurrentUI()
{
if (_context == null)
{
return;
}
if (_form == null)
{
_pendingRefresh = true;
return;
}
RefreshUI(_form, _context);
_pendingRefresh = false;
}
protected override int? OpenUIInternal(TContext context)
{
if (context == null)
{
Log.Warning("{0}.OpenUI() context is null.", GetType().Name);
return null;
}
_context = context;
if (_form != null && _formSerialId.HasValue && GameEntry.UI.HasUIForm(_formSerialId.Value))
{
RefreshUI(_form, _context);
return _formSerialId;
}
CloseUI();
_pendingRefresh = true;
SubscribeEvents();
_formSerialId = GameEntry.UI.OpenUIForm(UIFormTypeId, _context);
return _formSerialId;
}
public override void CloseUI()
{
_pendingRefresh = false;
UnsubscribeEvents();
if (_formSerialId.HasValue)
{
if (GameEntry.UI.HasUIForm(_formSerialId.Value))
{
GameEntry.UI.CloseUIForm(_formSerialId.Value);
}
_form = null;
_formSerialId = null;
return;
}
if (_form != null)
{
CloseLoadedFormDirect(_form);
_form = null;
}
}
private void SubscribeEvents()
{
if (_isBindEvent)
{
return;
}
GameEntry.Event.Subscribe(OpenUIFormSuccessEventArgs.EventId, OpenUIFormSuccess);
GameEntry.Event.Subscribe(CloseUIFormCompleteEventArgs.EventId, CloseUIFormComplete);
SubscribeCustomEvents();
_isBindEvent = true;
}
private void UnsubscribeEvents()
{
if (!_isBindEvent)
{
return;
}
GameEntry.Event.Unsubscribe(OpenUIFormSuccessEventArgs.EventId, OpenUIFormSuccess);
GameEntry.Event.Unsubscribe(CloseUIFormCompleteEventArgs.EventId, CloseUIFormComplete);
UnsubscribeCustomEvents();
_isBindEvent = false;
}
private void OpenUIFormSuccess(object sender, GameEventArgs e)
{
if (!(e is OpenUIFormSuccessEventArgs args))
{
return;
}
if (!_formSerialId.HasValue)
{
return;
}
if (args.UIForm == null || args.UIForm.SerialId != _formSerialId.Value || args.UserData != _context)
{
return;
}
_form = args.UIForm.Logic as TForm;
if (_form == null)
{
Log.Warning("{0} open success but form logic is invalid.", GetType().Name);
return;
}
if (_pendingRefresh)
{
RefreshCurrentUI();
}
}
private void CloseUIFormComplete(object sender, GameEventArgs e)
{
if (!(e is CloseUIFormCompleteEventArgs args))
{
return;
}
if (args.SerialId != _formSerialId)
{
return;
}
_form = null;
_formSerialId = null;
}
}
}
@@ -1,44 +0,0 @@
using SepCore.Definition;
using UnityGameFramework.Runtime;
namespace UI
{
public class TUIFormController : UIFormControllerCommonBase<UIContext, TUIForm>
{
private IUIUseCase _useCase;
protected override UIFormType UIFormTypeId => UIFormType.TUIForm;
protected override void RefreshUI(TUIForm form, UIContext context)
{
form.RefreshUI(context);
}
public override int? OpenUI(object userData = null)
{
if (userData is UIContext context)
{
return OpenUIInternal(context);
}
if (userData != null)
{
Log.Warning("TUIFormController.OpenUI() userData type is invalid.");
return null;
}
return OpenUIInternal(Context);
}
public override void BindUseCase(IUIUseCase useCase)
{
if (!(useCase is IUIUseCase uiFormUseCase))
{
Log.Error("LevelUpForm.BindUseCase() useCase is invalid.");
return;
}
_useCase = uiFormUseCase;
}
}
}
@@ -1,27 +0,0 @@
using UnityEngine;
using UnityGameFramework.Runtime;
namespace UI
{
public class TUIForm : UGuiForm
{
public void RefreshUI(UIContext context)
{
}
protected override void OnOpen(object userData)
{
base.OnOpen(userData);
if (!(userData is UIContext context))
{
Log.Error("UIContext is invalid.");
return;
}
RefreshUI(context);
}
}
}
@@ -1,15 +1,8 @@
//------------------------------------------------------------
// Game Framework
// Copyright © 2013-2021 Jiang Yin. All rights reserved.
// Homepage: https://gameframework.cn/
// Feedback: mailto:ellan@gameframework.cn
//------------------------------------------------------------
using UnityEngine;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.EventSystems;
namespace UI
namespace SepCore.UI
{
public class CommonButton : MonoBehaviour, IPointerEnterHandler, IPointerDownHandler, IPointerExitHandler,
IPointerUpHandler
@@ -85,4 +78,4 @@ namespace UI
_onPointerExitAction.Invoke();
}
}
}
}
@@ -1,109 +0,0 @@
using GameFramework;
namespace UI
{
/// <summary>
/// 对话框显示数据。
/// </summary>
public class DialogFormRawData
{
/// <summary>
/// 模式,即按钮数量。取值 1、2、3。
/// </summary>
public int Mode
{
get;
set;
}
/// <summary>
/// 标题。
/// </summary>
public string Title
{
get;
set;
}
/// <summary>
/// 消息内容。
/// </summary>
public string Message
{
get;
set;
}
/// <summary>
/// 弹出窗口时是否暂停游戏。
/// </summary>
public bool PauseGame
{
get;
set;
}
/// <summary>
/// 确认按钮文本。
/// </summary>
public string ConfirmText
{
get;
set;
}
/// <summary>
/// 确定按钮回调。
/// </summary>
public GameFrameworkAction<object> OnClickConfirm
{
get;
set;
}
/// <summary>
/// 取消按钮文本。
/// </summary>
public string CancelText
{
get;
set;
}
/// <summary>
/// 取消按钮回调。
/// </summary>
public GameFrameworkAction<object> OnClickCancel
{
get;
set;
}
/// <summary>
/// 中立按钮文本。
/// </summary>
public string OtherText
{
get;
set;
}
/// <summary>
/// 其它按钮回调。
/// </summary>
public GameFrameworkAction<object> OnClickOther
{
get;
set;
}
/// <summary>
/// 用户自定义数据。
/// </summary>
public object UserData
{
get;
set;
}
}
}
@@ -0,0 +1,65 @@
using GameFramework;
namespace SepCore.UI
{
/// <summary>
/// 对话框显示数据。
/// </summary>
public class DialogRawData
{
/// <summary>
/// 模式,即按钮数量。取值 1、2、3。
/// </summary>
public int Mode { get; set; }
/// <summary>
/// 标题。
/// </summary>
public string Title { get; set; }
/// <summary>
/// 消息内容。
/// </summary>
public string Message { get; set; }
/// <summary>
/// 弹出窗口时是否暂停游戏。
/// </summary>
public bool PauseGame { get; set; }
/// <summary>
/// 确认按钮文本。
/// </summary>
public string ConfirmText { get; set; }
/// <summary>
/// 确定按钮回调。
/// </summary>
public GameFrameworkAction<object> OnClickConfirm { get; set; }
/// <summary>
/// 取消按钮文本。
/// </summary>
public string CancelText { get; set; }
/// <summary>
/// 取消按钮回调。
/// </summary>
public GameFrameworkAction<object> OnClickCancel { get; set; }
/// <summary>
/// 中立按钮文本。
/// </summary>
public string OtherText { get; set; }
/// <summary>
/// 其它按钮回调。
/// </summary>
public GameFrameworkAction<object> OnClickOther { get; set; }
/// <summary>
/// 用户自定义数据。
/// </summary>
public object UserData { get; set; }
}
}
@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: ad9ca3c36c52b0a4e8b25c8b451966da
guid: 1f7f875b57135c5438301146eb0f3713
timeCreated: 1528026160
licenseType: Pro
MonoImporter:
@@ -1,4 +1,4 @@
namespace UI
namespace SepCore.UI
{
public class RoleItemRawData
{
@@ -1,4 +1,4 @@
namespace UI
namespace SepCore.UI
{
public class RolePropertyAreaRawData
{
@@ -1,11 +1,9 @@
using System.Collections;
using System.Collections.Generic;
using SepCore.Definition;
using UnityEngine;
namespace UI
namespace SepCore.UI
{
public class DisplayItemInfoFormRawData
public class DisplayItemInfoRawData
{
public int Index;
public string IconAssetName;
@@ -17,4 +15,4 @@ namespace UI
public bool IsWeapon;
public Vector3 TargetPos;
}
}
}
@@ -3,20 +3,20 @@ using Entity;
using CustomUtility;
using Entity.Weapon;
namespace UI
namespace SepCore.UI
{
public class DisplayItemInfoFormUseCase : IUIUseCase
public class DisplayItemInfoUseCase : IUIUseCase
{
private readonly Player _player;
private Player Player => _player;
public DisplayItemInfoFormUseCase(Player player)
public DisplayItemInfoUseCase(Player player)
{
_player = player;
}
public DisplayItemInfoFormRawData CreateModel(int index, bool isWeapon)
public DisplayItemInfoRawData CreateModel(int index, bool isWeapon)
{
if (index < 0 || Player == null)
{
@@ -37,7 +37,7 @@ namespace UI
return null;
}
return new DisplayItemInfoFormRawData
return new DisplayItemInfoRawData
{
IconAssetName = weapon.WeaponData.IconAssetName,
Title = weapon.WeaponData.Title,
@@ -60,7 +60,7 @@ namespace UI
return null;
}
return new DisplayItemInfoFormRawData
return new DisplayItemInfoRawData
{
IconAssetName = prop.IconAssetName,
Title = prop.Title,
@@ -1,11 +1,11 @@
using System.Collections.Generic;
using SepCore.DataTable;
namespace UI
namespace SepCore.UI
{
public class LevelUpFormRawData
public class LevelUpRawData
{
public List<DRLevelUpReward> Rewards;
public int RefreshPrice;
}
}
}
@@ -9,9 +9,9 @@ using UnityGameFramework.Runtime;
using CustomUtility;
using GameFramework.DataTable;
namespace UI
namespace SepCore.UI
{
public class LevelUpFormUseCase : IUIUseCase
public class LevelUpUseCase : IUIUseCase
{
private const int BaseRefreshPrice = 2;
private readonly Action _onCompleted;
@@ -21,11 +21,11 @@ namespace UI
private readonly List<DRLevelUpReward> _validRewards = new();
private int _refreshCount;
private LevelUpFormRawData _currentModel;
private LevelUpRawData _currentModel;
private readonly Player _player;
public LevelUpFormUseCase(Player player, Action onCompleted)
public LevelUpUseCase(Player player, Action onCompleted)
{
_player = player;
_onCompleted = onCompleted;
@@ -35,7 +35,7 @@ namespace UI
BuildRewardRarityPools();
}
public LevelUpFormRawData CreateInitialModel(int count = 4)
public LevelUpRawData CreateInitialModel(int count = 4)
{
_refreshCount = 0;
@@ -49,7 +49,7 @@ namespace UI
return _currentModel;
}
public LevelUpFormRawData TryRefresh(int refreshCost, int count = 4)
public LevelUpRawData TryRefresh(int refreshCost, int count = 4)
{
if (_currentModel == null)
{
@@ -68,7 +68,7 @@ namespace UI
return _currentModel;
}
public LevelUpFormRawData SelectReward(int selectedIndex, int count = 4)
public LevelUpRawData SelectReward(int selectedIndex, int count = 4)
{
if (_currentModel?.Rewards == null)
{
@@ -95,7 +95,7 @@ namespace UI
return null;
}
private LevelUpFormRawData BuildModel(int refreshPrice, int count)
private LevelUpRawData BuildModel(int refreshPrice, int count)
{
if (_allRewards == null || _allRewards.Length == 0)
{
@@ -120,7 +120,7 @@ namespace UI
selections.Add(reward);
}
return new LevelUpFormRawData
return new LevelUpRawData
{
Rewards = selections,
RefreshPrice = refreshPrice
@@ -1,6 +1,6 @@
using SepCore.Definition;
namespace UI
namespace SepCore.UI
{
public class DisplayItemRawData
{
@@ -2,7 +2,7 @@ using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace UI
namespace SepCore.UI
{
public class DisplayListAreaRawData
{
@@ -1,7 +1,7 @@
using SepCore.Definition;
using UnityEngine;
namespace UI
namespace SepCore.UI
{
public class GoodsItemRawData
{
@@ -1,7 +1,7 @@
using SepCore.Definition;
using UnityEngine;
namespace UI
namespace SepCore.UI
{
public class LevelUpRewardItemRawData
{
@@ -2,9 +2,9 @@ using System.Collections.Generic;
using SepCore.Definition;
using Entity.Weapon;
namespace UI
namespace SepCore.UI
{
public class ShopFormRawData
public class ShopRawData
{
public int CurrentLevel;
public int RefreshPrice;
@@ -11,7 +11,7 @@ using UnityEngine;
using UnityGameFramework.Runtime;
using Random = UnityEngine.Random;
namespace UI
namespace SepCore.UI
{
public sealed class ShopRefreshResult
{
@@ -25,7 +25,7 @@ namespace UI
public DisplayItemRawData DisplayItem;
}
public class ShopFormUseCase : IUIUseCase
public class ShopUseCase : IUIUseCase
{
private readonly Player _player;
private readonly int _currentLevel;
@@ -51,7 +51,7 @@ namespace UI
public int Price;
}
public ShopFormUseCase(Player player, int currentLevel, Action onShopFinish)
public ShopUseCase(Player player, int currentLevel, Action onShopFinish)
{
_player = player;
_currentLevel = currentLevel;
@@ -64,7 +64,7 @@ namespace UI
BuildGoodsRarityPools();
}
public ShopFormRawData CreateInitialModel()
public ShopRawData CreateInitialModel()
{
_refreshTime = 0;
@@ -75,7 +75,7 @@ namespace UI
}
int currentLevel = _currentLevel;
return new ShopFormRawData
return new ShopRawData
{
CurrentLevel = currentLevel,
RefreshPrice = currentLevel,
@@ -1,6 +1,6 @@
namespace UI
namespace SepCore.UI
{
public class SelectRoleFormRawData
public class SelectRoleRawData
{
public int[] RoleIds;
public string[] RoleIconNames;
@@ -4,9 +4,9 @@ using SepCore.DataTable;
using GameFramework.DataTable;
using Random = UnityEngine.Random;
namespace UI
namespace SepCore.UI
{
public class SelectRoleFormUseCase : IUIUseCase
public class SelectRoleUseCase : IUIUseCase
{
private readonly IDataTable<DRRole> _roleDataTable;
@@ -14,18 +14,18 @@ namespace UI
public int SelectedRoleId { get; private set; }
public SelectRoleFormUseCase(Action<int> onStartGame)
public SelectRoleUseCase(Action<int> onStartGame)
{
_onStartGame = onStartGame;
_roleDataTable = GameEntry.DataTable.GetDataTable<DRRole>();
}
public SelectRoleFormRawData CreateModel()
public SelectRoleRawData CreateModel()
{
return BuildModel(0);
}
public SelectRoleFormRawData SelectRole(int roleId)
public SelectRoleRawData SelectRole(int roleId)
{
SelectedRoleId = roleId;
return BuildModel(roleId);
@@ -54,7 +54,7 @@ namespace UI
return result;
}
private SelectRoleFormRawData BuildModel(int selectedRoleId)
private SelectRoleRawData BuildModel(int selectedRoleId)
{
DRRole[] roles = _roleDataTable.GetAllDataRows();
int count = _roleDataTable.Count;
@@ -67,7 +67,7 @@ namespace UI
}
DRRole selectedRole = selectedRoleId > 0 ? _roleDataTable.GetDataRow(selectedRoleId) : null;
return new SelectRoleFormRawData
return new SelectRoleRawData
{
RoleIds = roleIds,
RoleIconNames = iconNames,
@@ -0,0 +1,7 @@
namespace SepCore.UI
{
public class MenuRawData
{
}
}
@@ -1,7 +0,0 @@
namespace UI
{
public class StartMenuFormRawData
{
}
}