diff --git a/Client/Assets/Scripts/Data/DefineManager.cs b/Client/Assets/Scripts/Data/DefineManager.cs index 3e26eb7..80c1422 100644 --- a/Client/Assets/Scripts/Data/DefineManager.cs +++ b/Client/Assets/Scripts/Data/DefineManager.cs @@ -19,7 +19,7 @@ namespace Data public void Init() { // 加载所有 XML 文件路径 - var xmlFilePaths = FileHandler.LoadXmlFilesFromPaths(dataSetFilePath); + var xmlFilePaths = FileHandler.GetXmlFilePathsFromPaths(dataSetFilePath); // 遍历并加载每个 XML 文件 foreach (var xmlFilePath in xmlFilePaths) diff --git a/Client/Assets/Scripts/Utils/FileHandler.cs b/Client/Assets/Scripts/Utils/FileHandler.cs index 3e97b41..ac0ee43 100644 --- a/Client/Assets/Scripts/Utils/FileHandler.cs +++ b/Client/Assets/Scripts/Utils/FileHandler.cs @@ -1,8 +1,10 @@ using System; using System.Collections.Generic; using System.IO; +using System.Xml; using Newtonsoft.Json; using UnityEngine; +using Formatting = Newtonsoft.Json.Formatting; namespace Utils { @@ -158,7 +160,7 @@ namespace Utils /// /// 文件夹路径 /// - public static List LoadXmlFilesFromPaths(string[] paths) + public static List GetXmlFilePathsFromPaths(string[] paths) { var xmlFilePaths = new List(); @@ -194,6 +196,38 @@ namespace Utils return xmlFilePaths; } + + /// + /// 从指定路径加载所有 XML 文件并解析为 XmlDocument 对象。 + /// + /// 文件夹路径数组。 + /// 包含所有解析后的 XmlDocument 对象的列表。 + public static List LoadXmlFromPaths(string[] paths) + { + var xmlDocuments = new List(); + var xmlFilePaths = GetXmlFilePathsFromPaths(paths); + + foreach (var filePath in xmlFilePaths) + { + try + { + // 创建一个新的 XmlDocument 实例 + var xmlDoc = new XmlDocument(); + + // 加载 XML 文件内容 + xmlDoc.Load(filePath); + + // 将解析后的 XmlDocument 添加到结果列表中 + xmlDocuments.Add(xmlDoc); + } + catch (Exception ex) + { + Console.Error.WriteLine($"加载 XML 文件 {filePath} 时发生错误: {ex.Message}"); + } + } + + return xmlDocuments; + } } } \ No newline at end of file