(client) feat:图像加载失败时加载默认图像,生成实体身体结构
This commit is contained in:
@ -44,9 +44,61 @@ namespace Entity
|
||||
attributes = pawnDef.attributes.Clone();
|
||||
aiTree = ConvertToAIBase(pawnDef.behaviorTree);
|
||||
affiliation=pawnDef.affiliation;
|
||||
//定义的tag有限,不用这个了
|
||||
// if(!string.IsNullOrEmpty(affiliation))
|
||||
// gameObject.CompareTag(affiliation);
|
||||
InitBody(pawnDef.drawingOrder);
|
||||
}
|
||||
|
||||
public virtual void InitBody(DrawingOrderDef drawingOrder)
|
||||
{
|
||||
// 定义方向枚举和对应的 GetDrawingOrder 调用
|
||||
Orientation[] orientations = { Orientation.Down, Orientation.Up, Orientation.Left, Orientation.Right };
|
||||
|
||||
foreach (var orientation in orientations)
|
||||
{
|
||||
// 获取当前方向的绘图节点
|
||||
var drawNode = drawingOrder.GetDrawingOrder(orientation);
|
||||
|
||||
if (drawNode == null) continue;
|
||||
var directionRoot = new GameObject(orientation.ToString());
|
||||
directionRoot.transform.SetParent(body.transform, false);
|
||||
|
||||
InitBodyPart(drawNode, directionRoot);
|
||||
}
|
||||
}
|
||||
|
||||
// 递归初始化单个绘图节点及其子节点
|
||||
public virtual void InitBodyPart(DrawNodeDef drawNode, GameObject parent)
|
||||
{
|
||||
if(drawNode==null) return;
|
||||
// 创建新的 GameObject 表示当前节点
|
||||
var nodeObject = new GameObject(drawNode.nodeName);
|
||||
|
||||
// 设置节点的父对象
|
||||
nodeObject.transform.SetParent(parent.transform, false);
|
||||
|
||||
// 设置节点的位置
|
||||
nodeObject.transform.localPosition = new Vector3(drawNode.position.x, drawNode.position.y, 0);
|
||||
|
||||
// 根据节点类型设置其他特性(例如动画或图片)
|
||||
switch (drawNode.drawNodeType)
|
||||
{
|
||||
case DrawNodeType.Image:
|
||||
var spriteRenderer = nodeObject.AddComponent<SpriteRenderer>();
|
||||
spriteRenderer.color = Color.white; // 默认颜色
|
||||
break;
|
||||
|
||||
case DrawNodeType.Animation:
|
||||
var animator = nodeObject.AddComponent<Animator>();
|
||||
animator.runtimeAnimatorController = null; // 需要手动设置动画控制器
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
|
||||
// 递归初始化子节点
|
||||
foreach (var child in drawNode.children)
|
||||
{
|
||||
InitBodyPart(child, nodeObject);
|
||||
}
|
||||
}
|
||||
public void Tick()
|
||||
{
|
||||
|
Reference in New Issue
Block a user