DarkRewar / BaseTool

A big library of basic tools that you might need in your Unity projects.
MIT License
41 stars 6 forks source link

Created a `CooldownManager` to update all `Cooldown` #63

Closed DarkRewar closed 5 months ago

DarkRewar commented 5 months ago

Cooldown.Restart()

Cooldowns could be used like loop time feature (something that must be triggered each X seconds e.g.). So, it was possible to achieve this behaviour by using :

Cooldown _cd = 2; // each 2 seconds
...
if(_cd.IsReady)
{
    _cd.Reset();
    // Do something
}

This PR introduces a new method to check the IsReady and reset automatically :

Cooldown _cd = 2; // each 2 seconds
...
if(_cd.Restart())
{
    // Do something
}

CooldownManager

You could see that Update() is not necessary anymore. That's because every cooldown is registered to a CooldownManager when they are reset ; this manager updates every registered cooldown and clear them when they're ready.

⚠️ If you are using the Cooldown.Update() method, or you still want to use it, you must set the Cooldown.SubscribeToManager to false. Without that, the cooldown would be updated twice.