(client) feat:实现身体贴图加载

This commit is contained in:
m0_75251201
2025-07-24 23:19:48 +08:00
parent 8471f00b64
commit c4ddc0d693
20 changed files with 613 additions and 258 deletions

View File

@ -16,7 +16,7 @@ namespace Entity
public AIBase aiTree;
public JobBase currentJob;
public AttributesDef attributes;
public AttributesDef attributes=new();
public Vector3 direction;
public GameObject body;
public string affiliation;
@ -42,15 +42,18 @@ namespace Entity
private bool _isPlayerControlled = false;
private bool _warning = false;
private Dictionary<Orientation,List<ITick>> bodyNode=new();
private Orientation currentOrientation=Orientation.Down;
private Dictionary<Orientation,List<ITick>> bodyAnimationNode=new();
private Dictionary<Orientation, GameObject> bodyNodes = new();
private Orientation currentOrientation = Orientation.Down;
public virtual void Init(PawnDef pawnDef)
{
attributes = pawnDef.attributes.Clone();
aiTree = ConvertToAIBase(pawnDef.behaviorTree);
affiliation=pawnDef.affiliation;
affiliation = pawnDef.affiliation;
InitBody(pawnDef.drawingOrder);
}
public virtual void InitBody(DrawingOrderDef drawingOrder)
@ -60,8 +63,8 @@ namespace Entity
foreach (var orientation in orientations)
{
currentOrientation=orientation;
bodyNode[orientation]=new();
currentOrientation = orientation;
bodyAnimationNode[orientation] = new();
// 获取当前方向的绘图节点
var drawNode = drawingOrder.GetDrawingOrder(orientation);
@ -70,8 +73,15 @@ namespace Entity
directionRoot.transform.SetParent(body.transform, false);
InitBodyPart(drawNode, directionRoot);
bodyNodes[orientation] = directionRoot;
}
currentOrientation=Orientation.Down;
currentOrientation = Orientation.Down;
foreach (var bodyNode in bodyNodes)
{
bodyNode.Value.SetActive(false);
}
SetOrientation(Orientation.Down);
}
// 递归初始化单个绘图节点及其子节点
@ -83,19 +93,19 @@ namespace Entity
switch (drawNode.drawNodeType)
{
case DrawNodeType.Image:
nodeObject = Instantiate(imagePrefab.gameObject);
nodeObject = Instantiate(imagePrefab.gameObject,parent.transform);
break;
case DrawNodeType.Animation:
nodeObject = Instantiate(animatorPrefab.gameObject);
nodeObject = Instantiate(animatorPrefab.gameObject,parent.transform);
ITick tick = nodeObject.GetComponent<SpriteAnimator>();
if (tick != null)
bodyNode[currentOrientation].Add(tick);
bodyAnimationNode[currentOrientation].Add(tick);
break;
default:
throw new ArgumentOutOfRangeException();
}
nodeObject.transform.localPosition = drawNode.position;
// 递归初始化子节点
foreach (var child in drawNode.children)
{
@ -113,9 +123,9 @@ namespace Entity
AutoBehave();
}
foreach (var bodyPart in bodyNode.Values)
if (bodyAnimationNode.TryGetValue(currentOrientation, out var ticks))
{
foreach (var tick in bodyPart)
foreach (var tick in ticks)
{
tick.Tick();
}
@ -126,12 +136,19 @@ namespace Entity
{
}
public virtual void SetOrientation(Orientation orientation)
{
bodyNodes[currentOrientation]?.SetActive(false);
currentOrientation = orientation;
bodyNodes[orientation]?.SetActive(true);
}
/// <summary>
/// 往对应朝向移动moveSpeed*deltaTime的距离
/// </summary>
public virtual void TryMove()
{
transform.position+=direction * (attributes.moveSpeed * Time.deltaTime * (IsChase ? 1 : 0.5f));
transform.position += direction * (attributes.moveSpeed * Time.deltaTime * (IsChase ? 1 : 0.5f));
}
public virtual void OnHit(Entity from)
@ -156,6 +173,8 @@ namespace Entity
private void AutoBehave()
{
if(aiTree == null)
return;
if (currentJob == null || !currentJob.Running)
{
currentJob = aiTree.GetJob(this);