规范命名空间

具体来说就是 SepCore 开头,然后接所属的模块名,比如 SepCore.Entity,SepCore.Simulation,SepCore.Procedure
This commit is contained in:
SepComet
2026-06-03 16:57:40 +08:00
parent 5de3fdc795
commit edd7088804
210 changed files with 461 additions and 547 deletions
@@ -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: 2a0640fd52beabf479281c111c9e861f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -1,10 +1,7 @@
using System;
using Cysharp.Threading.Tasks;
using GameFramework;
using GameFramework.Config;
using UnityGameFramework.Runtime;
namespace UnityGameFramework.Runtime.AsyncTask
namespace SepCore.AsyncTask
{
/// <summary>
/// Config 异步扩展方法
@@ -5,7 +5,7 @@ using GameFramework.DataTable;
using SepCore.DataTable;
using UnityGameFramework.Runtime;
namespace UnityGameFramework.Runtime.AsyncTask
namespace SepCore.AsyncTask
{
/// <summary>
/// DataTable 异步扩展方法
@@ -1,10 +1,9 @@
using System;
using Cysharp.Threading.Tasks;
using GameFramework;
using GameFramework.Download;
using UnityGameFramework.Runtime;
using DownloadFailureEventArgs = UnityGameFramework.Runtime.DownloadFailureEventArgs;
using DownloadSuccessEventArgs = UnityGameFramework.Runtime.DownloadSuccessEventArgs;
namespace UnityGameFramework.Runtime.AsyncTask
namespace SepCore.AsyncTask
{
/// <summary>
/// Download 异步扩展方法
@@ -1,10 +1,11 @@
using System;
using Cysharp.Threading.Tasks;
using GameFramework;
using GameFramework.Entity;
using UnityGameFramework.Runtime;
using HideEntityCompleteEventArgs = UnityGameFramework.Runtime.HideEntityCompleteEventArgs;
using ShowEntityFailureEventArgs = UnityGameFramework.Runtime.ShowEntityFailureEventArgs;
using ShowEntitySuccessEventArgs = UnityGameFramework.Runtime.ShowEntitySuccessEventArgs;
namespace UnityGameFramework.Runtime.AsyncTask
namespace SepCore.AsyncTask
{
/// <summary>
/// Entity 异步扩展方法
@@ -22,7 +23,7 @@ namespace UnityGameFramework.Runtime.AsyncTask
/// <param name="userData">用户自定义数据</param>
/// <param name="timeout">超时时间(秒),0表示不超时</param>
/// <returns>显示的实体</returns>
public static UniTask<Entity> ShowEntityAsync(this EntityComponent entityComponent,
public static UniTask<UnityGameFramework.Runtime.Entity> ShowEntityAsync(this EntityComponent entityComponent,
int entityId,
Type entityLogicType,
string entityAssetName,
@@ -30,7 +31,7 @@ namespace UnityGameFramework.Runtime.AsyncTask
object userData = null,
float timeout = 30f)
{
UniTask<Entity> waitTask = AsyncTaskHelper.WaitSuccessOrFailureAsync<ShowEntitySuccessEventArgs, ShowEntityFailureEventArgs>(
UniTask<UnityGameFramework.Runtime.Entity> waitTask = AsyncTaskHelper.WaitSuccessOrFailureAsync<ShowEntitySuccessEventArgs, ShowEntityFailureEventArgs>(
ShowEntitySuccessEventArgs.EventId,
ShowEntityFailureEventArgs.EventId,
successArgs => successArgs.Entity.Id == entityId && ReferenceEquals(successArgs.UserData, userData),
@@ -104,7 +105,7 @@ namespace UnityGameFramework.Runtime.AsyncTask
/// <param name="timeout">超时时间(秒),0表示不超时</param>
/// <returns>隐藏完成事件</returns>
public static UniTask<HideEntityCompleteEventArgs> HideEntityAsync(this EntityComponent entityComponent,
Entity entity,
UnityGameFramework.Runtime.Entity entity,
object userData = null,
float timeout = 30f)
{
@@ -4,7 +4,7 @@ using GameFramework;
using GameFramework.Localization;
using UnityGameFramework.Runtime;
namespace UnityGameFramework.Runtime.AsyncTask
namespace SepCore.AsyncTask
{
/// <summary>
/// Localization 异步扩展方法
@@ -1,10 +1,9 @@
using System;
using Cysharp.Threading.Tasks;
using GameFramework;
using GameFramework.Network;
using UnityGameFramework.Runtime;
using NetworkClosedEventArgs = UnityGameFramework.Runtime.NetworkClosedEventArgs;
using NetworkConnectedEventArgs = UnityGameFramework.Runtime.NetworkConnectedEventArgs;
namespace UnityGameFramework.Runtime.AsyncTask
namespace SepCore.AsyncTask
{
/// <summary>
/// Network 异步扩展方法
@@ -73,4 +72,4 @@ namespace UnityGameFramework.Runtime.AsyncTask
);
}
}
}
}
@@ -1,10 +1,10 @@
using System;
using Cysharp.Threading.Tasks;
using GameFramework;
using GameFramework.Resource;
using UnityGameFramework.Runtime;
using ResourceApplySuccessEventArgs = UnityGameFramework.Runtime.ResourceApplySuccessEventArgs;
using ResourceUpdateAllCompleteEventArgs = UnityGameFramework.Runtime.ResourceUpdateAllCompleteEventArgs;
using ResourceVerifySuccessEventArgs = UnityGameFramework.Runtime.ResourceVerifySuccessEventArgs;
namespace UnityGameFramework.Runtime.AsyncTask
namespace SepCore.AsyncTask
{
/// <summary>
/// Resource 异步扩展方法
@@ -59,4 +59,4 @@ namespace UnityGameFramework.Runtime.AsyncTask
);
}
}
}
}
@@ -1,10 +1,11 @@
using System;
using Cysharp.Threading.Tasks;
using GameFramework;
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 UnityGameFramework.Runtime.AsyncTask
namespace SepCore.AsyncTask
{
/// <summary>
/// Scene 异步扩展方法
@@ -1,10 +1,10 @@
using System;
using Cysharp.Threading.Tasks;
using GameFramework;
using GameFramework.Sound;
using UnityGameFramework.Runtime;
using PlaySoundFailureEventArgs = UnityGameFramework.Runtime.PlaySoundFailureEventArgs;
using PlaySoundSuccessEventArgs = UnityGameFramework.Runtime.PlaySoundSuccessEventArgs;
namespace UnityGameFramework.Runtime.AsyncTask
namespace SepCore.AsyncTask
{
/// <summary>
/// Sound 异步扩展方法
@@ -29,17 +29,17 @@ namespace UnityGameFramework.Runtime.AsyncTask
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
);
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;
}
}
}
@@ -3,7 +3,7 @@ using SepCore.Definition;
using SepCore.UI;
using UnityGameFramework.Runtime;
namespace UnityGameFramework.Runtime.AsyncTask
namespace SepCore.AsyncTask
{
/// <summary>
/// UI 异步扩展方法
@@ -1,10 +1,7 @@
using System;
using Cysharp.Threading.Tasks;
using GameFramework;
using GameFramework.WebRequest;
using UnityGameFramework.Runtime;
namespace UnityGameFramework.Runtime.AsyncTask
namespace SepCore.AsyncTask
{
/// <summary>
/// WebRequest 异步扩展方法