feat: initial commit
This commit is contained in:
41
Assets/Common/Timer/Runtime/TimerManager.cs
Normal file
41
Assets/Common/Timer/Runtime/TimerManager.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
using System.Collections.Generic;
|
||||
using Common.Timer.Runtime.ScriptableObjects;
|
||||
using JoeSiu.Common.Infrastructure.Runtime;
|
||||
using TriInspector;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Common.Timer.Runtime
|
||||
{
|
||||
public class TimerManager : MonoSingleton<TimerManager>
|
||||
{
|
||||
[InfoBox("As ScriptableObject doesn't have Update() function, use this class to control the ScriptableObject timer's tick")]
|
||||
[SerializeField]
|
||||
private List<TimerBaseSO> _timerSOs = new();
|
||||
public IReadOnlyList<TimerBaseSO> TimerSOs => _timerSOs.AsReadOnly();
|
||||
|
||||
protected override void Awake()
|
||||
{
|
||||
base.Awake();
|
||||
DontDestroyOnLoad(this);
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
_timerSOs.ForEach(so => so?.Tick());
|
||||
}
|
||||
|
||||
public void Add(TimerBaseSO timerBaseSO)
|
||||
{
|
||||
if (_timerSOs.Contains(timerBaseSO)) return;
|
||||
_timerSOs.Add(timerBaseSO);
|
||||
Debug.Log($"Added TimerBaseSO '{timerBaseSO.name}' to {nameof(TimerManager)}", this);
|
||||
}
|
||||
|
||||
public void Remove(TimerBaseSO timerBaseSO)
|
||||
{
|
||||
if (!_timerSOs.Contains(timerBaseSO)) return;
|
||||
_timerSOs.Remove(timerBaseSO);
|
||||
Debug.Log( $"Removed TimerBaseSO '{timerBaseSO.name}' from {nameof(TimerManager)}", this);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user