https://github.com/aio-game/unity.timer
✨ Unity High Efficiency Timer ✨
https://github.com/aio-game/unity.timer
timer unity
Last synced: about 1 year ago
JSON representation
✨ Unity High Efficiency Timer ✨
- Host: GitHub
- URL: https://github.com/aio-game/unity.timer
- Owner: AIO-GAME
- License: mit
- Created: 2024-06-08T00:59:04.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-12-13T02:38:00.000Z (over 1 year ago)
- Last Synced: 2024-12-13T03:28:18.537Z (over 1 year ago)
- Topics: timer, unity
- Language: C#
- Homepage:
- Size: 190 KB
- Stars: 5
- Watchers: 0
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: .github/README.md
- Contributing: .github/CONTRIBUTING
- License: LICENSE.md
- Code of conduct: .github/CODE_OF_CONDUCT.md
- Security: .github/SECURITY.md
Awesome Lists containing this project
README
Unity Timer
English | 简体中文
## ⚙ 安装
Packages Manifest
````json
{
"dependencies": {
"com.aio.timer": "latest"
},
"scopedRegistries": [
{
"name": "package.openupm.com",
"url": "https://package.openupm.com",
"scopes": [
"com.aio.runner",
"com.aio.timer"
]
}
]
}
````
Unity PackageManager
> open upm *中国版*
~~~
Name: package.openupm.cn
URL: https://package.openupm.cn
Scope(s): com.aio.timer
~~~
> open upm *国际版*
~~~
Name: package.openupm.com
URL: https://package.openupm.com
Scope(s): com.aio.timer
~~~
Command Line
> open *upm-cli*
~~~
openupm add com.aio.timer
~~~
## ⭐ 关于
- **这是一个 高效时间轮 定时器工具类**
- ✅ **支持 Unity 2019.4 LTS 或更高版本**
- ✅ **支持 .NET 4.x 和 .NET Standard 2.0**
- ✅ **支持 自定义定时次数**
- ✅ **支持 子线程后台运行或主线程协程运行**
- ✅ **支持 自定义时间精度单位**
- ✅ **支持 自定义时间轮大小**
- ✅ **支持 时间轮动态扩容**
- ✅ **支持 同时添加1000000+ 定时任务**
- ✅ **支持 `int` `string` `enum` `Guid` 作为 循环任务KEY**
## 📚 使用
初始化
```csharp
TimerSystem.Initialize("updateLimit:long=10","capacity:int=8196");
```
自定义时间轮精度
```csharp
TimerSystemSettings.TimingUnitsEvent += Week;
public static void Week(ICollection<(long, long, long)> units)
{
var DistanceUnit = 2; // ms
var MS_SECOND = 1000;
var MS_MIN = 1000 * 60;
var MS_HOUR = MS_MIN * 60;
var MS_DAY = MS_HOUR * 24;
var MS_WEEK = MS_DAY * 7;
units.Add((MS_SECOND, DistanceUnit, MS_SECOND / DistanceUnit));
units.Add((MS_MIN, MS_SECOND, 60));
units.Add((MS_HOUR, MS_MIN, 60));
units.Add((MS_DAY, MS_HOUR, 24));
units.Add((MS_WEEK, MS_DAY, 7));
}
```
添加定时任务
```csharp
// 后台线程
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"); }); // 循环
```
移除循环定时任务
```csharp
TimerSystem.Pop(tid);
```
## ✨ 贡献者
## 📢 致谢
- **谢谢您选择我们的扩展包。**
- **如果此软件包对您有所帮助。**
- **请考虑通过添加⭐来表示支持。**