Skip to content

Commit

Permalink
Updated the src folder
Browse files Browse the repository at this point in the history
  • Loading branch information
jozzzzep committed Dec 19, 2022
1 parent ea7551e commit 11f952b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
35 changes: 18 additions & 17 deletions src/Cooldown.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,37 @@

namespace CooldownAPI
{
/// Tutorial and Examples: https://github.com/JosepeDev/CooldownAPI
/// Tutorial and Examples: https://github.com/jozzzzep/CooldownAPI
/// <summary>
/// A class for handling a cooldown in Unity using a timer
/// </summary>
public class Cooldown
{
/// Properties:
/// Properties ---------------------------------------------------------------------------------
/// - IsActive - Determines if the cooldown is currently active (timer higher than zero)
/// - Duration - Returns the value of the default duration of the Cooldown object.
/// - Timer - Returns the current value from the cooldown's timer
/// --------------------------------------------------------------------------------------------
///
/// Events:
/// Events -------------------------------------------------------------------------------------
/// - BecameInactive - An event that is raised when the cooldown becomes inactive
/// --------------------------------------------------------------------------------------------
///
/// Methods:
/// Methods ------------------------------------------------------------------------------------
/// - Activate() - Activates the cooldown with the default duration saved in the object.
/// - Activate(float) - Activates the cooldown with a custom duration.
/// - Deactivate() - Resets the timer (deactivates the cooldown).
/// - ChangeDuration() - Changes the deafult cooldown duration saved in the object.

private static CooldownsManager _cdm;
private static CooldownsManager CDM
/// --------------------------------------------------------------------------------------------

private static CooldownsManager cooldownsManager;
private static CooldownsManager CooldownsManager
{
get
{
if (_cdm == null)
_cdm = InitializeManager();
return _cdm;
if (cooldownsManager == null)
cooldownsManager = InitializeManager();
return cooldownsManager;
}
}

Expand All @@ -45,10 +48,14 @@ public Cooldown(float duration)
{
this.duration = duration;
Deactivate();
CDM.AddToManager(Update);
CooldownsManager.AddToManager(Update);
}

public delegate void BecameInactiveEventHandler();

/// <summary>
/// Raised when the cooldown becomes inactive
/// </summary>
public event BecameInactiveEventHandler BecameInactive;

/// <summary>
Expand Down Expand Up @@ -104,9 +111,6 @@ public void Deactivate()
public void ChangeDuration(float newDurationValue) =>
duration = newDurationValue;

/// <summary>
/// Used to initialize the cooldowns manager
/// </summary>
private static CooldownsManager InitializeManager()
{
var cdm = Object.FindObjectOfType<CooldownsManager>();
Expand All @@ -125,9 +129,6 @@ private void OnBecameInactive()
e();
}

/// <summary>
/// Do not call manually
/// </summary>
private void Update()
{
if (isActive)
Expand Down
2 changes: 1 addition & 1 deletion src/CooldownsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ internal class CooldownsManager : MonoBehaviour
{
/// The class that manages and calls all the cooldowns
/// No need to use or call it manually
/// Tutorial and Examples: https://github.com/JosepeDev/CooldownAPI
/// Tutorial and Examples: https://github.com/jozzzzep/CooldownAPI

private Action cooldownsUpdates;

Expand Down

0 comments on commit 11f952b

Please sign in to comment.