Merge pull request 'Complete Data Loading and Managing Logic' (#4) from zzdxxz/Gen_Hack-and-Slash-Roguelite_client:main into main
This commit is contained in:
@ -8,6 +8,7 @@ namespace Data
|
||||
public string defName;
|
||||
public string label;
|
||||
public string discription;
|
||||
public string packID;
|
||||
/// <summary>
|
||||
/// 初始化方法,根据传入的 XML 元素 (<paramref name="xmlDef"/>) 进行处理。
|
||||
/// </summary>
|
||||
|
@ -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)
|
||||
|
56
Client/Assets/Scripts/Data/DefinePack.cs
Normal file
56
Client/Assets/Scripts/Data/DefinePack.cs
Normal file
@ -0,0 +1,56 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Xml;
|
||||
|
||||
namespace Data
|
||||
{
|
||||
public struct PackAbout
|
||||
{
|
||||
public string name;
|
||||
public string description;
|
||||
public string author;
|
||||
}
|
||||
public class DefinePack
|
||||
{
|
||||
public string packID;
|
||||
public PackAbout packAbout;
|
||||
public List<Define> defines;
|
||||
|
||||
public void LoadPack(string packPath)
|
||||
{
|
||||
var packDatas=Utils.FileHandler.LoadXmlFromPath(packPath);
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// 从 List<c>XmlDocument</c> 中查找指定根元素名称的文档。
|
||||
/// </summary>
|
||||
/// <param name="xmlDocuments">XML 文档列表。</param>
|
||||
/// <param name="rootName">目标根元素名称。</param>
|
||||
/// <returns>符合条件的 XML 文档列表。</returns>
|
||||
public static List<XmlDocument> FindDocumentsWithRootName(List<XmlDocument> xmlDocuments, string rootName)
|
||||
{
|
||||
var result = new List<XmlDocument>();
|
||||
|
||||
foreach (var xmlDoc in xmlDocuments)
|
||||
{
|
||||
try
|
||||
{
|
||||
// 获取根节点
|
||||
var root = xmlDoc.DocumentElement;
|
||||
|
||||
if (root != null && root.Name == rootName)
|
||||
{
|
||||
// 如果根节点名称匹配,则添加到结果列表
|
||||
result.Add(xmlDoc);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.Error.WriteLine($"处理 XML 文档时发生错误: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
namespace Data
|
||||
{
|
||||
public class DefineSourceData
|
||||
{
|
||||
public string className;
|
||||
public string defName;
|
||||
public string label;
|
||||
public string discription;
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -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
|
||||
/// </summary>
|
||||
/// <param name="paths">文件夹路径</param>
|
||||
/// <returns></returns>
|
||||
public static List<string> LoadXmlFilesFromPaths(string[] paths)
|
||||
public static List<string> GetXmlFilePathsFromPaths(string[] paths)
|
||||
{
|
||||
var xmlFilePaths = new List<string>();
|
||||
|
||||
@ -194,6 +196,56 @@ namespace Utils
|
||||
|
||||
return xmlFilePaths;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从指定路径加载所有 XML 文件并解析为 XmlDocument 对象。
|
||||
/// </summary>
|
||||
/// <param name="paths">文件夹路径数组。</param>
|
||||
/// <returns>包含所有解析后的 XmlDocument 对象的列表。</returns>
|
||||
public static List<XmlDocument> LoadXmlFromPaths(string[] paths)
|
||||
{
|
||||
var xmlDocuments = new List<XmlDocument>();
|
||||
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;
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取指定单个路径下的所有 XML 文件。
|
||||
/// </summary>
|
||||
/// <param name="path">文件夹路径。</param>
|
||||
/// <returns>包含所有 XML 文件路径的列表。</returns>
|
||||
public static List<string> GetXmlFilePathsFromPath(string path)
|
||||
{
|
||||
return GetXmlFilePathsFromPaths(new[] { path });
|
||||
}
|
||||
/// <summary>
|
||||
/// 从指定单个路径加载所有 XML 文件并解析为 XmlDocument 对象。
|
||||
/// </summary>
|
||||
/// <param name="path">文件夹路径。</param>
|
||||
/// <returns>包含所有解析后的 XmlDocument 对象的列表。</returns>
|
||||
public static List<XmlDocument> LoadXmlFromPath(string path)
|
||||
{
|
||||
return LoadXmlFromPaths(new[] { path });
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user