(client) chore
This commit is contained in:
@ -11,18 +11,5 @@ namespace Data
|
||||
public int attackSpeed = 2;
|
||||
public int attackRange = 3;
|
||||
public int attackTargetCount = 1;
|
||||
public AttributesDef Clone()
|
||||
{
|
||||
return new AttributesDef
|
||||
{
|
||||
health = this.health,
|
||||
moveSpeed = this.moveSpeed,
|
||||
attack = this.attack,
|
||||
defense = this.defense,
|
||||
attackSpeed = this.attackSpeed,
|
||||
attackRange = this.attackRange,
|
||||
attackTargetCount = this.attackTargetCount
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
@ -228,7 +228,7 @@ namespace Data
|
||||
public static Define LoadDefineClass(XElement defineDoc, string className)
|
||||
{
|
||||
// 优化点1和2:反射缓存和改进的类型查找
|
||||
if (!_typeCache.TryGetValue(className, out Type type))
|
||||
if (!_typeCache.TryGetValue(className, out var type))
|
||||
{
|
||||
// 首先尝试使用 CoreNamespace
|
||||
var fullClassName = CoreNamespace + className;
|
||||
@ -249,7 +249,7 @@ namespace Data
|
||||
}
|
||||
|
||||
// 优化点1:构造函数缓存
|
||||
if (!_constructorCache.TryGetValue(type, out ConstructorInfo constructor))
|
||||
if (!_constructorCache.TryGetValue(type, out var constructor))
|
||||
{
|
||||
constructor = type.GetConstructor(Type.EmptyTypes);
|
||||
if (constructor == null)
|
||||
@ -305,7 +305,7 @@ namespace Data
|
||||
public static void DefaultInitDefine(Define define, XElement defineDoc, Type defineType)
|
||||
{
|
||||
// 优化点1:FieldInfo 缓存
|
||||
if (!_fieldCache.TryGetValue(defineType, out FieldInfo[] fields))
|
||||
if (!_fieldCache.TryGetValue(defineType, out var fields))
|
||||
{
|
||||
fields = defineType.GetFields(BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic);
|
||||
_fieldCache[defineType] = fields;
|
||||
@ -320,7 +320,7 @@ namespace Data
|
||||
try
|
||||
{
|
||||
// 优化点4:重构 ProcessArrayField 并引入通用转换辅助方法
|
||||
object value = ConvertXElementValueToType(element, field.FieldType);
|
||||
var value = ConvertXElementValueToType(element, field.FieldType);
|
||||
field.SetValue(define, value);
|
||||
}
|
||||
catch (Exception ex)
|
||||
@ -368,7 +368,7 @@ namespace Data
|
||||
private static object ProcessArrayField(Type fieldType, XElement element)
|
||||
{
|
||||
// 获取集合的元素类型
|
||||
Type elementType = fieldType.IsArray
|
||||
var elementType = fieldType.IsArray
|
||||
? fieldType.GetElementType()
|
||||
: fieldType.GetGenericArguments().FirstOrDefault(); // 使用 FirstOrDefault 以确保安全
|
||||
|
||||
|
@ -16,13 +16,4 @@ namespace Data
|
||||
public bool ssEquippable = false; // 是否可装备
|
||||
}
|
||||
|
||||
public class WeaponDef : ItemDef
|
||||
{
|
||||
public AttributesDef attributes;
|
||||
public WeaponDef() // 构造函数,用于设置武器的默认属性
|
||||
{
|
||||
maxStack = 1; // 武器默认最大堆叠为1
|
||||
ssEquippable = true; // 武器默认可装备
|
||||
}
|
||||
}
|
||||
}
|
18
Client/Assets/Scripts/Data/WeaponDef.cs
Normal file
18
Client/Assets/Scripts/Data/WeaponDef.cs
Normal file
@ -0,0 +1,18 @@
|
||||
namespace Data
|
||||
{
|
||||
public enum WeaponType
|
||||
{
|
||||
Melee, // 近战武器
|
||||
Ranged // 远程武器
|
||||
}
|
||||
public class WeaponDef : ItemDef
|
||||
{
|
||||
public WeaponType type = WeaponType.Melee;
|
||||
public AttributesDef attributes;
|
||||
public WeaponDef() // 构造函数,用于设置武器的默认属性
|
||||
{
|
||||
maxStack = 1; // 武器默认最大堆叠为1
|
||||
ssEquippable = true; // 武器默认可装备
|
||||
}
|
||||
}
|
||||
}
|
3
Client/Assets/Scripts/Data/WeaponDef.cs.meta
Normal file
3
Client/Assets/Scripts/Data/WeaponDef.cs.meta
Normal file
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3ed90cba91ce41e1ae443cf44a76c932
|
||||
timeCreated: 1756193931
|
Reference in New Issue
Block a user