123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- using System;
- using System.Collections.Generic;
- using UnityEngine;
- using Utility;
- namespace Mono.UI.Core
- {
- public class TimeComponent : Singleton<TimeComponent>
- {
- public Queue<CustomTimer> TimerPool = new Queue<CustomTimer>();
- public List<CustomTimer> CustomTimers = new List<CustomTimer>();
- public void Init()
- {
- }
- public void AddTimer(float time, Action action)
- {
- CustomTimer customTimer;
- if (TimerPool.Count > 0)
- {
- customTimer = TimerPool.Dequeue();
- }
- else
- {
- customTimer = new CustomTimer();
- }
- customTimer.CustomInit(time, action);
- CustomTimers.Add(customTimer);
- }
- public void Update()
- {
- for (var i = 0; i < CustomTimers.Count; i++)
- {
- CustomTimers[i].Update(Time.deltaTime);
- }
- }
- public void Rec(CustomTimer customTimer)
- {
- if (CustomTimers.Contains(customTimer))
- {
- CustomTimers.Remove(customTimer);
- TimerPool.Enqueue(customTimer);
- }
- }
- }
- }
|