A Meaningless PR #10
@ -1,13 +1,14 @@
|
||||
|
||||
using System.Text;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace Data
|
||||
{
|
||||
public class Define
|
||||
public abstract class Define
|
||||
{
|
||||
public string defName;
|
||||
public string label;
|
||||
public string discription;
|
||||
public string description;
|
||||
public string packID;
|
||||
/// <summary>
|
||||
/// 初始化方法,根据传入的 XML 元素 (<paramref name="xmlDef"/>) 进行处理。
|
||||
@ -34,9 +35,24 @@ namespace Data
|
||||
{
|
||||
defName = xmlDef.Element("defName")?.Value;
|
||||
label = xmlDef.Element("label")?.Value;
|
||||
discription = xmlDef.Element("discription")?.Value;
|
||||
description = xmlDef.Element("description")?.Value;
|
||||
return false;
|
||||
}
|
||||
public override string ToString()
|
||||
{
|
||||
// 定义对齐格式(左对齐,固定宽度)
|
||||
const int labelWidth = -15; // 标签左对齐,占15字符
|
||||
const int valueWidth = -30; // 值左对齐,占30字符
|
||||
|
||||
var sb = new StringBuilder();
|
||||
|
||||
sb.AppendLine($"{"DefName:",labelWidth}{defName,valueWidth}");
|
||||
sb.AppendLine($"{"Label:",labelWidth}{label,valueWidth}");
|
||||
sb.AppendLine($"{"Description:",labelWidth}{description,valueWidth}");
|
||||
sb.AppendLine($"{"PackID:",labelWidth}{packID,valueWidth}");
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -2,6 +2,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Xml.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
@ -9,7 +10,7 @@ namespace Data
|
||||
{
|
||||
|
||||
|
||||
public struct PackAbout
|
||||
public class PackAbout
|
||||
{
|
||||
public string name;
|
||||
public string description;
|
||||
@ -74,6 +75,30 @@ namespace Data
|
||||
.Select(e => e.Value.Trim())
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
// 定义字段标签和值的对齐格式(如左对齐,固定宽度)
|
||||
const int labelWidth = -12; // 负数为左对齐
|
||||
const int valueWidth = -30; // 负数为左对齐
|
||||
|
||||
// 使用StringBuilder高效拼接
|
||||
var sb = new StringBuilder();
|
||||
|
||||
// 基础字段(单行)
|
||||
sb.AppendLine($"{"Name:",labelWidth}{name,valueWidth}");
|
||||
sb.AppendLine($"{"Description:",labelWidth}{description,valueWidth}");
|
||||
sb.AppendLine($"{"Author:",labelWidth}{author,valueWidth}");
|
||||
sb.AppendLine($"{"Version:",labelWidth}{version,valueWidth}");
|
||||
sb.AppendLine($"{"PackID:",labelWidth}{packID,valueWidth}");
|
||||
|
||||
// 数组字段(多行,每项缩进)
|
||||
sb.AppendLine($"{"Necessary:",labelWidth}{string.Join(", ", necessary ?? Array.Empty<string>()),valueWidth}");
|
||||
sb.AppendLine($"{"After:",labelWidth}{string.Join(", ", after ?? Array.Empty<string>()),valueWidth}");
|
||||
sb.AppendLine($"{"Before:",labelWidth}{string.Join(", ", before ?? Array.Empty<string>()),valueWidth}");
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
public class DefinePack
|
||||
@ -234,5 +259,44 @@ namespace Data
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
// 对齐格式(左对齐,固定宽度)
|
||||
const int labelWidth = -15;
|
||||
const int valueWidth = -30;
|
||||
|
||||
var sb = new StringBuilder();
|
||||
|
||||
// 基础字段
|
||||
sb.AppendLine($"{"PackID:",labelWidth}{packID,valueWidth}");
|
||||
sb.AppendLine();
|
||||
|
||||
// PackAbout 对象
|
||||
sb.AppendLine("=== PackAbout ===");
|
||||
sb.AppendLine(packAbout?.ToString() ?? "N/A"); // 调用 PackAbout 的 ToString()
|
||||
sb.AppendLine();
|
||||
|
||||
// 字典字段(defines)
|
||||
sb.AppendLine("=== Defines ===");
|
||||
if (defines != null && defines.Count > 0)
|
||||
{
|
||||
foreach (var kvp in defines)
|
||||
{
|
||||
sb.AppendLine($"【{kvp.Key}】"); // 输出字典的键(类别名)
|
||||
foreach (var define in kvp.Value) // 遍历该类别下的所有 Define 对象
|
||||
{
|
||||
sb.AppendLine(define.ToString()); // 调用 Define 的 ToString()
|
||||
}
|
||||
sb.AppendLine(); // 每个类别后空一行
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
sb.AppendLine("No defines found.");
|
||||
}
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user