From 71ea2c1455af3af62d7ae1da65a560fdc9dfc8cd Mon Sep 17 00:00:00 2001 From: Star fire Date: Sun, 23 Jun 2024 23:50:31 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E2=9C=A8=20=E7=A7=BB=E9=99=A4=E5=A4=9A?= =?UTF-8?q?=E4=BD=99T4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Runtime/T4.meta | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 Runtime/T4.meta diff --git a/Runtime/T4.meta b/Runtime/T4.meta deleted file mode 100644 index 5573862..0000000 --- a/Runtime/T4.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: dfa72eeabd1a4b0a8c32564f2477583b -timeCreated: 1717811670 \ No newline at end of file From 22caf7f2bd4e40f159c2a5a62755968f733f9824 Mon Sep 17 00:00:00 2001 From: Star fire Date: Tue, 25 Jun 2024 15:30:37 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E2=9C=A8=20=E6=94=AF=E6=8C=81=E4=B8=BB?= =?UTF-8?q?=E7=BA=BF=E7=A8=8B=E6=89=A7=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/README.md | 24 +- .github/README_EN.md | 23 +- .gitignore | 6 - Runtime/Container/ITimerContainer.cs | 3 +- Runtime/Container/TimerContainer.Loop.cs | 23 +- Runtime/Container/TimerContainer.cs | 45 +- Runtime/Executor/ITimerExecutor.cs | 22 +- Runtime/Executor/TimerExecutor.Enumerator.cs | 21 +- Runtime/Executor/TimerExecutor.MainThread.cs | 52 +++ .../Executor/TimerExecutor.MainThread.cs.meta | 3 + Runtime/Executor/TimerExecutor.cs | 6 +- Runtime/Operator/ITimerOperator.cs | 5 +- Runtime/Operator/TimerOperator.Auto.cs | 8 +- Runtime/Operator/TimerOperator.Consume.cs | 37 +- Runtime/Operator/TimerOperator.Loop.cs | 2 +- Runtime/Properties.meta | 3 + Runtime/Properties/AssemblyInfo.cs | 15 + Runtime/Properties/AssemblyInfo.cs.meta | 3 + Runtime/System/T4.meta | 3 + Runtime/System/T4/TimerSystem.Push.cs | 383 ++++++++++++++++++ Runtime/System/T4/TimerSystem.Push.cs.meta | 11 + Runtime/System/T4/TimerSystem.Push.tt | 173 ++++++++ Runtime/System/T4/TimerSystem.Push.tt.meta | 3 + Runtime/System/T4/TimerSystem.PushMain.cs | 202 +++++++++ .../System/T4/TimerSystem.PushMain.cs.meta | 11 + Runtime/System/T4/TimerSystem.PushMain.tt | 171 ++++++++ .../System/T4/TimerSystem.PushMain.tt.meta | 3 + Runtime/System/TimerSystem.Add.cs | 9 +- Runtime/System/TimerSystem.Compatible.cs | 155 ------- Runtime/System/TimerSystem.Compatible.cs.meta | 3 - Runtime/System/TimerSystem.Exist.cs | 26 ++ Runtime/System/TimerSystem.Exist.cs.meta | 3 + Runtime/System/TimerSystem.Pop.cs | 39 ++ Runtime/System/TimerSystem.Pop.cs.meta | 3 + Runtime/System/TimerSystemSettings.cs | 3 +- 35 files changed, 1253 insertions(+), 249 deletions(-) create mode 100644 Runtime/Executor/TimerExecutor.MainThread.cs create mode 100644 Runtime/Executor/TimerExecutor.MainThread.cs.meta create mode 100644 Runtime/Properties.meta create mode 100644 Runtime/Properties/AssemblyInfo.cs create mode 100644 Runtime/Properties/AssemblyInfo.cs.meta create mode 100644 Runtime/System/T4.meta create mode 100644 Runtime/System/T4/TimerSystem.Push.cs create mode 100644 Runtime/System/T4/TimerSystem.Push.cs.meta create mode 100644 Runtime/System/T4/TimerSystem.Push.tt create mode 100644 Runtime/System/T4/TimerSystem.Push.tt.meta create mode 100644 Runtime/System/T4/TimerSystem.PushMain.cs create mode 100644 Runtime/System/T4/TimerSystem.PushMain.cs.meta create mode 100644 Runtime/System/T4/TimerSystem.PushMain.tt create mode 100644 Runtime/System/T4/TimerSystem.PushMain.tt.meta delete mode 100644 Runtime/System/TimerSystem.Compatible.cs delete mode 100644 Runtime/System/TimerSystem.Compatible.cs.meta create mode 100644 Runtime/System/TimerSystem.Exist.cs create mode 100644 Runtime/System/TimerSystem.Exist.cs.meta create mode 100644 Runtime/System/TimerSystem.Pop.cs create mode 100644 Runtime/System/TimerSystem.Pop.cs.meta diff --git a/.github/README.md b/.github/README.md index 1171c80..92d34ff 100644 --- a/.github/README.md +++ b/.github/README.md @@ -37,8 +37,8 @@ "name": "package.openupm.com", "url": "https://package.openupm.com", "scopes": [ - "com.aio.timer", - "com.aio.runner" + "com.aio.runner", + "com.aio.timer" ] } ] @@ -94,6 +94,7 @@ openupm add com.aio.timer - ✅ **支持 自定义时间轮大小** - ✅ **支持 时间轮动态扩容** - ✅ **支持 同时添加1000000+ 定时任务** +- ✅ **支持 `int` `string` `enum` `Guid` 作为 循环任务KEY** ## 📚 使用 @@ -127,15 +128,14 @@ public static void Week(ICollection<(long, long, long)> units)

添加定时任务

```csharp -TimerSystem.Push(1, () => { Debug.Log("1ms"); }); -TimerSystem.Push(2, () => { Debug.Log("2ms"); }); -TimerSystem.Push(1000, () => { Debug.Log("2s"); }); -``` - -

添加循环定时任务

- -```csharp -TimerSystem.PushLoop(tid, 3, () => { Debug.Log("3ms"); }); +// 后台线程 +TimerSystem.Push("KEY", 1, () => { Debug.Log("1ms"); }); // 自定义次数 默认为1 +TimerSystem.PushOnce("KEY", 2, () => { Debug.Log("2ms"); }); // 一次 +TimerSystem.PushLoop("KEY", 1000, () => { Debug.Log("2s"); }); // 循环 +// 主线程 +TimerSystem.PushMain("KEY", 1, () => { Debug.Log("1ms"); }, 1); // 自定义次数 默认为1 +TimerSystem.PushOnceMain("KEY", 2, () => { Debug.Log("2ms"); }); // 一次 +TimerSystem.PushLoopMain("KEY", 1000, () => { Debug.Log("2s"); }); // 循环 ```

移除循环定时任务

@@ -166,4 +166,4 @@ TimerSystem.Pop(tid); - **谢谢您选择我们的扩展包。** - **如果此软件包对您有所帮助。** -- **请考虑通过添加⭐来表示支持。** \ No newline at end of file +- **请考虑通过添加⭐来表示支持。** diff --git a/.github/README_EN.md b/.github/README_EN.md index a96446a..8bbfef7 100644 --- a/.github/README_EN.md +++ b/.github/README_EN.md @@ -37,8 +37,8 @@ "name": "package.openupm.com", "url": "https://package.openupm.com", "scopes": [ - "com.aio.timer", - "com.aio.runner" + "com.aio.runner", + "com.aio.timer" ] } ] @@ -94,6 +94,7 @@ openupm add com.aio.timer - **Support custom time wheel size.** - **Support time wheel dynamic expansion.** - **Support adding 1000000+ timing tasks at the same time.** +- **Support int` `string` `enum` `Guid` as loop task KEY** ## 📚 Usage @@ -127,14 +128,14 @@ public static void Week(ICollection<(long, long, long)> units)

Add timing task

```csharp -TimerSystem.Push(1, () => { Debug.Log("1s"); }); -TimerSystem.Push(2, () => { Debug.Log("2s"); }); -``` - -

Remove timing task

- -```csharp -TimerSystem.PushLoop(tid, 3, () => { Debug.Log("3s"); }); +// Sub-thread +TimerSystem.Push("KEY", 1, () => { Debug.Log("1ms"); }); // Custom times default is 1 +TimerSystem.PushOnce("KEY", 2, () => { Debug.Log("2ms"); }); // Once +TimerSystem.PushLoop("KEY", 1000, () => { Debug.Log("2s"); }); // Loop +// Main-thread +TimerSystem.PushMain("KEY", 1, () => { Debug.Log("1ms"); }, 1); // Custom times default is 1 +TimerSystem.PushOnceMain("KEY", 2, () => { Debug.Log("2ms"); }); // Once +TimerSystem.PushLoopMain("KEY", 1000, () => { Debug.Log("2s"); }); // Loop ```

Remove timing task

@@ -165,4 +166,4 @@ TimerSystem.Pop(tid); - **Thanks for using this software.** - **If this package is useful to you.** -- **Please ⭐ this repository to support the project.** \ No newline at end of file +- **Please ⭐ this repository to support the project.** diff --git a/.gitignore b/.gitignore index 96b970e..b0f2058 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ -!*.meta *.log *.DS_Store *.sln @@ -13,11 +12,6 @@ .vscode/ .consulo/ -!*.dll.meta -!*.asset.meta -!*.asmdef.meta -!*.cs.meta - [Bb]uild/ [Bb]uilds/ [Tt]emp/ diff --git a/Runtime/Container/ITimerContainer.cs b/Runtime/Container/ITimerContainer.cs index e92faa4..1105f7f 100644 --- a/Runtime/Container/ITimerContainer.cs +++ b/Runtime/Container/ITimerContainer.cs @@ -71,6 +71,7 @@ internal interface ITimerContainer : IDisposable /// /// 推送更新 /// + /// 执行器 void PushUpdate(ITimerExecutor timer); /// @@ -78,4 +79,4 @@ internal interface ITimerContainer : IDisposable /// void PushUpdate(List timer); } -} \ No newline at end of file +} diff --git a/Runtime/Container/TimerContainer.Loop.cs b/Runtime/Container/TimerContainer.Loop.cs index 8c0c96a..c39aea1 100644 --- a/Runtime/Container/TimerContainer.Loop.cs +++ b/Runtime/Container/TimerContainer.Loop.cs @@ -17,15 +17,9 @@ public TimerContainerLoop(long unit) { Unit = unit; - for (byte i = 0; i < TimerSystem.TimingUnits.Count; i++) - List.Add(new TimerOperatorLoop( - i, - TimerSystem.TimingUnits[i].Item2, - TimerSystem.TimingUnits[i].Item3, - DoneCallBack, - PushUpdate, - EvolutionCallBack - )); + var tuples = TimerSystem.TimingUnits; + for (byte i = 0; i < tuples.Count; i++) + List.Add(new TimerOperatorLoop(i, tuples[i].Item2, tuples[i].Item3, DoneCallBack, PushUpdate, EvolutionCallBack)); } protected override void Update() @@ -101,7 +95,7 @@ protected override void Update() #if UNITY_EDITOR Debug.Log( - $"[循环定时器:{ID}] [容器数量:{List.Count}] [状态:结束] 精度单位:{Unit} 当前时间:{Counter} 剩余任务数量:{RemainNum}"); + $"[循环定时器:{ID}] [容器数量:{List.Count}] [状态:结束] 精度单位:{Unit} 当前时间:{Counter} 剩余任务数量:{RemainNum}"); #endif } #if UNITY_EDITOR @@ -112,7 +106,7 @@ protected override void Update() { #if UNITY_EDITOR Debug.LogErrorFormat( - $"[循环定时器:{ID}] [容器数量:{List.Count}] [状态:异常] 精度单位:{Unit} 当前时间:{Counter} 剩余任务数量:{RemainNum} 异常信息:{e}"); + $"[循环定时器:{ID}] [容器数量:{List.Count}] [状态:异常] 精度单位:{Unit} 当前时间:{Counter} 剩余任务数量:{RemainNum} 异常信息:{e}"); #endif } finally @@ -130,9 +124,6 @@ private void DoneCallBack(List list) }); } - private void EvolutionCallBack(int Index, List list) - { - List[Index].AddTimerSource(list); - } + private void EvolutionCallBack(int Index, List list) { List[Index].AddTimerSource(list); } } -} \ No newline at end of file +} diff --git a/Runtime/Container/TimerContainer.cs b/Runtime/Container/TimerContainer.cs index de00add..66b7ed1 100644 --- a/Runtime/Container/TimerContainer.cs +++ b/Runtime/Container/TimerContainer.cs @@ -13,10 +13,19 @@ namespace AIO { public abstract class TimerContainer : ITimerContainer { + /// + /// 容器ID + /// private static int NUM; + /// + /// 定时器任务 + /// private Task TaskHandle; + /// + /// 构造函数 + /// protected TimerContainer() { Watch = Stopwatch.StartNew(); @@ -33,22 +42,31 @@ protected TimerContainer() #region ITimerContainer Members + /// public ITimerOperator this[int index] => List[index]; + /// public Stopwatch Watch { get; } + /// public List List { get; } + /// public long Unit { get; protected set; } + /// public long Counter { get; protected set; } + /// public int RemainNum { get; protected set; } + /// public int ID { get; } + /// public long UpdateCacheTime { get; protected set; } + /// public void Start() { if (List.Count <= 0) @@ -63,6 +81,7 @@ public void Start() TaskHandle = Task.Factory.StartNew(Update, TaskHandleToken); } + /// public void Cancel() { if (TaskHandle is null) return; @@ -70,6 +89,7 @@ public void Cancel() else TaskHandle.Dispose(); } + /// public virtual void Dispose() { if (TaskHandleTokenSource != null) @@ -94,15 +114,7 @@ public virtual void Dispose() } } - public override string ToString() - { - var builder = new StringBuilder(); - builder.AppendLine( - $"[{GetType().Name} ID:{ID}] [容器数量:{List.Count}] 精度单位:{Unit} 当前时间:{Counter} 剩余任务数量:{RemainNum}"); - foreach (var item in List) builder.AppendLine(item.ToString()).AppendLine(); - return builder.ToString(); - } - + /// public void PushUpdate(ITimerExecutor timer) { RemainNum += 1; @@ -120,6 +132,7 @@ public void PushUpdate(ITimerExecutor timer) } } + /// public void PushUpdate(List timer) { if (timer.Count == 0) return; @@ -140,16 +153,24 @@ public void PushUpdate(List timer) timer.RemoveAt(i); } - } - timer.Free(); + timer.Free(); + } } #endregion + public override string ToString() + { + var builder = new StringBuilder(); + builder.AppendLine($"[{GetType().Name} ID:{ID}] [容器数量:{List.Count}] 精度单位:{Unit} 当前时间:{Counter} 剩余任务数量:{RemainNum}"); + foreach (var item in List) builder.AppendLine(item.ToString()).AppendLine(); + return builder.ToString(); + } + /// /// 更新 /// protected abstract void Update(); } -} \ No newline at end of file +} diff --git a/Runtime/Executor/ITimerExecutor.cs b/Runtime/Executor/ITimerExecutor.cs index 7c2cd69..d38f01e 100644 --- a/Runtime/Executor/ITimerExecutor.cs +++ b/Runtime/Executor/ITimerExecutor.cs @@ -15,11 +15,16 @@ public interface ITimerExecutor : IComparable, IDisposable /// /// 定时器索引 /// + + long TID + { + get; #if UNITY_2021_1_OR_NEWER - long TID { get; protected set; } -#else - long TID { get; set; } + protected #endif + set; + } + /// /// 创建时间 单位毫秒 /// @@ -57,7 +62,14 @@ public interface ITimerExecutor : IComparable, IDisposable /// /// 操作索引 /// - byte OperatorIndex { get; set; } + byte OperatorIndex + { + get; +#if UNITY_2021_1_OR_NEWER + protected +#endif + set; + } /// /// 精度器 记录当前任务实际持续时间 @@ -94,4 +106,4 @@ internal interface ITimerExecutor : ITimerExecutor /// T Delegates { get; } } -} \ No newline at end of file +} diff --git a/Runtime/Executor/TimerExecutor.Enumerator.cs b/Runtime/Executor/TimerExecutor.Enumerator.cs index 285e881..2ef8ebe 100644 --- a/Runtime/Executor/TimerExecutor.Enumerator.cs +++ b/Runtime/Executor/TimerExecutor.Enumerator.cs @@ -49,6 +49,25 @@ Func delegateValue Delegates = delegateValue; } + /// + /// 定时计算器 + /// + /// 识别ID + /// 定时长度 单位为毫秒 + /// 循环次数 + /// 创建时间 + /// 委托函数 + internal TimerExecutorEnumerator( + int tid, + long duration, + int loop, + long createTime, + Func delegateValue + ) : base(duration, loop, createTime, tid) + { + Delegates = delegateValue; + } + protected override void xExecute() { try @@ -61,4 +80,4 @@ protected override void xExecute() } } } -} \ No newline at end of file +} diff --git a/Runtime/Executor/TimerExecutor.MainThread.cs b/Runtime/Executor/TimerExecutor.MainThread.cs new file mode 100644 index 0000000..99c7856 --- /dev/null +++ b/Runtime/Executor/TimerExecutor.MainThread.cs @@ -0,0 +1,52 @@ +#region + +using System; +using UnityEngine; + +#endregion + +namespace AIO +{ + /// + /// 定时任务处理器 + /// + internal sealed class TimerExecutorMainThread : TimerExecutor + { + /// + /// 定时计算器 + /// + /// 定时长度 单位为毫秒 + /// 循环次数 + /// 创建时间 + /// 委托函数 + internal TimerExecutorMainThread(long duration, int loop, long createTime, Action delegateValue) : base(duration, loop, createTime) + { + Delegates = delegateValue; + } + + /// + /// 定时计算器 + /// + /// 识别ID + /// 定时长度 单位为毫秒 + /// 循环次数 + /// 创建时间 + /// 委托函数 + internal TimerExecutorMainThread(long tid, long duration, int loop, long createTime, Action delegateValue) : base(duration, loop, createTime, tid) + { + Delegates = delegateValue; + } + + protected override void xExecute() + { + try + { + Runner.StartCoroutine(Delegates); + } + catch (Exception e) + { + Debug.LogError("TimerExecutorEnumerator Execute Error: " + e); + } + } + } +} diff --git a/Runtime/Executor/TimerExecutor.MainThread.cs.meta b/Runtime/Executor/TimerExecutor.MainThread.cs.meta new file mode 100644 index 0000000..dee350b --- /dev/null +++ b/Runtime/Executor/TimerExecutor.MainThread.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 1778efca133b47d8a702f5ee786f1940 +timeCreated: 1719287387 \ No newline at end of file diff --git a/Runtime/Executor/TimerExecutor.cs b/Runtime/Executor/TimerExecutor.cs index 512c2cc..ea02b86 100644 --- a/Runtime/Executor/TimerExecutor.cs +++ b/Runtime/Executor/TimerExecutor.cs @@ -57,9 +57,9 @@ protected TimerExecutor(long duration, int loop, long createTime) protected long TID { get; set; } - internal int Loop { get; set; } + private int Loop { get; set; } - internal byte OperatorIndex { get; set; } + private byte OperatorIndex { get; set; } /// /// 获取当前时间 @@ -192,4 +192,4 @@ public void Execute() protected abstract void xExecute(); } -} \ No newline at end of file +} diff --git a/Runtime/Operator/ITimerOperator.cs b/Runtime/Operator/ITimerOperator.cs index 516c555..a29ad9c 100644 --- a/Runtime/Operator/ITimerOperator.cs +++ b/Runtime/Operator/ITimerOperator.cs @@ -7,6 +7,9 @@ namespace AIO { + /// + /// 定时器操作器 + /// public interface ITimerOperator : IDisposable { /// @@ -101,4 +104,4 @@ public interface ITimerOperator : IDisposable /// void ReceiveFromData(ITimerOperator @operator); } -} \ No newline at end of file +} diff --git a/Runtime/Operator/TimerOperator.Auto.cs b/Runtime/Operator/TimerOperator.Auto.cs index 7b9efd3..ce47d72 100644 --- a/Runtime/Operator/TimerOperator.Auto.cs +++ b/Runtime/Operator/TimerOperator.Auto.cs @@ -4,8 +4,8 @@ public class TimerOperatorAuto : TimerOperator { public TimerOperatorAuto() { } - public TimerOperatorAuto(byte index, long unit, long slotUnit, int maxCount = 2048) : base(index, unit, - slotUnit, maxCount) { } + public TimerOperatorAuto(byte index, long unit, long slotUnit, int maxCount = 2048) + : base(index, unit, slotUnit, maxCount) { } public override int BottomUpdate(long nowTime) { @@ -65,7 +65,7 @@ public override void OtherUpdate(long nowTime) if (EvolutionList.Count > 0) { - AllCount = AllCount - EvolutionList.Count; + AllCount -= EvolutionList.Count; TimerSystem.UpdateSlot(Index - 1, EvolutionList); } else @@ -74,4 +74,4 @@ public override void OtherUpdate(long nowTime) } } } -} \ No newline at end of file +} diff --git a/Runtime/Operator/TimerOperator.Consume.cs b/Runtime/Operator/TimerOperator.Consume.cs index 4b0bed9..f2fde82 100644 --- a/Runtime/Operator/TimerOperator.Consume.cs +++ b/Runtime/Operator/TimerOperator.Consume.cs @@ -12,15 +12,26 @@ namespace AIO /// internal class TimerOperatorConsume : TimerOperator { - private Action> DoneEvent; - private Action> EvolutionEvent; - private Action> LoopEvent; + /// + /// 完成事件 + /// + private readonly Action> EventDone; + + /// + /// 循环事件 + /// + private readonly Action> EventLoop; + + /// + /// 进化事件 + /// + private readonly Action> EventEvolution; public TimerOperatorConsume( ITimerOperator timerOperator, - Action> doneEvent, - Action> loopEvent, - Action> evolutionEvent) + Action> eventDone, + Action> eventLoop, + Action> eventEvolution) { Index = timerOperator.Index; Slot = timerOperator.Slot; @@ -32,9 +43,9 @@ public TimerOperatorConsume( TimersCache = timerOperator.TimersCache; Timers = timerOperator.Timers; - DoneEvent = doneEvent; - LoopEvent = loopEvent; - EvolutionEvent = evolutionEvent; + EventDone = eventDone; + EventLoop = eventLoop; + EventEvolution = eventEvolution; } public override int BottomUpdate(long nowTime) @@ -63,10 +74,10 @@ public override int BottomUpdate(long nowTime) } AllCount -= finishNumber; - if (LoopList.Count > 0) LoopEvent.Invoke(LoopList); + if (LoopList.Count > 0) EventLoop.Invoke(LoopList); else LoopList.Free(); - if (DoneList.Count > 0) DoneEvent.Invoke(DoneList); + if (DoneList.Count > 0) EventDone.Invoke(DoneList); else DoneList.Free(); return finishNumber; @@ -95,7 +106,7 @@ public override void OtherUpdate(long nowTime) if (EvolutionList.Count > 0) { AllCount -= EvolutionList.Count; - EvolutionEvent.Invoke(Index - 1, EvolutionList); + EventEvolution?.Invoke(Index - 1, EvolutionList); } else { @@ -103,4 +114,4 @@ public override void OtherUpdate(long nowTime) } } } -} \ No newline at end of file +} diff --git a/Runtime/Operator/TimerOperator.Loop.cs b/Runtime/Operator/TimerOperator.Loop.cs index 9136d10..4373c09 100644 --- a/Runtime/Operator/TimerOperator.Loop.cs +++ b/Runtime/Operator/TimerOperator.Loop.cs @@ -103,4 +103,4 @@ public override void OtherUpdate(long nowTime) } } } -} \ No newline at end of file +} diff --git a/Runtime/Properties.meta b/Runtime/Properties.meta new file mode 100644 index 0000000..77f0665 --- /dev/null +++ b/Runtime/Properties.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 4eacad78615c46689a8b32142ea4356d +timeCreated: 1719280434 \ No newline at end of file diff --git a/Runtime/Properties/AssemblyInfo.cs b/Runtime/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..e40cd38 --- /dev/null +++ b/Runtime/Properties/AssemblyInfo.cs @@ -0,0 +1,15 @@ +#region + +using System.Runtime.InteropServices; +using UnityEngine; +using UnityEngine.Scripting; + +#endregion + +[assembly: UnityAPICompatibilityVersion("2019.4.0", true)] +[assembly: Preserve] +#if UNITY_2018_3_OR_NEWER +[assembly: AlwaysLinkAssembly] +#endif + +[assembly: ComVisible(false)] diff --git a/Runtime/Properties/AssemblyInfo.cs.meta b/Runtime/Properties/AssemblyInfo.cs.meta new file mode 100644 index 0000000..51a7fa4 --- /dev/null +++ b/Runtime/Properties/AssemblyInfo.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: b312a953d5bd4b0d9a0fd5989fc73c03 +timeCreated: 1719280434 \ No newline at end of file diff --git a/Runtime/System/T4.meta b/Runtime/System/T4.meta new file mode 100644 index 0000000..cf6dc59 --- /dev/null +++ b/Runtime/System/T4.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 6bd040e792584a888aa2030fb39e6ee8 +timeCreated: 1719286682 \ No newline at end of file diff --git a/Runtime/System/T4/TimerSystem.Push.cs b/Runtime/System/T4/TimerSystem.Push.cs new file mode 100644 index 0000000..261a4e5 --- /dev/null +++ b/Runtime/System/T4/TimerSystem.Push.cs @@ -0,0 +1,383 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace AIO +{ + partial class TimerSystem + { + #region Push + + #region Push Func + + /// + /// 添加定时任务处理器 + /// + /// 键值 + /// 间隔时间 + /// 委托 + /// 0:循环 1:循环次数 + public static void Push(int key, long duration, Func delegateValue, ushort loop = 1) => + AddUpdate(new TimerExecutorEnumerator(key, duration, loop == 0 ? -1 : loop, Counter, delegateValue)); + + /// + /// 添加定时任务处理器 + /// + /// 键值 + /// 间隔时间 + /// 委托 + /// 0:循环 1:循环次数 + public static void Push(long key, long duration, Func delegateValue, ushort loop = 1) => + AddUpdate(new TimerExecutorEnumerator(key, duration, loop == 0 ? -1 : loop, Counter, delegateValue)); + + /// + /// 添加定时任务处理器 + /// + /// 键值 + /// 间隔时间 + /// 委托 + /// 0:循环 1:循环次数 + public static void Push(E key, long duration, Func delegateValue, ushort loop = 1) + where E : Enum => AddUpdate(new TimerExecutorEnumerator(key.GetHashCode(), duration, loop == 0 ? -1 : loop, Counter, delegateValue)); + + /// + /// 添加定时任务处理器 + /// + /// 键值 + /// 间隔时间 + /// 委托 + /// 0:循环 1:循环次数 + public static void Push(Guid key, long duration, Func delegateValue, ushort loop = 1) => + AddUpdate(new TimerExecutorEnumerator(key.GetHashCode(), duration, loop == 0 ? -1 : loop, Counter, delegateValue)); + + /// + /// 添加定时任务处理器 + /// + /// 键值 + /// 间隔时间 + /// 委托 + /// 0:循环 1:循环次数 + public static void Push(string key, long duration, Func delegateValue, ushort loop = 1) + { + if (string.IsNullOrEmpty(key)) return; + AddUpdate(new TimerExecutorEnumerator(key.GetHashCode(), duration, loop == 0 ? -1 : loop, Counter, delegateValue)); + } + + #endregion + + #region Push Action + + /// + /// 添加定时任务处理器 + /// + /// 键值 + /// 间隔时间 + /// 委托 + /// 0:循环 1:循环次数 + public static void Push(int key, long duration, Action delegateValue, ushort loop = 1) => + AddUpdate(new TimerExecutorAction(key, duration, loop == 0 ? -1 : loop, Counter, delegateValue)); + + /// + /// 添加定时任务处理器 + /// + /// 键值 + /// 间隔时间 + /// 委托 + /// 0:循环 1:循环次数 + public static void Push(long key, long duration, Action delegateValue, ushort loop = 1) => + AddUpdate(new TimerExecutorAction(key, duration, loop == 0 ? -1 : loop, Counter, delegateValue)); + + /// + /// 添加定时任务处理器 + /// + /// 键值 + /// 间隔时间 + /// 委托 + /// 0:循环 1:循环次数 + public static void Push(E key, long duration, Action delegateValue, ushort loop = 1) + where E : Enum => AddUpdate(new TimerExecutorAction(key.GetHashCode(), duration, loop == 0 ? -1 : loop, Counter, delegateValue)); + + /// + /// 添加定时任务处理器 + /// + /// 键值 + /// 间隔时间 + /// 委托 + /// 0:循环 1:循环次数 + public static void Push(Guid key, long duration, Action delegateValue, ushort loop = 1) => + AddUpdate(new TimerExecutorAction(key.GetHashCode(), duration, loop == 0 ? -1 : loop, Counter, delegateValue)); + + /// + /// 添加定时任务处理器 + /// + /// 键值 + /// 间隔时间 + /// 委托 + /// 0:循环 1:循环次数 + public static void Push(string key, long duration, Action delegateValue, ushort loop = 1) + { + if (string.IsNullOrEmpty(key)) return; + AddUpdate(new TimerExecutorAction(key.GetHashCode(), duration, loop == 0 ? -1 : loop, Counter, delegateValue)); + } + + #endregion + + #endregion + + #region PushOnce + + #region PushOnce Func + + /// + /// 添加定时任务处理器 + /// + /// (一次性) + /// 键值 + /// 间隔时间 + /// 委托 + public static void PushOnce(int key, long duration, Func delegateValue) => + AddUpdate(new TimerExecutorEnumerator(key, duration, 1, Counter, delegateValue)); + + /// + /// 添加定时任务处理器 + /// + /// (一次性) + /// 键值 + /// 间隔时间 + /// 委托 + public static void PushOnce(long key, long duration, Func delegateValue) => + AddUpdate(new TimerExecutorEnumerator(key, duration, 1, Counter, delegateValue)); + + /// + /// 添加定时任务处理器 + /// + /// (一次性) + /// 键值 + /// 间隔时间 + /// 委托 + public static void PushOnce(E key, long duration, Func delegateValue) + where E : Enum => AddUpdate(new TimerExecutorEnumerator(key.GetHashCode(), duration, 1, Counter, delegateValue)); + + /// + /// 添加定时任务处理器 + /// + /// (一次性) + /// 键值 + /// 间隔时间 + /// 委托 + public static void PushOnce(Guid key, long duration, Func delegateValue) => + AddUpdate(new TimerExecutorEnumerator(key.GetHashCode(), duration, 1, Counter, delegateValue)); + + /// + /// 添加定时任务处理器 + /// + /// (一次性) + /// 键值 + /// 间隔时间 + /// 委托 + public static void PushOnce(string key, long duration, Func delegateValue) + { + if (string.IsNullOrEmpty(key)) return; + AddUpdate(new TimerExecutorEnumerator(key.GetHashCode(), duration, 1, Counter, delegateValue)); + } + + /// + /// 添加定时任务处理器 + /// + /// (一次性)(无键值) + /// 间隔时间 + /// 委托 + public static void PushOnce(long duration, Func delegateValue) => + AddUpdate(new TimerExecutorEnumerator(duration, 1, Counter, delegateValue)); + + #endregion + + #region PushOnce Action + + /// + /// 添加定时任务处理器 + /// + /// (一次性) + /// 键值 + /// 间隔时间 + /// 委托 + public static void PushOnce(int key, long duration, Action delegateValue) => + AddUpdate(new TimerExecutorAction(key, duration, 1, Counter, delegateValue)); + + /// + /// 添加定时任务处理器 + /// + /// (一次性) + /// 键值 + /// 间隔时间 + /// 委托 + public static void PushOnce(long key, long duration, Action delegateValue) => + AddUpdate(new TimerExecutorAction(key, duration, 1, Counter, delegateValue)); + + /// + /// 添加定时任务处理器 + /// + /// (一次性) + /// 键值 + /// 间隔时间 + /// 委托 + public static void PushOnce(E key, long duration, Action delegateValue) + where E : Enum => AddUpdate(new TimerExecutorAction(key.GetHashCode(), duration, 1, Counter, delegateValue)); + + /// + /// 添加定时任务处理器 + /// + /// (一次性) + /// 键值 + /// 间隔时间 + /// 委托 + public static void PushOnce(Guid key, long duration, Action delegateValue) => + AddUpdate(new TimerExecutorAction(key.GetHashCode(), duration, 1, Counter, delegateValue)); + + /// + /// 添加定时任务处理器 + /// + /// (一次性) + /// 键值 + /// 间隔时间 + /// 委托 + public static void PushOnce(string key, long duration, Action delegateValue) + { + if (string.IsNullOrEmpty(key)) return; + AddUpdate(new TimerExecutorAction(key.GetHashCode(), duration, 1, Counter, delegateValue)); + } + + /// + /// 添加定时任务处理器 + /// + /// (一次性)(无键值) + /// 间隔时间 + /// 委托 + public static void PushOnce(long duration, Action delegateValue) => + AddUpdate(new TimerExecutorAction(duration, 1, Counter, delegateValue)); + + #endregion + + #endregion + + #region PushLoop + + #region PushLoop Func + + /// + /// 添加定时任务处理器 + /// + /// (循环) + /// 键值 + /// 间隔时间 + /// 委托 + public static void PushLoop(int key, long duration, Func delegateValue) => + AddUpdate(new TimerExecutorEnumerator(key, duration, -1, Counter, delegateValue)); + + /// + /// 添加定时任务处理器 + /// + /// (循环) + /// 键值 + /// 间隔时间 + /// 委托 + public static void PushLoop(long key, long duration, Func delegateValue) => + AddUpdate(new TimerExecutorEnumerator(key, duration, -1, Counter, delegateValue)); + + /// + /// 添加定时任务处理器 + /// + /// (循环) + /// 键值 + /// 间隔时间 + /// 委托 + public static void PushLoop(E key, long duration, Func delegateValue) + where E : Enum => AddUpdate(new TimerExecutorEnumerator(key.GetHashCode(), duration, -1, Counter, delegateValue)); + + /// + /// 添加定时任务处理器 + /// + /// (循环) + /// 键值 + /// 间隔时间 + /// 委托 + public static void PushLoop(Guid key, long duration, Func delegateValue) => + AddUpdate(new TimerExecutorEnumerator(key.GetHashCode(), duration, -1, Counter, delegateValue)); + + /// + /// 添加定时任务处理器 + /// + /// (循环) + /// 键值 + /// 间隔时间 + /// 委托 + public static void PushLoop(string key, long duration, Func delegateValue) + { + if (string.IsNullOrEmpty(key)) return; + AddUpdate(new TimerExecutorEnumerator(key.GetHashCode(), duration, -1, Counter, delegateValue)); + } + + #endregion + + #region PushLoop Action + + /// + /// 添加定时任务处理器 + /// + /// (循环) + /// 键值 + /// 间隔时间 + /// 委托 + public static void PushLoop(int key, long duration, Action delegateValue) => + AddUpdate(new TimerExecutorAction(key, duration, -1, Counter, delegateValue)); + + /// + /// 添加定时任务处理器 + /// + /// (循环) + /// 键值 + /// 间隔时间 + /// 委托 + public static void PushLoop(long key, long duration, Action delegateValue) => + AddUpdate(new TimerExecutorAction(key, duration, -1, Counter, delegateValue)); + + /// + /// 添加定时任务处理器 + /// + /// (循环) + /// 键值 + /// 间隔时间 + /// 委托 + public static void PushLoop(E key, long duration, Action delegateValue) + where E : Enum => AddUpdate(new TimerExecutorAction(key.GetHashCode(), duration, -1, Counter, delegateValue)); + + /// + /// 添加定时任务处理器 + /// + /// (循环) + /// 键值 + /// 间隔时间 + /// 委托 + public static void PushLoop(Guid key, long duration, Action delegateValue) => + AddUpdate(new TimerExecutorAction(key.GetHashCode(), duration, -1, Counter, delegateValue)); + + /// + /// 添加定时任务处理器 + /// + /// (循环) + /// 键值 + /// 间隔时间 + /// 委托 + public static void PushLoop(string key, long duration, Action delegateValue) + { + if (string.IsNullOrEmpty(key)) return; + AddUpdate(new TimerExecutorAction(key.GetHashCode(), duration, -1, Counter, delegateValue)); + } + + #endregion + + #endregion + + } +} diff --git a/Runtime/System/T4/TimerSystem.Push.cs.meta b/Runtime/System/T4/TimerSystem.Push.cs.meta new file mode 100644 index 0000000..997188d --- /dev/null +++ b/Runtime/System/T4/TimerSystem.Push.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: dc56134102feeb742be2964374d8d114 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/System/T4/TimerSystem.Push.tt b/Runtime/System/T4/TimerSystem.Push.tt new file mode 100644 index 0000000..1b7ac26 --- /dev/null +++ b/Runtime/System/T4/TimerSystem.Push.tt @@ -0,0 +1,173 @@ +<#@ template language="C#" #> +<#@ import namespace="System.Text" #> +<#@ import namespace="System.Collections.Generic" #> +<#@ import namespace="System.Linq" #> +<# + var SummaryPush = """ + /// + /// 添加定时任务处理器 + /// + /// 键值 + /// 间隔时间 + /// 委托 + /// 0:循环 1:循环次数 + """; + var SummaryPushOnce = """ + /// + /// 添加定时任务处理器 + /// + /// (一次性) + /// 键值 + /// 间隔时间 + /// 委托 + """; + var SummaryPushOnceNoKey = """ + /// + /// 添加定时任务处理器 + /// + /// (一次性)(无键值) + /// 间隔时间 + /// 委托 + """; + var SummaryPushLoop = """ + /// + /// 添加定时任务处理器 + /// + /// (循环) + /// 键值 + /// 间隔时间 + /// 委托 + """; + var dic = new Dictionary(); + dic["Func"] = "TimerExecutorEnumerator"; + dic["Action"] = "TimerExecutorAction"; +#> +using System; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace AIO +{ + partial class TimerSystem + { + #region Push +<# + foreach (var pair in dic) + { +#> + + #region Push <#=pair.Key#> + + <#=SummaryPush#> + public static void Push(int key, long duration, <#=pair.Key#> delegateValue, ushort loop = 1) => + AddUpdate(new <#=pair.Value#>(key, duration, loop == 0 ? -1 : loop, Counter, delegateValue)); + + <#=SummaryPush#> + public static void Push(long key, long duration, <#=pair.Key#> delegateValue, ushort loop = 1) => + AddUpdate(new <#=pair.Value#>(key, duration, loop == 0 ? -1 : loop, Counter, delegateValue)); + + <#=SummaryPush#> + public static void Push(E key, long duration, <#=pair.Key#> delegateValue, ushort loop = 1) + where E : Enum => AddUpdate(new <#=pair.Value#>(key.GetHashCode(), duration, loop == 0 ? -1 : loop, Counter, delegateValue)); + + <#=SummaryPush#> + public static void Push(Guid key, long duration, <#=pair.Key#> delegateValue, ushort loop = 1) => + AddUpdate(new <#=pair.Value#>(key.GetHashCode(), duration, loop == 0 ? -1 : loop, Counter, delegateValue)); + + <#=SummaryPush#> + public static void Push(string key, long duration, <#=pair.Key#> delegateValue, ushort loop = 1) + { + if (string.IsNullOrEmpty(key)) return; + AddUpdate(new <#=pair.Value#>(key.GetHashCode(), duration, loop == 0 ? -1 : loop, Counter, delegateValue)); + } + + #endregion +<# + } +#> + + #endregion + + #region PushOnce +<# + foreach (var pair in dic) + { +#> + + #region PushOnce <#=pair.Key#> + + <#=SummaryPushOnce#> + public static void PushOnce(int key, long duration, <#=pair.Key#> delegateValue) => + AddUpdate(new <#=pair.Value#>(key, duration, 1, Counter, delegateValue)); + + <#=SummaryPushOnce#> + public static void PushOnce(long key, long duration, <#=pair.Key#> delegateValue) => + AddUpdate(new <#=pair.Value#>(key, duration, 1, Counter, delegateValue)); + + <#=SummaryPushOnce#> + public static void PushOnce(E key, long duration, <#=pair.Key#> delegateValue) + where E : Enum => AddUpdate(new <#=pair.Value#>(key.GetHashCode(), duration, 1, Counter, delegateValue)); + + <#=SummaryPushOnce#> + public static void PushOnce(Guid key, long duration, <#=pair.Key#> delegateValue) => + AddUpdate(new <#=pair.Value#>(key.GetHashCode(), duration, 1, Counter, delegateValue)); + + <#=SummaryPushOnce#> + public static void PushOnce(string key, long duration, <#=pair.Key#> delegateValue) + { + if (string.IsNullOrEmpty(key)) return; + AddUpdate(new <#=pair.Value#>(key.GetHashCode(), duration, 1, Counter, delegateValue)); + } + + <#=SummaryPushOnceNoKey#> + public static void PushOnce(long duration, <#=pair.Key#> delegateValue) => + AddUpdate(new <#=pair.Value#>(duration, 1, Counter, delegateValue)); + + #endregion +<# + } +#> + + #endregion + + #region PushLoop +<# + foreach (var pair in dic) + { +#> + + #region PushLoop <#=pair.Key#> + + <#=SummaryPushLoop#> + public static void PushLoop(int key, long duration, <#=pair.Key#> delegateValue) => + AddUpdate(new <#=pair.Value#>(key, duration, -1, Counter, delegateValue)); + + <#=SummaryPushLoop#> + public static void PushLoop(long key, long duration, <#=pair.Key#> delegateValue) => + AddUpdate(new <#=pair.Value#>(key, duration, -1, Counter, delegateValue)); + + <#=SummaryPushLoop#> + public static void PushLoop(E key, long duration, <#=pair.Key#> delegateValue) + where E : Enum => AddUpdate(new <#=pair.Value#>(key.GetHashCode(), duration, -1, Counter, delegateValue)); + + <#=SummaryPushLoop#> + public static void PushLoop(Guid key, long duration, <#=pair.Key#> delegateValue) => + AddUpdate(new <#=pair.Value#>(key.GetHashCode(), duration, -1, Counter, delegateValue)); + + <#=SummaryPushLoop#> + public static void PushLoop(string key, long duration, <#=pair.Key#> delegateValue) + { + if (string.IsNullOrEmpty(key)) return; + AddUpdate(new <#=pair.Value#>(key.GetHashCode(), duration, -1, Counter, delegateValue)); + } + + #endregion +<# + } +#> + + #endregion + + } +} diff --git a/Runtime/System/T4/TimerSystem.Push.tt.meta b/Runtime/System/T4/TimerSystem.Push.tt.meta new file mode 100644 index 0000000..68254e5 --- /dev/null +++ b/Runtime/System/T4/TimerSystem.Push.tt.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 05f5505bf4974adca0c2a3291a9b6634 +timeCreated: 1719286720 \ No newline at end of file diff --git a/Runtime/System/T4/TimerSystem.PushMain.cs b/Runtime/System/T4/TimerSystem.PushMain.cs new file mode 100644 index 0000000..6c3b3f3 --- /dev/null +++ b/Runtime/System/T4/TimerSystem.PushMain.cs @@ -0,0 +1,202 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace AIO +{ + partial class TimerSystem + { + #region Push + + #region PushMain Action + + /// + /// 添加定时任务处理器 + /// + /// 键值 + /// 间隔时间 + /// 委托 + /// 0:循环 1:循环次数 + public static void PushMain(int key, long duration, Action delegateValue, ushort loop = 1) => + AddUpdate(new TimerExecutorMainThread(key, duration, loop == 0 ? -1 : loop, Counter, delegateValue)); + + /// + /// 添加定时任务处理器 + /// + /// 键值 + /// 间隔时间 + /// 委托 + /// 0:循环 1:循环次数 + public static void PushMain(long key, long duration, Action delegateValue, ushort loop = 1) => + AddUpdate(new TimerExecutorMainThread(key, duration, loop == 0 ? -1 : loop, Counter, delegateValue)); + + /// + /// 添加定时任务处理器 + /// + /// 键值 + /// 间隔时间 + /// 委托 + /// 0:循环 1:循环次数 + public static void PushMain(E key, long duration, Action delegateValue, ushort loop = 1) + where E : Enum => AddUpdate(new TimerExecutorMainThread(key.GetHashCode(), duration, loop == 0 ? -1 : loop, Counter, delegateValue)); + + /// + /// 添加定时任务处理器 + /// + /// 键值 + /// 间隔时间 + /// 委托 + /// 0:循环 1:循环次数 + public static void PushMain(Guid key, long duration, Action delegateValue, ushort loop = 1) => + AddUpdate(new TimerExecutorMainThread(key.GetHashCode(), duration, loop == 0 ? -1 : loop, Counter, delegateValue)); + + /// + /// 添加定时任务处理器 + /// + /// 键值 + /// 间隔时间 + /// 委托 + /// 0:循环 1:循环次数 + public static void PushMain(string key, long duration, Action delegateValue, ushort loop = 1) + { + if (string.IsNullOrEmpty(key)) return; + AddUpdate(new TimerExecutorMainThread(key.GetHashCode(), duration, loop == 0 ? -1 : loop, Counter, delegateValue)); + } + + #endregion + + #endregion + + #region PushOnce + + #region PushOnce Action + + /// + /// 添加定时任务处理器 + /// + /// (一次性) + /// 键值 + /// 间隔时间 + /// 委托 + public static void PushOnceMain(int key, long duration, Action delegateValue) => + AddUpdate(new TimerExecutorMainThread(key, duration, 1, Counter, delegateValue)); + + /// + /// 添加定时任务处理器 + /// + /// (一次性) + /// 键值 + /// 间隔时间 + /// 委托 + public static void PushOnceMain(long key, long duration, Action delegateValue) => + AddUpdate(new TimerExecutorMainThread(key, duration, 1, Counter, delegateValue)); + + /// + /// 添加定时任务处理器 + /// + /// (一次性) + /// 键值 + /// 间隔时间 + /// 委托 + public static void PushOnceMain(E key, long duration, Action delegateValue) + where E : Enum => AddUpdate(new TimerExecutorMainThread(key.GetHashCode(), duration, 1, Counter, delegateValue)); + + /// + /// 添加定时任务处理器 + /// + /// (一次性) + /// 键值 + /// 间隔时间 + /// 委托 + public static void PushOnceMain(Guid key, long duration, Action delegateValue) => + AddUpdate(new TimerExecutorMainThread(key.GetHashCode(), duration, 1, Counter, delegateValue)); + + /// + /// 添加定时任务处理器 + /// + /// (一次性) + /// 键值 + /// 间隔时间 + /// 委托 + public static void PushOnceMain(string key, long duration, Action delegateValue) + { + if (string.IsNullOrEmpty(key)) return; + AddUpdate(new TimerExecutorMainThread(key.GetHashCode(), duration, 1, Counter, delegateValue)); + } + + /// + /// 添加定时任务处理器 + /// + /// (一次性)(无键值) + /// 间隔时间 + /// 委托 + public static void PushOnceMain(long duration, Action delegateValue) => + AddUpdate(new TimerExecutorMainThread(duration, 1, Counter, delegateValue)); + + #endregion + + #endregion + + #region PushLoop + + #region PushLoop Action + + /// + /// 添加定时任务处理器 + /// + /// (循环) + /// 键值 + /// 间隔时间 + /// 委托 + public static void PushLoopMain(int key, long duration, Action delegateValue) => + AddUpdate(new TimerExecutorMainThread(key, duration, -1, Counter, delegateValue)); + + /// + /// 添加定时任务处理器 + /// + /// (循环) + /// 键值 + /// 间隔时间 + /// 委托 + public static void PushLoopMain(long key, long duration, Action delegateValue) => + AddUpdate(new TimerExecutorMainThread(key, duration, -1, Counter, delegateValue)); + + /// + /// 添加定时任务处理器 + /// + /// (循环) + /// 键值 + /// 间隔时间 + /// 委托 + public static void PushLoopMain(E key, long duration, Action delegateValue) + where E : Enum => AddUpdate(new TimerExecutorMainThread(key.GetHashCode(), duration, -1, Counter, delegateValue)); + + /// + /// 添加定时任务处理器 + /// + /// (循环) + /// 键值 + /// 间隔时间 + /// 委托 + public static void PushLoopMain(Guid key, long duration, Action delegateValue) => + AddUpdate(new TimerExecutorMainThread(key.GetHashCode(), duration, -1, Counter, delegateValue)); + + /// + /// 添加定时任务处理器 + /// + /// (循环) + /// 键值 + /// 间隔时间 + /// 委托 + public static void PushLoopMain(string key, long duration, Action delegateValue) + { + if (string.IsNullOrEmpty(key)) return; + AddUpdate(new TimerExecutorMainThread(key.GetHashCode(), duration, -1, Counter, delegateValue)); + } + + #endregion + + #endregion + } +} diff --git a/Runtime/System/T4/TimerSystem.PushMain.cs.meta b/Runtime/System/T4/TimerSystem.PushMain.cs.meta new file mode 100644 index 0000000..d62ac8f --- /dev/null +++ b/Runtime/System/T4/TimerSystem.PushMain.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 0b57348046747f241a3cc76bc1468da4 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/System/T4/TimerSystem.PushMain.tt b/Runtime/System/T4/TimerSystem.PushMain.tt new file mode 100644 index 0000000..afbdcf1 --- /dev/null +++ b/Runtime/System/T4/TimerSystem.PushMain.tt @@ -0,0 +1,171 @@ +<#@ template language="C#" #> +<#@ import namespace="System.Text" #> +<#@ import namespace="System.Collections.Generic" #> +<#@ import namespace="System.Linq" #> +<# + var SummaryPush = """ + /// + /// 添加定时任务处理器 + /// + /// 键值 + /// 间隔时间 + /// 委托 + /// 0:循环 1:循环次数 + """; + var SummaryPushOnce = """ + /// + /// 添加定时任务处理器 + /// + /// (一次性) + /// 键值 + /// 间隔时间 + /// 委托 + """; + var SummaryPushOnceNoKey = """ + /// + /// 添加定时任务处理器 + /// + /// (一次性)(无键值) + /// 间隔时间 + /// 委托 + """; + var SummaryPushLoop = """ + /// + /// 添加定时任务处理器 + /// + /// (循环) + /// 键值 + /// 间隔时间 + /// 委托 + """; + var dic = new Dictionary(); + dic["Action"] = "TimerExecutorMainThread"; +#> +using System; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace AIO +{ + partial class TimerSystem + { + #region Push +<# + foreach (var pair in dic) + { +#> + + #region PushMain <#= pair.Key #> + + <#= SummaryPush #> + public static void PushMain(int key, long duration, <#= pair.Key #> delegateValue, ushort loop = 1) => + AddUpdate(new <#= pair.Value #>(key, duration, loop == 0 ? -1 : loop, Counter, delegateValue)); + + <#= SummaryPush #> + public static void PushMain(long key, long duration, <#= pair.Key #> delegateValue, ushort loop = 1) => + AddUpdate(new <#= pair.Value #>(key, duration, loop == 0 ? -1 : loop, Counter, delegateValue)); + + <#= SummaryPush #> + public static void PushMain(E key, long duration, <#= pair.Key #> delegateValue, ushort loop = 1) + where E : Enum => AddUpdate(new <#= pair.Value #>(key.GetHashCode(), duration, loop == 0 ? -1 : loop, Counter, delegateValue)); + + <#= SummaryPush #> + public static void PushMain(Guid key, long duration, <#= pair.Key #> delegateValue, ushort loop = 1) => + AddUpdate(new <#= pair.Value #>(key.GetHashCode(), duration, loop == 0 ? -1 : loop, Counter, delegateValue)); + + <#= SummaryPush #> + public static void PushMain(string key, long duration, <#= pair.Key #> delegateValue, ushort loop = 1) + { + if (string.IsNullOrEmpty(key)) return; + AddUpdate(new <#= pair.Value #>(key.GetHashCode(), duration, loop == 0 ? -1 : loop, Counter, delegateValue)); + } + + #endregion +<# + } +#> + + #endregion + + #region PushOnce +<# + foreach (var pair in dic) + { +#> + + #region PushOnce <#= pair.Key #> + + <#= SummaryPushOnce #> + public static void PushOnceMain(int key, long duration, <#= pair.Key #> delegateValue) => + AddUpdate(new <#= pair.Value #>(key, duration, 1, Counter, delegateValue)); + + <#= SummaryPushOnce #> + public static void PushOnceMain(long key, long duration, <#= pair.Key #> delegateValue) => + AddUpdate(new <#= pair.Value #>(key, duration, 1, Counter, delegateValue)); + + <#= SummaryPushOnce #> + public static void PushOnceMain(E key, long duration, <#= pair.Key #> delegateValue) + where E : Enum => AddUpdate(new <#= pair.Value #>(key.GetHashCode(), duration, 1, Counter, delegateValue)); + + <#= SummaryPushOnce #> + public static void PushOnceMain(Guid key, long duration, <#= pair.Key #> delegateValue) => + AddUpdate(new <#= pair.Value #>(key.GetHashCode(), duration, 1, Counter, delegateValue)); + + <#= SummaryPushOnce #> + public static void PushOnceMain(string key, long duration, <#= pair.Key #> delegateValue) + { + if (string.IsNullOrEmpty(key)) return; + AddUpdate(new <#= pair.Value #>(key.GetHashCode(), duration, 1, Counter, delegateValue)); + } + + <#= SummaryPushOnceNoKey #> + public static void PushOnceMain(long duration, <#= pair.Key #> delegateValue) => + AddUpdate(new <#= pair.Value #>(duration, 1, Counter, delegateValue)); + + #endregion +<# + } +#> + + #endregion + + #region PushLoop +<# + foreach (var pair in dic) + { +#> + + #region PushLoop <#= pair.Key #> + + <#= SummaryPushLoop #> + public static void PushLoopMain(int key, long duration, <#= pair.Key #> delegateValue) => + AddUpdate(new <#= pair.Value #>(key, duration, -1, Counter, delegateValue)); + + <#= SummaryPushLoop #> + public static void PushLoopMain(long key, long duration, <#= pair.Key #> delegateValue) => + AddUpdate(new <#= pair.Value #>(key, duration, -1, Counter, delegateValue)); + + <#= SummaryPushLoop #> + public static void PushLoopMain(E key, long duration, <#= pair.Key #> delegateValue) + where E : Enum => AddUpdate(new <#= pair.Value #>(key.GetHashCode(), duration, -1, Counter, delegateValue)); + + <#= SummaryPushLoop #> + public static void PushLoopMain(Guid key, long duration, <#= pair.Key #> delegateValue) => + AddUpdate(new <#= pair.Value #>(key.GetHashCode(), duration, -1, Counter, delegateValue)); + + <#= SummaryPushLoop #> + public static void PushLoopMain(string key, long duration, <#= pair.Key #> delegateValue) + { + if (string.IsNullOrEmpty(key)) return; + AddUpdate(new <#= pair.Value #>(key.GetHashCode(), duration, -1, Counter, delegateValue)); + } + + #endregion +<# + } +#> + + #endregion + } +} diff --git a/Runtime/System/T4/TimerSystem.PushMain.tt.meta b/Runtime/System/T4/TimerSystem.PushMain.tt.meta new file mode 100644 index 0000000..5c71b16 --- /dev/null +++ b/Runtime/System/T4/TimerSystem.PushMain.tt.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 0e7d615d0fbf4cc3af693fd12fcaa5c0 +timeCreated: 1719296440 \ No newline at end of file diff --git a/Runtime/System/TimerSystem.Add.cs b/Runtime/System/TimerSystem.Add.cs index 4295f81..d018b32 100644 --- a/Runtime/System/TimerSystem.Add.cs +++ b/Runtime/System/TimerSystem.Add.cs @@ -38,7 +38,7 @@ internal static void UpdateSlot(int index, List timer) #region Add - private static void AddUpdate(ITimerExecutor timer) + private static ITimerExecutor AddUpdate(ITimerExecutor timer) { for (byte i = 0; i < TimingUnits.Count - 1; i++) { @@ -53,7 +53,7 @@ private static void AddUpdate(ITimerExecutor timer) if (TimerSystemSettings.EnableLoopThread && timer.Loop == -1) { LoopContainer.PushUpdate(timer); - return; + return timer; } if (RemainNum >= Capacity) @@ -72,12 +72,13 @@ private static void AddUpdate(ITimerExecutor timer) AddLoop(timer); RemainNum = RemainNum + 1; + return timer; } /// /// 添加定时任务处理器 /// - internal static void AddLoop(ITimerExecutor timer) + private static void AddLoop(ITimerExecutor timer) { lock (MainList) { @@ -125,4 +126,4 @@ internal static void AddLoop(List timers) #endregion } -} \ No newline at end of file +} diff --git a/Runtime/System/TimerSystem.Compatible.cs b/Runtime/System/TimerSystem.Compatible.cs deleted file mode 100644 index 51188e8..0000000 --- a/Runtime/System/TimerSystem.Compatible.cs +++ /dev/null @@ -1,155 +0,0 @@ -#region - -using System; -using System.Collections; - -#endregion - -namespace AIO -{ - partial class TimerSystem - { - /// - /// 取出循环任务 - /// - public static void Pop(long tid) - { - if (!TimerExecutors.ContainsKey(tid)) return; - TimerExecutors[tid].Loop = -2; - TimerExecutors.Remove(tid); - } - - /// - /// 取出循环任务 - /// - public static void Pop(string tidstrtiding) - { - var tid = tidstrtiding.GetHashCode(); - if (TimerExecutors.ContainsKey(tid)) - { - TimerExecutors[tid].Loop = -2; - TimerExecutors.Remove(tid); - } - } - - /// - /// 判断任务是否存在 - /// - public static bool Exist(long tid) - { - return TimerExecutors.ContainsKey(tid); - } - - /// - /// 判断任务是否存在 - /// - public static bool Exist(string tid) - { - return TimerExecutors.ContainsKey(tid.GetHashCode()); - } - - #region Timer Executor Enumerator - - /// - /// 添加定时任务处理器 - /// - public static void Push(long duration, Func delegateValue) - { - AddUpdate(new TimerExecutorEnumerator(duration, 1, Counter, delegateValue)); - } - - /// - /// 添加定时任务处理器 - /// - public static void PushLoop(long duration, Func delegateValue) - { - AddUpdate(new TimerExecutorEnumerator(duration, -1, Counter, delegateValue)); - } - - /// - /// 添加定时任务处理器 是否循环 0循环 1循环次数 - /// - public static void Push(long duration, ushort loop, Func delegateValue) - { - AddUpdate(new TimerExecutorEnumerator(duration, loop == 0 ? -1 : loop, Counter, delegateValue)); - } - - /// - /// 添加定时任务处理器 是否循环 0循环 1循环次数 - /// - public static void Push(long duration, byte loop, Func delegateValue) - { - AddUpdate(new TimerExecutorEnumerator(duration, loop == 0 ? -1 : loop, Counter, delegateValue)); - } - - #endregion - - #region Timer Executor Action - - /// - /// 添加定时任务处理器 - /// - public static void Push(long duration, Action delegateValue) - { - AddUpdate(new TimerExecutorAction(duration, 1, Counter, delegateValue)); - } - - /// - /// 添加定时任务处理器 - /// - public static void Push(long tid, long duration, Action delegateValue) - { - AddUpdate(new TimerExecutorAction(tid, duration, 1, Counter, delegateValue)); - } - - /// - /// 添加定时任务处理器 - /// - public static void Push(string tid, long duration, Action delegateValue) - { - AddUpdate(new TimerExecutorAction(tid.GetHashCode(), duration, 1, Counter, delegateValue)); - } - - /// - /// 添加定时任务处理器 - /// - public static void PushLoop(long duration, Action delegateValue) - { - AddUpdate(new TimerExecutorAction(duration, -1, Counter, delegateValue)); - } - - /// - /// 添加定时任务处理器 - /// - public static void PushLoop(long tid, long duration, Action delegateValue) - { - AddUpdate(new TimerExecutorAction(tid, duration, -1, Counter, delegateValue)); - } - - /// - /// 添加定时任务处理器 - /// - public static void PushLoop(string tid, long duration, Action delegateValue) - { - AddUpdate(new TimerExecutorAction(tid.GetHashCode(), duration, -1, Counter, delegateValue)); - } - - /// - /// 添加定时任务处理器 是否循环 0循环 1循环次数 - /// - public static void Push(long duration, ushort loop, Action delegateValue) - { - AddUpdate(new TimerExecutorAction(duration, loop == 0 ? -1 : loop, Counter, delegateValue)); - } - - /// - /// 添加定时任务处理器 是否循环 0循环 1循环次数 - /// - public static void Push(long duration, byte loop, Action delegateValue) - { - AddUpdate(new TimerExecutorAction(duration, loop == 0 ? -1 : loop, Counter, delegateValue)); - } - - #endregion - } -} \ No newline at end of file diff --git a/Runtime/System/TimerSystem.Compatible.cs.meta b/Runtime/System/TimerSystem.Compatible.cs.meta deleted file mode 100644 index 8019582..0000000 --- a/Runtime/System/TimerSystem.Compatible.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 6d7e68ed03c14deeb92a1b3ec445842e -timeCreated: 1688913518 \ No newline at end of file diff --git a/Runtime/System/TimerSystem.Exist.cs b/Runtime/System/TimerSystem.Exist.cs new file mode 100644 index 0000000..bd73861 --- /dev/null +++ b/Runtime/System/TimerSystem.Exist.cs @@ -0,0 +1,26 @@ +#region + +using System; + +#endregion + +namespace AIO +{ + partial class TimerSystem + { + /// + /// 判断任务是否存在 + /// + public static bool Exist(long key) { return TimerExecutors.ContainsKey(key); } + + /// + /// 判断任务是否存在 + /// + public static bool Exist(string key) { return TimerExecutors.ContainsKey(key.GetHashCode()); } + + /// + /// 判断任务是否存在 + /// + public static bool Exist(E key) where E : Enum { return TimerExecutors.ContainsKey(key.GetHashCode()); } + } +} diff --git a/Runtime/System/TimerSystem.Exist.cs.meta b/Runtime/System/TimerSystem.Exist.cs.meta new file mode 100644 index 0000000..bf81629 --- /dev/null +++ b/Runtime/System/TimerSystem.Exist.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 613a9b3745ed4b5fa6b7e214747903e6 +timeCreated: 1719285275 \ No newline at end of file diff --git a/Runtime/System/TimerSystem.Pop.cs b/Runtime/System/TimerSystem.Pop.cs new file mode 100644 index 0000000..d2f6486 --- /dev/null +++ b/Runtime/System/TimerSystem.Pop.cs @@ -0,0 +1,39 @@ +#region + +using System; +using System.Collections; + +#endregion + +namespace AIO +{ + partial class TimerSystem + { + /// + /// 取出循环任务 + /// + /// 任务ID + public static void Pop(long key) + { + if (!TimerExecutors.TryGetValue(key, out var executor)) return; + executor.Loop = -2; + TimerExecutors.Remove(key); + } + + /// + /// 取出循环任务 + /// + /// 任务ID + public static void Pop(string key) + { + if (string.IsNullOrEmpty(key)) return; + Pop(key.GetHashCode()); + } + + /// + /// 取出循环任务 + /// + /// 任务ID + public static void Pop(E key) where E : Enum { Pop(key.GetHashCode()); } + } +} diff --git a/Runtime/System/TimerSystem.Pop.cs.meta b/Runtime/System/TimerSystem.Pop.cs.meta new file mode 100644 index 0000000..57438b9 --- /dev/null +++ b/Runtime/System/TimerSystem.Pop.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 80102914ddf64293996c7c38ca5e65f0 +timeCreated: 1719285244 \ No newline at end of file diff --git a/Runtime/System/TimerSystemSettings.cs b/Runtime/System/TimerSystemSettings.cs index 7eb639a..79cd3b2 100644 --- a/Runtime/System/TimerSystemSettings.cs +++ b/Runtime/System/TimerSystemSettings.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using UnityEngine; namespace AIO { @@ -66,4 +67,4 @@ public static void Min(ICollection<(long, long, long)> units) public static void Second(ICollection<(long, long, long)> units) { units.Add((Unit.Time.MS_SECOND, DistanceUnit, Unit.Time.MS_SECOND / DistanceUnit)); } } -} \ No newline at end of file +} From 56eaa2442f258abb0621f8cd42d5b7905c76d146 Mon Sep 17 00:00:00 2001 From: Star fire Date: Tue, 25 Jun 2024 15:49:35 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E2=9C=A8=20up=20version=201.x=20->=201.0.1?= =?UTF-8?q?-preview?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 8ca7adc..e139ed5 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "com.aio.timer", "displayName": "AIO Unity Timer", "description": "unity3d timer system", - "version": "1.0.0-preview", + "version": "1.0.1-preview", "unity": "2019.4", "category": "Runtime", "unityRelease": "0f1", @@ -15,7 +15,7 @@ "url": "https://github.com/AIO-GAME/Unity.Timer.git" }, "relatedPackages": { - "com.aio.runner": "1.0.0-preview" + "com.aio.runner": "1.0.2-preview" }, "keywords": [ "timing wheel",