(client)feat:实现子弹定义以及生成,实现初始化动画,实现血条 (#43)
Co-authored-by: zzdxxz <2079238449@qq.com> Co-committed-by: zzdxxz <2079238449@qq.com>
This commit is contained in:
@ -1,7 +1,19 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Data
|
||||
{
|
||||
public enum Relation
|
||||
{
|
||||
Neutral,
|
||||
Hostile,
|
||||
Friendly,
|
||||
}
|
||||
|
||||
public class AffiliationDef : Define
|
||||
{
|
||||
|
||||
public Relation defaultRelation = Relation.Neutral;
|
||||
public List<string> hostileFactions = new();
|
||||
public List<string> neutralFactions = new();
|
||||
public List<string> friendlyFactions = new();
|
||||
}
|
||||
}
|
@ -7,7 +7,7 @@ namespace Data
|
||||
public class BehaviorTreeDef : Define
|
||||
{
|
||||
public BehaviorTreeDef[] childTree;
|
||||
public string className="Selector";
|
||||
public string className= "ThinkNode_Selector";
|
||||
public string value;
|
||||
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
namespace Data
|
||||
{
|
||||
public class BuildingDef:PawnDef
|
||||
public class BuildingDef : EntityDef
|
||||
{
|
||||
public bool IsBlocked = true;
|
||||
public float slowDown = 0f;
|
||||
}
|
||||
}
|
8
Client/Assets/Scripts/Data/BulletDef.cs
Normal file
8
Client/Assets/Scripts/Data/BulletDef.cs
Normal file
@ -0,0 +1,8 @@
|
||||
namespace Data
|
||||
{
|
||||
public class BulletDef:EntityDef
|
||||
{
|
||||
public string className;
|
||||
public string value;
|
||||
}
|
||||
}
|
3
Client/Assets/Scripts/Data/BulletDef.cs.meta
Normal file
3
Client/Assets/Scripts/Data/BulletDef.cs.meta
Normal file
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3f32fe058231409aaef631564bc51317
|
||||
timeCreated: 1755173999
|
@ -7,7 +7,7 @@ using UnityEngine;
|
||||
|
||||
namespace Data
|
||||
{
|
||||
public class CharacterDef : PawnDef
|
||||
public class CharacterDef : EntityDef
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
@ -279,10 +280,14 @@ namespace Data
|
||||
value = reference;
|
||||
}
|
||||
}
|
||||
else if(field.FieldType.IsArray)
|
||||
else if(field.FieldType.IsArray||typeof(IList).IsAssignableFrom(field.FieldType))
|
||||
{
|
||||
value = ProcessArrayField(field, element);
|
||||
}
|
||||
else if (field.FieldType.IsEnum)
|
||||
{
|
||||
value = Enum.Parse(field.FieldType, element.Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
value = Convert.ChangeType(element.Value, field.FieldType);
|
||||
@ -291,13 +296,14 @@ namespace Data
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.LogWarning($"Error setting field {field.Name}: {ex.Message}");
|
||||
Debug.LogWarning($"Error setting field ,field name:{field.Name}; value: {element.Value}; error: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static object ProcessArrayField(FieldInfo field, XElement element)
|
||||
{
|
||||
Type elementType = field.FieldType.GetElementType();
|
||||
var elementType = field.FieldType.GetElementType();
|
||||
if (elementType == null) return null;
|
||||
|
||||
var arrayElements = new List<object>();
|
||||
@ -305,7 +311,7 @@ namespace Data
|
||||
{
|
||||
if (elementType.IsSubclassOf(typeof(Define)))
|
||||
{
|
||||
Define nestedDefine = (Define)Activator.CreateInstance(elementType);
|
||||
var nestedDefine = (Define)Activator.CreateInstance(elementType);
|
||||
DefaultInitDefine(nestedDefine, liElement, elementType);
|
||||
arrayElements.Add(nestedDefine);
|
||||
}
|
||||
@ -326,8 +332,8 @@ namespace Data
|
||||
}
|
||||
|
||||
// 构建结果数组
|
||||
Array resultArray = Array.CreateInstance(elementType, arrayElements.Count);
|
||||
for (int i = 0; i < arrayElements.Count; i++)
|
||||
var resultArray = Array.CreateInstance(elementType, arrayElements.Count);
|
||||
for (var i = 0; i < arrayElements.Count; i++)
|
||||
{
|
||||
resultArray.SetValue(arrayElements[i], i);
|
||||
}
|
||||
|
@ -26,37 +26,63 @@ namespace Data
|
||||
public DrawNodeDef drawingOrder_left;
|
||||
public DrawNodeDef drawingOrder_right;
|
||||
public string texturePath;
|
||||
public int pixelsPerUnit = 16;
|
||||
public float pixelsPerUnit = 16;
|
||||
|
||||
public DrawNodeDef GetDrawingOrder(Orientation orientation)
|
||||
public DrawNodeDef GetDrawingOrder(Orientation orientation, out Orientation sourceOrientation)
|
||||
{
|
||||
// 定义一个临时变量用于存储结果
|
||||
DrawNodeDef result = null;
|
||||
|
||||
// 初始化 sourceOrientation 为默认值
|
||||
sourceOrientation = Orientation.Down;
|
||||
|
||||
// 根据传入的 Orientation 获取对应的 DrawingOrderDef
|
||||
switch (orientation)
|
||||
{
|
||||
case Orientation.Down:
|
||||
result = drawingOrder_down;
|
||||
sourceOrientation = Orientation.Down;
|
||||
break;
|
||||
case Orientation.Up:
|
||||
result = drawingOrder_up;
|
||||
sourceOrientation = Orientation.Up;
|
||||
break;
|
||||
case Orientation.Left:
|
||||
result = drawingOrder_left;
|
||||
sourceOrientation = Orientation.Left;
|
||||
break;
|
||||
case Orientation.Right:
|
||||
result = drawingOrder_right;
|
||||
sourceOrientation = Orientation.Right;
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentException("Invalid orientation value.");
|
||||
}
|
||||
|
||||
// 如果当前方向的结果为空,则尝试用 drawingOrder_down 填充
|
||||
if (result == null) result = drawingOrder_down;
|
||||
if (result == null)
|
||||
{
|
||||
result = drawingOrder_down;
|
||||
sourceOrientation = Orientation.Down; // 更新 sourceOrientation
|
||||
}
|
||||
|
||||
// 如果 drawingOrder_down 仍然为空,则尝试用其他非空方向填充
|
||||
if (result == null) result = drawingOrder_up ?? drawingOrder_left ?? drawingOrder_right;
|
||||
if (result != null) return result;
|
||||
if (drawingOrder_up != null)
|
||||
{
|
||||
result = drawingOrder_up;
|
||||
sourceOrientation = Orientation.Up; // 更新 sourceOrientation
|
||||
}
|
||||
else if (drawingOrder_left != null)
|
||||
{
|
||||
result = drawingOrder_left;
|
||||
sourceOrientation = Orientation.Left; // 更新 sourceOrientation
|
||||
}
|
||||
else if (drawingOrder_right != null)
|
||||
{
|
||||
result = drawingOrder_right;
|
||||
sourceOrientation = Orientation.Right; // 更新 sourceOrientation
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@ -5,13 +5,13 @@ using System.Xml.Linq;
|
||||
|
||||
namespace Data
|
||||
{
|
||||
public class PawnDef : Define
|
||||
public class EntityDef : Define
|
||||
{
|
||||
public AttributesDef attributes;
|
||||
public DrawingOrderDef drawingOrder;
|
||||
|
||||
public BehaviorTreeDef behaviorTree;
|
||||
public string affiliation;
|
||||
public AffiliationDef affiliation;
|
||||
|
||||
|
||||
}
|
@ -1,13 +1,23 @@
|
||||
namespace Data
|
||||
{
|
||||
public enum ItemRarity
|
||||
{
|
||||
Common,
|
||||
Uncommon,
|
||||
Rare,
|
||||
Epic,
|
||||
Legendary
|
||||
}
|
||||
public class ItemDef:Define
|
||||
{
|
||||
public ImageDef texture;
|
||||
public AttributesDef attributes;
|
||||
public ItemRarity rarity = ItemRarity.Common;
|
||||
public int maxStack = 1; // 最大堆叠数量,默认为1
|
||||
public bool ssEquippable = false; // 是否可装备
|
||||
}
|
||||
|
||||
public class WeaponDef : ItemDef
|
||||
{
|
||||
|
||||
public AttributesDef attributes;
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Xml.Linq;
|
||||
using UnityEngine.Tilemaps;
|
||||
|
||||
namespace Data
|
||||
{
|
||||
@ -7,6 +8,7 @@ namespace Data
|
||||
{
|
||||
public ImageDef texture;
|
||||
public string name = "";
|
||||
public Tile.ColliderType collider = Tile.ColliderType.None;
|
||||
|
||||
public override bool Init(XElement xmlDef)
|
||||
{
|
||||
|
@ -1,6 +1,6 @@
|
||||
namespace Data
|
||||
{
|
||||
public class MonsterDef:PawnDef
|
||||
public class MonsterDef:EntityDef
|
||||
{
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user