diff --git a/Client/Assets/Scripts/Data/DefinePack.cs b/Client/Assets/Scripts/Data/DefinePack.cs
index e14972d..4f51f73 100644
--- a/Client/Assets/Scripts/Data/DefinePack.cs
+++ b/Client/Assets/Scripts/Data/DefinePack.cs
@@ -1,14 +1,81 @@
using System;
using System.Collections.Generic;
+using System.Linq;
using System.Xml;
+using UnityEngine;
namespace Data
{
+
public struct PackAbout
{
public string name;
public string description;
public string author;
+ public string version;
+ public string packID;
+
+ public string[] necessary;
+ public string[] after;
+ public string[] before;
+
+ ///
+ /// 使用静态方法从 XML 文档创建 PackAbout 实例。
+ ///
+ /// XML 文档。
+ /// 初始化的 PackAbout 实例。
+ public static PackAbout FromXmlDocument(XmlDocument doc)
+ {
+ var aboutNode = doc.DocumentElement;
+ if (aboutNode == null)
+ {
+ throw new ArgumentException("XML 文档无效,根节点为空。");
+ }
+
+ // 初始化 PackAbout 实例
+ PackAbout result = new();
+
+ // 读取子节点内容
+ result.name = aboutNode["name"]?.InnerText ?? "Unknown";
+ result.description = aboutNode["description"]?.InnerText ?? "Unknown";
+ result.version = aboutNode["version"]?.InnerText ?? "Unknown";
+ result.packID = aboutNode["packID"]?.InnerText ?? "Unknown";
+
+ // 读取 "sort" 节点下的子节点
+ XmlNode sortNode = aboutNode["sort"];
+ if (sortNode != null)
+ {
+ result.before = GetChildNodeValues(sortNode["before"]);
+ result.after = GetChildNodeValues(sortNode["after"]);
+ result.necessary = GetChildNodeValues(sortNode["necessary"]);
+ }
+ else
+ {
+ result.before = Array.Empty();
+ result.after = Array.Empty();
+ result.necessary = Array.Empty();
+ }
+
+ return result;
+ }
+
+ ///
+ /// 获取子节点的所有文本值并返回为字符串数组。
+ ///
+ /// 父节点。
+ /// 字符串数组。
+ private static string[] GetChildNodeValues(XmlNode node)
+ {
+ if (node == null || node.ChildNodes.Count == 0)
+ {
+ return Array.Empty();
+ }
+
+ return node.ChildNodes.Cast()
+ .Where(n => n.NodeType == XmlNodeType.Text)
+ .Select(n => n.Value.Trim())
+ .ToArray();
+ }
}
public class DefinePack
{
@@ -16,10 +83,23 @@ namespace Data
public PackAbout packAbout;
public List defines;
- public void LoadPack(string packPath)
+ public bool LoadPack(string packPath)
{
var packDatas=Utils.FileHandler.LoadXmlFromPath(packPath);
-
+ var aboutXmls=FindDocumentsWithRootName(packDatas,"About");
+ if (aboutXmls == null || aboutXmls.Count < 1)
+ {
+ Debug.LogError("包缺少配置文件,加载跳过");
+ return false;
+ }
+ var aboutXml=aboutXmls[0];
+ packAbout=PackAbout.FromXmlDocument(aboutXml);
+ if (aboutXmls.Count > 1)
+ {
+ Debug.LogWarning("包拥有多个配置文件,系统选择了加载序的第一个,请避免这种情况");
+ }
+
+ return true;
}
///
/// 从 ListXmlDocument 中查找指定根元素名称的文档。