feat: add shared codegen support
This commit is contained in:
@@ -1,17 +1,21 @@
|
||||
#if UNITY_5_3_OR_NEWER
|
||||
using UnityEngine;
|
||||
#endif
|
||||
|
||||
namespace ShrinkNetwork
|
||||
{
|
||||
public static class ShrinkNetworkRuntime
|
||||
{
|
||||
public static ShrinkNetworkService Default { get; private set; }
|
||||
public static ShrinkNetworkService Default { get; private set; } = null!;
|
||||
|
||||
static ShrinkNetworkRuntime()
|
||||
{
|
||||
RebuildDefault();
|
||||
}
|
||||
|
||||
#if UNITY_5_3_OR_NEWER
|
||||
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
|
||||
#endif
|
||||
private static void ResetOnPlayModeEnter()
|
||||
{
|
||||
RebuildDefault();
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#nullable enable
|
||||
|
||||
using System;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
@@ -16,14 +18,14 @@ namespace ShrinkNetwork
|
||||
private readonly ShrinkKcpTransportOptions _options;
|
||||
private readonly object _syncRoot = new();
|
||||
|
||||
private CancellationTokenSource _cts;
|
||||
private UdpClient _udpClient;
|
||||
private ShrinkKcpPeer _peer;
|
||||
private CancellationTokenSource? _cts;
|
||||
private UdpClient? _udpClient;
|
||||
private ShrinkKcpPeer? _peer;
|
||||
private long _handshakeNonce;
|
||||
private int _started;
|
||||
private int _connected;
|
||||
|
||||
public ShrinkKcpClientTransport(string host, int port, ShrinkKcpTransportOptions options = null, long sessionId = 1)
|
||||
public ShrinkKcpClientTransport(string host, int port, ShrinkKcpTransportOptions? options = null, long sessionId = 1)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(host))
|
||||
throw new ArgumentException("Host cannot be empty.", nameof(host));
|
||||
@@ -39,7 +41,7 @@ namespace ShrinkNetwork
|
||||
|
||||
public bool IsStarted => Volatile.Read(ref _started) == 1;
|
||||
|
||||
public event Action<ShrinkNetworkTransportEvent> OnEvent;
|
||||
public event Action<ShrinkNetworkTransportEvent>? OnEvent;
|
||||
|
||||
public void Start()
|
||||
{
|
||||
@@ -52,7 +54,7 @@ namespace ShrinkNetwork
|
||||
_udpClient.Connect(_host, _port);
|
||||
|
||||
_handshakeNonce = CreateHandshakeNonce();
|
||||
ReceiveLoopAsync(_cts.Token).Forget();
|
||||
ReceiveLoopAsync(_udpClient, _cts.Token).Forget();
|
||||
HandshakeLoopAsync(_cts.Token).Forget();
|
||||
UpdateLoopAsync(_cts.Token).Forget();
|
||||
}
|
||||
@@ -145,7 +147,7 @@ namespace ShrinkNetwork
|
||||
}
|
||||
}
|
||||
|
||||
private async UniTaskVoid ReceiveLoopAsync(CancellationToken cancellationToken)
|
||||
private async UniTaskVoid ReceiveLoopAsync(UdpClient udpClient, CancellationToken cancellationToken)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -154,7 +156,7 @@ namespace ShrinkNetwork
|
||||
UdpReceiveResult result;
|
||||
try
|
||||
{
|
||||
result = await _udpClient.ReceiveAsync();
|
||||
result = await udpClient.ReceiveAsync();
|
||||
}
|
||||
catch (ObjectDisposedException)
|
||||
{
|
||||
|
||||
@@ -37,7 +37,6 @@ namespace ShrinkNetwork
|
||||
private CancellationTokenSource? _cts;
|
||||
private UdpClient? _udpClient;
|
||||
private long _sessionIdGenerator;
|
||||
private int _conversationIdGenerator;
|
||||
|
||||
public ShrinkKcpServerTransport(IPAddress listeningAddress, int port, ShrinkKcpTransportOptions? options = null)
|
||||
{
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "com.cneicy.shrink-network",
|
||||
"version": "0.2.1",
|
||||
"version": "0.3.0",
|
||||
"displayName": "ShrinkNetwork",
|
||||
"description": "面向 Unity 的轻量网络框架,提供会话、消息注册、RPC、权限控制,以及 TCP/KCP 传输抽象。",
|
||||
"unity": "2022.3",
|
||||
|
||||
Reference in New Issue
Block a user