time 增加
All checks were successful
Plugin Library CI / publish (00.BuildOriginality) (push) Successful in 7s
Plugin Library CI / publish (00.StaryEvo) (push) Successful in 11s
Plugin Library CI / publish (00.StaryEvoTools) (push) Successful in 10s
Plugin Library CI / publish (01.HybridCLR) (push) Successful in 7s
Plugin Library CI / publish (02.InformationSave) (push) Successful in 5s
Plugin Library CI / publish (03.YooAsset) (push) Successful in 38s
Plugin Library CI / publish (04.AudioCore) (push) Successful in 3s
Plugin Library CI / publish (05.TableTextConversion) (push) Successful in 4s
Plugin Library CI / publish (06.UIFarme) (push) Successful in 17s
Plugin Library CI / publish (09.CodeChecker) (push) Successful in 19s
Plugin Library CI / publish (11.PointCloudTools) (push) Successful in 3s
Plugin Library CI / publish (12.WeixinMinigame) (push) Successful in 1m2s
Plugin Library CI / publish (07.RKTools) (push) Successful in 3s
Plugin Library CI / publish (08.UniTask) (push) Successful in 3s
Plugin Library CI / publish (10.StoryEditor) (push) Successful in 4s
Plugin Library CI / publish (10.XNode) (push) Successful in 4s
All checks were successful
Plugin Library CI / publish (00.BuildOriginality) (push) Successful in 7s
Plugin Library CI / publish (00.StaryEvo) (push) Successful in 11s
Plugin Library CI / publish (00.StaryEvoTools) (push) Successful in 10s
Plugin Library CI / publish (01.HybridCLR) (push) Successful in 7s
Plugin Library CI / publish (02.InformationSave) (push) Successful in 5s
Plugin Library CI / publish (03.YooAsset) (push) Successful in 38s
Plugin Library CI / publish (04.AudioCore) (push) Successful in 3s
Plugin Library CI / publish (05.TableTextConversion) (push) Successful in 4s
Plugin Library CI / publish (06.UIFarme) (push) Successful in 17s
Plugin Library CI / publish (09.CodeChecker) (push) Successful in 19s
Plugin Library CI / publish (11.PointCloudTools) (push) Successful in 3s
Plugin Library CI / publish (12.WeixinMinigame) (push) Successful in 1m2s
Plugin Library CI / publish (07.RKTools) (push) Successful in 3s
Plugin Library CI / publish (08.UniTask) (push) Successful in 3s
Plugin Library CI / publish (10.StoryEditor) (push) Successful in 4s
Plugin Library CI / publish (10.XNode) (push) Successful in 4s
This commit is contained in:
67
Assets/00.StaryEvo/Runtime/Tool/Timer/TimerSystem.cs
Normal file
67
Assets/00.StaryEvo/Runtime/Tool/Timer/TimerSystem.cs
Normal file
@@ -0,0 +1,67 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Stary.Evo;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Stary.Evo
|
||||
{
|
||||
public interface ITimerSystem : ISystem
|
||||
{
|
||||
void CreateTimer(string timerName, float timeDuration, Action onArrivalTimeComplete);
|
||||
void RemoveTimer(string timerName);
|
||||
}
|
||||
|
||||
public class TimerSystem : AbstractSystem, ITimerSystem
|
||||
{
|
||||
private static Dictionary<string, TimerController>
|
||||
_timerControllers = new Dictionary<string, TimerController>();
|
||||
|
||||
private static GameObject timerSystem;
|
||||
|
||||
protected override void OnInit()
|
||||
{
|
||||
_timerControllers = new Dictionary<string, TimerController>();
|
||||
timerSystem = new GameObject("Timer");
|
||||
}
|
||||
|
||||
public void CreateTimer(string timerName, float timeDuration, Action onArrivalTimeComplete)
|
||||
{
|
||||
if (_timerControllers.ContainsKey(timerName))
|
||||
{
|
||||
Debug.LogError($"TimerSystem CreateTimer 重复创建定时器 {timerName}");
|
||||
return;
|
||||
}
|
||||
|
||||
var _timer = new GameObject(timerName);
|
||||
_timer.transform.SetParent(timerSystem.transform);
|
||||
var timerController = _timer.AddComponent<TimerController>();
|
||||
_timerControllers.Add(timerName, timerController);
|
||||
timerController.StartTimer(timeDuration, onArrivalTimeComplete);
|
||||
}
|
||||
|
||||
public void RemoveTimer(string timerName)
|
||||
{
|
||||
if (_timerControllers.ContainsKey(timerName))
|
||||
{
|
||||
var timerController = _timerControllers[timerName];
|
||||
GameObject.Destroy(timerController.gameObject);
|
||||
_timerControllers.Remove(timerName);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public override void Dispose()
|
||||
{
|
||||
foreach (var controller in _timerControllers)
|
||||
{
|
||||
if (controller.Value != null)
|
||||
{
|
||||
GameObject.Destroy(controller.Value.gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
GameObject.Destroy(timerSystem.gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user