mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-07 16:45:10 +00:00
同步服务器导出SceneType
同步服务器导出SceneType
This commit is contained in:
@@ -70,6 +70,10 @@ public static class Define
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public static string ClientCustomExportDirectory;
|
public static string ClientCustomExportDirectory;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
/// SceneConfig.xlsx的位置
|
||||||
|
/// </summary>
|
||||||
|
public static string SceneConfigPath;
|
||||||
|
/// <summary>
|
||||||
/// 自定义导出代码存放的程序集
|
/// 自定义导出代码存放的程序集
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static string CustomExportAssembly;
|
public static string CustomExportAssembly;
|
||||||
|
@@ -69,6 +69,8 @@ public static class TEngineSettingsHelper
|
|||||||
Define.ServerCustomExportDirectory = FileHelper.GetFullPath(root["Export:ServerCustomExportDirectory:Value"]);
|
Define.ServerCustomExportDirectory = FileHelper.GetFullPath(root["Export:ServerCustomExportDirectory:Value"]);
|
||||||
// 客户端自定义导出代码
|
// 客户端自定义导出代码
|
||||||
Define.ClientCustomExportDirectory = FileHelper.GetFullPath(root["Export:ClientCustomExportDirectory: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"]);
|
Define.CustomExportAssembly = FileHelper.GetFullPath(root["Export:CustomExportAssembly:Value"]);
|
||||||
}
|
}
|
||||||
|
@@ -60,6 +60,10 @@
|
|||||||
"Value": "../../Client/Unity/Assets/Scripts/Hotfix/Generate/CustomExport/",
|
"Value": "../../Client/Unity/Assets/Scripts/Hotfix/Generate/CustomExport/",
|
||||||
"Comment": "客户端自定义导出代码文件夹位置"
|
"Comment": "客户端自定义导出代码文件夹位置"
|
||||||
},
|
},
|
||||||
|
"SceneConfigPath": {
|
||||||
|
"Value": "../../../Config/Excel/Server/SceneConfig.xlsx",
|
||||||
|
"Comment": "SceneConfig.xlsx的位置"
|
||||||
|
},
|
||||||
"CustomExportAssembly": {
|
"CustomExportAssembly": {
|
||||||
"Value": "Logic",
|
"Value": "Logic",
|
||||||
"Comment": "自定义导出代码存放的程序集"
|
"Comment": "自定义导出代码存放的程序集"
|
||||||
|
@@ -1,48 +1,104 @@
|
|||||||
#if TENGINE_NET
|
#if TENGINE_NET
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using TEngine.Core;
|
using TEngine.Core;
|
||||||
|
using TEngine.Helper;
|
||||||
|
|
||||||
namespace TEngine.Model;
|
namespace TEngine.Model;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 将场景类型配置表转换为枚举和字典的自定义导出类。
|
||||||
|
/// </summary>
|
||||||
public sealed class SceneTypeConfigToEnum : ACustomExport
|
public sealed class SceneTypeConfigToEnum : ACustomExport
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 执行自定义导出操作。
|
||||||
|
/// </summary>
|
||||||
public override void Run()
|
public override void Run()
|
||||||
{
|
{
|
||||||
var serverSceneType = new HashSet<string>();
|
// 获取场景配置表的完整路径
|
||||||
var instanceList = SceneConfigData.Instance.List;
|
using var excelPackage = ExcelHelper.LoadExcel(Define.SceneConfigPath);
|
||||||
|
var sceneType = new Dictionary<string, string>();
|
||||||
foreach (var sceneConfig in instanceList)
|
var sceneSubType = new Dictionary<string, string>();
|
||||||
|
// 获取场景类型配置工作表
|
||||||
|
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<string> sceneTypes)
|
private void Write(CustomExportType customExportType, Dictionary<string, string> sceneTypes, Dictionary<string, string> sceneSubType)
|
||||||
{
|
{
|
||||||
var index = 0;
|
|
||||||
var strBuilder = new StringBuilder();
|
var strBuilder = new StringBuilder();
|
||||||
var dicBuilder = new StringBuilder();
|
var dicBuilder = new StringBuilder();
|
||||||
|
|
||||||
|
// 添加命名空间和注释头部
|
||||||
strBuilder.AppendLine("namespace TEngine\n{");
|
strBuilder.AppendLine("namespace TEngine\n{");
|
||||||
strBuilder.AppendLine("\t// 生成器自动生成,请不要手动编辑。");
|
strBuilder.AppendLine("\t// 生成器自动生成,请不要手动编辑。");
|
||||||
strBuilder.AppendLine("\tpublic class SceneType\n\t{");
|
// 生成场景类型的静态类
|
||||||
dicBuilder.AppendLine("\n\t\tpublic static readonly Dictionary<string, int> SceneDic = new Dictionary<string, int>()\n\t\t{");
|
strBuilder.AppendLine("\tpublic static class SceneType\n\t{");
|
||||||
|
dicBuilder.AppendLine("\n\t\tpublic static readonly Dictionary<string, int> SceneTypeDic = new Dictionary<string, int>()\n\t\t{");
|
||||||
foreach (var str in sceneTypes)
|
|
||||||
|
// 遍历场景类型字典,生成场景类型的常量和字典项
|
||||||
|
foreach (var (sceneTypeId, sceneTypeStr) in sceneTypes)
|
||||||
{
|
{
|
||||||
index++;
|
dicBuilder.AppendLine($"\t\t\t{{ \"{sceneTypeStr}\", {sceneTypeId} }},");
|
||||||
dicBuilder.AppendLine($"\t\t\t{{ \"{str}\", {index} }},");
|
strBuilder.AppendLine($"\t\tpublic const int {sceneTypeStr} = {sceneTypeId};");
|
||||||
strBuilder.AppendLine($"\t\tpublic const int {str} = {index};");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 添加场景类型字典尾部,合并到主字符串构建器中
|
||||||
|
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<string, int> SceneSubTypeDic = new Dictionary<string, int>()\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};");
|
dicBuilder.AppendLine("\t\t};");
|
||||||
strBuilder.Append(dicBuilder);
|
strBuilder.Append(dicBuilder);
|
||||||
strBuilder.AppendLine("\t}\n}");
|
strBuilder.AppendLine("\t}\n}");
|
||||||
|
|
||||||
|
// 调用外部方法将生成的代码写入文件
|
||||||
Write("SceneType.cs", strBuilder.ToString(), customExportType);
|
Write("SceneType.cs", strBuilder.ToString(), customExportType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -7,6 +7,7 @@ namespace TEngine
|
|||||||
public const int Addressable = 2;
|
public const int Addressable = 2;
|
||||||
public const int Map = 3;
|
public const int Map = 3;
|
||||||
public const int Chat = 4;
|
public const int Chat = 4;
|
||||||
|
public const int Center = 5;
|
||||||
|
|
||||||
public static readonly Dictionary<string, int> SceneTypeDic = new Dictionary<string, int>()
|
public static readonly Dictionary<string, int> SceneTypeDic = new Dictionary<string, int>()
|
||||||
{
|
{
|
||||||
@@ -14,6 +15,7 @@ namespace TEngine
|
|||||||
{ "Addressable", 2 },
|
{ "Addressable", 2 },
|
||||||
{ "Map", 3 },
|
{ "Map", 3 },
|
||||||
{ "Chat", 4 },
|
{ "Chat", 4 },
|
||||||
|
{ "Center", 5 },
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user