(client) feat:实现健康状态定义,实现事件定义
This commit is contained in:
@ -25,6 +25,7 @@ namespace Entity
|
||||
var maxIndex = Inventory != null && Inventory.Capacity > 0 ? Inventory.Capacity - 1 : 0;
|
||||
var clampedValue = Mathf.Clamp(value, 0, maxIndex);
|
||||
_currentSelected = clampedValue;
|
||||
InitWeaponAnimator();
|
||||
}
|
||||
}
|
||||
|
||||
@ -68,29 +69,6 @@ namespace Entity
|
||||
return remainingQuantity;
|
||||
}
|
||||
|
||||
// public override void TryAttack()
|
||||
// {
|
||||
// if (IsAttacking)
|
||||
// return;
|
||||
// if (!DefineManager.Instance.defines.TryGetValue(nameof(BulletDef), out var def))
|
||||
// return;
|
||||
// // 修正:First() 可能会在一个空的 Values 集合上抛出异常。
|
||||
// // 更好的做法是使用 TryGetValue 或 FirstOrDefault 并检查结果。
|
||||
// // 这里假设至少有一个 BulletDef 存在,如果不是,需要更复杂的错误处理。
|
||||
// var bulletDefEntry = def.Values.FirstOrDefault();
|
||||
// if (bulletDefEntry == null)
|
||||
// {
|
||||
// Debug.LogError("No BulletDef found in DefineManager. Cannot attack.");
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// var bulletDef = (BulletDef)bulletDefEntry;
|
||||
//
|
||||
// Vector3 dir = MousePosition.GetWorldPosition();
|
||||
// EntityManage.Instance.GenerateBulletEntity(Program.Instance.FocusedDimensionId, bulletDef, Position,
|
||||
// dir - Position, this);
|
||||
// }
|
||||
|
||||
public override WeaponResource GetCurrentWeapon()
|
||||
{
|
||||
var currentSelectItem = Inventory.GetSlot(CurrentSelected);
|
||||
|
@ -32,6 +32,12 @@ namespace Entity
|
||||
|
||||
public EntityPrefab entityPrefab;
|
||||
public EntityDef entityDef;
|
||||
/// <summary>
|
||||
/// 手上拿着显示的贴图
|
||||
/// </summary>
|
||||
public GameObject weaponAnimator;
|
||||
|
||||
public ITick[] weaponAnimatorNodeList;
|
||||
|
||||
/// <summary>
|
||||
/// 人工智能行为树,定义实体的行为逻辑。
|
||||
@ -183,13 +189,32 @@ namespace Entity
|
||||
this.entityDef = entityDef;
|
||||
|
||||
HideHealthBar();
|
||||
InitWeaponAnimator();
|
||||
}
|
||||
|
||||
protected virtual void InitWeaponAnimator()
|
||||
{
|
||||
for (var i = 0; i < weaponAnimator.transform.childCount; i++)
|
||||
{
|
||||
Destroy(weaponAnimator.transform.GetChild(i).gameObject);
|
||||
weaponAnimatorNodeList = null;
|
||||
}
|
||||
var weapon = GetCurrentWeapon();
|
||||
if (weapon == null)
|
||||
{
|
||||
weaponAnimator.SetActive(false);
|
||||
return;
|
||||
}
|
||||
|
||||
var weaponAnimation = weapon.InstantiateAttackAnimation(weaponAnimator.transform);
|
||||
weaponAnimatorNodeList = weaponAnimation.animationComponents;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 初始化实体的身体部分,包括不同朝向下的绘图节点。
|
||||
/// </summary>
|
||||
/// <param name="drawingOrder">绘制顺序定义。</param>
|
||||
public virtual void InitBody(DrawingOrderDef drawingOrder)
|
||||
protected virtual void InitBody(DrawingOrderDef drawingOrder)
|
||||
{
|
||||
// 预缓存枚举值(避免每次循环重复调用 Enum.GetValues)
|
||||
var states = Enum.GetValues(typeof(EntityState)).Cast<EntityState>().ToArray();
|
||||
@ -295,7 +320,7 @@ namespace Entity
|
||||
/// <param name="drawNode">绘图节点定义。</param>
|
||||
/// <param name="parent">父节点对象。</param>
|
||||
/// <returns>创建的GameObject,如果失败则返回null</returns>
|
||||
public virtual GameObject InitBodyPart(DrawNodeDef drawNode, GameObject parent)
|
||||
protected virtual GameObject InitBodyPart(DrawNodeDef drawNode, GameObject parent)
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -470,6 +495,13 @@ namespace Entity
|
||||
}
|
||||
}
|
||||
|
||||
if (weaponAnimatorNodeList != null)
|
||||
{
|
||||
foreach (var tick in weaponAnimatorNodeList)
|
||||
{
|
||||
tick.Tick();
|
||||
}
|
||||
}
|
||||
if (IsShowingHealthBarUI)
|
||||
{
|
||||
_hitBarUIShowTimer -= Time.deltaTime;
|
||||
|
Reference in New Issue
Block a user