Merge branch 'temp827'
This commit is contained in:
@ -32,6 +32,12 @@ namespace Entity
|
||||
|
||||
public EntityPrefab entityPrefab;
|
||||
public EntityDef entityDef;
|
||||
/// <summary>
|
||||
/// 手上拿着显示的贴图
|
||||
/// </summary>
|
||||
public GameObject weaponAnimator;
|
||||
|
||||
public ITick[] weaponAnimatorNodeList;
|
||||
|
||||
/// <summary>
|
||||
/// 人工智能行为树,定义实体的行为逻辑。
|
||||
@ -46,7 +52,13 @@ namespace Entity
|
||||
/// <summary>
|
||||
/// 实体的属性定义,包括生命值、攻击力、防御力等。
|
||||
/// </summary>
|
||||
public Attributes attributes = new();
|
||||
public virtual Attributes attributes { get; protected set; }
|
||||
|
||||
private Attributes _baseAttributes;
|
||||
public virtual Attributes baseAttributes
|
||||
{
|
||||
get { return _baseAttributes ??= new Attributes(entityDef.attributes); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 实体当前的移动方向。
|
||||
@ -164,7 +176,6 @@ namespace Entity
|
||||
private Coroutine _attackCoroutine;
|
||||
|
||||
|
||||
|
||||
[SerializeField] private float _hitBarUIShowTime = 5;
|
||||
private float _hitBarUIShowTimer = 0;
|
||||
private int _walkingTimer = 0;
|
||||
@ -183,13 +194,34 @@ namespace Entity
|
||||
this.entityDef = entityDef;
|
||||
|
||||
HideHealthBar();
|
||||
InitWeaponAnimator();
|
||||
}
|
||||
|
||||
protected virtual void InitWeaponAnimator()
|
||||
{
|
||||
if (!weaponAnimator)
|
||||
return;
|
||||
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 +327,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
|
||||
{
|
||||
@ -434,7 +466,7 @@ namespace Entity
|
||||
/// <summary>
|
||||
/// 更新实体的逻辑,包括玩家控制和自动行为。
|
||||
/// </summary>
|
||||
public void Tick()
|
||||
public virtual void Tick()
|
||||
{
|
||||
if (_walkingTimer > 0)
|
||||
{
|
||||
@ -470,6 +502,13 @@ namespace Entity
|
||||
}
|
||||
}
|
||||
|
||||
if (weaponAnimatorNodeList != null)
|
||||
{
|
||||
foreach (var tick in weaponAnimatorNodeList)
|
||||
{
|
||||
tick.Tick();
|
||||
}
|
||||
}
|
||||
if (IsShowingHealthBarUI)
|
||||
{
|
||||
_hitBarUIShowTimer -= Time.deltaTime;
|
||||
@ -488,14 +527,12 @@ namespace Entity
|
||||
if (IsAttacking || IsDead) return; // 死亡时无法攻击
|
||||
|
||||
// 尝试获取当前武器
|
||||
WeaponResource currentWeapon = GetCurrentWeapon();
|
||||
var currentWeapon = GetCurrentWeapon();
|
||||
|
||||
// 如果没有武器,可以选择进行徒手攻击或者直接返回
|
||||
// 暂时设定为:如果没有武器,则不进行攻击
|
||||
if (currentWeapon == null)
|
||||
{
|
||||
// 可以在这里添加一个默认的徒手攻击逻辑,或者播放一个“不能攻击”的提示
|
||||
Debug.Log($"{name} 没有装备武器,无法攻击。");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -744,7 +781,7 @@ namespace Entity
|
||||
}
|
||||
|
||||
// STEP 4: 等待到攻击判定时间
|
||||
float elapsedTime = 0f;
|
||||
var elapsedTime = 0f;
|
||||
while (elapsedTime < weapon.AttackDetectionTime)
|
||||
{
|
||||
if (IsDead)
|
||||
@ -766,7 +803,7 @@ namespace Entity
|
||||
|
||||
ExecuteWeaponAction(weapon);
|
||||
|
||||
float remainingAnimationTime = weapon.AttackAnimationTime - elapsedTime;
|
||||
var remainingAnimationTime = weapon.AttackAnimationTime - elapsedTime;
|
||||
if (remainingAnimationTime > 0)
|
||||
{
|
||||
yield return new WaitForSeconds(remainingAnimationTime);
|
||||
@ -851,10 +888,10 @@ namespace Entity
|
||||
|
||||
// 获取子弹方向。这里使用实体当前的移动方向作为子弹发射方向
|
||||
// 更复杂的逻辑可能根据鼠标位置、目标位置等确定
|
||||
Vector3 bulletDirection = direction; // 实体当前的朝向
|
||||
var bulletDirection = direction; // 实体当前的朝向
|
||||
if (PlayerControlled && Input.GetMouseButton(0)) // 玩家控制时,如果鼠标按下,尝试朝鼠标方向发射
|
||||
{
|
||||
Vector3 mouseWorldPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
|
||||
var mouseWorldPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
|
||||
mouseWorldPos.z = transform.position.z; // 保持Z轴一致
|
||||
bulletDirection = (mouseWorldPos - transform.position).normalized;
|
||||
}
|
||||
|
Reference in New Issue
Block a user