This commit is contained in:
CortexCore 2024-06-11 15:39:09 +08:00
parent 3e8bd54a08
commit 0e1bf20595
3 changed files with 86 additions and 26 deletions

View File

@ -170,8 +170,16 @@ namespace BITKit.Net
var id = reader.ReadInt32(); var id = reader.ReadInt32();
try try
{ {
var value = BITBinary.Read(reader); if (reader.ReadBoolean())
_p2p.TryAdd(id,value); {
var value = BITBinary.Read(reader);
_p2p.TryAdd(id,value);
}
else
{
var message = reader.ReadString();
_p2p.TryAdd(id,new Exception(message));
}
} }
catch (Exception e) catch (Exception e)
{ {
@ -189,21 +197,30 @@ namespace BITKit.Net
{ {
throw new NotImplementedException($"未找到对应的方法:{commandObj.GetType().FullName}"); throw new NotImplementedException($"未找到对应的方法:{commandObj.GetType().FullName}");
} }
var value = await func.As<Func<object, UniTask<object>>>().Invoke(commandObj);
using var _ms = new MemoryStream(); using var _ms = new MemoryStream();
using var _writer = new BinaryWriter(_ms); using var _writer = new BinaryWriter(_ms);
_writer.Write((byte)NetCommandType.ReturnToServer); _writer.Write((byte)NetCommandType.ReturnToServer);
_writer.Write(requestId); _writer.Write(requestId);
BITBinary.Write(_writer, value); try
var _bytes = _ms.ToArray(); {
commandQueue.Enqueue(_bytes); var value = await func.As<Func<object, UniTask<object>>>().Invoke(commandObj);
_writer.Write(true);
BITBinary.Write(_writer, value);
var _bytes = _ms.ToArray();
commandQueue.Enqueue(_bytes);
}
catch (Exception e)
{
BIT4Log.LogException(e);
_writer.Write(false);
_writer.Write(e.Message);
}
} }
catch(Exception e) catch(Exception e)
{ {
BIT4Log.LogException(e); BIT4Log.LogException(e);
} }
break; break;
default: default:
BIT4Log.Log<KcpClient>($"未知消息类型:{type},字节:{(byte)type}"); BIT4Log.Log<KcpClient>($"未知消息类型:{type},字节:{(byte)type}");
@ -280,6 +297,10 @@ namespace BITKit.Net
if (_p2p.TryRemove(id, out var value)) if (_p2p.TryRemove(id, out var value))
{ {
if (value is Exception e)
{
throw e;
}
return (T)value; return (T)value;
} }
await Task.Delay(100); await Task.Delay(100);

View File

@ -189,36 +189,59 @@ namespace BITKit.Net
server.Send(Id,new byte[]{(byte)NetCommandType.Ping},channel); server.Send(Id,new byte[]{(byte)NetCommandType.Ping},channel);
break; break;
case NetCommandType.GetFromServer: case NetCommandType.GetFromServer:
{
var requestId = reader.ReadInt32();
var commandObj = BITBinary.Read(reader);
using var _ms = new MemoryStream();
using var _writer = new BinaryWriter(_ms);
_writer.Write((byte)NetCommandType.ReturnToClient);
_writer.Write(requestId);
try try
{ {
var requestId = reader.ReadInt32(); if (_rpc.TryGetValue(commandObj.GetType()!.FullName!, out var func) is false)
var commandObj = BITBinary.Read(reader);
if (_rpc.TryGetValue(commandObj.GetType().FullName, out var func) is false)
{ {
throw new NotImplementedException($"未找到对应的方法:{commandObj.GetType().FullName}"); _writer.Write(false);
_writer.Write("未找到对应的Rpc方法");
}
else
{
try
{
var value = await func.As<Func<object, UniTask<object>>>().Invoke(commandObj);
_writer.Write(true);
BITBinary.Write(_writer, value);
}
catch (Exception e)
{
BIT4Log.LogException(e);
_writer.Write(false);
_writer.Write(e.Message);
}
} }
var value =await func.As<Func<object,UniTask<object>>>().Invoke(commandObj);
using var _ms = new MemoryStream();
using var _writer = new BinaryWriter(_ms);
_writer.Write((byte)NetCommandType.ReturnToClient);
_writer.Write(requestId);
BITBinary.Write(_writer,value);
var _bytes = _ms.ToArray(); var _bytes = _ms.ToArray();
server.Send(Id,_bytes,KcpChannel.Reliable); server.Send(Id, _bytes, KcpChannel.Reliable);
} }
catch (Exception e) catch (Exception e)
{ {
BIT4Log.LogException(e); BIT4Log.LogException(e);
Send(Id,NetCommandType.ReturnToClient,-1,0);
} }
}
break; break;
case NetCommandType.ReturnToServer: case NetCommandType.ReturnToServer:
{ {
var id = reader.ReadInt32(); var id = reader.ReadInt32();
var value = BITBinary.Read(reader); if (reader.ReadBoolean())
_p2p.TryAdd(id, value); {
var value = BITBinary.Read(reader);
_p2p.TryAdd(id, value);
}
else
{
var message = reader.ReadString();
_p2p.TryAdd(id, new Exception(message));
}
} }
break; break;
default: default:
@ -274,6 +297,10 @@ namespace BITKit.Net
if (_p2p.TryRemove(index, out var value)) if (_p2p.TryRemove(index, out var value))
{ {
if (value is Exception e)
{
throw e;
}
return (T)value; return (T)value;
} }
await Task.Delay(100); await Task.Delay(100);

View File

@ -15,6 +15,7 @@ namespace BITKit.GameEditor
public class ScriptableObjectGroupEditor<T> : EditorWindow where T : ScriptableObject public class ScriptableObjectGroupEditor<T> : EditorWindow where T : ScriptableObject
{ {
protected virtual string AssetsPath => $"Assets/Artists/"; protected virtual string AssetsPath => $"Assets/Artists/";
protected virtual string ExportPathKey => $"{typeof(T).Name}.ExportPath";
protected readonly List<T> List=new(); protected readonly List<T> List=new();
private ListView _listView; private ListView _listView;
@ -105,15 +106,26 @@ namespace BITKit.GameEditor
private void ExportData() private void ExportData()
{ {
var exportPath = EditorUtility.OpenFolderPanel("select path", "",typeof(T).FullName); var path = Environment.CurrentDirectory;
if (PlayerPrefs.HasKey(ExportPathKey))
{
path = PlayerPrefs.GetString(ExportPathKey);
}
var exportPath = EditorUtility.SaveFilePanel("select path", path, $"{typeof(T).Name}.bytes", "bytes");
if(string.IsNullOrEmpty(exportPath))return; if(string.IsNullOrEmpty(exportPath))return;
PlayerPrefs.SetString(ExportPathKey, exportPath);
PlayerPrefs.Save();
ExportData(exportPath); ExportData(exportPath);
} }
protected virtual void ExportData(string path) protected virtual void ExportData(string path)
{ {
throw new NotImplementedException($"暂未实现{typeof(T).Name}的导出功能");
} }
protected virtual void ItemsChosen(IEnumerable<object> obj) protected virtual void ItemsChosen(IEnumerable<object> obj)