56 lines
1.4 KiB
C#
56 lines
1.4 KiB
C#
|
|
using System;
|
|||
|
|
using Stary.Evo;
|
|||
|
|
using UnityEngine;
|
|||
|
|
using UnityEngine.Serialization;
|
|||
|
|
|
|||
|
|
namespace Stary.Evo
|
|||
|
|
{
|
|||
|
|
public class TimerController : MonoBehaviour, IController
|
|||
|
|
{
|
|||
|
|
public string TimerName => gameObject.name;
|
|||
|
|
private bool isStart = false;
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 持续时间
|
|||
|
|
/// </summary>
|
|||
|
|
private float timeDuration;
|
|||
|
|
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 时间到达的事件
|
|||
|
|
/// </summary>
|
|||
|
|
private Action onArrivalTimeComplete;
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 持续时间最大阈值
|
|||
|
|
/// </summary>
|
|||
|
|
public float timeDurationMax;
|
|||
|
|
|
|||
|
|
public void StartTimer(float timeDurationMax, Action onArrivalTimeComplete)
|
|||
|
|
{
|
|||
|
|
this.timeDurationMax = timeDurationMax;
|
|||
|
|
this.onArrivalTimeComplete = onArrivalTimeComplete;
|
|||
|
|
timeDuration = 0;
|
|||
|
|
isStart = true;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void Update()
|
|||
|
|
{
|
|||
|
|
if (isStart)
|
|||
|
|
{
|
|||
|
|
timeDuration += Time.deltaTime;
|
|||
|
|
if (timeDuration >= timeDurationMax)
|
|||
|
|
{
|
|||
|
|
onArrivalTimeComplete?.Invoke();
|
|||
|
|
this.GetSystem<TimerSystem>().RemoveTimer(TimerName);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public IArchitecture GetArchitecture()
|
|||
|
|
{
|
|||
|
|
ITimerSystem system = this.GetSystem<TimerSystem>();
|
|||
|
|
return system.GetArchitecture();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|