From 8be7911ade078f615b79f6f29659320e86959821 Mon Sep 17 00:00:00 2001 From: Josepe <72740829+JosepeDev@users.noreply.github.com> Date: Mon, 23 Nov 2020 14:31:15 +0200 Subject: [PATCH 1/7] Update README.md --- README.md | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 85 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index fa82abe..ca88dbb 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,89 @@ # Cooldown System -Simple tools for handling and managing cooldowns in UnityEngine efficiently +Simple tools for handling and managing cooldowns in UnityEngine efficiently. +### Content +- [Setup & Examples](#setup-and-examples) +- Examples +- Documentations + - CooldownManager + - Cooldown + +# Setup And Examples +Let's say you want to add a cooldown to some behaviour in your game. +- First, create and initialize a **CooldownManager** object. (Do this inside a **MonoBehaviour** class) +```csharp +CooldownManager cooldownManager = new CooldownManager(); +``` +- Very simple. +Now the last step, call the method **Update() of your CooldownManager** inside the **Update()** method +```csharp +void Update() +{ + cooldownManager.Update(); +} +``` +You're all set and can add cooldowns. +Let's start with creating a cooldown. +Let's say we have an **attack method** in our game for the **player**. +When the player **presses** a key, we want to **attack**. +But we also want to **apply a cooldown** when the player **attacks**. +And also to **prevent** the player from attacking **if** the cooldown **is active**. +First let's **create** a **Cooldown** for the attack and call it "**attackCooldown**" +Also let's create a **float** variable for the **amount of seconds** between attacks. +Let's say we want 3.25 seconds cooldown duration. +```csharp +float attackCoodldownDuration = 3.25f; +Cooldown attackCooldown; +``` +Now to **initialize** it. All you got to to is to **set** its value to the method **NewCooldown()** +When you **initialize** a Cooldown object, you set its **default duration** value. +And it's the float variable we initialized before. +Initialize all your cooldowns inside **Start()** or **Awake()** +```csharp +void Awake() +{ + attackCooldown = cooldownManager.NewCooldown(attackCooldownDuration); +} +``` +Done. The cooldown is ready. +Let's activate it when we attack. We just need to use the method **Activate()** +```csharp +void Attack() +{ + // some attack behaviour + ... + // cooldown activation + attackCooldown.Activate(); +} +``` +Now, let's **prevent** the player from attacing **if** the cooldown **is active**. +We can do this by checking the value **IsActive**. +```csharp +if (player is pressing the attack button) +{ + if (attackCooldown.IsActive == false) + { + Attack(); + } +} +``` +A **Cooldown** object contains **two** properties. A **timer** and a default **duration**. +The Cooldown is considered "**active**" when its **timer** is equal to **zero**. +The timer is **decreasing** when the **Update()** method of the **CooldownManager** is called. +Let's say we want to add a special, shorter attack, and apply a **short cooldown** for the attack, with a **different duration**. +We can do it with the **Activate()** method by **inputting** a **custom duration** to it. +```csharp +void SpecialAttack() +{ + // some attack behaviour + ... + // cooldown activation + attackCooldown.Activate(1.7f); // cooldown applied with a custom duration. +} +``` +You can also **change** the **default duration** at any time with the method **ChangeDuration()** +```csharp +attackCooldown.ChangeDuration(8f); +``` # [WIKI]: * **[Examples & Tutorial]** From 39c43f4c08f9e38e6cbb6a5c95b0ad85ac7234d7 Mon Sep 17 00:00:00 2001 From: Josepe <72740829+JosepeDev@users.noreply.github.com> Date: Mon, 23 Nov 2020 14:36:43 +0200 Subject: [PATCH 2/7] Update README.md --- README.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ca88dbb..c5f6abb 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,6 @@ Simple tools for handling and managing cooldowns in UnityEngine efficiently. ### Content - [Setup & Examples](#setup-and-examples) -- Examples - Documentations - CooldownManager - Cooldown @@ -84,6 +83,15 @@ You can also **change** the **default duration** at any time with the method **C ```csharp attackCooldown.ChangeDuration(8f); ``` +You can also **manually** disable the cooldown and reset its timer to zero. +Use the method **Deactivate()** +``` +attackCooldown.Deactivate(); +``` +# Documentations +### CooldownManager +- +### Cooldown # [WIKI]: * **[Examples & Tutorial]** From 382ed94c48a81193f6bc7bed08d36ffc15024f3c Mon Sep 17 00:00:00 2001 From: Josepe <72740829+JosepeDev@users.noreply.github.com> Date: Mon, 23 Nov 2020 14:37:29 +0200 Subject: [PATCH 3/7] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c5f6abb..37676d3 100644 --- a/README.md +++ b/README.md @@ -8,11 +8,11 @@ Simple tools for handling and managing cooldowns in UnityEngine efficiently. # Setup And Examples Let's say you want to add a cooldown to some behaviour in your game. -- First, create and initialize a **CooldownManager** object. (Do this inside a **MonoBehaviour** class) +First, create and initialize a **CooldownManager** object. (Do this inside a **MonoBehaviour** class) ```csharp CooldownManager cooldownManager = new CooldownManager(); ``` -- Very simple. +Very simple. Now the last step, call the method **Update() of your CooldownManager** inside the **Update()** method ```csharp void Update() From e96a798c9d27575585ee52d73b1a83812ccde2a2 Mon Sep 17 00:00:00 2001 From: Josepe <72740829+JosepeDev@users.noreply.github.com> Date: Mon, 23 Nov 2020 15:18:57 +0200 Subject: [PATCH 4/7] Update README.md --- README.md | 60 ++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 42 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 37676d3..da99c5d 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ -# Cooldown System -Simple tools for handling and managing cooldowns in UnityEngine efficiently. +# CooldownAPI +Simple and easy tool for handling and managing cooldowns in UnityEngine efficiently. ### Content - [Setup & Examples](#setup-and-examples) -- Documentations - - CooldownManager - - Cooldown +- [Documentations](#documentations) + - [CooldownManager](cooldownmanager) + - [Cooldown](cooldown) # Setup And Examples Let's say you want to add a cooldown to some behaviour in your game. @@ -90,17 +90,41 @@ attackCooldown.Deactivate(); ``` # Documentations ### CooldownManager -- +![img](https://i.imgur.com/trJDZ2P.jpg) +- Methods + - **Update()** + Call this method inside Update() in a MonoBehaviour inherited class. + Updates the value of all the cooldowns that are subscribed to the specified manager. + Decreases all the cooldowns timers by the time at once. + A cooldown is subscribed automatically to the CooldownManager it has been created with. + + - **NewCooldown(float duration)** + Returns a new Cooldown object. Better than creating a Cooldown with a constructor. + Subscribes the cooldown created to the Update() method of the manager it has been created with. + ### Cooldown - -# [WIKI]: -* **[Examples & Tutorial]** -* **[CooldownsManager]** class - -For handling and creating cooldowns in UnityEngine efficiently -* **[Cooldown]** class - -For handling a single cooldown in UnityEngine - recommended to use the manager - -[WIKI]: https://github.com/JosepeDev/Cooldown-System/wiki -[Examples & Tutorial]: https://github.com/JosepeDev/Cooldown-System/wiki/Examples-&-Tutorial -[CooldownsManager]: https://github.com/JosepeDev/Cooldown-System/wiki/CooldownsManager-Class -[Cooldown]: https://github.com/JosepeDev/Cooldown-System/wiki/Cooldown-Class +![img](https://i.imgur.com/kHITH1f.jpg) +- Properties + - **IsActive** + Determines if the cooldown is currently active. + Returns true if the timer is higher than zero. + + - **Duration** + Returns the default duration value of the Cooldown object. + The default duration is set upon initialization. + It used when you call the Activate() method without inputting parameters. + +- Methods + - **Activate()** + Activates the cooldown with the default duration. + You can get the default duration's value form the Duration propertie. + + - **Activate(float customDuration)** + Activates the cooldown with a custom duration. + + - **Deactivate()** + Deactivates the cooldown manually. + Resets the timer's value to zero. + + - **ChangeDuration(float duration)** + For changing the default duration's value. From 9222a1c9c11eaca64f4e8067e0f839d5e086f0fd Mon Sep 17 00:00:00 2001 From: Josepe <72740829+JosepeDev@users.noreply.github.com> Date: Mon, 23 Nov 2020 15:19:58 +0200 Subject: [PATCH 5/7] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index da99c5d..55209d9 100644 --- a/README.md +++ b/README.md @@ -3,8 +3,8 @@ Simple and easy tool for handling and managing cooldowns in UnityEngine efficien ### Content - [Setup & Examples](#setup-and-examples) - [Documentations](#documentations) - - [CooldownManager](cooldownmanager) - - [Cooldown](cooldown) + - [CooldownManager](#cooldownmanager) + - [Cooldown](#cooldown) # Setup And Examples Let's say you want to add a cooldown to some behaviour in your game. From 70fbf06a494ea0f4d60800b0a4169979c60dc180 Mon Sep 17 00:00:00 2001 From: Josepe <72740829+JosepeDev@users.noreply.github.com> Date: Mon, 23 Nov 2020 15:33:48 +0200 Subject: [PATCH 6/7] Update README.md --- README.md | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 55209d9..cce6e0c 100644 --- a/README.md +++ b/README.md @@ -3,21 +3,21 @@ Simple and easy tool for handling and managing cooldowns in UnityEngine efficien ### Content - [Setup & Examples](#setup-and-examples) - [Documentations](#documentations) - - [CooldownManager](#cooldownmanager) + - [CooldownsManager](#cooldownsmanager) - [Cooldown](#cooldown) # Setup And Examples Let's say you want to add a cooldown to some behaviour in your game. -First, create and initialize a **CooldownManager** object. (Do this inside a **MonoBehaviour** class) +First, create and initialize a **CooldownsManager** object. (Do this inside a **MonoBehaviour** class) ```csharp -CooldownManager cooldownManager = new CooldownManager(); +CooldownsManager cooldownsManager = new CooldownsManager(); ``` Very simple. -Now the last step, call the method **Update() of your CooldownManager** inside the **Update()** method +Now the last step, call the method **Update() of your CooldownsManager** inside the **Update()** method ```csharp void Update() { - cooldownManager.Update(); + cooldownsManager.Update(); } ``` You're all set and can add cooldowns. @@ -40,7 +40,7 @@ Initialize all your cooldowns inside **Start()** or **Awake()** ```csharp void Awake() { - attackCooldown = cooldownManager.NewCooldown(attackCooldownDuration); + attackCooldown = cooldownsManager.NewCooldown(attackCooldownDuration); } ``` Done. The cooldown is ready. @@ -67,8 +67,8 @@ if (player is pressing the attack button) ``` A **Cooldown** object contains **two** properties. A **timer** and a default **duration**. The Cooldown is considered "**active**" when its **timer** is equal to **zero**. -The timer is **decreasing** when the **Update()** method of the **CooldownManager** is called. -Let's say we want to add a special, shorter attack, and apply a **short cooldown** for the attack, with a **different duration**. +The timer is **decreasing** when the **Update()** method of the **CooldownsManager** is called. +Let's say we want to add a special, shorter attack, and apply a **short cooldown** for it with a **different duration**. We can do it with the **Activate()** method by **inputting** a **custom duration** to it. ```csharp void SpecialAttack() @@ -89,18 +89,18 @@ Use the method **Deactivate()** attackCooldown.Deactivate(); ``` # Documentations -### CooldownManager +### CooldownsManager ![img](https://i.imgur.com/trJDZ2P.jpg) - Methods - **Update()** Call this method inside Update() in a MonoBehaviour inherited class. Updates the value of all the cooldowns that are subscribed to the specified manager. Decreases all the cooldowns timers by the time at once. - A cooldown is subscribed automatically to the CooldownManager it has been created with. + A cooldown is subscribed automatically to the CooldownsManager it has been created with. - **NewCooldown(float duration)** Returns a new Cooldown object. Better than creating a Cooldown with a constructor. - Subscribes the cooldown created to the Update() method of the manager it has been created with. + Subscribes the cooldown created to the Update() method of the CooldownsManager it has been created with. ### Cooldown ![img](https://i.imgur.com/kHITH1f.jpg) From 2f967c9c359dc3e0d2b2fe9e163217f860e8eaf8 Mon Sep 17 00:00:00 2001 From: Josepe <72740829+JosepeDev@users.noreply.github.com> Date: Mon, 23 Nov 2020 15:41:08 +0200 Subject: [PATCH 7/7] Update README.md --- README.md | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index cce6e0c..36893cb 100644 --- a/README.md +++ b/README.md @@ -90,7 +90,9 @@ attackCooldown.Deactivate(); ``` # Documentations ### CooldownsManager -![img](https://i.imgur.com/trJDZ2P.jpg) +A class for handling and managing multiple cooldowns efficiently. +![img](https://i.imgur.com/s6orwHe.jpg) + - Methods - **Update()** Call this method inside Update() in a MonoBehaviour inherited class. @@ -103,7 +105,10 @@ attackCooldown.Deactivate(); Subscribes the cooldown created to the Update() method of the CooldownsManager it has been created with. ### Cooldown -![img](https://i.imgur.com/kHITH1f.jpg) +A class for handling a single cooldown in Unity using a timer. +It is recommended to create a CooldownManager inside a class you want to use cooldowns in. +![img](https://i.imgur.com/kHITH1f.jpg) + - Properties - **IsActive** Determines if the cooldown is currently active.