Skip to content

Latest commit

 

History

History
169 lines (139 loc) · 4.24 KB

README_EN.md

File metadata and controls

169 lines (139 loc) · 4.24 KB

https://github.com/AIO-GAME

Unity Timer

简体中文 | English

⚙ Install

Packages Manifest
{
  "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 Chinese Version

Name: package.openupm.cn
URL: https://package.openupm.cn
Scope(s): com.aio.timer

open upm International Version

Name: package.openupm.com
URL: https://package.openupm.com
Scope(s): com.aio.timer
Command Line

open upm-cli

openupm add com.aio.timer

⭐ About

  • This is a high-performance timer tool class based on the efficient time wheel.
  • Support Unity 2019.4 LTS or higher.
  • Support .NET 4.x and .NET Standard 2.0.
  • Support custom timing times.
  • Support sub-thread background operation or main thread coroutine operation.
  • Support custom time precision unit.
  • 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

Initialize

TimerSystem.Initialize("updateLimit:long=10","capacity:int=8196");

Custom time wheel accuracy

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));
}

Add timing task

// 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

TimerSystem.Pop(tid);

✨ Contributors

xinansky
xinansky

📢 Thanks

  • Thanks for using this software.
  • If this package is useful to you.
  • Please ⭐ this repository to support the project.