feat: add shared runtime and codegen support

This commit is contained in:
2026-09-05 02:34:04 +08:00
parent 005ebf43cf
commit eb7fa55656
5 changed files with 26 additions and 182 deletions
+11 -9
View File
@@ -5,7 +5,7 @@ using System.Linq;
using System.Threading;
using Cysharp.Threading.Tasks;
using ShrinkEventBus;
using UnityEngine;
using ShrinkSDK.Runtime;
namespace ShrinkNetwork.Integration
{
@@ -24,7 +24,9 @@ namespace ShrinkNetwork.Integration
private static Dictionary<Type, ShrinkNetworkEventRegistration> _networkEventTypes = new();
private static bool _initialized;
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
#if UNITY_5_3_OR_NEWER
[UnityEngine.RuntimeInitializeOnLoadMethod(UnityEngine.RuntimeInitializeLoadType.SubsystemRegistration)]
#endif
private static void ResetStaticState()
{
EventBus.Posted -= HandleLocalEventPosted;
@@ -215,9 +217,8 @@ namespace ShrinkNetwork.Integration
}
catch (Exception ex)
{
Debug.LogException(ex);
Debug.LogError(
$"[ShrinkNetwork.Integration] 序列化网络事件失败: {eventArgs.GetType().FullName}");
ShrinkRuntimeServices.Logger.Error(
$"[ShrinkNetwork.Integration] 序列化网络事件失败: {eventArgs.GetType().FullName}", ex);
continue;
}
@@ -236,9 +237,8 @@ namespace ShrinkNetwork.Integration
}
catch (Exception ex)
{
Debug.LogException(ex);
Debug.LogError(
$"[ShrinkNetwork.Integration] 转发网络事件失败: {eventArgs.GetType().FullName}, Session={session.SessionId}");
ShrinkRuntimeServices.Logger.Error(
$"[ShrinkNetwork.Integration] 转发网络事件失败: {eventArgs.GetType().FullName}, Session={session.SessionId}", ex);
}
}
}
@@ -349,7 +349,7 @@ namespace ShrinkNetwork.Integration
}
catch (Exception ex)
{
Debug.LogException(ex);
ShrinkRuntimeServices.Logger.Error("[ShrinkNetwork.Integration] 处理网络事件请求失败。", ex);
return new ShrinkNetworkEventResultResponse
{
ErrorCode = ShrinkRpcErrorCode.HandlerException,
@@ -481,6 +481,7 @@ namespace ShrinkNetwork.Integration
/// handlers. Use ShrinkNetworkDispatchQueue when a hard per-frame budget is
/// required instead of an unbounded PlayerLoop backlog.
/// </summary>
#if UNITY_5_3_OR_NEWER
public sealed class ShrinkNetworkUnityMainThreadDispatchScheduler : IShrinkNetworkDispatchScheduler
{
public async UniTask<bool> ScheduleAsync(Func<UniTask> callback)
@@ -493,4 +494,5 @@ namespace ShrinkNetwork.Integration
return true;
}
}
#endif
}