1
This commit is contained in:
@@ -1,228 +0,0 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using BITKit;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
|
||||
namespace BITKit.Net
|
||||
{
|
||||
[Serializable]
|
||||
public sealed class GameNet : INetClient,INetServer,INetProvider
|
||||
{
|
||||
private static INetClient _netClientImplementation=>GameNetProvider.NetClient;
|
||||
private static INetProvider _netProviderImplementation=>GameNetProvider.NetProvider;
|
||||
private static INetServer _netServerImplementation1=>GameNetProvider.NetServer;
|
||||
|
||||
object INetClient.Source => _netClientImplementation.Source;
|
||||
object INetServer.Source => _netServerImplementation1.Source;
|
||||
|
||||
public event Action OnStartConnect
|
||||
{
|
||||
add => _netClientImplementation.OnStartConnect += value;
|
||||
remove => _netClientImplementation.OnStartConnect -= value;
|
||||
}
|
||||
|
||||
public event Action OnConnected
|
||||
{
|
||||
add => _netClientImplementation.OnConnected += value;
|
||||
remove => _netClientImplementation.OnConnected -= value;
|
||||
}
|
||||
|
||||
public event Action OnDisconnected
|
||||
{
|
||||
add => _netClientImplementation.OnDisconnected += value;
|
||||
remove => _netClientImplementation.OnDisconnected -= value;
|
||||
}
|
||||
|
||||
public event Action OnConnectedFailed
|
||||
{
|
||||
add => _netClientImplementation.OnConnectedFailed += value;
|
||||
remove => _netClientImplementation.OnConnectedFailed -= value;
|
||||
}
|
||||
|
||||
public bool IsConnected => _netClientImplementation.IsConnected;
|
||||
|
||||
bool INetServer.ManualTick
|
||||
{
|
||||
get => _netServerImplementation1.ManualTick;
|
||||
set => _netServerImplementation1.ManualTick = value;
|
||||
}
|
||||
bool INetClient.ManualTick
|
||||
{
|
||||
get => _netClientImplementation.ManualTick;
|
||||
set => _netClientImplementation.ManualTick = value;
|
||||
}
|
||||
|
||||
public int Ping => _netClientImplementation.Ping;
|
||||
|
||||
public int Id => _netClientImplementation.Id;
|
||||
|
||||
public void Disconnect()
|
||||
{
|
||||
_netClientImplementation.Disconnect();
|
||||
}
|
||||
|
||||
public UniTask<bool> Connect(string address = "localhost", ushort port = 27014)
|
||||
{
|
||||
return _netClientImplementation.Connect(address, port);
|
||||
}
|
||||
|
||||
public void SendServerMessage(string message)
|
||||
{
|
||||
_netClientImplementation.SendServerMessage(message);
|
||||
}
|
||||
|
||||
public void ServerCommand<T>(T command = default)
|
||||
{
|
||||
_netProviderImplementation.ServerCommand(command);
|
||||
}
|
||||
|
||||
public void AllClientCommand<T>(T command = default)
|
||||
{
|
||||
_netProviderImplementation.AllClientCommand(command);
|
||||
}
|
||||
|
||||
public void ClientCommand<T>(int id, T command)
|
||||
{
|
||||
_netProviderImplementation.ClientCommand(id, command);
|
||||
}
|
||||
|
||||
public UniTask<T> GetFromServer<T>(string path=default,params object[] pars)=>_netProviderImplementation.GetFromServer<T>(path,pars);
|
||||
|
||||
public UniTask<T> GetFromClient<T>(int id,string path=default, params object[] pars)=>_netProviderImplementation.GetFromClient<T>(id,path, pars);
|
||||
|
||||
public void AddRpcHandle(object rpcHandle)
|
||||
{
|
||||
_netProviderImplementation.AddRpcHandle(rpcHandle);
|
||||
}
|
||||
|
||||
public void AddCommandListener<T>(Action<T> handle)
|
||||
{
|
||||
_netProviderImplementation.AddCommandListener(handle);
|
||||
}
|
||||
|
||||
public void RemoveCommandListener<T>(Action<T> handle)
|
||||
{
|
||||
_netProviderImplementation.RemoveCommandListener(handle);
|
||||
}
|
||||
|
||||
public void AddCommandListener<T>(Func<T, UniTask<T>> func)
|
||||
{
|
||||
_netProviderImplementation.AddCommandListener(func);
|
||||
}
|
||||
|
||||
public void RemoveCommandListener<T>(Func<T, UniTask<T>> func)
|
||||
{
|
||||
_netProviderImplementation.RemoveCommandListener(func);
|
||||
}
|
||||
public void SendRT(string rpcName, params object[] pars)
|
||||
{
|
||||
_netProviderImplementation.SendRT(rpcName, pars);
|
||||
}
|
||||
|
||||
public void SendTargetRT(int id, string rpcName, params object[] pars)
|
||||
{
|
||||
_netProviderImplementation.SendTargetRT(id, rpcName, pars);
|
||||
}
|
||||
|
||||
public void SendAllRT(string rpcName, params object[] pars)
|
||||
{
|
||||
_netProviderImplementation.SendAllRT(rpcName, pars);
|
||||
}
|
||||
|
||||
public void Tick()
|
||||
{
|
||||
_netProviderImplementation.Tick();
|
||||
}
|
||||
|
||||
public void HandShake()
|
||||
{
|
||||
_netProviderImplementation.HandShake();
|
||||
}
|
||||
|
||||
public event Action<int> OnClientConnected
|
||||
{
|
||||
add => _netServerImplementation1.OnClientConnected += value;
|
||||
remove => _netServerImplementation1.OnClientConnected -= value;
|
||||
}
|
||||
|
||||
public event Action<int> OnClientDisconnected
|
||||
{
|
||||
add => _netServerImplementation1.OnClientDisconnected += value;
|
||||
remove => _netServerImplementation1.OnClientDisconnected -= value;
|
||||
}
|
||||
|
||||
public event Action OnStartServer
|
||||
{
|
||||
add => _netServerImplementation1.OnStartServer += value;
|
||||
remove => _netServerImplementation1.OnStartServer -= value;
|
||||
}
|
||||
|
||||
public event Action OnStopServer
|
||||
{
|
||||
add => _netServerImplementation1.OnStopServer += value;
|
||||
remove => _netServerImplementation1.OnStopServer -= value;
|
||||
}
|
||||
|
||||
public void StartServer(ushort port = 27014)
|
||||
{
|
||||
_netServerImplementation1.StartServer(port);
|
||||
}
|
||||
|
||||
public void StopServer(bool dispose = false)
|
||||
{
|
||||
_netServerImplementation1.StopServer(dispose);
|
||||
}
|
||||
|
||||
public bool IsRunningServer => _netServerImplementation1 is { IsRunningServer: true };
|
||||
|
||||
public void SendMessageToClient(int id, string message)
|
||||
{
|
||||
_netServerImplementation1.SendMessageToClient(id, message);
|
||||
}
|
||||
|
||||
public void SendMessageToAll(string message)
|
||||
{
|
||||
_netServerImplementation1.SendMessageToAll(message);
|
||||
}
|
||||
|
||||
public IDictionary<int, EndPoint> Connections => _netServerImplementation1.Connections;
|
||||
|
||||
public void AddCommandListenerWithId<T>(Action<int, T> handle)
|
||||
{
|
||||
_netServerImplementation1.AddCommandListenerWithId(handle);
|
||||
}
|
||||
|
||||
public void KickClient(int id)
|
||||
{
|
||||
_netServerImplementation1.KickClient(id);
|
||||
}
|
||||
}
|
||||
|
||||
public class GameNetProvider : MonoBehaviour
|
||||
{
|
||||
public static INetClient NetClient { get; private set; }
|
||||
public static INetServer NetServer { get; private set; }
|
||||
|
||||
public static INetProvider NetProvider => (NetClient, NetServer) switch
|
||||
{
|
||||
(not null,null)=>NetClient as INetProvider,
|
||||
(null,not null)=>NetServer as INetProvider,
|
||||
(not null, { IsRunningServer: true }) =>NetServer as INetProvider,
|
||||
({ IsConnected: true },not null) =>NetClient as INetProvider,
|
||||
_ => null
|
||||
};
|
||||
|
||||
[SerializeField] private MonoBehaviour netClient;
|
||||
[SerializeField] private MonoBehaviour netServer;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
NetClient = netClient as INetClient;
|
||||
NetServer = netServer as INetServer;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 64fa60f31192679458dff793286a1b4b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,279 +0,0 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using BITKit.Net.Examples;
|
||||
using UnityEngine;
|
||||
using Cysharp.Threading.Tasks;
|
||||
namespace BITKit.Net.Kcp
|
||||
{
|
||||
[CustomType(typeof(INetClient))]
|
||||
[CustomType(typeof(INetProvider))]
|
||||
public class MonoKcpClient : MonoBehaviour,INetClient,INetProvider
|
||||
{
|
||||
internal static MonoKcpClient Singleton { get; private set; }
|
||||
|
||||
[SerializeField,ReadOnly] private int rate;
|
||||
[SerializeReference,SubclassSelector] private ITicker ticker;
|
||||
[SerializeField] private string m_host;
|
||||
[SerializeField] private ushort m_port;
|
||||
[SerializeField] private bool connectOnStart;
|
||||
[SerializeField] private bool autoReconnect;
|
||||
|
||||
[Header(Constant.Header.Debug)]
|
||||
[SerializeField]
|
||||
[ReadOnly] private int id;
|
||||
[SerializeField]
|
||||
[ReadOnly]private Vector2 traffic;
|
||||
[SerializeField]
|
||||
[ReadOnly]private string upTraffic;
|
||||
[SerializeField]
|
||||
[ReadOnly]private string downTraffic;
|
||||
[SerializeField, ReadOnly] private bool isConnected;
|
||||
|
||||
#if UNITY_EDITOR
|
||||
[SerializeField] private Optional<string> allowDebugHost;
|
||||
[SerializeField] private Optional<ushort> allowDebugPort;
|
||||
#endif
|
||||
private KcpNetClient client;
|
||||
private INetClient _netClientImplementation=>client;
|
||||
private INetProvider _netProviderImplementation=>client;
|
||||
|
||||
private readonly IntervalUpdate _reconnectInterval = new(3);
|
||||
|
||||
public event Action OnStartConnect
|
||||
{
|
||||
add => _netClientImplementation.OnStartConnect += value;
|
||||
remove => _netClientImplementation.OnStartConnect -= value;
|
||||
}
|
||||
|
||||
public event Action OnConnected
|
||||
{
|
||||
add => _netClientImplementation.OnConnected += value;
|
||||
remove => _netClientImplementation.OnConnected -= value;
|
||||
}
|
||||
|
||||
public event Action OnDisconnected
|
||||
{
|
||||
add => _netClientImplementation.OnDisconnected += value;
|
||||
remove => _netClientImplementation.OnDisconnected -= value;
|
||||
}
|
||||
|
||||
public event Action OnConnectedFailed
|
||||
{
|
||||
add => _netClientImplementation.OnConnectedFailed += value;
|
||||
remove => _netClientImplementation.OnConnectedFailed -= value;
|
||||
}
|
||||
|
||||
public bool IsConnected => _netClientImplementation.IsConnected;
|
||||
public bool ManualTick
|
||||
{
|
||||
get => client.ManualTick;
|
||||
set => client.ManualTick = value;
|
||||
}
|
||||
|
||||
public int Ping => _netClientImplementation.Ping;
|
||||
|
||||
public int Id => _netClientImplementation.Id;
|
||||
|
||||
public void Disconnect()
|
||||
{
|
||||
_netClientImplementation.Disconnect();
|
||||
}
|
||||
|
||||
public UniTask<bool> Connect(string address = "localhost", ushort port = 27014)
|
||||
{
|
||||
if(address is "localhost" or null)
|
||||
address = m_host;
|
||||
if(port is 27014 or 0)
|
||||
port = m_port;
|
||||
|
||||
m_host = address;
|
||||
m_port = port;
|
||||
|
||||
return _netClientImplementation.Connect(address, port);
|
||||
}
|
||||
|
||||
public void SendServerMessage(string message)
|
||||
{
|
||||
_netClientImplementation.SendServerMessage(message);
|
||||
}
|
||||
|
||||
public void ServerCommand<T>(T command = default)
|
||||
{
|
||||
_netProviderImplementation.ServerCommand(command);
|
||||
}
|
||||
|
||||
public void AllClientCommand<T>(T command = default)
|
||||
{
|
||||
_netProviderImplementation.AllClientCommand(command);
|
||||
}
|
||||
|
||||
public void ClientCommand<T>(int id, T command)
|
||||
{
|
||||
_netProviderImplementation.ClientCommand(id, command);
|
||||
}
|
||||
|
||||
public UniTask<T> GetFromServer<T>(string path = null, params object[] pars)
|
||||
{
|
||||
return client.GetFromServer<T>(path, pars);
|
||||
}
|
||||
|
||||
public UniTask<T> GetFromClient<T>(int id, string path = null, params object[] pars)
|
||||
{
|
||||
return client.GetFromClient<T>(id, path, pars);
|
||||
}
|
||||
|
||||
public UniTask<T> GetFromServer<T>(string path=null,T command = default)
|
||||
{
|
||||
return _netProviderImplementation.GetFromServer<T>(path,command);
|
||||
}
|
||||
|
||||
public UniTask<T> GetFromClient<T>(int id,string path=null, T command = default)
|
||||
{
|
||||
return _netProviderImplementation.GetFromClient<T>(id,path, command);
|
||||
}
|
||||
public void AddRpcHandle(object rpcHandle)
|
||||
{
|
||||
_netProviderImplementation.AddRpcHandle(rpcHandle);
|
||||
}
|
||||
|
||||
public void AddCommandListener<T>(Action<T> handle)
|
||||
{
|
||||
_netProviderImplementation.AddCommandListener(handle);
|
||||
}
|
||||
|
||||
public void RemoveCommandListener<T>(Action<T> handle)
|
||||
{
|
||||
_netProviderImplementation.RemoveCommandListener(handle);
|
||||
}
|
||||
|
||||
public void AddCommandListener<T>(Func<T, UniTask<T>> func)
|
||||
{
|
||||
_netProviderImplementation.AddCommandListener(func);
|
||||
}
|
||||
|
||||
public void RemoveCommandListener<T>(Func<T, UniTask<T>> func)
|
||||
{
|
||||
_netProviderImplementation.RemoveCommandListener(func);
|
||||
}
|
||||
public void SendRT(string rpcName, params object[] pars)
|
||||
{
|
||||
_netProviderImplementation.SendRT(rpcName, pars);
|
||||
}
|
||||
|
||||
public void SendTargetRT(int id, string rpcName, params object[] pars)
|
||||
{
|
||||
_netProviderImplementation.SendTargetRT(id, rpcName, pars);
|
||||
}
|
||||
|
||||
public void SendAllRT(string rpcName, params object[] pars)
|
||||
{
|
||||
_netProviderImplementation.SendAllRT(rpcName, pars);
|
||||
}
|
||||
|
||||
public void Tick()
|
||||
{
|
||||
_netProviderImplementation.Tick();
|
||||
|
||||
}
|
||||
|
||||
public void HandShake()
|
||||
{
|
||||
_netProviderImplementation.HandShake();
|
||||
}
|
||||
private void Awake()
|
||||
{
|
||||
Singleton = this;
|
||||
client = new KcpNetClient();
|
||||
}
|
||||
private void Start()
|
||||
{
|
||||
if (ticker is not null)
|
||||
{
|
||||
ManualTick = true;
|
||||
ticker.Add(OnTick);
|
||||
}
|
||||
destroyCancellationToken.Register(() =>
|
||||
{
|
||||
if (IsConnected)
|
||||
Disconnect();
|
||||
ticker?.Remove(OnTick);
|
||||
});
|
||||
|
||||
if (!connectOnStart) return;
|
||||
#if UNITY_EDITOR
|
||||
var _host = allowDebugHost.Allow ? allowDebugHost.Value : m_host;
|
||||
var _port = allowDebugPort.Allow ? allowDebugPort.Value : m_port;
|
||||
Connect(_host, _port).Forget();
|
||||
#else
|
||||
Connect(m_host, m_port).Forget();
|
||||
#endif
|
||||
}
|
||||
|
||||
private void OnTick(float obj)
|
||||
{
|
||||
if (destroyCancellationToken.IsCancellationRequested) return;
|
||||
|
||||
client.AutoReconnect = autoReconnect;
|
||||
id = Id;
|
||||
Tick();
|
||||
traffic = client.Traffic;
|
||||
upTraffic = NetUtils.GetFileSize((long)traffic.x);
|
||||
downTraffic = NetUtils.GetFileSize((long)traffic.y);
|
||||
isConnected = IsConnected;
|
||||
}
|
||||
[BIT]
|
||||
private void EditorConnect()
|
||||
{
|
||||
BITAppForUnity.ThrowIfNotPlaying();
|
||||
Connect(m_host, m_port).Forget();
|
||||
}
|
||||
[BIT]
|
||||
private void EditorDisconnect()
|
||||
{
|
||||
BITAppForUnity.ThrowIfNotPlaying();
|
||||
Disconnect();
|
||||
}
|
||||
[BIT]
|
||||
private async void Hello()
|
||||
{
|
||||
BITAppForUnity.ThrowIfNotPlaying();
|
||||
var stopWatch = new Stopwatch();
|
||||
|
||||
stopWatch.Start();
|
||||
var value =await GetFromServer<SimplePing>(null,new SimplePing()
|
||||
{
|
||||
StartTime = DateTime.Now
|
||||
});
|
||||
stopWatch.Stop();
|
||||
BIT4Log.Log<MonoKcpClient>($"已返回\n开始:{value.StartTime}\n结束:{value.EndTime}\n延迟:{stopWatch.ElapsedMilliseconds}ms");
|
||||
|
||||
|
||||
SendRT(nameof(KCPNetServer.OnNetRpcTest),64,12.8f,true);
|
||||
|
||||
|
||||
stopWatch.Reset();
|
||||
stopWatch.Start();
|
||||
var hello =
|
||||
await GetFromServer<string>(
|
||||
nameof(KCPNetServer.MyRpcTest),
|
||||
"hello"
|
||||
);
|
||||
stopWatch.Stop();
|
||||
BIT4Log.Log<MonoKcpClient>($"已返回\n{hello}\n延迟:{stopWatch.ElapsedMilliseconds}ms");
|
||||
|
||||
stopWatch.Reset();
|
||||
stopWatch.Start();
|
||||
var helloAsync =
|
||||
await GetFromServer<string>(
|
||||
nameof(KCPNetServer.MyRpcTestAsync),
|
||||
"hello"
|
||||
);
|
||||
stopWatch.Stop();
|
||||
BIT4Log.Log<MonoKcpClient>($"已返回\n{helloAsync},\n延迟:{stopWatch.ElapsedMilliseconds}ms");
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e97c2d299cde4c14eae93069ecb68701
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,196 +0,0 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
|
||||
namespace BITKit.Net.Kcp
|
||||
{
|
||||
public class MonoKcpServer : MonoBehaviour,INetServer,INetProvider
|
||||
{
|
||||
[SerializeField, ReadOnly] private int rate;
|
||||
[SerializeField] private ushort initialPort;
|
||||
[SerializeReference,SubclassSelector] private ITicker ticker;
|
||||
|
||||
private INetServer _netServerImplementation => _server;
|
||||
private KCPNetServer _server=>_serverInstance??=new KCPNetServer();
|
||||
private KCPNetServer _serverInstance;
|
||||
|
||||
public bool ManualTick
|
||||
{
|
||||
get => _netServerImplementation.ManualTick;
|
||||
set => _netServerImplementation.ManualTick = value;
|
||||
}
|
||||
public event Action<int> OnClientConnected
|
||||
{
|
||||
add => _netServerImplementation.OnClientConnected += value;
|
||||
remove => _netServerImplementation.OnClientConnected -= value;
|
||||
}
|
||||
|
||||
public event Action<int> OnClientDisconnected
|
||||
{
|
||||
add => _netServerImplementation.OnClientDisconnected += value;
|
||||
remove => _netServerImplementation.OnClientDisconnected -= value;
|
||||
}
|
||||
|
||||
public event Action OnStartServer
|
||||
{
|
||||
add => _netServerImplementation.OnStartServer += value;
|
||||
remove => _netServerImplementation.OnStartServer -= value;
|
||||
}
|
||||
|
||||
public event Action OnStopServer
|
||||
{
|
||||
add => _netServerImplementation.OnStopServer += value;
|
||||
remove => _netServerImplementation.OnStopServer -= value;
|
||||
}
|
||||
public void StartServer(ushort port = 27014)
|
||||
{
|
||||
if(port == 27014)port = initialPort;
|
||||
_netServerImplementation.StartServer(port);
|
||||
}
|
||||
public void StopServer(bool dispose = false)
|
||||
{
|
||||
_netServerImplementation.StopServer(dispose);
|
||||
}
|
||||
|
||||
public bool IsRunningServer => _netServerImplementation.IsRunningServer;
|
||||
|
||||
public void SendMessageToClient(int id, string message)
|
||||
{
|
||||
_netServerImplementation.SendMessageToClient(id, message);
|
||||
}
|
||||
|
||||
public void SendMessageToAll(string message)
|
||||
{
|
||||
_netServerImplementation.SendMessageToAll(message);
|
||||
}
|
||||
|
||||
public IDictionary<int, EndPoint> Connections => _netServerImplementation.Connections;
|
||||
|
||||
public void AddCommandListenerWithId<T>(Action<int, T> handle)
|
||||
{
|
||||
_netServerImplementation.AddCommandListenerWithId(handle);
|
||||
}
|
||||
|
||||
public void KickClient(int id)
|
||||
{
|
||||
_netServerImplementation.KickClient(id);
|
||||
}
|
||||
|
||||
[BIT]
|
||||
private void EditorStartServer()
|
||||
{
|
||||
BITAppForUnity.ThrowIfNotPlaying();
|
||||
StartServer(initialPort);
|
||||
}
|
||||
[BIT]
|
||||
private void EditorStopServer()
|
||||
{
|
||||
BITAppForUnity.ThrowIfNotPlaying();
|
||||
StopServer();
|
||||
}
|
||||
[BIT]
|
||||
private void RandomAPort()
|
||||
{
|
||||
initialPort = (ushort)UnityEngine.Random.Range(10000, ushort.MaxValue);
|
||||
}
|
||||
|
||||
public void ServerCommand<T>(T command = default)
|
||||
{
|
||||
_server.ServerCommand(command);
|
||||
}
|
||||
|
||||
public void AllClientCommand<T>(T command = default)
|
||||
{
|
||||
_server.AllClientCommand(command);
|
||||
}
|
||||
|
||||
public void ClientCommand<T>(int id, T command)
|
||||
{
|
||||
_server.ClientCommand(id, command);
|
||||
}
|
||||
|
||||
public UniTask<T> GetFromServer<T>(string path = null, params object[] pars)
|
||||
{
|
||||
return _serverInstance.GetFromServer<T>(path, pars);
|
||||
}
|
||||
|
||||
public UniTask<T> GetFromClient<T>(int id, string path = null, params object[] pars)
|
||||
{
|
||||
return _serverInstance.GetFromClient<T>(id, path, pars);
|
||||
}
|
||||
public void AddRpcHandle(object rpcHandle)
|
||||
{
|
||||
_server.AddRpcHandle(rpcHandle);
|
||||
}
|
||||
|
||||
public void AddCommandListener<T>(Action<T> handle)
|
||||
{
|
||||
_server.AddCommandListener(handle);
|
||||
}
|
||||
|
||||
public void AddCommandListener<T>(Func<T,UniTask<T>> func)
|
||||
{
|
||||
_serverInstance.AddCommandListener(func);
|
||||
}
|
||||
|
||||
public void RemoveCommandListener<T>(Func<T,UniTask<T>> func)
|
||||
{
|
||||
_serverInstance.RemoveCommandListener(func);
|
||||
}
|
||||
|
||||
public void RemoveCommandListener<T>(Action<T> handle)
|
||||
{
|
||||
_server.RemoveCommandListener(handle);
|
||||
}
|
||||
|
||||
public void SendRT(string rpcName, params object[] pars)
|
||||
{
|
||||
_server.SendRT(rpcName, pars);
|
||||
}
|
||||
|
||||
public void SendTargetRT(int id, string rpcName, params object[] pars)
|
||||
{
|
||||
_server.SendTargetRT(id, rpcName, pars);
|
||||
}
|
||||
|
||||
public void SendAllRT(string rpcName, params object[] pars)
|
||||
{
|
||||
_server.SendAllRT(rpcName, pars);
|
||||
}
|
||||
|
||||
public void Tick()
|
||||
{
|
||||
_server.Tick();
|
||||
}
|
||||
|
||||
public void HandShake()
|
||||
{
|
||||
_server.HandShake();
|
||||
}
|
||||
|
||||
|
||||
private void Start()
|
||||
{
|
||||
if (ticker is not null)
|
||||
{
|
||||
ManualTick = true;
|
||||
ticker.Add(OnTick);
|
||||
}
|
||||
|
||||
destroyCancellationToken.Register(() =>
|
||||
{
|
||||
if (IsRunningServer)
|
||||
StopServer(true);
|
||||
ticker?.Remove(OnTick);
|
||||
});
|
||||
}
|
||||
private void OnTick(float deltaTime)
|
||||
{
|
||||
Tick();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 23c7dbd4bc26161488daef24f737e581
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user