From d754eebc6d703b55cc4768dbb19f802930a7b8d1 Mon Sep 17 00:00:00 2001 From: Kevin Li Date: Mon, 4 Sep 2023 14:06:38 +0800 Subject: [PATCH] .Net compatible --- README.md | 60 ++++++++++++++++++++++------------------ Runtime/GameEventMgr.cs | 28 +++++++++---------- Runtime/MessageSender.cs | 2 +- 3 files changed, 48 insertions(+), 42 deletions(-) diff --git a/README.md b/README.md index a54cc22..222968c 100644 --- a/README.md +++ b/README.md @@ -9,20 +9,39 @@ ## 安装 .NET 6.0 运行时(必须使用6.0版本) * 下载离线安装包 -https://dotnet.microsoft.com/zh-cn/download/dotnet/thank-you/runtime-6.0.21-macos-x64-installer + - Mac: https://dotnet.microsoft.com/zh-cn/download/dotnet/thank-you/sdk-6.0.413-macos-x64-installer + - Windows: https://dotnet.microsoft.com/zh-cn/download/dotnet/thank-you/sdk-6.0.413-windows-x64-installer -* 或者使用 homebrew +* Mac下建议使用 homebrew brew tap isen-ng/dotnet-sdk-versions brew install --cask dotnet-sdk6-0-400 ## 安装 protobuf-net.Protogen 命令行程序 dotnet tool install --global protobuf-net.Protogen --version 3.2.12 -## 进入项目目录 -cd upm_guru_dof_lib/Runtime/ServerProtos +* Windows +protogen 的安装目录为 C:\Users\用户名\.dotnet\tools ,可直接在 cmd 命令行下运行 protogen + +* Macos +在 Macos 下 protogen 的安装目录为 /Users/用户名/.dotnet/tools,可能需要手动将 +``` +PATH=PATH:/Users/用户名/.dotnet/tools +``` +加入到 ~/.bash_profile中,因为 homebrew 加入的 PATH ~/.dotnet/tools 无效 ## 生成 cs 文件 -~/.dotnet/tools/protogen messages.proto --csharp_out=../NetworkGen + +* Windows +``` +cd DofKcpDemo\ServerProtos +protogen messages.proto --csharp_out=..\Assets\Scripts\NetworkGen +``` + +* MacOS +``` +cd DofKcpDemo/ServerProtos +~/.dotnet/tools/protogen messages.proto --csharp_out=../Assets/Scripts/NetworkGen +``` ## 安装和接入 @@ -30,25 +49,12 @@ cd upm_guru_dof_lib/Runtime/ServerProtos - 本插件需要使用公司内部的Gitlab加载对应的repo, 详见 [Castbox内部git服务器Gitea使用指南](https://docs.google.com/document/d/1DiGPDD5Teu2QcYaBhqAcsqMbb3DJ5sdnTQMuvVzJSUk/edit#heading=h.w9tkkzwwyjxf) - 根据文档部署好本机配置后, 请在Unity内部配置如下参数 - - TBD - - TBD - - TBD - - -## 逻辑实现 - -- TBD - - - - -## 问题答疑 - -- Q -> A - -- Q -> A - -- Q -> A \ No newline at end of file + - 修改位于项目Packages/manifest.json文件,在dependencies中添加 + ``` + { + "dependencies": { + "com.guru.unity.gurukcp": "git@git.chengdu.pundit.company:castbox/upm_guru_dof_lib.git", + ... + } + } + ``` \ No newline at end of file diff --git a/Runtime/GameEventMgr.cs b/Runtime/GameEventMgr.cs index 50dcdce..ea558a0 100644 --- a/Runtime/GameEventMgr.cs +++ b/Runtime/GameEventMgr.cs @@ -29,7 +29,7 @@ namespace Guru _isDebugMode = is_debug_mode; - if(_isDebugMode) + if (_isDebugMode) { Debug.Log($"[GameEventMgr]Init: Running in debug mode"); } @@ -49,17 +49,17 @@ namespace Guru } } - private readonly Queue> _listenerListQueue = new (); - private readonly Queue> _listenerBondingListQueue = new (); - private readonly Dictionary> _eventTable = new (); - private readonly Dictionary> _eventObjTable = new (); - private readonly Dictionary> _pendingAddTable = new (); - private readonly Dictionary> _pendingObjAddTable = new (); - private readonly Dictionary> _pendingRemoveTable = new (); - private readonly Dictionary> _pendingObjRemoveTable = new (); + private readonly Queue> _listenerListQueue = new Queue>(); + private readonly Queue> _listenerBondingListQueue = new Queue>(); + private readonly Dictionary> _eventTable = new Dictionary>(); + private readonly Dictionary> _eventObjTable = new Dictionary>(); + private readonly Dictionary> _pendingAddTable = new Dictionary>(); + private readonly Dictionary> _pendingObjAddTable = new Dictionary>(); + private readonly Dictionary> _pendingRemoveTable = new Dictionary>(); + private readonly Dictionary> _pendingObjRemoveTable = new Dictionary>(); // Using raising event list to prevent infinite loop call or changing delegate list - private readonly List _raisingEventIds = new (); + private readonly List _raisingEventIds = new List(); private GameEventMgr() { } @@ -133,7 +133,7 @@ namespace Guru for (int i = 0; i < listeners.Count; i++) { - if(listeners[i].gameObject == null) + if (listeners[i].gameObject == null) { listeners.RemoveAt(i--); } @@ -143,7 +143,7 @@ namespace Guru private List SpawnDelegateList() { - if(_listenerListQueue.Count > 0) + if (_listenerListQueue.Count > 0) { return _listenerListQueue.Dequeue(); } @@ -410,7 +410,7 @@ namespace Guru { var listener = listeners[i]; - if(listener != null) + if (listener != null) { try { @@ -423,7 +423,7 @@ namespace Guru LogException(ex, event_id.ToString(), "DoRaise"); } } - } + } } _raisingEventIds.Remove(event_id); diff --git a/Runtime/MessageSender.cs b/Runtime/MessageSender.cs index f8765fc..7391338 100644 --- a/Runtime/MessageSender.cs +++ b/Runtime/MessageSender.cs @@ -16,7 +16,7 @@ namespace DofLibrary { private long _cid; private Ukcp _client; - private MemoryStream _localSendMs = new(1024 * 1024 * 1); + private MemoryStream _localSendMs = new MemoryStream(1024 * 1024 * 1); /// /// 设置 kcp 客户端,用于发送消息