(client) feat:实现实体动态创建,实体右键菜单
Co-authored-by: m0_75251201 <m0_75251201@noreply.gitcode.com> Reviewed-on: Roguelite-Game-Developing-Team/Gen_Hack-and-Slash-Roguelite#41
This commit is contained in:
@ -8,49 +8,12 @@ namespace Data
|
||||
public class PawnDef : Define
|
||||
{
|
||||
public AttributesDef attributes;
|
||||
public string aiController;
|
||||
public string texturePath = null;
|
||||
public DrawingOrderDef
|
||||
drawingOrder_down,
|
||||
drawingOrder_up,
|
||||
drawingOrder_left,
|
||||
drawingOrder_right;
|
||||
public DrawingOrderDef drawingOrder;
|
||||
|
||||
public BehaviorTreeDef behaviorTree;
|
||||
public string affiliation;
|
||||
|
||||
|
||||
public DrawingOrderDef GetDrawingOrder(Orientation orientation)
|
||||
{
|
||||
// 定义一个临时变量用于存储结果
|
||||
DrawingOrderDef result = null;
|
||||
|
||||
// 根据传入的 Orientation 获取对应的 DrawingOrderDef
|
||||
switch (orientation)
|
||||
{
|
||||
case Orientation.Down:
|
||||
result = drawingOrder_down;
|
||||
break;
|
||||
case Orientation.Up:
|
||||
result = drawingOrder_up;
|
||||
break;
|
||||
case Orientation.Left:
|
||||
result = drawingOrder_left;
|
||||
break;
|
||||
case Orientation.Right:
|
||||
result = drawingOrder_right;
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentException("Invalid orientation value.");
|
||||
}
|
||||
|
||||
// 如果当前方向的结果为空,则尝试用 drawingOrder_down 填充
|
||||
if (result == null) result = drawingOrder_down;
|
||||
|
||||
// 如果 drawingOrder_down 仍然为空,则尝试用其他非空方向填充
|
||||
if (result == null) result = drawingOrder_up ?? drawingOrder_left ?? drawingOrder_right;
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
public class MonsterDef:PawnDef
|
||||
{
|
||||
@ -60,29 +23,38 @@ namespace Data
|
||||
public class BehaviorTreeDef : Define
|
||||
{
|
||||
public BehaviorTreeDef[] childTree;
|
||||
public string className;
|
||||
public string className="Selector";
|
||||
public string condition;
|
||||
|
||||
|
||||
public override bool Init(XElement xmlDef)
|
||||
{
|
||||
base.Init(xmlDef);
|
||||
|
||||
// 从当前节点获取className和condition属性
|
||||
className = xmlDef.Attribute("className")?.Value ?? className;
|
||||
condition = xmlDef.Attribute("condition")?.Value;
|
||||
|
||||
var nodes = xmlDef.Elements("Node");
|
||||
var xElements = nodes as XElement[] ?? nodes.ToArray();
|
||||
if (!xElements.Any())
|
||||
return false;
|
||||
if (!nodes.Any())
|
||||
return true; // 没有子节点也是有效的
|
||||
|
||||
className = xmlDef.Attribute("className")?.Value;
|
||||
List<BehaviorTreeDef> children = new();
|
||||
foreach (var node in xElements)
|
||||
foreach (var node in nodes)
|
||||
{
|
||||
var childNode = new BehaviorTreeDef();
|
||||
childNode.Init(node);
|
||||
if (!childNode.Init(node))
|
||||
return false;
|
||||
children.Add(childNode);
|
||||
}
|
||||
|
||||
childTree = children.ToArray();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public class AffiliationDef : Define
|
||||
{
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user