Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Feedback Simple Timer Tool [Open-Source]

Discussion in 'Assets and Asset Store' started by himarsus, Jul 26, 2023.

  1. himarsus

    himarsus

    Joined:
    Oct 13, 2021
    Posts:
    1
    Hey there!

    I've always found it to be a simple yet tedious task to develop timers. So, after searching through numerous references and articles, I've created and uploaded a small and straightforward tool based on a Timer Manager with a set of interesting features. As a novelty, unlike others, I've added key events during the timer's duration to trigger whatever the user wants.

    That's why I've decided to share the progress and final outcome here. Hope you like it!

    Github Link: https://github.com/himar33/TimerTool-Unity-Utility
    Itch.io Link: https://himar33.itch.io/timer-tool
    Unity Asset Store:
    [I'm waiting to upload it to the asset store!]

    About
    TimerTool is a versatile and easy-to-use timer utility for Unity, designed to streamline time-based operations and events in your projects. This tool allows developers to create, manage, and control timers with various functionalities, including real-time and game-time support, pausing, looping, and event-triggering at specific intervals.

    Features
    • Easy Timer Creation: Effortlessly create timers with customizable durations and loop settings
    Code (CSharp):
    1. _timer = new Timer(
    2.     duration: _duration,
    3.     isLooped: _isLooped,
    4.     usesRealTime: _usesRealTime,
    5.     onFinish: _onFinish,
    6.     onUpdate: _onUpdate,
    7.     timerEvents: _timerEvents);
    • Simple and intuitive inspector manager:

    • Event Triggering: Register events to occur at specific intervals during the timer's execution, adding dynamic interactions to your projects.

    • Simplified Time Calculations: Obtain elapsed time, remaining time, and ratios effortlessly with dedicated methods.
    Code (CSharp):
    1. /// <summary>
    2. /// Returns the elapsed time (in seconds) since the timer started. If the timer has finished or the world time exceeds the finish time,
    3. /// it returns the total duration of the timer to prevent negative values.
    4. /// </summary>
    5. /// <returns>The elapsed time in seconds.</returns>
    6. public float GetTimeElapsed()
    7. {
    8.     if (this.IsFinished || this.GetWorldTime() >= this.GetFinishTime())
    9.     {
    10.         return this.Duration;
    11.     }
    12.  
    13.     return this._timeBeforeStop ??
    14.            this._timeBeforePause ??
    15.            this.GetWorldTime() - this._startTime;
    16. }
    17.  
    18. /// <summary>
    19. /// Returns the remaining time (in seconds) until the timer completes its duration.
    20. /// </summary>
    21. /// <returns>The remaining time in seconds.</returns>
    22. public float GetTimeRemaining()
    23. {
    24.     return this.Duration - this.GetTimeElapsed();
    25. }
    26.  
    27. // And more functions like these...