更改文件架构
This commit is contained in:
61
Packages/Common~/Scripts/SubSystems/Timer/TimerSystem.cs
Normal file
61
Packages/Common~/Scripts/SubSystems/Timer/TimerSystem.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Concurrent;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.TestTools;
|
||||
namespace BITKit
|
||||
{
|
||||
using SubSystems;
|
||||
public class BITTimer
|
||||
{
|
||||
internal BITTimer() { }
|
||||
public static BITTimer Create(float addTime = 1, UnityAction action = null)
|
||||
{
|
||||
BITTimer timer = new();
|
||||
timer.excuteTime = Utility.Time.time + addTime;
|
||||
timer.onExcute = action;
|
||||
TimerSystem.queue.Enqueue(timer);
|
||||
return timer;
|
||||
}
|
||||
public float excuteTime;
|
||||
public bool isActive { get; internal set; }
|
||||
public UnityAction onExcute;
|
||||
public void Cancel()
|
||||
{
|
||||
isActive = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
namespace BITKit.SubSystems
|
||||
{
|
||||
public class TimerSystem : SubBITSystem
|
||||
{
|
||||
internal static List<BITTimer> timers = new();
|
||||
internal static ConcurrentQueue<BITTimer> queue = new();
|
||||
public override void OnUpdate(float deltaTime)
|
||||
{
|
||||
List<BITTimer> nexts = new();
|
||||
lock (timers)
|
||||
{
|
||||
timers.ForEach(x =>
|
||||
{
|
||||
if (x.excuteTime > Utility.Time.time)
|
||||
{
|
||||
if (x.onExcute is not null) x.onExcute();
|
||||
x.isActive = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
nexts.Add(x);
|
||||
}
|
||||
});
|
||||
while (queue.TryDequeue(out var timer))
|
||||
{
|
||||
nexts.Add(timer);
|
||||
}
|
||||
timers = nexts;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5f5d87ad298669f4dbf822bb7031b7f6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user