Files
taptap2024_GJ_chidouren/Assets/Scripts/Game/Component/FsmMonoData/AttackTimer.cs
2024-10-23 18:46:37 +08:00

40 lines
1.2 KiB
C#

using System;
using Framework.Audio;
using Framework.Timer;
using Sirenix.OdinInspector;
using UnityEngine;
public class AttackTimer : MonoBehaviour
{
[SerializeField , Header ("准备时间")] private float AttackBeforeTime = 1.5f;
[SerializeField, Header ("追逐时长")] private float AttackRealTime;
private TimeHandler _atkReadyTimeHandler;
private TimeHandler _timeHandler;
[ProgressBar (0 , "Curprogress")] public float Curprogress => this._timeHandler?.CurProgress ?? 0;
public bool IsRunning => this._timeHandler?.IsPlaying ?? false;
public void StartAttack (Action callback)
{
this._timeHandler?.Kill ();
this._timeHandler = null;
_atkReadyTimeHandler?.Kill ();
this._atkReadyTimeHandler = GameUpdateMgr.Instance.CreateTimer (this.AttackBeforeTime , () =>
{
this._timeHandler = GameUpdateMgr.Instance.CreateTimer (this.AttackRealTime , callback);
});
}
public void StopAttack ()
{
this._timeHandler?.Kill ();
this._timeHandler = null;
}
private void OnDisable ()
{
StopAttack ();
}
}