- 引入 UnityGameFramework
- 使用 Luban 替代原来的 UGF 的数据表
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: edd16bf2e418bec43bc774c7fc6c60d6
|
||||
folderAsset: yes
|
||||
timeCreated: 1528026145
|
||||
licenseType: Pro
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,140 @@
|
||||
//------------------------------------------------------------
|
||||
// Game Framework
|
||||
// Copyright © 2013-2021 Jiang Yin. All rights reserved.
|
||||
// Homepage: https://gameframework.cn/
|
||||
// Feedback: mailto:ellan@gameframework.cn
|
||||
//------------------------------------------------------------
|
||||
|
||||
using UnityEngine;
|
||||
using UnityGameFramework.Runtime;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 游戏入口。
|
||||
/// </summary>
|
||||
public partial class GameEntry : MonoBehaviour
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取游戏基础组件。
|
||||
/// </summary>
|
||||
public static BaseComponent Base { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取配置组件。
|
||||
/// </summary>
|
||||
public static ConfigComponent Config { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取数据结点组件。
|
||||
/// </summary>
|
||||
public static DataNodeComponent DataNode { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取数据表组件。
|
||||
/// </summary>
|
||||
public static DataTableComponent DataTable { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取调试组件。
|
||||
/// </summary>
|
||||
public static DebuggerComponent Debugger { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取下载组件。
|
||||
/// </summary>
|
||||
public static DownloadComponent Download { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取实体组件。
|
||||
/// </summary>
|
||||
public static EntityComponent Entity { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取事件组件。
|
||||
/// </summary>
|
||||
public static EventComponent Event { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取文件系统组件。
|
||||
/// </summary>
|
||||
public static FileSystemComponent FileSystem { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取有限状态机组件。
|
||||
/// </summary>
|
||||
public static FsmComponent Fsm { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取本地化组件。
|
||||
/// </summary>
|
||||
public static LocalizationComponent Localization { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取网络组件。
|
||||
/// </summary>
|
||||
//public static NetworkComponent Network { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取对象池组件。
|
||||
/// </summary>
|
||||
public static ObjectPoolComponent ObjectPool { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取流程组件。
|
||||
/// </summary>
|
||||
public static ProcedureComponent Procedure { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取资源组件。
|
||||
/// </summary>
|
||||
public static ResourceComponent Resource { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取场景组件。
|
||||
/// </summary>
|
||||
public static SceneComponent Scene { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取配置组件。
|
||||
/// </summary>
|
||||
public static SettingComponent Setting { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取声音组件。
|
||||
/// </summary>
|
||||
public static SoundComponent Sound { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取界面组件。
|
||||
/// </summary>
|
||||
public static UIComponent UI { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取网络组件。
|
||||
/// </summary>
|
||||
public static WebRequestComponent WebRequest { get; private set; }
|
||||
|
||||
private static void InitBuiltinComponents()
|
||||
{
|
||||
Base = UnityGameFramework.Runtime.GameEntry.GetComponent<BaseComponent>();
|
||||
Config = UnityGameFramework.Runtime.GameEntry.GetComponent<ConfigComponent>();
|
||||
DataNode = UnityGameFramework.Runtime.GameEntry.GetComponent<DataNodeComponent>();
|
||||
DataTable = UnityGameFramework.Runtime.GameEntry.GetComponent<DataTableComponent>();
|
||||
Debugger = UnityGameFramework.Runtime.GameEntry.GetComponent<DebuggerComponent>();
|
||||
Download = UnityGameFramework.Runtime.GameEntry.GetComponent<DownloadComponent>();
|
||||
Entity = UnityGameFramework.Runtime.GameEntry.GetComponent<EntityComponent>();
|
||||
Event = UnityGameFramework.Runtime.GameEntry.GetComponent<EventComponent>();
|
||||
FileSystem = UnityGameFramework.Runtime.GameEntry.GetComponent<FileSystemComponent>();
|
||||
Fsm = UnityGameFramework.Runtime.GameEntry.GetComponent<FsmComponent>();
|
||||
Localization = UnityGameFramework.Runtime.GameEntry.GetComponent<LocalizationComponent>();
|
||||
//Network = UnityGameFramework.Runtime.GameEntry.GetComponent<NetworkComponent>();
|
||||
ObjectPool = UnityGameFramework.Runtime.GameEntry.GetComponent<ObjectPoolComponent>();
|
||||
Procedure = UnityGameFramework.Runtime.GameEntry.GetComponent<ProcedureComponent>();
|
||||
Resource = UnityGameFramework.Runtime.GameEntry.GetComponent<ResourceComponent>();
|
||||
Scene = UnityGameFramework.Runtime.GameEntry.GetComponent<SceneComponent>();
|
||||
Setting = UnityGameFramework.Runtime.GameEntry.GetComponent<SettingComponent>();
|
||||
Sound = UnityGameFramework.Runtime.GameEntry.GetComponent<SoundComponent>();
|
||||
UI = UnityGameFramework.Runtime.GameEntry.GetComponent<UIComponent>();
|
||||
WebRequest = UnityGameFramework.Runtime.GameEntry.GetComponent<WebRequestComponent>();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 98387342fa09ebd46a2ab54100d80c2f
|
||||
timeCreated: 1528026146
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,18 @@
|
||||
using SepCore.CustomComponent;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// 游戏入口。
|
||||
/// </summary>
|
||||
public partial class GameEntry : MonoBehaviour
|
||||
{
|
||||
public static BuiltinDataComponent BuiltinData { get; private set; }
|
||||
|
||||
public static LubanComponent Luban { get; private set; }
|
||||
|
||||
private static void InitCustomComponents()
|
||||
{
|
||||
BuiltinData = UnityGameFramework.Runtime.GameEntry.GetComponent<BuiltinDataComponent>();
|
||||
Luban = UnityGameFramework.Runtime.GameEntry.GetComponent<LubanComponent>();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f95ee7b97daca3f44a2f5cf743bb39ac
|
||||
timeCreated: 1528026146
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,20 @@
|
||||
//------------------------------------------------------------
|
||||
// Game Framework
|
||||
// Copyright © 2013-2021 Jiang Yin. All rights reserved.
|
||||
// Homepage: https://gameframework.cn/
|
||||
// Feedback: mailto:ellan@gameframework.cn
|
||||
//------------------------------------------------------------
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// 游戏入口。
|
||||
/// </summary>
|
||||
public partial class GameEntry : MonoBehaviour
|
||||
{
|
||||
private void Start()
|
||||
{
|
||||
InitBuiltinComponents();
|
||||
InitCustomComponents();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3d09b8a3e8c0e7e4dbcfd2fa52bf69ea
|
||||
timeCreated: 1528026145
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: -100
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 28c1c3400ef7ad14dbf54687b42b17f3
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 298887d9780dd6c40b43a3c398bab293
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,127 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using GameFramework.Event;
|
||||
|
||||
namespace SepCore.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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 32dddf8dedbcf384db9e3320cdc285ce
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,61 @@
|
||||
using Cysharp.Threading.Tasks;
|
||||
using UnityGameFramework.Runtime;
|
||||
|
||||
namespace SepCore.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;
|
||||
}
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c268d17be2de9c242939823c820012e4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,59 @@
|
||||
using Cysharp.Threading.Tasks;
|
||||
using GameFramework.Download;
|
||||
using UnityGameFramework.Runtime;
|
||||
using DownloadFailureEventArgs = UnityGameFramework.Runtime.DownloadFailureEventArgs;
|
||||
using DownloadSuccessEventArgs = UnityGameFramework.Runtime.DownloadSuccessEventArgs;
|
||||
|
||||
namespace SepCore.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);
|
||||
}
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cfc5e4ff432a8564a99f65529449b370
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,118 @@
|
||||
using System;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using GameFramework.Entity;
|
||||
using UnityGameFramework.Runtime;
|
||||
using HideEntityCompleteEventArgs = UnityGameFramework.Runtime.HideEntityCompleteEventArgs;
|
||||
using ShowEntityFailureEventArgs = UnityGameFramework.Runtime.ShowEntityFailureEventArgs;
|
||||
using ShowEntitySuccessEventArgs = UnityGameFramework.Runtime.ShowEntitySuccessEventArgs;
|
||||
|
||||
namespace SepCore.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<UnityGameFramework.Runtime.Entity> ShowEntityAsync(this EntityComponent entityComponent,
|
||||
int entityId,
|
||||
Type entityLogicType,
|
||||
string entityAssetName,
|
||||
string entityGroupName,
|
||||
object userData = null,
|
||||
float timeout = 30f)
|
||||
{
|
||||
UniTask<UnityGameFramework.Runtime.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,
|
||||
UnityGameFramework.Runtime.Entity entity,
|
||||
object userData = null,
|
||||
float timeout = 30f)
|
||||
{
|
||||
return HideEntityAsync(entityComponent, entity.Id, userData, timeout);
|
||||
}
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0049c1a3ff0446246b18d6b2ab0f29c6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
using Cysharp.Threading.Tasks;
|
||||
using UnityGameFramework.Runtime;
|
||||
|
||||
namespace SepCore.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;
|
||||
}
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2d8cd831d31f1e746bbc65c5591dc930
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,75 @@
|
||||
using Cysharp.Threading.Tasks;
|
||||
using UnityGameFramework.Runtime;
|
||||
using NetworkClosedEventArgs = UnityGameFramework.Runtime.NetworkClosedEventArgs;
|
||||
using NetworkConnectedEventArgs = UnityGameFramework.Runtime.NetworkConnectedEventArgs;
|
||||
|
||||
namespace SepCore.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
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
+11
@@ -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 Cysharp.Threading.Tasks;
|
||||
using UnityGameFramework.Runtime;
|
||||
using ResourceApplySuccessEventArgs = UnityGameFramework.Runtime.ResourceApplySuccessEventArgs;
|
||||
using ResourceUpdateAllCompleteEventArgs = UnityGameFramework.Runtime.ResourceUpdateAllCompleteEventArgs;
|
||||
using ResourceVerifySuccessEventArgs = UnityGameFramework.Runtime.ResourceVerifySuccessEventArgs;
|
||||
|
||||
namespace SepCore.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
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e1e5440eb71427c42a16164ab6a664e2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,66 @@
|
||||
using Cysharp.Threading.Tasks;
|
||||
using GameFramework.Scene;
|
||||
using UnityGameFramework.Runtime;
|
||||
using LoadSceneFailureEventArgs = UnityGameFramework.Runtime.LoadSceneFailureEventArgs;
|
||||
using LoadSceneSuccessEventArgs = UnityGameFramework.Runtime.LoadSceneSuccessEventArgs;
|
||||
using UnloadSceneFailureEventArgs = UnityGameFramework.Runtime.UnloadSceneFailureEventArgs;
|
||||
using UnloadSceneSuccessEventArgs = UnityGameFramework.Runtime.UnloadSceneSuccessEventArgs;
|
||||
|
||||
namespace SepCore.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;
|
||||
}
|
||||
}
|
||||
}
|
||||
+11
@@ -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 Cysharp.Threading.Tasks;
|
||||
using GameFramework.Sound;
|
||||
using UnityGameFramework.Runtime;
|
||||
using PlaySoundFailureEventArgs = UnityGameFramework.Runtime.PlaySoundFailureEventArgs;
|
||||
using PlaySoundSuccessEventArgs = UnityGameFramework.Runtime.PlaySoundSuccessEventArgs;
|
||||
|
||||
namespace SepCore.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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+11
@@ -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.UI;
|
||||
using UnityGameFramework.Runtime;
|
||||
using SepCore.Definition;
|
||||
|
||||
namespace SepCore.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:
|
||||
+101
@@ -0,0 +1,101 @@
|
||||
using Cysharp.Threading.Tasks;
|
||||
using UnityGameFramework.Runtime;
|
||||
using WebRequestFailureEventArgs = UnityGameFramework.Runtime.WebRequestFailureEventArgs;
|
||||
using WebRequestSuccessEventArgs = UnityGameFramework.Runtime.WebRequestSuccessEventArgs;
|
||||
|
||||
namespace SepCore.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;
|
||||
}
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 579cf8ed8a820d34d9e7e46f60a3f176
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,79 @@
|
||||
using System;
|
||||
using SepCore.Definition;
|
||||
using SepCore.Utility;
|
||||
using UnityGameFramework.Runtime;
|
||||
|
||||
namespace SepCore.Entity
|
||||
{
|
||||
public static class EntityExtension
|
||||
{
|
||||
private static int _serialId = 0;
|
||||
|
||||
public static EntityBase GetGameEntity(this EntityComponent entityComponent, int entityId)
|
||||
{
|
||||
UnityGameFramework.Runtime.Entity entity = entityComponent.GetEntity(entityId);
|
||||
if (entity == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return (EntityBase)entity.Logic;
|
||||
}
|
||||
|
||||
public static void HideEntity(this EntityComponent entityComponent, EntityBase entity)
|
||||
{
|
||||
entityComponent.HideEntity(entity.Entity);
|
||||
}
|
||||
|
||||
public static void AttachEntity(this EntityComponent entityComponent, EntityBase entityBase, int ownerId,
|
||||
string parentTransformPath = null, object userData = null)
|
||||
{
|
||||
entityComponent.AttachEntity(entityBase.Entity, ownerId, parentTransformPath, userData);
|
||||
}
|
||||
|
||||
public static void ShowEntity<T>(this EntityComponent entityComponent, EntityDataBase data, string group,
|
||||
int priority) where T : EntityBase
|
||||
{
|
||||
if (data == null)
|
||||
{
|
||||
Log.Warning("Data is invalid.");
|
||||
return;
|
||||
}
|
||||
|
||||
EntityConfig entityConfig = GameEntry.Luban.Get<EntityConfig>(data.TypeId);
|
||||
if (entityConfig == null)
|
||||
{
|
||||
Log.Warning("Can not load entity id '{0}' from data table.", data.TypeId.ToString());
|
||||
return;
|
||||
}
|
||||
|
||||
entityComponent.ShowEntity(data.Id, typeof(T), AssetUtility.GetEntityAsset(entityConfig.AssetName), group,
|
||||
priority, data);
|
||||
}
|
||||
|
||||
private static void ShowEntity(this EntityComponent entityComponent, Type logicType, string entityGroup,
|
||||
int priority, EntityDataBase data)
|
||||
{
|
||||
if (data == null)
|
||||
{
|
||||
Log.Warning("Data is invalid.");
|
||||
return;
|
||||
}
|
||||
|
||||
EntityConfig entityConfig = GameEntry.Luban.Get<EntityConfig>(data.TypeId);
|
||||
if (entityConfig == null)
|
||||
{
|
||||
Log.Warning("Can not load entity id '{0}' from data table.", data.TypeId.ToString());
|
||||
return;
|
||||
}
|
||||
|
||||
entityComponent.ShowEntity(data.Id, logicType, AssetUtility.GetEntityAsset(entityConfig.AssetName), entityGroup,
|
||||
priority, data);
|
||||
}
|
||||
|
||||
public static int SerialId(this EntityComponent entityComponent)
|
||||
{
|
||||
return ++_serialId;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 626632079980ad34595c3b43a062a664
|
||||
timeCreated: 1528026153
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,165 @@
|
||||
using GameFramework.Sound;
|
||||
using SepCore.Definition;
|
||||
using SepCore.Entity;
|
||||
using SepCore.Utility;
|
||||
using UnityGameFramework.Runtime;
|
||||
|
||||
namespace SepCore.Sound
|
||||
{
|
||||
public static class SoundExtension
|
||||
{
|
||||
private const float FadeVolumeDuration = 1f;
|
||||
private static int? s_MusicSerialId = null;
|
||||
|
||||
public static int? PlayMusic(this SoundComponent soundComponent, int musicId, object userData = null)
|
||||
{
|
||||
soundComponent.StopMusic();
|
||||
|
||||
MusicConfig musicConfig = GameEntry.Luban.Get<MusicConfig>(musicId);
|
||||
if (musicConfig == null)
|
||||
{
|
||||
Log.Warning("Can not load music '{0}' from data table.", musicId.ToString());
|
||||
return null;
|
||||
}
|
||||
|
||||
PlaySoundParams playSoundParams = PlaySoundParams.Create();
|
||||
playSoundParams.Priority = 64;
|
||||
playSoundParams.Loop = true;
|
||||
playSoundParams.VolumeInSoundGroup = 1f;
|
||||
playSoundParams.FadeInSeconds = FadeVolumeDuration;
|
||||
playSoundParams.SpatialBlend = 0f;
|
||||
s_MusicSerialId = soundComponent.PlaySound(AssetUtility.GetMusicAsset(musicConfig.AssetName), "Music",
|
||||
Constant.AssetPriority.MusicAsset, playSoundParams, null, userData);
|
||||
return s_MusicSerialId;
|
||||
}
|
||||
|
||||
public static void StopMusic(this SoundComponent soundComponent)
|
||||
{
|
||||
if (!s_MusicSerialId.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
soundComponent.StopSound(s_MusicSerialId.Value, FadeVolumeDuration);
|
||||
s_MusicSerialId = null;
|
||||
}
|
||||
|
||||
public static int? PlaySound(this SoundComponent soundComponent, int soundId, EntityBase bindingEntity = null,
|
||||
object userData = null)
|
||||
{
|
||||
SoundConfig soundConfig = GameEntry.Luban.Get<SoundConfig>(soundId);
|
||||
if (soundConfig == null)
|
||||
{
|
||||
Log.Warning("Can not load sound '{0}' from data table.", soundId.ToString());
|
||||
return null;
|
||||
}
|
||||
|
||||
PlaySoundParams playSoundParams = PlaySoundParams.Create();
|
||||
playSoundParams.Priority = soundConfig.Priority;
|
||||
playSoundParams.Loop = soundConfig.Loop;
|
||||
playSoundParams.VolumeInSoundGroup = soundConfig.Volume;
|
||||
playSoundParams.SpatialBlend = soundConfig.SpatialBlend;
|
||||
return soundComponent.PlaySound(AssetUtility.GetSoundAsset(soundConfig.AssetName), "Sound",
|
||||
Constant.AssetPriority.SoundAsset, playSoundParams, bindingEntity != null ? bindingEntity.Entity : null,
|
||||
userData);
|
||||
}
|
||||
|
||||
public static int? PlayUISound(this SoundComponent soundComponent, int uiSoundId, object userData = null)
|
||||
{
|
||||
UISoundConfig uiSoundConfig = GameEntry.Luban.Get<UISoundConfig>(uiSoundId);
|
||||
if (uiSoundConfig == null)
|
||||
{
|
||||
Log.Warning("Can not load UI sound '{0}' from data table.", uiSoundId.ToString());
|
||||
return null;
|
||||
}
|
||||
|
||||
PlaySoundParams playSoundParams = PlaySoundParams.Create();
|
||||
playSoundParams.Priority = uiSoundConfig.Priority;
|
||||
playSoundParams.Loop = false;
|
||||
playSoundParams.VolumeInSoundGroup = uiSoundConfig.Volume;
|
||||
playSoundParams.SpatialBlend = 0f;
|
||||
return soundComponent.PlaySound(AssetUtility.GetUISoundAsset(uiSoundConfig.AssetName), "UISound",
|
||||
Constant.AssetPriority.UISoundAsset, playSoundParams, userData);
|
||||
}
|
||||
|
||||
public static bool IsMuted(this SoundComponent soundComponent, string soundGroupName)
|
||||
{
|
||||
if (string.IsNullOrEmpty(soundGroupName))
|
||||
{
|
||||
Log.Warning("Sound group is invalid.");
|
||||
return true;
|
||||
}
|
||||
|
||||
ISoundGroup soundGroup = soundComponent.GetSoundGroup(soundGroupName);
|
||||
if (soundGroup == null)
|
||||
{
|
||||
Log.Warning("Sound group '{0}' is invalid.", soundGroupName);
|
||||
return true;
|
||||
}
|
||||
|
||||
return soundGroup.Mute;
|
||||
}
|
||||
|
||||
public static void Mute(this SoundComponent soundComponent, string soundGroupName, bool mute)
|
||||
{
|
||||
if (string.IsNullOrEmpty(soundGroupName))
|
||||
{
|
||||
Log.Warning("Sound group is invalid.");
|
||||
return;
|
||||
}
|
||||
|
||||
ISoundGroup soundGroup = soundComponent.GetSoundGroup(soundGroupName);
|
||||
if (soundGroup == null)
|
||||
{
|
||||
Log.Warning("Sound group '{0}' is invalid.", soundGroupName);
|
||||
return;
|
||||
}
|
||||
|
||||
soundGroup.Mute = mute;
|
||||
|
||||
GameEntry.Setting.SetBool(
|
||||
GameFramework.Utility.Text.Format(Constant.Setting.SoundGroupMuted, soundGroupName), mute);
|
||||
GameEntry.Setting.Save();
|
||||
}
|
||||
|
||||
public static float GetVolume(this SoundComponent soundComponent, string soundGroupName)
|
||||
{
|
||||
if (string.IsNullOrEmpty(soundGroupName))
|
||||
{
|
||||
Log.Warning("Sound group is invalid.");
|
||||
return 0f;
|
||||
}
|
||||
|
||||
ISoundGroup soundGroup = soundComponent.GetSoundGroup(soundGroupName);
|
||||
if (soundGroup == null)
|
||||
{
|
||||
Log.Warning("Sound group '{0}' is invalid.", soundGroupName);
|
||||
return 0f;
|
||||
}
|
||||
|
||||
return soundGroup.Volume;
|
||||
}
|
||||
|
||||
public static void SetVolume(this SoundComponent soundComponent, string soundGroupName, float volume)
|
||||
{
|
||||
if (string.IsNullOrEmpty(soundGroupName))
|
||||
{
|
||||
Log.Warning("Sound group is invalid.");
|
||||
return;
|
||||
}
|
||||
|
||||
ISoundGroup soundGroup = soundComponent.GetSoundGroup(soundGroupName);
|
||||
if (soundGroup == null)
|
||||
{
|
||||
Log.Warning("Sound group '{0}' is invalid.", soundGroupName);
|
||||
return;
|
||||
}
|
||||
|
||||
soundGroup.Volume = volume;
|
||||
|
||||
GameEntry.Setting.SetFloat(
|
||||
GameFramework.Utility.Text.Format(Constant.Setting.SoundGroupVolume, soundGroupName), volume);
|
||||
GameEntry.Setting.Save();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cded0c5c73a207a498c6e5af208e5f7e
|
||||
timeCreated: 1528026160
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,121 @@
|
||||
using GameFramework.UI;
|
||||
using SepCore.Definition;
|
||||
using SepCore.Utility;
|
||||
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)
|
||||
{
|
||||
UIFormConfig uiFormConfig = GameEntry.Luban.Get<UIFormConfig>(uiFormId);
|
||||
if (uiFormConfig == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
string assetName = AssetUtility.GetUIFormAsset(uiFormConfig.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)
|
||||
{
|
||||
UIFormConfig uiFormConfig = GameEntry.Luban.Get<UIFormConfig>(uiFormId);
|
||||
if (uiFormConfig == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
string assetName = AssetUtility.GetUIFormAsset(uiFormConfig.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)
|
||||
{
|
||||
UIFormConfig uiFormConfig = GameEntry.Luban.Get<UIFormConfig>(uiFormId);
|
||||
if (uiFormConfig == null)
|
||||
{
|
||||
Log.Warning("Can not load UI form '{0}' from data table.", uiFormId.ToString());
|
||||
return null;
|
||||
}
|
||||
|
||||
string assetName = AssetUtility.GetUIFormAsset(uiFormConfig.AssetName);
|
||||
if (!uiFormConfig.AllowMultiInstance)
|
||||
{
|
||||
if (uiComponent.IsLoadingUIForm(assetName))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (uiComponent.HasUIForm(assetName))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return uiComponent.OpenUIForm(assetName, uiFormConfig.UIGroupName, Constant.AssetPriority.UIFormAsset,
|
||||
uiFormConfig.PauseCoveredUIForm, userData);
|
||||
}
|
||||
|
||||
public static void OpenDialog(this UIComponent uiComponent, DialogParams dialogParams)
|
||||
{
|
||||
uiComponent.OpenUIForm(UIFormType.DialogForm, dialogParams);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9cfc2c881ce240349901812c61f4476b
|
||||
timeCreated: 1528026162
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,70 @@
|
||||
using GameFramework.Localization;
|
||||
using System;
|
||||
using System.Xml;
|
||||
using UnityGameFramework.Runtime;
|
||||
|
||||
namespace SepCore.Localization
|
||||
{
|
||||
/// <summary>
|
||||
/// XML 格式的本地化辅助器。
|
||||
/// </summary>
|
||||
public class XmlLocalizationHelper : DefaultLocalizationHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// 解析字典。
|
||||
/// </summary>
|
||||
/// <param name="dictionaryString">要解析的字典字符串。</param>
|
||||
/// <param name="userData">用户自定义数据。</param>
|
||||
/// <returns>是否解析字典成功。</returns>
|
||||
public override bool ParseData(ILocalizationManager localizationManager, string dictionaryString, object userData)
|
||||
{
|
||||
try
|
||||
{
|
||||
string currentLanguage = GameEntry.Localization.Language.ToString();
|
||||
XmlDocument xmlDocument = new XmlDocument();
|
||||
xmlDocument.LoadXml(dictionaryString);
|
||||
XmlNode xmlRoot = xmlDocument.SelectSingleNode("Dictionaries");
|
||||
XmlNodeList xmlNodeDictionaryList = xmlRoot.ChildNodes;
|
||||
for (int i = 0; i < xmlNodeDictionaryList.Count; i++)
|
||||
{
|
||||
XmlNode xmlNodeDictionary = xmlNodeDictionaryList.Item(i);
|
||||
if (xmlNodeDictionary.Name != "Dictionary")
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
string language = xmlNodeDictionary.Attributes.GetNamedItem("Language").Value;
|
||||
if (language != currentLanguage)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
XmlNodeList xmlNodeStringList = xmlNodeDictionary.ChildNodes;
|
||||
for (int j = 0; j < xmlNodeStringList.Count; j++)
|
||||
{
|
||||
XmlNode xmlNodeString = xmlNodeStringList.Item(j);
|
||||
if (xmlNodeString.Name != "String")
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
string key = xmlNodeString.Attributes.GetNamedItem("Key").Value;
|
||||
string value = xmlNodeString.Attributes.GetNamedItem("Value").Value;
|
||||
if (!localizationManager.AddRawString(key, value))
|
||||
{
|
||||
Log.Warning("Can not add raw string with key '{0}' which may be invalid or duplicate.", key);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Log.Warning("Can not parse dictionary data with exception '{0}'.", exception.ToString());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 44a338771c89a5348b00b9b0c13c1907
|
||||
timeCreated: 1528026156
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 255b8544e4a40d94490e9a2718f6f1e9
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 33ba0562010e2da46883baefb271f573
|
||||
folderAsset: yes
|
||||
timeCreated: 1528026146
|
||||
licenseType: Pro
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,54 @@
|
||||
using SepCore.Definition;
|
||||
using SepCore.UI;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Serialization;
|
||||
using UnityGameFramework.Runtime;
|
||||
|
||||
namespace SepCore.CustomComponent
|
||||
{
|
||||
public class BuiltinDataComponent : GameFrameworkComponent
|
||||
{
|
||||
[FormerlySerializedAs("m_BuildInfoTextAsset")] [SerializeField] private TextAsset _buildInfoTextAsset = null;
|
||||
|
||||
[FormerlySerializedAs("m_DefaultDictionaryTextAsset")] [SerializeField] private TextAsset _defaultDictionaryTextAsset = null;
|
||||
|
||||
[FormerlySerializedAs("m_UpdateResourceFormTemplate")] [SerializeField] private GameObject _updateResourceFormTemplate = null;
|
||||
|
||||
private BuildInfo _buildInfo = null;
|
||||
|
||||
public BuildInfo BuildInfo => _buildInfo;
|
||||
|
||||
public GameObject UpdateResourceFormTemplate => _updateResourceFormTemplate;
|
||||
|
||||
public void InitBuildInfo()
|
||||
{
|
||||
if (_buildInfoTextAsset == null || string.IsNullOrEmpty(_buildInfoTextAsset.text))
|
||||
{
|
||||
Log.Info("Build info can not be found or empty.");
|
||||
return;
|
||||
}
|
||||
|
||||
_buildInfo = GameFramework.Utility.Json.ToObject<BuildInfo>(_buildInfoTextAsset.text);
|
||||
if (_buildInfo == null)
|
||||
{
|
||||
Log.Warning("Parse build info failure.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public void InitDefaultDictionary()
|
||||
{
|
||||
if (_defaultDictionaryTextAsset == null || string.IsNullOrEmpty(_defaultDictionaryTextAsset.text))
|
||||
{
|
||||
Log.Info("Default dictionary can not be found or empty.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!GameEntry.Localization.ParseData(_defaultDictionaryTextAsset.text))
|
||||
{
|
||||
Log.Warning("Parse default dictionary failure.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cfb0b001fcb30fe45ac95ddb8c28ba57
|
||||
timeCreated: 1528026146
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0d03aa2b156c24d25a59994ee920721d
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,211 @@
|
||||
using GameFramework.Resource;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Luban;
|
||||
using SepCore.Definition;
|
||||
using UnityEngine;
|
||||
using UnityGameFramework.Runtime;
|
||||
|
||||
namespace SepCore.CustomComponent
|
||||
{
|
||||
/// <summary>
|
||||
/// Luban 数据表组件。
|
||||
/// 生成的数据结构与枚举位于 Assets/GameMain/Scripts/Base/Gen。
|
||||
/// 负责加载 Luban 导出的二进制数据表(.bytes)并构建 SepCore.Definition.Tables。
|
||||
/// 注意:表名列表需与 SepCore.Definition.Tables 构造函数保持一致。
|
||||
/// </summary>
|
||||
public class LubanComponent : GameFrameworkComponent
|
||||
{
|
||||
private static readonly string[] TableNames = new string[]
|
||||
{
|
||||
"tbglobalconfig",
|
||||
"tbrarityconfig",
|
||||
"tbdifficultyconfig",
|
||||
"tbcharacterconfig",
|
||||
"tbbattleactionconfig",
|
||||
"tbthreatlevelconfig",
|
||||
"tbenemyconfig",
|
||||
"tbenemypartyconfig",
|
||||
"tbitemconfig",
|
||||
"tbresourcepointconfig",
|
||||
"tbenemydropconfig",
|
||||
"tbentityconfig",
|
||||
"tbmusicconfig",
|
||||
"tbsceneconfig",
|
||||
"tbsoundconfig",
|
||||
"tbuiformconfig",
|
||||
"tbuisoundconfig",
|
||||
};
|
||||
|
||||
private sealed class TableAccessor
|
||||
{
|
||||
public Func<Tables, int, object> RowGetter;
|
||||
public Func<Tables, object> ListGetter;
|
||||
}
|
||||
|
||||
private static readonly Dictionary<Type, TableAccessor> TableAccessors =
|
||||
new Dictionary<Type, TableAccessor>
|
||||
{
|
||||
{ typeof(CharacterConfig), Accessor(tables => id => tables.TbCharacterConfig.GetOrDefault(id), tables => tables.TbCharacterConfig.DataList) },
|
||||
{ typeof(BattleActionConfig), Accessor(tables => id => tables.TbBattleActionConfig.GetOrDefault(id), tables => tables.TbBattleActionConfig.DataList) },
|
||||
{ typeof(ThreatLevelConfig), Accessor(tables => id => tables.TbThreatLevelConfig.GetOrDefault(id), tables => tables.TbThreatLevelConfig.DataList) },
|
||||
{ typeof(EnemyConfig), Accessor(tables => id => tables.TbEnemyConfig.GetOrDefault(id), tables => tables.TbEnemyConfig.DataList) },
|
||||
{ typeof(EnemyPartyConfig), Accessor(tables => id => tables.TbEnemyPartyConfig.GetOrDefault(id), tables => tables.TbEnemyPartyConfig.DataList) },
|
||||
{ typeof(ItemConfig), Accessor(tables => id => tables.TbItemConfig.GetOrDefault(id), tables => tables.TbItemConfig.DataList) },
|
||||
{ typeof(ResourcePointConfig), Accessor(tables => id => tables.TbResourcePointConfig.GetOrDefault(id), tables => tables.TbResourcePointConfig.DataList) },
|
||||
{ typeof(EnemyDropConfig), Accessor(tables => id => tables.TbEnemyDropConfig.GetOrDefault(id), tables => tables.TbEnemyDropConfig.DataList) },
|
||||
{ typeof(RarityConfig), Accessor(tables => id => tables.TbRarityConfig.GetOrDefault((Rarity)id), tables => tables.TbRarityConfig.DataList) },
|
||||
{ typeof(DifficultyConfig), Accessor(tables => id => tables.TbDifficultyConfig.GetOrDefault((DifficultyTier)id), tables => tables.TbDifficultyConfig.DataList) },
|
||||
{ typeof(EntityConfig), Accessor(tables => id => tables.TbEntityConfig.GetOrDefault(id), tables => tables.TbEntityConfig.DataList) },
|
||||
{ typeof(MusicConfig), Accessor(tables => id => tables.TbMusicConfig.GetOrDefault(id), tables => tables.TbMusicConfig.DataList) },
|
||||
{ typeof(SceneConfig), Accessor(tables => id => tables.TbSceneConfig.GetOrDefault(id), tables => tables.TbSceneConfig.DataList) },
|
||||
{ typeof(SoundConfig), Accessor(tables => id => tables.TbSoundConfig.GetOrDefault(id), tables => tables.TbSoundConfig.DataList) },
|
||||
{ typeof(UIFormConfig), Accessor(tables => id => tables.TbUIFormConfig.GetOrDefault(id), tables => tables.TbUIFormConfig.DataList) },
|
||||
{ typeof(UISoundConfig), Accessor(tables => id => tables.TbUISoundConfig.GetOrDefault(id), tables => tables.TbUISoundConfig.DataList) },
|
||||
};
|
||||
|
||||
private static TableAccessor Accessor<TValue>(Func<Tables, Func<int, object>> rowGetterFactory,
|
||||
Func<Tables, List<TValue>> listGetter) where TValue : BeanBase
|
||||
{
|
||||
return new TableAccessor
|
||||
{
|
||||
RowGetter = (tables, id) => rowGetterFactory(tables)(id),
|
||||
ListGetter = tables => listGetter(tables)
|
||||
};
|
||||
}
|
||||
|
||||
private Dictionary<string, byte[]> _tableBytes = null;
|
||||
private int _remainCount = 0;
|
||||
private Action _onLoadSuccess = null;
|
||||
private Action<string> _onLoadFailure = null;
|
||||
|
||||
/// <summary>
|
||||
/// 获取 Luban 数据表管理器,加载完成后可用。
|
||||
/// </summary>
|
||||
public SepCore.Definition.Tables Tables { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取数据表是否已加载完成。
|
||||
/// </summary>
|
||||
public bool IsReady => Tables != null;
|
||||
|
||||
/// <summary>
|
||||
/// 按 id 获取数据行,未找到时返回 null。
|
||||
/// </summary>
|
||||
/// <typeparam name="T">数据行类型(对应生成的 xxxConfig 类)。</typeparam>
|
||||
/// <param name="id">数据行主键。</param>
|
||||
/// <returns>数据行,未找到时返回 null。</returns>
|
||||
public T Get<T>(int id) where T : class
|
||||
{
|
||||
if (Tables == null)
|
||||
{
|
||||
throw new InvalidOperationException("Luban data tables are not loaded yet.");
|
||||
}
|
||||
|
||||
TableAccessor accessor;
|
||||
if (!TableAccessors.TryGetValue(typeof(T), out accessor))
|
||||
{
|
||||
throw new NotSupportedException("No table getter is registered for type '" + typeof(T).FullName + "'.");
|
||||
}
|
||||
|
||||
return (T)accessor.RowGetter(Tables, id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取整个表的所有数据行。
|
||||
/// </summary>
|
||||
/// <typeparam name="T">数据行类型(对应生成的 xxxConfig 类)。</typeparam>
|
||||
/// <returns>表内全部数据行,可安全遍历。</returns>
|
||||
public IReadOnlyList<T> GetTable<T>() where T : class
|
||||
{
|
||||
if (Tables == null)
|
||||
{
|
||||
throw new InvalidOperationException("Luban data tables are not loaded yet.");
|
||||
}
|
||||
|
||||
TableAccessor accessor;
|
||||
if (!TableAccessors.TryGetValue(typeof(T), out accessor))
|
||||
{
|
||||
throw new NotSupportedException("No table getter is registered for type '" + typeof(T).FullName + "'.");
|
||||
}
|
||||
|
||||
return (IReadOnlyList<T>)accessor.ListGetter(Tables);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步加载所有数据表。
|
||||
/// </summary>
|
||||
/// <param name="onSuccess">加载成功回调。</param>
|
||||
/// <param name="onFailure">加载失败回调,参数为错误信息。</param>
|
||||
public void LoadTables(Action onSuccess, Action<string> onFailure)
|
||||
{
|
||||
if (IsReady)
|
||||
{
|
||||
onSuccess?.Invoke();
|
||||
return;
|
||||
}
|
||||
|
||||
_onLoadSuccess = onSuccess;
|
||||
_onLoadFailure = onFailure;
|
||||
_tableBytes = new Dictionary<string, byte[]>(TableNames.Length);
|
||||
_remainCount = TableNames.Length;
|
||||
|
||||
foreach (string tableName in TableNames)
|
||||
{
|
||||
GameEntry.Resource.LoadAsset(GetTableAssetPath(tableName), Constant.AssetPriority.DataTableAsset,
|
||||
new LoadAssetCallbacks(OnLoadTableSuccess, OnLoadTableFailure), tableName);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnLoadTableSuccess(string assetName, object asset, float duration, object userData)
|
||||
{
|
||||
string tableName = (string)userData;
|
||||
TextAsset textAsset = asset as TextAsset;
|
||||
if (textAsset == null)
|
||||
{
|
||||
OnLoadTableFailure(assetName, LoadResourceStatus.AssetError, "Table asset is invalid.", userData);
|
||||
return;
|
||||
}
|
||||
|
||||
_tableBytes[tableName] = textAsset.bytes;
|
||||
if (--_remainCount > 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
Tables = new SepCore.Definition.Tables(name => new Luban.ByteBuf(_tableBytes[name]));
|
||||
_tableBytes = null;
|
||||
Log.Info("Load Luban data tables OK.");
|
||||
Action onLoadSuccess = _onLoadSuccess;
|
||||
_onLoadSuccess = null;
|
||||
_onLoadFailure = null;
|
||||
onLoadSuccess?.Invoke();
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Log.Error("Build Luban data tables failure with exception '{0}'.", exception);
|
||||
Action<string> onLoadFailure = _onLoadFailure;
|
||||
_onLoadSuccess = null;
|
||||
_onLoadFailure = null;
|
||||
onLoadFailure?.Invoke(exception.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
private void OnLoadTableFailure(string assetName, LoadResourceStatus status, string errorMessage, object userData)
|
||||
{
|
||||
Log.Error("Can not load data table '{0}' from '{1}' with error message '{2}'.", (string)userData, assetName,
|
||||
errorMessage);
|
||||
Action<string> onLoadFailure = _onLoadFailure;
|
||||
_onLoadSuccess = null;
|
||||
_onLoadFailure = null;
|
||||
onLoadFailure?.Invoke(errorMessage);
|
||||
}
|
||||
|
||||
private static string GetTableAssetPath(string tableName)
|
||||
{
|
||||
return GameFramework.Utility.Text.Format("Assets/GameMain/DataTables/{0}.bytes", tableName);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7686ced148554a92ba9da1fd22a26d01
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5479812568543994bbbcdbee6c42fce1
|
||||
folderAsset: yes
|
||||
timeCreated: 1528026148
|
||||
licenseType: Pro
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,86 @@
|
||||
//------------------------------------------------------------
|
||||
// Game Framework
|
||||
// Copyright © 2013-2021 Jiang Yin. All rights reserved.
|
||||
// Homepage: https://gameframework.cn/
|
||||
// Feedback: mailto:ellan@gameframework.cn
|
||||
//------------------------------------------------------------
|
||||
|
||||
using GameFramework.Debugger;
|
||||
using GameFramework.Localization;
|
||||
using SepCore.Definition;
|
||||
using UnityEngine;
|
||||
using UnityGameFramework.Runtime;
|
||||
|
||||
namespace SepCore.Debugger
|
||||
{
|
||||
public class ChangeLanguageDebuggerWindow : IDebuggerWindow
|
||||
{
|
||||
private Vector2 m_ScrollPosition = Vector2.zero;
|
||||
private bool m_NeedRestart = false;
|
||||
|
||||
public void Initialize(params object[] args)
|
||||
{
|
||||
}
|
||||
|
||||
public void Shutdown()
|
||||
{
|
||||
}
|
||||
|
||||
public void OnEnter()
|
||||
{
|
||||
}
|
||||
|
||||
public void OnLeave()
|
||||
{
|
||||
}
|
||||
|
||||
public void OnUpdate(float elapseSeconds, float realElapseSeconds)
|
||||
{
|
||||
if (m_NeedRestart)
|
||||
{
|
||||
m_NeedRestart = false;
|
||||
UnityGameFramework.Runtime.GameEntry.Shutdown(ShutdownType.Restart);
|
||||
}
|
||||
}
|
||||
|
||||
public void OnDraw()
|
||||
{
|
||||
m_ScrollPosition = GUILayout.BeginScrollView(m_ScrollPosition);
|
||||
{
|
||||
DrawSectionChangeLanguage();
|
||||
}
|
||||
GUILayout.EndScrollView();
|
||||
}
|
||||
|
||||
private void DrawSectionChangeLanguage()
|
||||
{
|
||||
GUILayout.Label("<b>Change Language</b>");
|
||||
GUILayout.BeginHorizontal("box");
|
||||
{
|
||||
if (GUILayout.Button("Chinese Simplified", GUILayout.Height(30)))
|
||||
{
|
||||
GameEntry.Localization.Language = Language.ChineseSimplified;
|
||||
SaveLanguage();
|
||||
}
|
||||
if (GUILayout.Button("Chinese Traditional", GUILayout.Height(30)))
|
||||
{
|
||||
GameEntry.Localization.Language = Language.ChineseTraditional;
|
||||
SaveLanguage();
|
||||
}
|
||||
if (GUILayout.Button("English", GUILayout.Height(30)))
|
||||
{
|
||||
GameEntry.Localization.Language = Language.English;
|
||||
SaveLanguage();
|
||||
}
|
||||
}
|
||||
GUILayout.EndHorizontal();
|
||||
}
|
||||
|
||||
private void SaveLanguage()
|
||||
{
|
||||
GameEntry.Setting.SetString(Constant.Setting.Language, GameEntry.Localization.Language.ToString());
|
||||
GameEntry.Setting.Save();
|
||||
m_NeedRestart = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 278a7992e66d1ea4081597614f912f3d
|
||||
timeCreated: 1528026148
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"name": "SepCore.Runtime",
|
||||
"rootNamespace": "SepCore.Runtime",
|
||||
"references": [
|
||||
"GUID:75469ad4d38634e559750d17036d5f7c",
|
||||
"GUID:6055be8ebefd69e48b49212b09b47b2f",
|
||||
"GUID:363c5eb08ff8e6a439b85e37b8c20d96",
|
||||
"GUID:a04b272484018094ab427253f20c416c",
|
||||
"GUID:3bb549212964b4192b427888ac9382e7",
|
||||
"GUID:f51ebe6a0ceec4240a699833d6309b23"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 11ec41dbc3557e6499b2845ba531a9b0
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9c08362ea1ab4a34f967437fe28255cf
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,82 @@
|
||||
//------------------------------------------------------------
|
||||
// Game Framework
|
||||
// Copyright © 2013-2021 Jiang Yin. All rights reserved.
|
||||
// Homepage: https://gameframework.cn/
|
||||
// Feedback: mailto:ellan@gameframework.cn
|
||||
//------------------------------------------------------------
|
||||
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
namespace SepCore.UI
|
||||
{
|
||||
public class CommonButton : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler, IPointerDownHandler, IPointerUpHandler
|
||||
{
|
||||
private const float FadeTime = 0.3f;
|
||||
private const float OnHoverAlpha = 0.7f;
|
||||
private const float OnClickAlpha = 0.6f;
|
||||
|
||||
[SerializeField]
|
||||
private UnityEvent m_OnHover = null;
|
||||
|
||||
[SerializeField]
|
||||
private UnityEvent m_OnClick = null;
|
||||
|
||||
private CanvasGroup m_CanvasGroup = null;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
m_CanvasGroup = gameObject.GetOrAddComponent<CanvasGroup>();
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
m_CanvasGroup.alpha = 1f;
|
||||
}
|
||||
|
||||
public void OnPointerEnter(PointerEventData eventData)
|
||||
{
|
||||
if (eventData.button != PointerEventData.InputButton.Left)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
StopAllCoroutines();
|
||||
StartCoroutine(m_CanvasGroup.FadeToAlpha(OnHoverAlpha, FadeTime));
|
||||
m_OnHover.Invoke();
|
||||
}
|
||||
|
||||
public void OnPointerExit(PointerEventData eventData)
|
||||
{
|
||||
if (eventData.button != PointerEventData.InputButton.Left)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
StopAllCoroutines();
|
||||
StartCoroutine(m_CanvasGroup.FadeToAlpha(1f, FadeTime));
|
||||
}
|
||||
|
||||
public void OnPointerDown(PointerEventData eventData)
|
||||
{
|
||||
if (eventData.button != PointerEventData.InputButton.Left)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
m_CanvasGroup.alpha = OnClickAlpha;
|
||||
m_OnClick.Invoke();
|
||||
}
|
||||
|
||||
public void OnPointerUp(PointerEventData eventData)
|
||||
{
|
||||
if (eventData.button != PointerEventData.InputButton.Left)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
m_CanvasGroup.alpha = OnHoverAlpha;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a5079836f95c2a44b96fa331487ebb70
|
||||
timeCreated: 1528026160
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,116 @@
|
||||
//------------------------------------------------------------
|
||||
// Game Framework
|
||||
// Copyright © 2013-2021 Jiang Yin. All rights reserved.
|
||||
// Homepage: https://gameframework.cn/
|
||||
// Feedback: mailto:ellan@gameframework.cn
|
||||
//------------------------------------------------------------
|
||||
|
||||
using GameFramework;
|
||||
|
||||
namespace SepCore.UI
|
||||
{
|
||||
/// <summary>
|
||||
/// 对话框显示数据。
|
||||
/// </summary>
|
||||
public class DialogParams
|
||||
{
|
||||
/// <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 string UserData
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ad9ca3c36c52b0a4e8b25c8b451966da
|
||||
timeCreated: 1528026160
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,243 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using SepCore.Sound;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityGameFramework.Runtime;
|
||||
|
||||
namespace SepCore.UI
|
||||
{
|
||||
public abstract class UGuiForm : UIFormLogic
|
||||
{
|
||||
public const int DepthFactor = 100;
|
||||
private const float FadeTime = 0.3f;
|
||||
|
||||
private static Font _mainFont = null;
|
||||
private static TMP_FontAsset _mainTMPFont = null;
|
||||
private Canvas _cachedCanvas = null;
|
||||
private CanvasGroup _canvasGroup = null;
|
||||
private List<Canvas> _cachedCanvasContainer = new List<Canvas>();
|
||||
|
||||
public int OriginalDepth { get; private set; }
|
||||
|
||||
public int Depth => _cachedCanvas.sortingOrder;
|
||||
|
||||
public void Close()
|
||||
{
|
||||
Close(false);
|
||||
}
|
||||
|
||||
public void Close(bool ignoreFade)
|
||||
{
|
||||
StopAllCoroutines();
|
||||
|
||||
if (ignoreFade)
|
||||
{
|
||||
GameEntry.UI.CloseUIForm(this);
|
||||
}
|
||||
else
|
||||
{
|
||||
StartCoroutine(CloseCo(FadeTime));
|
||||
}
|
||||
}
|
||||
|
||||
public void PlayUISound(int uiSoundId)
|
||||
{
|
||||
GameEntry.Sound.PlayUISound(uiSoundId);
|
||||
}
|
||||
|
||||
public static void SetMainFont(Font mainFont)
|
||||
{
|
||||
if (mainFont == null)
|
||||
{
|
||||
Log.Error("Main font is invalid.");
|
||||
return;
|
||||
}
|
||||
|
||||
_mainFont = mainFont;
|
||||
}
|
||||
|
||||
public static void SetMainTMPFont(TMP_FontAsset mainTMPFont)
|
||||
{
|
||||
if (mainTMPFont == null)
|
||||
{
|
||||
Log.Error("Main font is invalid.");
|
||||
return;
|
||||
}
|
||||
|
||||
_mainTMPFont = mainTMPFont;
|
||||
}
|
||||
|
||||
#if UNITY_2017_3_OR_NEWER
|
||||
protected override void OnInit(object userData)
|
||||
#else
|
||||
protected internal override void OnInit(object userData)
|
||||
#endif
|
||||
{
|
||||
base.OnInit(userData);
|
||||
|
||||
_cachedCanvas = gameObject.GetOrAddComponent<Canvas>();
|
||||
_cachedCanvas.overrideSorting = true;
|
||||
OriginalDepth = _cachedCanvas.sortingOrder;
|
||||
|
||||
_canvasGroup = gameObject.GetOrAddComponent<CanvasGroup>();
|
||||
|
||||
RectTransform rect = GetComponent<RectTransform>();
|
||||
rect.anchorMin = Vector2.zero;
|
||||
rect.anchorMax = Vector2.one;
|
||||
rect.anchoredPosition = Vector2.zero;
|
||||
rect.sizeDelta = Vector2.zero;
|
||||
|
||||
gameObject.GetOrAddComponent<GraphicRaycaster>();
|
||||
|
||||
if (_mainTMPFont == null)
|
||||
{
|
||||
Log.Warning("Main TMP font isn't set.");
|
||||
}
|
||||
else
|
||||
{
|
||||
var tmp_texts = GetComponentsInChildren<TMP_Text>(true);
|
||||
foreach (var text in tmp_texts)
|
||||
{
|
||||
text.font = _mainTMPFont;
|
||||
if (!string.IsNullOrEmpty(text.text))
|
||||
{
|
||||
text.text = GameEntry.Localization.GetString(text.text);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (_mainFont == null)
|
||||
{
|
||||
Log.Warning("Main font isn't set.");
|
||||
}
|
||||
else
|
||||
{
|
||||
var texts = GetComponentsInChildren<Text>(true);
|
||||
foreach (var text in texts)
|
||||
{
|
||||
text.font = _mainFont;
|
||||
if (!string.IsNullOrEmpty(text.text))
|
||||
{
|
||||
text.text = GameEntry.Localization.GetString(text.text);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if UNITY_2017_3_OR_NEWER
|
||||
protected override void OnRecycle()
|
||||
#else
|
||||
protected internal override void OnRecycle()
|
||||
#endif
|
||||
{
|
||||
base.OnRecycle();
|
||||
}
|
||||
|
||||
#if UNITY_2017_3_OR_NEWER
|
||||
protected override void OnOpen(object userData)
|
||||
#else
|
||||
protected internal override void OnOpen(object userData)
|
||||
#endif
|
||||
{
|
||||
base.OnOpen(userData);
|
||||
|
||||
_canvasGroup.alpha = 0f;
|
||||
StopAllCoroutines();
|
||||
StartCoroutine(_canvasGroup.FadeToAlpha(1f, FadeTime));
|
||||
}
|
||||
|
||||
#if UNITY_2017_3_OR_NEWER
|
||||
protected override void OnClose(bool isShutdown, object userData)
|
||||
#else
|
||||
protected internal override void OnClose(bool isShutdown, object userData)
|
||||
#endif
|
||||
{
|
||||
base.OnClose(isShutdown, userData);
|
||||
}
|
||||
|
||||
#if UNITY_2017_3_OR_NEWER
|
||||
protected override void OnPause()
|
||||
#else
|
||||
protected internal override void OnPause()
|
||||
#endif
|
||||
{
|
||||
base.OnPause();
|
||||
}
|
||||
|
||||
#if UNITY_2017_3_OR_NEWER
|
||||
protected override void OnResume()
|
||||
#else
|
||||
protected internal override void OnResume()
|
||||
#endif
|
||||
{
|
||||
base.OnResume();
|
||||
|
||||
_canvasGroup.alpha = 0f;
|
||||
StopAllCoroutines();
|
||||
StartCoroutine(_canvasGroup.FadeToAlpha(1f, FadeTime));
|
||||
}
|
||||
|
||||
#if UNITY_2017_3_OR_NEWER
|
||||
protected override void OnCover()
|
||||
#else
|
||||
protected internal override void OnCover()
|
||||
#endif
|
||||
{
|
||||
base.OnCover();
|
||||
}
|
||||
|
||||
#if UNITY_2017_3_OR_NEWER
|
||||
protected override void OnReveal()
|
||||
#else
|
||||
protected internal override void OnReveal()
|
||||
#endif
|
||||
{
|
||||
base.OnReveal();
|
||||
}
|
||||
|
||||
#if UNITY_2017_3_OR_NEWER
|
||||
protected override void OnRefocus(object userData)
|
||||
#else
|
||||
protected internal override void OnRefocus(object userData)
|
||||
#endif
|
||||
{
|
||||
base.OnRefocus(userData);
|
||||
}
|
||||
|
||||
#if UNITY_2017_3_OR_NEWER
|
||||
protected override void OnUpdate(float elapseSeconds, float realElapseSeconds)
|
||||
#else
|
||||
protected internal override void OnUpdate(float elapseSeconds, float realElapseSeconds)
|
||||
#endif
|
||||
{
|
||||
base.OnUpdate(elapseSeconds, realElapseSeconds);
|
||||
}
|
||||
|
||||
#if UNITY_2017_3_OR_NEWER
|
||||
protected override void OnDepthChanged(int uiGroupDepth, int depthInUIGroup)
|
||||
#else
|
||||
protected internal override void OnDepthChanged(int uiGroupDepth, int depthInUIGroup)
|
||||
#endif
|
||||
{
|
||||
int oldDepth = Depth;
|
||||
base.OnDepthChanged(uiGroupDepth, depthInUIGroup);
|
||||
int deltaDepth = UGuiGroupHelper.DepthFactor * uiGroupDepth + DepthFactor * depthInUIGroup - oldDepth +
|
||||
OriginalDepth;
|
||||
GetComponentsInChildren(true, _cachedCanvasContainer);
|
||||
for (int i = 0; i < _cachedCanvasContainer.Count; i++)
|
||||
{
|
||||
_cachedCanvasContainer[i].sortingOrder += deltaDepth;
|
||||
}
|
||||
|
||||
_cachedCanvasContainer.Clear();
|
||||
}
|
||||
|
||||
private IEnumerator CloseCo(float duration)
|
||||
{
|
||||
yield return _canvasGroup.FadeToAlpha(0f, duration);
|
||||
GameEntry.UI.CloseUIForm(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0b92f84dc56dc764a9c261fe47df5520
|
||||
timeCreated: 1528026161
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,46 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityGameFramework.Runtime;
|
||||
|
||||
namespace SepCore.UI
|
||||
{
|
||||
/// <summary>
|
||||
/// uGUI 界面组辅助器。
|
||||
/// </summary>
|
||||
public class UGuiGroupHelper : UIGroupHelperBase
|
||||
{
|
||||
public const int DepthFactor = 10000;
|
||||
|
||||
private int m_Depth = 0;
|
||||
private Canvas m_CachedCanvas = null;
|
||||
|
||||
/// <summary>
|
||||
/// 设置界面组深度。
|
||||
/// </summary>
|
||||
/// <param name="depth">界面组深度。</param>
|
||||
public override void SetDepth(int depth)
|
||||
{
|
||||
m_Depth = depth;
|
||||
m_CachedCanvas.overrideSorting = true;
|
||||
m_CachedCanvas.sortingOrder = DepthFactor * depth;
|
||||
}
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
m_CachedCanvas = gameObject.GetOrAddComponent<Canvas>();
|
||||
gameObject.GetOrAddComponent<GraphicRaycaster>();
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
m_CachedCanvas.overrideSorting = true;
|
||||
m_CachedCanvas.sortingOrder = DepthFactor * m_Depth;
|
||||
|
||||
RectTransform transform = GetComponent<RectTransform>();
|
||||
transform.anchorMin = Vector2.zero;
|
||||
transform.anchorMax = Vector2.one;
|
||||
transform.anchoredPosition = Vector2.zero;
|
||||
transform.sizeDelta = Vector2.zero;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 05a35a4a1f7dd5646a70cb1a73348780
|
||||
timeCreated: 1528026161
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,37 @@
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace SepCore.UI
|
||||
{
|
||||
public static class UIExtension
|
||||
{
|
||||
public static IEnumerator FadeToAlpha(this CanvasGroup canvasGroup, float alpha, float duration)
|
||||
{
|
||||
float time = 0f;
|
||||
float originalAlpha = canvasGroup.alpha;
|
||||
while (time < duration)
|
||||
{
|
||||
time += Time.deltaTime;
|
||||
canvasGroup.alpha = Mathf.Lerp(originalAlpha, alpha, time / duration);
|
||||
yield return new WaitForEndOfFrame();
|
||||
}
|
||||
|
||||
canvasGroup.alpha = alpha;
|
||||
}
|
||||
|
||||
public static IEnumerator SmoothValue(this Slider slider, float value, float duration)
|
||||
{
|
||||
float time = 0f;
|
||||
float originalValue = slider.value;
|
||||
while (time < duration)
|
||||
{
|
||||
time += Time.deltaTime;
|
||||
slider.value = Mathf.Lerp(originalValue, value, time / duration);
|
||||
yield return new WaitForEndOfFrame();
|
||||
}
|
||||
|
||||
slider.value = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 75bcd42d756109f43ba02364f595a6b5
|
||||
timeCreated: 1528026162
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user