From b3b01ff03701a89217e13ec32b386ecda96793ed Mon Sep 17 00:00:00 2001 From: m0_75251201 Date: Mon, 14 Jul 2025 14:33:55 +0800 Subject: [PATCH 1/4] =?UTF-8?q?(client)=20chore:=E6=94=B9=E8=BF=9BDefine?= =?UTF-8?q?=E7=9A=84=E6=89=93=E5=8D=B0=E5=87=BD=E6=95=B0=EF=BC=8C=E4=BD=BF?= =?UTF-8?q?=E5=85=B6=E8=83=BD=E6=89=93=E5=8D=B0=E5=AD=90=E7=B1=BB=E5=8F=8A?= =?UTF-8?q?=E5=85=B6=E9=80=92=E5=BD=92Define=E5=86=85=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Client/Assets/Scripts/Data/Define.cs | 80 ++++++++++++++++++++++++---- 1 file changed, 71 insertions(+), 9 deletions(-) diff --git a/Client/Assets/Scripts/Data/Define.cs b/Client/Assets/Scripts/Data/Define.cs index 97d24d9..3f85e18 100644 --- a/Client/Assets/Scripts/Data/Define.cs +++ b/Client/Assets/Scripts/Data/Define.cs @@ -1,4 +1,9 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; using System.Text; using System.Xml.Linq; @@ -38,21 +43,78 @@ namespace Data 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}"); + + // 使用反射获取当前类的所有字段和属性 + var fieldsAndProperties = GetAllFieldsAndProperties(this); + + foreach (var member in fieldsAndProperties) + { + var name = member.Name; + var value = GetValue(member, this); + + if (value is IList list && list.Count > 0) // 如果是列表类型 + { + sb.AppendLine($"{name}:"); + foreach (var item in list) + { + sb.AppendLine($" - {FormatValue(item)}"); + } + } + else if (value is Define defineObject) // 如果是继承自 Define 的子类 + { + if (!string.IsNullOrEmpty(defineObject.defName)) + { + sb.AppendLine($"{name}: {defineObject.defName}"); + } + else + { + sb.AppendLine($"{name}:"); + sb.AppendLine(Indent(defineObject.ToString(), " ")); + } + } + else + { + sb.AppendLine($"{name}: {FormatValue(value)}"); + } + } return sb.ToString(); } + + private static IEnumerable GetAllFieldsAndProperties(object obj) + { + var type = obj.GetType(); + return type.GetFields(BindingFlags.Public | BindingFlags.Instance) + .Cast() + .Concat(type.GetProperties(BindingFlags.Public | BindingFlags.Instance).Cast()); + } + + private static object GetValue(MemberInfo member, object obj) + { + switch (member) + { + case FieldInfo field: + return field.GetValue(obj); + case PropertyInfo property: + return property.GetValue(obj); + default: + throw new ArgumentException("Unsupported member type."); + } + } + + private static string FormatValue(object value) + { + return value?.ToString() ?? "null"; + } + + private static string Indent(string text, string prefix) + { + return string.Join(Environment.NewLine, text.Split('\n').Select(line => prefix + line)); + } } } \ No newline at end of file -- 2.43.0 From 5bf17958ff25309842fbd56d81766ed07325f5df Mon Sep 17 00:00:00 2001 From: m0_75251201 Date: Mon, 14 Jul 2025 15:00:56 +0800 Subject: [PATCH 2/4] =?UTF-8?q?(client)=20feat:=E6=B7=BB=E5=8A=A0=E5=B1=9E?= =?UTF-8?q?=E6=80=A7=E7=9B=B8=E5=85=B3=E5=AE=9A=E4=B9=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Assets/Scripts/Data/AttributesDefine.cs | 37 +++++++++++++++++++ Client/Assets/Scripts/Data/CharacterDefine.cs | 3 ++ 2 files changed, 40 insertions(+) create mode 100644 Client/Assets/Scripts/Data/AttributesDefine.cs diff --git a/Client/Assets/Scripts/Data/AttributesDefine.cs b/Client/Assets/Scripts/Data/AttributesDefine.cs new file mode 100644 index 0000000..0a678b2 --- /dev/null +++ b/Client/Assets/Scripts/Data/AttributesDefine.cs @@ -0,0 +1,37 @@ + + +namespace Data +{ + public class CharacterAttributesDef : Define + { + public int health = 10; + public float moveSpeed = 1; + } + public class WeaponAttributesDef : Define + { + public float attack = 1; + public float defense = 0; + public float attackSpeed = 2; + public float attackRange = 3; + public int attackTargetCount = 1; + } + public class MonsterAttributesDef : Define + { + public int health = 10; + public float moveSpeed = 1; + public float attack = 1; + public float defense = 0; + public float attackSpeed = 2; + public float attackRange = 3; + public int attackTargetCount = 1; + } + public class BuildingAttributesDef : Define + { + public int health = 10; + public float attack = 1; + public float defense = 0; + public float attackSpeed = 2; + public float attackRange = 3; + public int attackTargetCount = 1; + } +} \ No newline at end of file diff --git a/Client/Assets/Scripts/Data/CharacterDefine.cs b/Client/Assets/Scripts/Data/CharacterDefine.cs index 82ecd12..167902b 100644 --- a/Client/Assets/Scripts/Data/CharacterDefine.cs +++ b/Client/Assets/Scripts/Data/CharacterDefine.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.Text.RegularExpressions; using System.Xml.Linq; +using UnityEditor.ShaderGraph.Internal; using UnityEngine; namespace Data @@ -131,4 +132,6 @@ namespace Data } } } + + } \ No newline at end of file -- 2.43.0 From b4bdf5f4a0e8ba760558bb5083e479825676651d Mon Sep 17 00:00:00 2001 From: m0_75251201 Date: Mon, 14 Jul 2025 15:05:29 +0800 Subject: [PATCH 3/4] =?UTF-8?q?(client)=20chore:=E5=B1=9E=E6=80=A7?= =?UTF-8?q?=E5=8F=98=E9=87=8F=E7=B1=BB=E5=9E=8B=E4=B8=8E=E7=AD=96=E5=88=92?= =?UTF-8?q?=E4=BA=A4=E6=B5=81=E8=B0=83=E6=95=B4=E4=B8=BA=E6=95=B4=E6=95=B0?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Assets/Scripts/Data/AttributesDefine.cs | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/Client/Assets/Scripts/Data/AttributesDefine.cs b/Client/Assets/Scripts/Data/AttributesDefine.cs index 0a678b2..e85fcf2 100644 --- a/Client/Assets/Scripts/Data/AttributesDefine.cs +++ b/Client/Assets/Scripts/Data/AttributesDefine.cs @@ -5,33 +5,33 @@ namespace Data public class CharacterAttributesDef : Define { public int health = 10; - public float moveSpeed = 1; + public int moveSpeed = 1; } public class WeaponAttributesDef : Define { - public float attack = 1; - public float defense = 0; - public float attackSpeed = 2; - public float attackRange = 3; + public int attack = 1; + public int defense = 0; + public int attackSpeed = 2; + public int attackRange = 3; public int attackTargetCount = 1; } public class MonsterAttributesDef : Define { public int health = 10; - public float moveSpeed = 1; - public float attack = 1; - public float defense = 0; - public float attackSpeed = 2; - public float attackRange = 3; + public int moveSpeed = 1; + public int attack = 1; + public int defense = 0; + public int attackSpeed = 2; + public int attackRange = 3; public int attackTargetCount = 1; } public class BuildingAttributesDef : Define { public int health = 10; - public float attack = 1; - public float defense = 0; - public float attackSpeed = 2; - public float attackRange = 3; + public int attack = 1; + public int defense = 0; + public int attackSpeed = 2; + public int attackRange = 3; public int attackTargetCount = 1; } } \ No newline at end of file -- 2.43.0 From 1e60c852d0057509e7daa25d4f4668c489ab8097 Mon Sep 17 00:00:00 2001 From: m0_75251201 Date: Mon, 14 Jul 2025 17:30:50 +0800 Subject: [PATCH 4/4] =?UTF-8?q?(client)=20chore:=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E6=B8=B2=E6=9F=93=E6=A0=91=E5=AE=9A=E4=B9=89=E5=8A=A0=E8=BD=BD?= =?UTF-8?q?=EF=BC=8C=E5=85=81=E8=AE=B8=E9=BB=98=E8=AE=A4=E5=8A=A0=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Scripts/Data/AttributesDefine.cs.meta | 2 +- Client/Assets/Scripts/Data/CharacterDefine.cs | 20 ++++++++++++------- Client/Assets/Scripts/Data/DefinePack.cs | 4 ++-- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/Client/Assets/Scripts/Data/AttributesDefine.cs.meta b/Client/Assets/Scripts/Data/AttributesDefine.cs.meta index 76c19b5..33abf30 100644 --- a/Client/Assets/Scripts/Data/AttributesDefine.cs.meta +++ b/Client/Assets/Scripts/Data/AttributesDefine.cs.meta @@ -1,2 +1,2 @@ fileFormatVersion: 2 -guid: 9ff25140406bbd94499d6fb418c4add5 \ No newline at end of file +guid: 449907b94fa9f8742a43a61b7fc2e5dc \ No newline at end of file diff --git a/Client/Assets/Scripts/Data/CharacterDefine.cs b/Client/Assets/Scripts/Data/CharacterDefine.cs index 167902b..3c9abf0 100644 --- a/Client/Assets/Scripts/Data/CharacterDefine.cs +++ b/Client/Assets/Scripts/Data/CharacterDefine.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Text.RegularExpressions; using System.Xml.Linq; using UnityEditor.ShaderGraph.Internal; @@ -23,6 +24,7 @@ namespace Data public class CharacterDef : Define { + public CharacterAttributesDef attributes; public string texturePath = null; public DrawingOrderDef drawingOrder_down, @@ -71,14 +73,18 @@ namespace Data public override bool Init(XElement xmlDef) { base.Init(xmlDef); - foreach (var node in xmlDef.Elements("DrawNodeDef")) - { - var drawNode = new DrawNodeDef(); - drawNode.Init(node); - drawNodes.Add(drawNode); - } - return true; + var nodes = xmlDef.Elements("DrawNodeDef"); + if (nodes.Count() == 0) + return false; + foreach (var node in nodes) + { + var drawNode = new DrawNodeDef(); + drawNode.Init(node); + drawNodes.Add(drawNode); + } + + return true;; } } diff --git a/Client/Assets/Scripts/Data/DefinePack.cs b/Client/Assets/Scripts/Data/DefinePack.cs index 25e39cb..550229e 100644 --- a/Client/Assets/Scripts/Data/DefinePack.cs +++ b/Client/Assets/Scripts/Data/DefinePack.cs @@ -153,7 +153,7 @@ namespace Data } } - private Define LoadDefineClass(XElement defineDoc,string className) + private static Define LoadDefineClass(XElement defineDoc,string className) { var assembly = Assembly.GetExecutingAssembly(); @@ -211,7 +211,7 @@ namespace Data return define; } - public void DefaultInitDefine(Define define,XElement defineDoc,Type defineType) + public static void DefaultInitDefine(Define define,XElement defineDoc,Type defineType) { var fields = defineType.GetFields(BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic); -- 2.43.0