35 lines
900 B
C#
35 lines
900 B
C#
|
|
using System;
|
||
|
|
using UnityEngine;
|
||
|
|
|
||
|
|
namespace OTG.Lab06.Abilities
|
||
|
|
{
|
||
|
|
[Serializable]
|
||
|
|
public sealed class AbilityRuntime
|
||
|
|
{
|
||
|
|
public AbilityRuntime(AbilityData data)
|
||
|
|
{
|
||
|
|
Data = data;
|
||
|
|
}
|
||
|
|
|
||
|
|
public AbilityData Data { get; }
|
||
|
|
public float CooldownRemaining { get; private set; }
|
||
|
|
public bool IsReady => CooldownRemaining <= 0f;
|
||
|
|
public float CooldownNormalized => Data == null || Data.cooldown <= 0f ? 0f : Mathf.Clamp01(CooldownRemaining / Data.cooldown);
|
||
|
|
|
||
|
|
public void Tick(float deltaTime)
|
||
|
|
{
|
||
|
|
if (CooldownRemaining <= 0f)
|
||
|
|
{
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
CooldownRemaining = Mathf.Max(0f, CooldownRemaining - deltaTime);
|
||
|
|
}
|
||
|
|
|
||
|
|
public void StartCooldown()
|
||
|
|
{
|
||
|
|
CooldownRemaining = Data == null ? 0f : Mathf.Max(0f, Data.cooldown);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|