diff --git a/Assets/GameScripts/DotNet/Core/Define.cs b/Assets/GameScripts/DotNet/Core/Define.cs index 314be151..89b54685 100644 --- a/Assets/GameScripts/DotNet/Core/Define.cs +++ b/Assets/GameScripts/DotNet/Core/Define.cs @@ -70,6 +70,10 @@ public static class Define /// public static string ClientCustomExportDirectory; /// + /// SceneConfig.xlsx的位置 + /// + public static string SceneConfigPath; + /// /// 自定义导出代码存放的程序集 /// public static string CustomExportAssembly; diff --git a/Assets/GameScripts/DotNet/Core/TEngineSettingsHelper.cs b/Assets/GameScripts/DotNet/Core/TEngineSettingsHelper.cs index e53ab5ea..01b8dfcc 100644 --- a/Assets/GameScripts/DotNet/Core/TEngineSettingsHelper.cs +++ b/Assets/GameScripts/DotNet/Core/TEngineSettingsHelper.cs @@ -69,6 +69,8 @@ public static class TEngineSettingsHelper Define.ServerCustomExportDirectory = FileHelper.GetFullPath(root["Export:ServerCustomExportDirectory:Value"]); // 客户端自定义导出代码 Define.ClientCustomExportDirectory = FileHelper.GetFullPath(root["Export:ClientCustomExportDirectory:Value"]); + // SceneConfig.xlsx的位置 + Define.SceneConfigPath = FileHelper.GetFullPath(root["Export:SceneConfigPath:Value"]); // 自定义导出代码存放的程序集 Define.CustomExportAssembly = FileHelper.GetFullPath(root["Export:CustomExportAssembly:Value"]); } diff --git a/DotNet/App/TEngineSettings.json b/DotNet/App/TEngineSettings.json index 24c9ccf0..91d4b627 100644 --- a/DotNet/App/TEngineSettings.json +++ b/DotNet/App/TEngineSettings.json @@ -60,6 +60,10 @@ "Value": "../../Client/Unity/Assets/Scripts/Hotfix/Generate/CustomExport/", "Comment": "客户端自定义导出代码文件夹位置" }, + "SceneConfigPath": { + "Value": "../../../Config/Excel/Server/SceneConfig.xlsx", + "Comment": "SceneConfig.xlsx的位置" + }, "CustomExportAssembly": { "Value": "Logic", "Comment": "自定义导出代码存放的程序集" diff --git a/DotNet/Logic/src/CustomExport/SceneTypeConfigToEnum.cs b/DotNet/Logic/src/CustomExport/SceneTypeConfigToEnum.cs index f5b035a8..c666a4a9 100644 --- a/DotNet/Logic/src/CustomExport/SceneTypeConfigToEnum.cs +++ b/DotNet/Logic/src/CustomExport/SceneTypeConfigToEnum.cs @@ -1,48 +1,104 @@ #if TENGINE_NET using System.Text; using TEngine.Core; +using TEngine.Helper; namespace TEngine.Model; +/// +/// 将场景类型配置表转换为枚举和字典的自定义导出类。 +/// public sealed class SceneTypeConfigToEnum : ACustomExport { + /// + /// 执行自定义导出操作。 + /// public override void Run() { - var serverSceneType = new HashSet(); - var instanceList = SceneConfigData.Instance.List; - - foreach (var sceneConfig in instanceList) + // 获取场景配置表的完整路径 + using var excelPackage = ExcelHelper.LoadExcel(Define.SceneConfigPath); + var sceneType = new Dictionary(); + var sceneSubType = new Dictionary(); + // 获取场景类型配置工作表 + var sceneTypeConfig = excelPackage.Workbook.Worksheets["SceneTypeConfig"]; + // 遍历场景类型配置表的行 + for (var row = 3; row <= sceneTypeConfig.Dimension.Rows; row++) { - serverSceneType.Add(sceneConfig.SceneType); - } + var sceneTypeId = sceneTypeConfig.GetCellValue(row, 1); + var sceneTypeStr = sceneTypeConfig.GetCellValue(row, 2); - if (serverSceneType.Count > 0) + 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++) { - Write(CustomExportType.Server, serverSceneType); + 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, HashSet sceneTypes) + private void Write(CustomExportType customExportType, Dictionary sceneTypes, Dictionary sceneSubType) { - var index = 0; var strBuilder = new StringBuilder(); var dicBuilder = new StringBuilder(); + // 添加命名空间和注释头部 strBuilder.AppendLine("namespace TEngine\n{"); strBuilder.AppendLine("\t// 生成器自动生成,请不要手动编辑。"); - strBuilder.AppendLine("\tpublic class SceneType\n\t{"); - dicBuilder.AppendLine("\n\t\tpublic static readonly Dictionary SceneDic = new Dictionary()\n\t\t{"); - - foreach (var str in sceneTypes) + // 生成场景类型的静态类 + 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) { - index++; - dicBuilder.AppendLine($"\t\t\t{{ \"{str}\", {index} }},"); - strBuilder.AppendLine($"\t\tpublic const int {str} = {index};"); + 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); } } diff --git a/DotNet/Logic/src/Generate/CustomExport/SceneType.cs b/DotNet/Logic/src/Generate/CustomExport/SceneType.cs index a40f4ceb..be2bf356 100644 --- a/DotNet/Logic/src/Generate/CustomExport/SceneType.cs +++ b/DotNet/Logic/src/Generate/CustomExport/SceneType.cs @@ -7,6 +7,7 @@ namespace TEngine public const int Addressable = 2; public const int Map = 3; public const int Chat = 4; + public const int Center = 5; public static readonly Dictionary SceneTypeDic = new Dictionary() { @@ -14,6 +15,7 @@ namespace TEngine { "Addressable", 2 }, { "Map", 3 }, { "Chat", 4 }, + { "Center", 5 }, }; }