将 Enemy 攻击冷却计时器 由 Enemy 内部维护迁移到 TimerModule 维护
This commit is contained in:
@@ -3,6 +3,7 @@ using SepCore.AsyncTask;
|
||||
using SepCore.CustomUtility;
|
||||
using SepCore.Definition;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using SepCore.Timer;
|
||||
using UnityEngine;
|
||||
using UnityGameFramework.Runtime;
|
||||
|
||||
@@ -27,7 +28,8 @@ namespace SepCore.Entity
|
||||
private float _attackRangeSquared;
|
||||
private float _attackCooldown = 1f;
|
||||
private int _attackDamage = 1;
|
||||
private float _currAttackTimer;
|
||||
private TimerHandle _attackTimerHandle;
|
||||
private bool _canAttack;
|
||||
|
||||
[SerializeField] private float _projectileSpeed = 12f;
|
||||
[SerializeField] private float _projectileLifeTime = 3f;
|
||||
@@ -81,7 +83,8 @@ namespace SepCore.Entity
|
||||
_projectileSpawnHeightOffset);
|
||||
_projectileAssetName = ReadStringParam(ProjectileAssetNameParamKey, _projectileAssetName);
|
||||
|
||||
_currAttackTimer = 0f;
|
||||
_canAttack = false;
|
||||
_attackTimerHandle = GameEntry.Timer.ScheduleOnce(_attackCooldown, () => _canAttack = true, this);
|
||||
this.CachedTransform.position = enemyData.Position;
|
||||
}
|
||||
else
|
||||
@@ -94,8 +97,6 @@ namespace SepCore.Entity
|
||||
{
|
||||
base.OnUpdate(elapseSeconds, realElapseSeconds);
|
||||
|
||||
_currAttackTimer += elapseSeconds;
|
||||
|
||||
if (_target == null)
|
||||
{
|
||||
_movementComponent.SetMove(false);
|
||||
@@ -108,7 +109,12 @@ namespace SepCore.Entity
|
||||
if (distanceSquared <= _attackRangeSquared)
|
||||
{
|
||||
_movementComponent.SetMove(false);
|
||||
TryFireProjectile();
|
||||
if (_canAttack)
|
||||
{
|
||||
TryFireProjectile();
|
||||
_canAttack = false;
|
||||
_attackTimerHandle = GameEntry.Timer.ScheduleOnce(_attackCooldown, () => _canAttack = true, this);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -121,14 +127,14 @@ namespace SepCore.Entity
|
||||
{
|
||||
_movementComponent.OnReset();
|
||||
_healthComponent.OnReset();
|
||||
_currAttackTimer = 0f;
|
||||
GameEntry.Timer.Cancel(_attackTimerHandle);
|
||||
_attackTimerHandle = TimerHandle.Invalid;
|
||||
|
||||
base.OnHide(isShutdown, userData);
|
||||
}
|
||||
|
||||
private void TryFireProjectile()
|
||||
{
|
||||
if (_currAttackTimer < _attackCooldown || _target == null) return;
|
||||
if (!EnsureEnemyProjectileGroup()) return;
|
||||
|
||||
Vector3 spawnPosition = this.CachedTransform.position +
|
||||
@@ -165,8 +171,6 @@ namespace SepCore.Entity
|
||||
EnemyProjectileGroupName,
|
||||
Constant.AssetPriority.BulletAsset,
|
||||
projectileData).Forget();
|
||||
|
||||
_currAttackTimer = 0f;
|
||||
}
|
||||
|
||||
private static bool EnsureEnemyProjectileGroup()
|
||||
|
||||
Reference in New Issue
Block a user