(client) chore:完善函数注释
This commit is contained in:
@ -152,8 +152,25 @@ namespace Data
|
||||
// Debug.Log($"插入{className},{def.defName}");
|
||||
}
|
||||
}
|
||||
|
||||
private static Define LoadDefineClass(XElement defineDoc,string className)
|
||||
/// <summary>
|
||||
/// 根据指定的 XML 元素 (<paramref name="defineDoc"/>) 和类名 (<paramref name="className"/>),
|
||||
/// 动态加载并初始化一个继承自 <see cref="Define"/> 的类实例。
|
||||
/// </summary>
|
||||
/// <param name="defineDoc">包含类定义的 XML 元素 (<see cref="XElement"/>)。</param>
|
||||
/// <param name="className">目标类的全限定名或简短名称。</param>
|
||||
/// <returns>
|
||||
/// 如果成功加载并初始化,则返回对应的 <see cref="Define"/> 类实例;
|
||||
/// 否则返回 null。
|
||||
/// </returns>
|
||||
/// <exception cref="ArgumentNullException">
|
||||
/// 如果 <paramref name="defineDoc"/> 或 <paramref name="className"/> 为 null 或空字符串,则抛出此异常。
|
||||
/// </exception>
|
||||
/// <remarks>
|
||||
/// 该方法通过反射动态加载指定类,并检查其是否继承自 <see cref="Define"/>。
|
||||
/// 如果类存在且满足条件,则尝试调用其 <see cref="Define.Init(XElement)"/> 方法进行初始化。
|
||||
/// 如果初始化失败,则使用默认初始化方法 (<see cref="DefaultInitDefine(Define, XElement, Type)"/>)。
|
||||
/// </remarks>
|
||||
public static Define LoadDefineClass(XElement defineDoc,string className)
|
||||
{
|
||||
var assembly = Assembly.GetExecutingAssembly();
|
||||
|
||||
@ -210,7 +227,22 @@ namespace Data
|
||||
|
||||
return define;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 初始化指定的 <paramref name="define"/> 对象,根据 <paramref name="defineDoc"/> 中的 XML 元素内容,
|
||||
/// 将对应的字段值赋给 <paramref name="define"/> 对象。
|
||||
/// </summary>
|
||||
/// <param name="define">需要初始化的对象实例。</param>
|
||||
/// <param name="defineDoc">包含字段定义的 XML 元素 (<see cref="XElement"/>)。</param>
|
||||
/// <param name="defineType">目标对象的类型 (<see cref="Type"/>)。</param>
|
||||
/// <exception cref="ArgumentNullException">
|
||||
/// 如果 <paramref name="define"/>、<paramref name="defineDoc"/> 或 <paramref name="defineType"/> 为 null,则抛出此异常。
|
||||
/// </exception>
|
||||
/// <remarks>
|
||||
/// 该方法会遍历 <paramref name="defineType"/> 的所有字段(包括公共和非公共字段),
|
||||
/// 并尝试从 <paramref name="defineDoc"/> 中找到与字段名称匹配的子元素。
|
||||
/// 如果找到匹配的子元素,则将其值转换为字段的类型并赋值给字段。
|
||||
/// 如果字段类型继承自 <see cref="Define"/>,则递归调用 <see cref="LoadDefineClass(XElement, string)"/> 方法进行加载。
|
||||
/// </remarks>
|
||||
public static void DefaultInitDefine(Define define,XElement defineDoc,Type defineType)
|
||||
{
|
||||
var fields = defineType.GetFields(BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic);
|
||||
|
@ -12,7 +12,15 @@ namespace Managers
|
||||
|
||||
public Dictionary<string, Dictionary<string, Define>> defines = new();
|
||||
public Dictionary<string, DefinePack> packs = new();
|
||||
|
||||
/// <summary>
|
||||
/// 初始化定义管理器,加载所有定义包并构建定义字典。
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 该方法执行以下操作:
|
||||
/// 1. 获取指定路径下的所有子文件夹,每个子文件夹代表一个定义包。
|
||||
/// 2. 遍历每个定义包,尝试加载其中的定义数据。
|
||||
/// 3. 将加载的定义数据按类型分类,并存储到定义字典中。
|
||||
/// </remarks>
|
||||
public void Init()
|
||||
{
|
||||
var packFolder = Configs.ConfigProcessor.GetSubFolders(new(dataSetFilePath));
|
||||
|
Reference in New Issue
Block a user