diff --git a/Assets/GameScripts/DotNet/Core/CoreErrorCode.cs b/Assets/GameScripts/DotNet/Core/CoreErrorCode.cs index 6df44d9c..0febebbb 100644 --- a/Assets/GameScripts/DotNet/Core/CoreErrorCode.cs +++ b/Assets/GameScripts/DotNet/Core/CoreErrorCode.cs @@ -6,5 +6,6 @@ namespace TEngine.Core public const uint ErrNotFoundRoute = 100000003; // 没有找到Route消息 public const uint ErrRouteTimeout = 100000004; // 发送Route消息超时 public const uint Error_NotFindEntity = 100000008; // 没有找到Entity + public const uint Error_CopyTimeout = 100000009; // CopyTimeout不能小于或等于0 } } \ No newline at end of file diff --git a/Assets/GameScripts/DotNet/Core/Entitas/Scene/Scene.cs b/Assets/GameScripts/DotNet/Core/Entitas/Scene/Scene.cs index 72d6fdb9..3db147d1 100644 --- a/Assets/GameScripts/DotNet/Core/Entitas/Scene/Scene.cs +++ b/Assets/GameScripts/DotNet/Core/Entitas/Scene/Scene.cs @@ -9,7 +9,7 @@ using TEngine.Core.DataBase; #pragma warning disable CS8618 namespace TEngine { - public sealed class Scene : Entity, INotSupportedPool + public class Scene : Entity, INotSupportedPool { public string Name { get; private set; } public uint LocationId { get; private set; } @@ -18,7 +18,8 @@ namespace TEngine public SceneConfigInfo SceneInfo { get; private set; } #endif #if TENGINE_NET - public string SceneType { get; private set; } + public int SceneType { get; private set; } + public int SceneSubType { get; private set; } public World World { get; private set; } public Server Server { get; private set; } #endif @@ -36,7 +37,8 @@ namespace TEngine #if TENGINE_NET World = null; Server = null; - SceneType = null; + SceneType = 0; + SceneSubType = 0; #endif #if TENGINE_UNITY SceneInfo = null; @@ -58,6 +60,16 @@ namespace TEngine } } #if TENGINE_UNITY + public static Scene Create() + { + var sceneId = IdFactory.NextRunTimeId(); + var scene = Create(sceneId, sceneId); + scene.Scene = scene; + scene.Parent = scene; + Scenes.Add(scene); + return scene; + } + public static Scene Create(string name) { var sceneId = IdFactory.NextRunTimeId(); @@ -68,6 +80,7 @@ namespace TEngine Scenes.Add(scene); return scene; } + public void CreateSession(string remoteAddress, NetworkProtocolType networkProtocolType, Action onConnectComplete, Action onConnectFail,Action onConnectDisconnect, int connectTimeout = 5000) { var address = NetworkHelper.ToIPEndPoint(remoteAddress); @@ -78,19 +91,20 @@ namespace TEngine } #else /// - /// 创建一个Scene、但这个Scene是在某个Scene下面的Scene + /// 创建一个Scene、但这个Scene是在某个Scene下面的Scene。 /// /// - /// /// + /// + /// /// - public static async FTask Create(Scene scene, string sceneType, string sceneName) + public static async FTask Create(Scene scene, int sceneType, int sceneSubType) where T : Scene, new() { - var newScene = Create(scene); + var newScene = Create(scene); newScene.Scene = scene; newScene.Parent = scene; - newScene.Name = sceneName; newScene.SceneType = sceneType; + newScene.SceneSubType = sceneSubType; newScene.Server = scene.Server; newScene.LocationId = scene.Server.Id; @@ -99,13 +113,13 @@ namespace TEngine newScene.World = scene.World; } - if (!string.IsNullOrEmpty(sceneType)) + if (sceneType > 0) { await EventSystem.Instance.PublishAsync(new OnCreateScene(scene)); } Scenes.Add(scene); - return scene; + return newScene; } /// @@ -113,14 +127,14 @@ namespace TEngine /// /// /// - /// + /// /// /// /// /// /// /// - public static async FTask Create(Server server, string sceneType, string sceneName, long sceneId =0, uint worldId =0, string networkProtocol = null, string outerBindIp = null, int outerPort = 0) + public static async FTask Create(Server server, int sceneType = 0, int sceneSubType = 0, long sceneId = 0, uint worldId = 0, string networkProtocol = null, string outerBindIp = null, int outerPort = 0) { if (sceneId == 0) { @@ -130,8 +144,8 @@ namespace TEngine var scene = Create(sceneId, sceneId); scene.Scene = scene; scene.Parent = scene; - scene.Name = sceneName; scene.SceneType = sceneType; + scene.SceneSubType = sceneSubType; scene.Server = server; scene.LocationId = server.Id; @@ -150,22 +164,9 @@ namespace TEngine serverNetworkComponent.Initialize(networkProtocolType, NetworkTarget.Outer, address); } - if (!string.IsNullOrEmpty(sceneType)) + if (sceneType > 0) { - switch (sceneType) - { - case "Addressable": - { - scene.AddComponent(); - break; - } - default: - { - // 没有SceneType目前只有代码创建的Scene才会这样、目前只有Server的Scene是这样 - await EventSystem.Instance.PublishAsync(new OnCreateScene(scene)); - break; - } - } + await EventSystem.Instance.PublishAsync(new OnCreateScene(scene)); } Scenes.Add(scene); diff --git a/Assets/GameScripts/DotNet/Core/Entitas/Scene/SceneTypeConfigToEnum.cs b/Assets/GameScripts/DotNet/Core/Entitas/Scene/SceneTypeConfigToEnum.cs new file mode 100644 index 00000000..4a41616f --- /dev/null +++ b/Assets/GameScripts/DotNet/Core/Entitas/Scene/SceneTypeConfigToEnum.cs @@ -0,0 +1,89 @@ +#if TENGINE_NET +using System.Text; +using TEngine.Core; +using TEngine.Helper; + +namespace TEngine.CustomExport; + +public sealed class SceneTypeConfigToEnum : ACustomExport +{ + public override void Run() + { + var fullPath = FileHelper.GetFullPath("../../../Config/Excel/Server/SceneConfig.xlsx"); + using var excelPackage = ExcelHelper.LoadExcel(fullPath); + var sceneType = new Dictionary(); + var sceneSubType = new Dictionary(); + var sceneTypeConfig = excelPackage.Workbook.Worksheets["SceneTypeConfig"]; + + for (var row = 3; row <= sceneTypeConfig.Dimension.Rows; row++) + { + var sceneTypeId = sceneTypeConfig.GetCellValue(row, 1); + var sceneTypeStr = sceneTypeConfig.GetCellValue(row, 2); + + if (string.IsNullOrEmpty(sceneTypeId) || string.IsNullOrEmpty(sceneTypeStr)) + { + continue; + } + + sceneType.Add(sceneTypeId, sceneTypeStr); + } + + var sceneSubTypeConfig = excelPackage.Workbook.Worksheets["SceneSubTypeConfig"]; + + for (var row = 3; row <= sceneSubTypeConfig.Dimension.Rows; row++) + { + var sceneSubTypeId = sceneSubTypeConfig.GetCellValue(row, 1); + var sceneSubTypeStr = sceneSubTypeConfig.GetCellValue(row, 2); + + if (string.IsNullOrEmpty(sceneSubTypeId) || string.IsNullOrEmpty(sceneSubTypeStr)) + { + continue; + } + + sceneSubType.Add(sceneSubTypeId, sceneSubTypeStr); + } + + if (sceneType.Count > 0 || sceneSubType.Count > 0) + { + Write(CustomExportType.Server, sceneType, sceneSubType); + } + } + + private void Write(CustomExportType customExportType, Dictionary sceneTypes, Dictionary sceneSubType) + { + var strBuilder = new StringBuilder(); + var dicBuilder = new StringBuilder(); + + strBuilder.AppendLine("namespace TEngine\n{"); + strBuilder.AppendLine("\t// 生成器自动生成,请不要手动编辑。"); + strBuilder.AppendLine("\tpublic static class SceneType\n\t{"); + dicBuilder.AppendLine("\n\t\tpublic static readonly Dictionary SceneTypeDic = new Dictionary()\n\t\t{"); + + foreach (var (sceneTypeId, sceneTypeStr) in sceneTypes) + { + dicBuilder.AppendLine($"\t\t\t{{ \"{sceneTypeStr}\", {sceneTypeId} }},"); + strBuilder.AppendLine($"\t\tpublic const int {sceneTypeStr} = {sceneTypeId};"); + } + + dicBuilder.AppendLine("\t\t};"); + strBuilder.Append(dicBuilder); + strBuilder.AppendLine("\t}\n"); + + strBuilder.AppendLine("\t// 生成器自动生成,请不要手动编辑。"); + strBuilder.AppendLine("\tpublic static class SceneSubType\n\t{"); + + dicBuilder.Clear(); + dicBuilder.AppendLine("\n\t\tpublic static readonly Dictionary SceneSubTypeDic = new Dictionary()\n\t\t{"); + foreach (var (sceneSubTypeId, sceneSubTypeStr) in sceneSubType) + { + dicBuilder.AppendLine($"\t\t\t{{ \"{sceneSubTypeStr}\", {sceneSubTypeId} }},"); + strBuilder.AppendLine($"\t\tpublic const int {sceneSubTypeStr} = {sceneSubTypeId};"); + } + dicBuilder.AppendLine("\t\t};"); + strBuilder.Append(dicBuilder); + strBuilder.AppendLine("\t}\n}"); + + Write("SceneType.cs", strBuilder.ToString(), customExportType); + } +} +#endif \ No newline at end of file diff --git a/Assets/GameScripts/DotNet/Core/Entitas/Scene/SceneTypeConfigToEnum.cs.meta b/Assets/GameScripts/DotNet/Core/Entitas/Scene/SceneTypeConfigToEnum.cs.meta new file mode 100644 index 00000000..1b33f896 --- /dev/null +++ b/Assets/GameScripts/DotNet/Core/Entitas/Scene/SceneTypeConfigToEnum.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: d254c1aefb624046ab545bd8cebbe57c +timeCreated: 1690561569 \ No newline at end of file diff --git a/Assets/GameScripts/DotNet/Core/Exporter/Excel/ExcelExporter.cs b/Assets/GameScripts/DotNet/Core/Exporter/Excel/ExcelExporter.cs index 895e561d..d25fc203 100644 --- a/Assets/GameScripts/DotNet/Core/Exporter/Excel/ExcelExporter.cs +++ b/Assets/GameScripts/DotNet/Core/Exporter/Excel/ExcelExporter.cs @@ -4,17 +4,12 @@ using System.Reflection; using System.Runtime.Loader; using System.Text; using System.Text.RegularExpressions; +using TEngine.CustomExport; using TEngine.DataStructure; -using TEngine.Core; using Newtonsoft.Json; using OfficeOpenXml; +using TEngine.Helper; using static System.String; -#pragma warning disable CS8625 -#pragma warning disable CS8604 -#pragma warning disable CS8602 -#pragma warning disable CS8601 -#pragma warning disable CS8600 -#pragma warning disable CS8618 namespace TEngine.Core; @@ -28,10 +23,14 @@ public sealed class ExcelExporter private readonly OneToManyList _tables = new OneToManyList(); private readonly ConcurrentDictionary _excelTables = new ConcurrentDictionary(); private readonly ConcurrentDictionary _worksheets = new ConcurrentDictionary(); + + static ExcelExporter() + { + ExcelPackage.LicenseContext = LicenseContext.NonCommercial; + } public ExcelExporter(ExportType exportType) { - ExcelPackage.LicenseContext = LicenseContext.NonCommercial; var versionFilePath = Define.ExcelVersionFile; switch (exportType) @@ -86,6 +85,9 @@ public sealed class ExcelExporter task.Add(Task.Run(customExport.Run)); } } + + // 添加生成SceneType的自定义导出 + task.Add(Task.Run(new SceneTypeConfigToEnum().Run)); Task.WaitAll(task.ToArray()); } @@ -226,7 +228,7 @@ public sealed class ExcelExporter { // 列名字第一个字符是#不参与导出 - var colName = GetCellValue(worksheet, 5, col); + var colName = worksheet.GetCellValue(5, col); if (colName.StartsWith("#", StringComparison.Ordinal)) { continue; @@ -234,14 +236,14 @@ public sealed class ExcelExporter // 数值列不参与导出 - var numericalCol = GetCellValue(worksheet, 3, col); + var numericalCol = worksheet.GetCellValue(3, col); if (numericalCol != "" && numericalCol != "0") { continue; } - var serverType = GetCellValue(worksheet, 1, col); - var clientType = GetCellValue(worksheet, 2, col); + var serverType = worksheet.GetCellValue(1, col); + var clientType = worksheet.GetCellValue(2, col); var isExportServer = !IsNullOrEmpty(serverType) && serverType != "0"; var isExportClient = !IsNullOrEmpty(clientType) && clientType != "0"; @@ -350,7 +352,7 @@ public sealed class ExcelExporter foreach (var colIndex in cols) { - var colName = GetCellValue(excelWorksheet, 5, colIndex); + var colName = excelWorksheet.GetCellValue(5, colIndex); if (colNameSet.Contains(colName)) { @@ -363,19 +365,19 @@ public sealed class ExcelExporter if (isServer) { - colType = GetCellValue(excelWorksheet, 1, colIndex); + colType = excelWorksheet.GetCellValue(1, colIndex); if (IsNullOrEmpty(colType) || colType == "0") { - colType = GetCellValue(excelWorksheet, 2, colIndex); + colType = excelWorksheet.GetCellValue(2, colIndex); } } else { - colType = GetCellValue(excelWorksheet, 2, colIndex); + colType = excelWorksheet.GetCellValue(2, colIndex); } - var remarks = GetCellValue(excelWorksheet, 4, colIndex); + var remarks = excelWorksheet.GetCellValue(4, colIndex); fileBuilder.Append($"\n\t\t[ProtoMember({++index}, IsRequired = true)]\n"); fileBuilder.Append( @@ -436,12 +438,12 @@ public sealed class ExcelExporter for (var row = 7; row <= rows; row++) { - if (GetCellValue(excelWorksheet, row, 1).StartsWith("#", StringComparison.Ordinal)) + if (excelWorksheet.GetCellValue(row, 1).StartsWith("#", StringComparison.Ordinal)) { continue; } - var id = GetCellValue(excelWorksheet, row, 3); + var id = excelWorksheet.GetCellValue(row, 3); if (idCheck.Contains(id)) { @@ -525,21 +527,21 @@ public sealed class ExcelExporter { string colType; var colIndex = cols[i]; - var colName = GetCellValue(excelWorksheet, 5, colIndex); - var value = GetCellValue(excelWorksheet, row, colIndex); + var colName = excelWorksheet.GetCellValue(5, colIndex); + var value = excelWorksheet.GetCellValue(row, colIndex); if (isServer) { - colType = GetCellValue(excelWorksheet, 1, colIndex); + colType = excelWorksheet.GetCellValue(1, colIndex); if (IsNullOrEmpty(colType) || colType == "0") { - colType = GetCellValue(excelWorksheet, 2, colIndex); + colType = excelWorksheet.GetCellValue(2, colIndex); } } else { - colType = GetCellValue(excelWorksheet, 2, colIndex); + colType = excelWorksheet.GetCellValue(2, colIndex); } try @@ -566,7 +568,7 @@ public sealed class ExcelExporter dynamicInfo.Json.AppendLine($"{json},"); } } - + public ExcelWorksheet LoadExcel(string name, bool isAddToDic) { if (_worksheets.TryGetValue(name, out var worksheet)) @@ -574,7 +576,7 @@ public sealed class ExcelExporter return worksheet; } - worksheet = new ExcelPackage(name).Workbook.Worksheets[0]; + worksheet = ExcelHelper.LoadExcel(name).Workbook.Worksheets[0]; if (isAddToDic) { @@ -585,26 +587,6 @@ public sealed class ExcelExporter return worksheet; } - private string GetCellValue(ExcelWorksheet sheet, int row, int column) - { - var cell = sheet.Cells[row, column]; - - try - { - if (cell.Value == null) - { - return ""; - } - - var s = cell.GetValue(); - return s.Trim(); - } - catch (Exception e) - { - throw new Exception($"Rows {row} Columns {column} Content {cell.Text} {e}"); - } - } - private void SetNewValue(PropertyInfo propertyInfo, AProto config, string type, string value) { if (IsNullOrWhiteSpace(value)) @@ -753,20 +735,6 @@ public sealed class ExcelExporter return; } - // case "AttrConfig": - // { - // if (value.Trim() == "" || value.Trim() == "{}") - // { - // propertyInfo.SetValue(config, null); - // return; - // } - // - // var attr = new AttrConfig {KV = JsonConvert.DeserializeObject>(value)}; - // - // propertyInfo.SetValue(config, attr); - // - // return; - // } default: throw new NotSupportedException($"不支持此类型: {type}"); } diff --git a/Assets/GameScripts/DotNet/Core/Helper/ExcelHelper.cs b/Assets/GameScripts/DotNet/Core/Helper/ExcelHelper.cs new file mode 100644 index 00000000..88e103db --- /dev/null +++ b/Assets/GameScripts/DotNet/Core/Helper/ExcelHelper.cs @@ -0,0 +1,34 @@ +#if TENGINE_NET +using OfficeOpenXml; + +namespace TEngine.Helper; + +public static class ExcelHelper +{ + public static ExcelPackage LoadExcel(string name) + { + return new ExcelPackage(name); + } + + public static string GetCellValue(this ExcelWorksheet sheet, int row, int column) + { + ExcelRange cell = sheet.Cells[row, column]; + + try + { + if (cell.Value == null) + { + return ""; + } + + string s = cell.GetValue(); + + return s.Trim(); + } + catch (Exception e) + { + throw new Exception($"Rows {row} Columns {column} Content {cell.Text} {e}"); + } + } +} +#endif \ No newline at end of file diff --git a/Assets/GameScripts/DotNet/Core/Helper/ExcelHelper.cs.meta b/Assets/GameScripts/DotNet/Core/Helper/ExcelHelper.cs.meta new file mode 100644 index 00000000..f5b66430 --- /dev/null +++ b/Assets/GameScripts/DotNet/Core/Helper/ExcelHelper.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 2ea3356f30cb40949949691a0e258a05 +timeCreated: 1690561972 \ No newline at end of file diff --git a/Assets/GameScripts/DotNet/Core/Helper/FileHelper.cs b/Assets/GameScripts/DotNet/Core/Helper/FileHelper.cs index 5cf647a3..88c91469 100644 --- a/Assets/GameScripts/DotNet/Core/Helper/FileHelper.cs +++ b/Assets/GameScripts/DotNet/Core/Helper/FileHelper.cs @@ -5,6 +5,16 @@ namespace TEngine.Core { public static class FileHelper { + /// + /// 获取文件全路径。 + /// + /// + /// + public static string GetFullPath(string relativePath) + { + return Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(), relativePath)); + } + /// /// 拷贝文件到目标路径、如果目标目录不存在会自动创建目录 /// diff --git a/Assets/GameScripts/DotNet/Core/Network/Base/Server/SceneConfigInfo.cs b/Assets/GameScripts/DotNet/Core/Network/Base/Server/SceneConfigInfo.cs index 3da40038..ea3370e2 100644 --- a/Assets/GameScripts/DotNet/Core/Network/Base/Server/SceneConfigInfo.cs +++ b/Assets/GameScripts/DotNet/Core/Network/Base/Server/SceneConfigInfo.cs @@ -3,9 +3,11 @@ namespace TEngine public class SceneConfigInfo { public uint Id; - public string Name; public long EntityId; - public string SceneType; + public int SceneType; + public int SceneSubType; + public string SceneTypeStr; + public string SceneSubTypeStr; public uint ServerConfigId; public uint WorldId; public int OuterPort; diff --git a/Assets/GameScripts/DotNet/Core/Network/Base/Server/Server.cs b/Assets/GameScripts/DotNet/Core/Network/Base/Server/Server.cs index 19f1d951..92635894 100644 --- a/Assets/GameScripts/DotNet/Core/Network/Base/Server/Server.cs +++ b/Assets/GameScripts/DotNet/Core/Network/Base/Server/Server.cs @@ -140,7 +140,7 @@ namespace TEngine Id = serverConfigId }; - server.Scene = await Scene.Create(server,null,$"ServerScene{serverConfigId}"); + server.Scene = await Scene.Create(server); // 创建网络、Server下的网络只能是内部网络、外部网络是在Scene中定义 @@ -155,7 +155,7 @@ namespace TEngine foreach (var sceneConfig in sceneInfos) { - await Scene.Create(server, sceneConfig.SceneType, sceneConfig.Name, sceneConfig.EntityId, + await Scene.Create(server, sceneConfig.SceneType, sceneConfig.SceneSubType, sceneConfig.EntityId, sceneConfig.WorldId, sceneConfig.NetworkProtocol, outerBindIp, sceneConfig.OuterPort); } diff --git a/Assets/GameScripts/DotNet/Core/Network/Message/Addressable/AddressableHelper.cs b/Assets/GameScripts/DotNet/Core/Network/Message/Addressable/AddressableHelper.cs index 0a68a031..31d8a46f 100644 --- a/Assets/GameScripts/DotNet/Core/Network/Message/Addressable/AddressableHelper.cs +++ b/Assets/GameScripts/DotNet/Core/Network/Message/Addressable/AddressableHelper.cs @@ -12,7 +12,7 @@ namespace TEngine.Core.Network foreach (var sceneConfigInfo in sceneConfigInfos) { - if (sceneConfigInfo.SceneType == "Addressable") + if (sceneConfigInfo.SceneTypeStr == "Addressable") { AddressableScenes.Add(sceneConfigInfo); } diff --git a/Assets/GameScripts/DotNet/Core/TEngineSettingsHelper.cs b/Assets/GameScripts/DotNet/Core/TEngineSettingsHelper.cs index 13714034..e53ab5ea 100644 --- a/Assets/GameScripts/DotNet/Core/TEngineSettingsHelper.cs +++ b/Assets/GameScripts/DotNet/Core/TEngineSettingsHelper.cs @@ -36,46 +36,41 @@ public static class TEngineSettingsHelper private static void LoadProtoConfig(IConfigurationRoot root) { // ProtoBuf文件所在的位置文件夹位置 - Define.ProtoBufDirectory = root["Export:ProtoBufDirectory:Value"].GetFullPath(); + Define.ProtoBufDirectory = FileHelper.GetFullPath(root["Export:ProtoBufDirectory:Value"]); // ProtoBuf生成到服务端的文件夹位置 - Define.ProtoBufServerDirectory = root["Export:ProtoBufServerDirectory:Value"].GetFullPath(); + Define.ProtoBufServerDirectory = FileHelper.GetFullPath(root["Export:ProtoBufServerDirectory:Value"]); // ProtoBuf生成到客户端的文件夹位置 - Define.ProtoBufClientDirectory = root["Export:ProtoBufClientDirectory:Value"].GetFullPath(); + Define.ProtoBufClientDirectory = FileHelper.GetFullPath(root["Export:ProtoBufClientDirectory:Value"]); // ProtoBuf生成代码模板的位置 - Define.ProtoBufTemplatePath = root["Export:ProtoBufTemplatePath:Value"].GetFullPath(); + Define.ProtoBufTemplatePath = FileHelper.GetFullPath(root["Export:ProtoBufTemplatePath:Value"]); } private static void LoadExcelConfig(IConfigurationRoot root) { // Excel配置文件根目录 - Define.ExcelProgramPath = root["Export:ExcelProgramPath:Value"].GetFullPath(); + Define.ExcelProgramPath = FileHelper.GetFullPath(root["Export:ExcelProgramPath:Value"]); // Excel版本文件的位置 - Define.ExcelVersionFile = root["Export:ExcelVersionFile:Value"].GetFullPath(); + Define.ExcelVersionFile = FileHelper.GetFullPath(root["Export:ExcelVersionFile:Value"]); // Excel生成服务器代码的文件夹位置 - Define.ExcelServerFileDirectory = root["Export:ExcelServerFileDirectory:Value"].GetFullPath(); + Define.ExcelServerFileDirectory = FileHelper.GetFullPath(root["Export:ExcelServerFileDirectory:Value"]); // Excel生成客户端代码文件夹位置 - Define.ExcelClientFileDirectory = root["Export:ExcelClientFileDirectory:Value"].GetFullPath(); + Define.ExcelClientFileDirectory = FileHelper.GetFullPath(root["Export:ExcelClientFileDirectory:Value"]); // Excel生成服务器二进制数据文件夹位置 - Define.ExcelServerBinaryDirectory = root["Export:ExcelServerBinaryDirectory:Value"].GetFullPath(); + Define.ExcelServerBinaryDirectory = FileHelper.GetFullPath(root["Export:ExcelServerBinaryDirectory:Value"]); // Excel生成客户端二进制数据文件夹位置 - Define.ExcelClientBinaryDirectory = root["Export:ExcelClientBinaryDirectory:Value"].GetFullPath(); + Define.ExcelClientBinaryDirectory = FileHelper.GetFullPath(root["Export:ExcelClientBinaryDirectory:Value"]); // Excel生成服务器Json数据文件夹位置 - Define.ExcelServerJsonDirectory = root["Export:ExcelServerJsonDirectory:Value"].GetFullPath(); + Define.ExcelServerJsonDirectory = FileHelper.GetFullPath(root["Export:ExcelServerJsonDirectory:Value"]); // Excel生成客户端Json数据文件夹位置 - Define.ExcelClientJsonDirectory = root["Export:ExcelClientJsonDirectory:Value"].GetFullPath(); + Define.ExcelClientJsonDirectory = FileHelper.GetFullPath(root["Export:ExcelClientJsonDirectory:Value"]); // Excel生成代码模板的位置 - Define.ExcelTemplatePath = root["Export:ExcelTemplatePath:Value"].GetFullPath(); + Define.ExcelTemplatePath = FileHelper.GetFullPath(root["Export:ExcelTemplatePath:Value"]); // 服务器自定义导出代码文件夹位置 - Define.ServerCustomExportDirectory = root["Export:ServerCustomExportDirectory:Value"].GetFullPath(); + Define.ServerCustomExportDirectory = FileHelper.GetFullPath(root["Export:ServerCustomExportDirectory:Value"]); // 客户端自定义导出代码 - Define.ClientCustomExportDirectory = root["Export:ClientCustomExportDirectory:Value"].GetFullPath(); + Define.ClientCustomExportDirectory = FileHelper.GetFullPath(root["Export:ClientCustomExportDirectory:Value"]); // 自定义导出代码存放的程序集 - Define.CustomExportAssembly = root["Export:CustomExportAssembly:Value"].GetFullPath(); - } - - private static string GetFullPath(this string relativePath) - { - return Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(), relativePath)); + Define.CustomExportAssembly = FileHelper.GetFullPath(root["Export:CustomExportAssembly:Value"]); } } #endif \ No newline at end of file diff --git a/DotNet/Config/Binary/SceneConfigData.bytes b/DotNet/Config/Binary/SceneConfigData.bytes index 9db43dca..95f9233e 100644 Binary files a/DotNet/Config/Binary/SceneConfigData.bytes and b/DotNet/Config/Binary/SceneConfigData.bytes differ diff --git a/DotNet/Config/Excel/Server/SceneConfig.xlsx b/DotNet/Config/Excel/Server/SceneConfig.xlsx index 7aed6363..c88e40ad 100644 Binary files a/DotNet/Config/Excel/Server/SceneConfig.xlsx and b/DotNet/Config/Excel/Server/SceneConfig.xlsx differ diff --git a/DotNet/Config/Excel/Version.txt b/DotNet/Config/Excel/Version.txt index a61a561f..a09cb158 100644 --- a/DotNet/Config/Excel/Version.txt +++ b/DotNet/Config/Excel/Version.txt @@ -1 +1 @@ -{"MachineConfig":1690328264682,"SceneConfig":1690415187917,"ServerConfig":1690328264682,"WorldConfig":1690328264683} \ No newline at end of file +{"MachineConfig":1690328264682,"SceneConfig":1690589593259,"ServerConfig":1690328264682,"WorldConfig":1690328264683} \ No newline at end of file diff --git a/DotNet/Config/Json/Server/SceneConfigData.Json b/DotNet/Config/Json/Server/SceneConfigData.Json index 7aa3e0b3..9264e9e8 100644 --- a/DotNet/Config/Json/Server/SceneConfigData.Json +++ b/DotNet/Config/Json/Server/SceneConfigData.Json @@ -1,6 +1,6 @@ {"List":[ -{"Id":1,"EntityId":17246978048,"ServerConfigId":1024,"WorldId":0,"SceneType":"Gate","Name":"Gate","NetworkProtocol":"KCP","OuterPort":20000}, -{"Id":2,"EntityId":34493956096,"ServerConfigId":2048,"WorldId":0,"SceneType":"Addressable","Name":"Addressable1","NetworkProtocol":null,"OuterPort":0}, -{"Id":4,"EntityId":68920803328,"ServerConfigId":3072,"WorldId":0,"SceneType":"Map","Name":"Map1","NetworkProtocol":null,"OuterPort":0}, -{"Id":5,"EntityId":86167781376,"ServerConfigId":4096,"WorldId":0,"SceneType":"Chat","Name":"Chat1","NetworkProtocol":null,"OuterPort":0} +{"Id":1,"EntityId":17246978048,"ServerConfigId":1024,"WorldId":0,"SceneType":"Gate","SceneSubType":"Gate","NetworkProtocol":"KCP","OuterPort":20000}, +{"Id":2,"EntityId":34493956096,"ServerConfigId":2048,"WorldId":0,"SceneType":"Addressable","SceneSubType":"Addressable","NetworkProtocol":null,"OuterPort":0}, +{"Id":4,"EntityId":68920803328,"ServerConfigId":3072,"WorldId":0,"SceneType":"Map","SceneSubType":"Map","NetworkProtocol":null,"OuterPort":0}, +{"Id":5,"EntityId":86167781376,"ServerConfigId":4096,"WorldId":0,"SceneType":"Chat","SceneSubType":"Chat","NetworkProtocol":null,"OuterPort":0} ]} diff --git a/DotNet/Logic/src/Generate/ConfigTable/Entity/SceneConfig.cs b/DotNet/Logic/src/Generate/ConfigTable/Entity/SceneConfig.cs index 9499190d..8d519d35 100644 --- a/DotNet/Logic/src/Generate/ConfigTable/Entity/SceneConfig.cs +++ b/DotNet/Logic/src/Generate/ConfigTable/Entity/SceneConfig.cs @@ -79,13 +79,13 @@ namespace TEngine [ProtoMember(2, IsRequired = true)] public long EntityId { get; set; } // 实体Id [ProtoMember(3, IsRequired = true)] - public uint ServerConfigId { get; set; } // 服务配置Id + public uint ServerConfigId { get; set; } // 路由Id [ProtoMember(4, IsRequired = true)] public uint WorldId { get; set; } // 世界Id [ProtoMember(5, IsRequired = true)] public string SceneType { get; set; } // Scene类型 [ProtoMember(6, IsRequired = true)] - public string Name { get; set; } // 名称 + public string SceneSubType { get; set; } // Scene子类型 [ProtoMember(7, IsRequired = true)] public string NetworkProtocol { get; set; } // 协议类型 [ProtoMember(8, IsRequired = true)] diff --git a/DotNet/Logic/src/Generate/CustomExport/SceneType.cs b/DotNet/Logic/src/Generate/CustomExport/SceneType.cs index e4ccaa18..a40f4ceb 100644 --- a/DotNet/Logic/src/Generate/CustomExport/SceneType.cs +++ b/DotNet/Logic/src/Generate/CustomExport/SceneType.cs @@ -1,14 +1,31 @@ namespace TEngine { // 生成器自动生成,请不要手动编辑。 - public class SceneType + public static class SceneType { public const int Gate = 1; public const int Addressable = 2; public const int Map = 3; public const int Chat = 4; - public static readonly Dictionary SceneDic = new Dictionary() + public static readonly Dictionary SceneTypeDic = new Dictionary() + { + { "Gate", 1 }, + { "Addressable", 2 }, + { "Map", 3 }, + { "Chat", 4 }, + }; + } + + // 生成器自动生成,请不要手动编辑。 + public static class SceneSubType + { + public const int Gate = 1; + public const int Addressable = 2; + public const int Map = 3; + public const int Chat = 4; + + public static readonly Dictionary SceneSubTypeDic = new Dictionary() { { "Gate", 1 }, { "Addressable", 2 }, diff --git a/DotNet/Logic/src/Helper/AddressableSceneHelper.cs b/DotNet/Logic/src/Helper/AddressableSceneHelper.cs index 9cb7b3a6..80371194 100644 --- a/DotNet/Logic/src/Helper/AddressableSceneHelper.cs +++ b/DotNet/Logic/src/Helper/AddressableSceneHelper.cs @@ -19,12 +19,12 @@ public static class AddressableSceneHelper return sceneEntityId; } - public static long GetSceneEntityIdByType(Logic.SceneType sceneType) + public static long GetSceneEntityIdByType(string sceneType) { var sceneEntityId = 0L; foreach (var sceneConfig in SceneConfigData.Instance.List) { - if (sceneConfig.SceneType.Parse() == sceneType) + if (sceneConfig.SceneType == sceneType) { sceneEntityId = sceneConfig.EntityId; break; diff --git a/DotNet/Logic/src/Helper/ConfigTableSystem.cs b/DotNet/Logic/src/Helper/ConfigTableSystem.cs index 9ccb9d11..931933f6 100644 --- a/DotNet/Logic/src/Helper/ConfigTableSystem.cs +++ b/DotNet/Logic/src/Helper/ConfigTableSystem.cs @@ -71,8 +71,10 @@ public static class ConfigTableSystem return new SceneConfigInfo() { Id = sceneConfig.Id, - SceneType = sceneConfig.SceneType, - Name = sceneConfig.Name, + SceneType = SceneType.SceneTypeDic[sceneConfig.SceneType], + SceneSubType = SceneSubType.SceneSubTypeDic[sceneConfig.SceneSubType], + SceneTypeStr = sceneConfig.SceneType, + SceneSubTypeStr = sceneConfig.SceneSubType, NetworkProtocol = sceneConfig.NetworkProtocol, ServerConfigId = sceneConfig.ServerConfigId, WorldId = sceneConfig.WorldId, @@ -123,8 +125,10 @@ public static class ConfigTableSystem { Id = sceneConfig.Id, EntityId = sceneConfig.EntityId, - SceneType = sceneConfig.SceneType, - Name = sceneConfig.Name, + SceneType = SceneType.SceneTypeDic[sceneConfig.SceneType], + SceneSubType = SceneSubType.SceneSubTypeDic[sceneConfig.SceneSubType], + SceneTypeStr = sceneConfig.SceneType, + SceneSubTypeStr = sceneConfig.SceneSubType, NetworkProtocol = sceneConfig.NetworkProtocol, ServerConfigId = sceneConfig.ServerConfigId, WorldId = sceneConfig.WorldId, diff --git a/DotNet/Logic/src/OnCreateScene.cs b/DotNet/Logic/src/OnCreateScene.cs index 25458261..e3408cc0 100644 --- a/DotNet/Logic/src/OnCreateScene.cs +++ b/DotNet/Logic/src/OnCreateScene.cs @@ -3,36 +3,6 @@ using TEngine.Core.Network; namespace TEngine.Logic; -[Flags] -public enum SceneType: long -{ - /// - /// 场景无。 - /// - None = 0, - - /// - /// 场景Gate。 - /// - Gate = 1, - - /// - /// 场景Addressable。 - /// 负责进程间消息通信。 - /// - Addressable = 1 << 2, - - /// - /// 游戏场景服。 - /// - Map = 1 << 3, - - /// - /// 游戏聊天服。 - /// - Chat = 1 << 4, -} - /// /// 场景创建回调。 /// 常用于定义场景需要添加的组件。 @@ -46,13 +16,19 @@ public class OnCreateScene : AsyncEventSystem // 比如Address协议这里、我就是做了一个管理Address地址的一个组件挂在到Address这个Scene下面了 // 比如Map下你需要一些自定义组件、你也可以在这里操作 var scene = self.Scene; - switch (scene.SceneType.Parse()) + switch (scene.SceneType) { case SceneType.Gate: { self.Scene.AddComponent(); break; } + case SceneType.Addressable: + { + // 挂载管理Address地址组件 + scene.AddComponent(); + break; + } } Log.Info($"scene create: {self.Scene.SceneType} {self.Scene.Name} SceneId:{self.Scene.Id} LocationId:{self.Scene.LocationId} WorldId:{self.Scene.World?.Id}");