This commit is contained in:
CortexCore
2024-06-08 10:07:40 +08:00
parent ccc9957809
commit b9731c20a1
11 changed files with 231 additions and 44 deletions

View File

@@ -89,15 +89,9 @@ namespace BITKit.Net
_netProviderImplementation.ClientCommand(id, command);
}
public UniTask<T> GetFromServer<T>(string addressablePath = Constant.System.Internal)
{
return _netProviderImplementation.GetFromServer<T>(addressablePath);
}
public UniTask<T> GetFromServer<T>(T command = default)=>_netProviderImplementation.GetFromServer<T>(command);
public UniTask<T> GetFromClient<T>(int id, string addressablePath = Constant.System.Internal)
{
return _netProviderImplementation.GetFromClient<T>(id, addressablePath);
}
public UniTask<T> GetFromClient<T>(int id, T command = default)=>_netProviderImplementation.GetFromClient(id, command);
public void AddRpcHandle(object rpcHandle)
{
@@ -109,11 +103,15 @@ namespace BITKit.Net
_netProviderImplementation.AddCommandListener(handle);
}
public void RemoveCommandListener<T>(Action<T> handle)
public void AddCommandListener<T>(Func<T, T> func)
{
_netProviderImplementation.RemoveCommandListener(handle);
throw new NotImplementedException();
}
public void RemoveCommandListener<T>(Func<T, T> func)
{
throw new NotImplementedException();
}
public void SendRT(string rpcName, params object[] pars)
{
_netProviderImplementation.SendRT(rpcName, pars);

View File

@@ -1,6 +1,7 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using BITKit.Net.Examples;
using UnityEngine;
using Cysharp.Threading.Tasks;
namespace BITKit.Net.Kcp
@@ -95,16 +96,15 @@ namespace BITKit.Net.Kcp
_netProviderImplementation.ClientCommand(id, command);
}
public UniTask<T> GetFromServer<T>(string addressablePath = Constant.System.Internal)
public UniTask<T> GetFromServer<T>(T command = default)
{
return _netProviderImplementation.GetFromServer<T>(addressablePath);
return _netProviderImplementation.GetFromServer<T>(command);
}
public UniTask<T> GetFromClient<T>(int id, string addressablePath = Constant.System.Internal)
public UniTask<T> GetFromClient<T>(int id, T command = default)
{
return _netProviderImplementation.GetFromClient<T>(id, addressablePath);
return _netProviderImplementation.GetFromClient<T>(id, command);
}
public void AddRpcHandle(object rpcHandle)
{
_netProviderImplementation.AddRpcHandle(rpcHandle);
@@ -115,11 +115,15 @@ namespace BITKit.Net.Kcp
_netProviderImplementation.AddCommandListener(handle);
}
public void RemoveCommandListener<T>(Action<T> handle)
public void AddCommandListener<T>(Func<T, T> func)
{
_netProviderImplementation.RemoveCommandListener(handle);
throw new NotImplementedException();
}
public void RemoveCommandListener<T>(Func<T, T> func)
{
throw new NotImplementedException();
}
public void SendRT(string rpcName, params object[] pars)
{
_netProviderImplementation.SendRT(rpcName, pars);
@@ -214,6 +218,16 @@ namespace BITKit.Net.Kcp
BITAppForUnity.ThrowIfNotPlaying();
Disconnect();
}
[BIT]
private async void Hello()
{
BITAppForUnity.ThrowIfNotPlaying();
var value =await GetFromServer(new SimplePing()
{
StartTime = DateTime.Now
});
BIT4Log.Log<MonoKcpClient>($"已返回\n开始:{value.StartTime}\n结束:{value.EndTime}\n延迟:{(value.EndTime-value.StartTime).TotalMilliseconds}ms");
}
}
}

View File

@@ -76,16 +76,15 @@ namespace BITKit.Net.Kcp
_netProviderImplementation.ClientCommand(id, command);
}
public UniTask<T> GetFromServer<T>(string addressablePath = Constant.System.Internal)
public UniTask<T> GetFromServer<T>(T command = default)
{
return _netProviderImplementation.GetFromServer<T>(addressablePath);
return _netProviderImplementation.GetFromServer<T>(command);
}
public UniTask<T> GetFromClient<T>(int id, string addressablePath = Constant.System.Internal)
public UniTask<T> GetFromClient<T>(int id, T command = default)
{
return _netProviderImplementation.GetFromClient<T>(id, addressablePath);
return _netProviderImplementation.GetFromClient<T>(id, command);
}
public void AddRpcHandle(object rpcHandle)
{
_netProviderImplementation.AddRpcHandle(rpcHandle);
@@ -96,11 +95,15 @@ namespace BITKit.Net.Kcp
_netProviderImplementation.AddCommandListener(handle);
}
public void RemoveCommandListener<T>(Action<T> handle)
public void AddCommandListener<T>(Func<T, T> func)
{
_netProviderImplementation.RemoveCommandListener(handle);
throw new NotImplementedException();
}
public void RemoveCommandListener<T>(Func<T, T> func)
{
throw new NotImplementedException();
}
public void SendRT(string rpcName, params object[] pars)
{
_netProviderImplementation.SendRT(rpcName, pars);

View File

@@ -108,16 +108,15 @@ namespace BITKit.Net.Kcp
_server.ClientCommand(id, command);
}
public UniTask<T> GetFromServer<T>(string addressablePath = Constant.System.Internal)
public UniTask<T> GetFromServer<T>(T command = default)
{
return _server.GetFromServer<T>(addressablePath);
return _serverInstance.GetFromServer(command);
}
public UniTask<T> GetFromClient<T>(int id, string addressablePath = Constant.System.Internal)
public UniTask<T> GetFromClient<T>(int id, T command = default)
{
return _server.GetFromClient<T>(id, addressablePath);
return _serverInstance.GetFromClient(id, command);
}
public void AddRpcHandle(object rpcHandle)
{
_server.AddRpcHandle(rpcHandle);
@@ -128,6 +127,16 @@ namespace BITKit.Net.Kcp
_server.AddCommandListener(handle);
}
public void AddCommandListener<T>(Func<T, T> func)
{
_serverInstance.AddCommandListener(func);
}
public void RemoveCommandListener<T>(Func<T, T> func)
{
_serverInstance.RemoveCommandListener(func);
}
public void RemoveCommandListener<T>(Action<T> handle)
{
_server.RemoveCommandListener(handle);