(client) feat: Complete data processing logic
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Xml;
|
||||
using System.Xml.Linq;
|
||||
using Newtonsoft.Json;
|
||||
using UnityEngine;
|
||||
using Formatting = Newtonsoft.Json.Formatting;
|
||||
@ -196,37 +196,30 @@ namespace Utils
|
||||
|
||||
return xmlFilePaths;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从指定路径加载所有 XML 文件并解析为 XmlDocument 对象。
|
||||
/// 从指定路径加载所有 XML 文件并解析为 XDocument 对象。
|
||||
/// </summary>
|
||||
/// <param name="paths">文件夹路径数组。</param>
|
||||
/// <returns>包含所有解析后的 XmlDocument 对象的列表。</returns>
|
||||
public static List<XmlDocument> LoadXmlFromPaths(string[] paths)
|
||||
/// <returns>包含所有解析后的 XDocument 对象的列表。</returns>
|
||||
public static List<XDocument> LoadXmlFromPaths(string[] paths)
|
||||
{
|
||||
var xmlDocuments = new List<XmlDocument>();
|
||||
var xDocuments = new List<XDocument>();
|
||||
var xmlFilePaths = GetXmlFilePathsFromPaths(paths);
|
||||
|
||||
foreach (var filePath in xmlFilePaths)
|
||||
{
|
||||
try
|
||||
{
|
||||
// 创建一个新的 XmlDocument 实例
|
||||
var xmlDoc = new XmlDocument();
|
||||
|
||||
// 加载 XML 文件内容
|
||||
xmlDoc.Load(filePath);
|
||||
|
||||
// 将解析后的 XmlDocument 添加到结果列表中
|
||||
xmlDocuments.Add(xmlDoc);
|
||||
var xDoc = XDocument.Load(filePath);
|
||||
xDocuments.Add(xDoc);
|
||||
}
|
||||
catch (Exception ex)
|
||||
catch (System.Exception ex)
|
||||
{
|
||||
Console.Error.WriteLine($"加载 XML 文件 {filePath} 时发生错误: {ex.Message}");
|
||||
Debug.LogError($"加载 XML 文件 {filePath} 时发生错误: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
return xmlDocuments;
|
||||
return xDocuments;
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取指定单个路径下的所有 XML 文件。
|
||||
@ -238,14 +231,42 @@ namespace Utils
|
||||
return GetXmlFilePathsFromPaths(new[] { path });
|
||||
}
|
||||
/// <summary>
|
||||
/// 从指定单个路径加载所有 XML 文件并解析为 XmlDocument 对象。
|
||||
/// 从指定单个路径加载所有 XML 文件并解析为 XDocument 对象。
|
||||
/// </summary>
|
||||
/// <param name="path">文件夹路径。</param>
|
||||
/// <returns>包含所有解析后的 XmlDocument 对象的列表。</returns>
|
||||
public static List<XmlDocument> LoadXmlFromPath(string path)
|
||||
/// <returns>包含所有解析后的 XDocument 对象的列表。</returns>
|
||||
public static List<XDocument> LoadXmlFromPath(string path)
|
||||
{
|
||||
return LoadXmlFromPaths(new[] { path });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取文件夹列表中所有直接子文件夹的路径。
|
||||
/// </summary>
|
||||
/// <param name="folderPaths">文件夹路径列表。</param>
|
||||
/// <returns>包含所有子文件夹路径的列表。</returns>
|
||||
public static List<string> GetSubFolders(List<string> folderPaths)
|
||||
{
|
||||
List<string> result = new List<string>();
|
||||
|
||||
foreach (string folderPath in folderPaths)
|
||||
{
|
||||
if (Directory.Exists(folderPath))
|
||||
{
|
||||
// 获取当前文件夹的直接子文件夹
|
||||
string[] subFolders = Directory.GetDirectories(folderPath);
|
||||
|
||||
// 将子文件夹路径添加到结果列表中
|
||||
result.AddRange(subFolders);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning($"警告: 文件夹不存在 - {folderPath}");
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user