Files
UnityPackages/Assets/Common/Timer/Runtime/ScriptableObjects/StopwatchSO.cs
2025-12-01 12:36:01 +08:00

62 lines
1.9 KiB
C#

using System;
using TriInspector;
using UnityEngine;
namespace Common.Timer.Runtime.ScriptableObjects
{
[CreateAssetMenu(fileName = "Stopwatch", menuName = "JoeSiu/Common/Stopwatch")]
public class StopwatchSO : TimerBaseSO, IStopwatch
{
protected override ITimer Timer => _stopwatch;
[SerializeField, InlineProperty, HideLabel]
[InfoBox("The stopwatch in ScriptableObject will be deactivated by default")]
private Stopwatch _stopwatch = new(false, 10f);
public float Duration
{
get => _stopwatch.Duration;
set => _stopwatch.Duration = value;
}
public float RemainingTime
{
get => _stopwatch.RemainingTime;
set => _stopwatch.RemainingTime = value;
}
public float Progress
{
get => _stopwatch.Progress;
set => _stopwatch.Progress = value;
}
public bool IsTimeReached => _stopwatch.IsTimeReached;
public bool DeactivateOnTimeReached
{
get => _stopwatch.DeactivateOnTimeReached;
set => _stopwatch.DeactivateOnTimeReached = value;
}
public event Action OnTimeReached
{
add => _stopwatch.OnTimeReached += value;
remove => _stopwatch.OnTimeReached -= value;
}
protected override void Activate_Internal(bool resetTime = false)
{
_stopwatch.Activate(resetTime);
}
public virtual void SetDuration(float value) => _stopwatch.SetDuration(value);
public virtual void SetRemainingTime(float value) => _stopwatch.SetRemainingTime(value);
public virtual void SetProgress(float value) => _stopwatch.SetProgress(value);
public void EndTime() => _stopwatch.EndTime();
public override void Reinitialize()
{
_stopwatch = new(false, _stopwatch.Duration);
}
}
}