124 lines
3.0 KiB
C#
124 lines
3.0 KiB
C#
using System;
|
|
using Cysharp.Threading.Tasks;
|
|
|
|
namespace BITKit.Net.Kcp
|
|
{
|
|
[Serializable]
|
|
public class MonoKcpClientSingleton : INetProvider,INetClient
|
|
{
|
|
private INetClient _netClientImplementation => MonoKcpClient.Singleton;
|
|
private INetProvider _netProviderImplementation => MonoKcpClient.Singleton;
|
|
|
|
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 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 addressablePath = Constant.System.Internal)
|
|
{
|
|
return _netProviderImplementation.GetFromServer<T>(addressablePath);
|
|
}
|
|
|
|
public UniTask<T> GetFromClient<T>(int id, string addressablePath = Constant.System.Internal)
|
|
{
|
|
return _netProviderImplementation.GetFromClient<T>(id, addressablePath);
|
|
}
|
|
|
|
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 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();
|
|
}
|
|
}
|
|
}
|
|
|