Search Unity

Introducing SubRoutines: A Powerful Tool for Managing Conditional Events and Routines in Your Games

Discussion in 'Assets and Asset Store' started by Zephni, Jan 7, 2023.

  1. Zephni

    Zephni

    Joined:
    Apr 23, 2015
    Posts:
    100
    Hi everyone!

    I'm excited to announce the release of my new asset SubRoutines on the Unity Asset Store. SubRoutines is a collection of public static methods that makes it easier to manage conditional events and routines in Unity.

    Unlike coroutines, SubRoutines update at the same time as all game objects, and do not require a special and separate IEnumerator method to run, which often feel clunky. This saves both computation and developer time, and allows you to use Time.deltaTime and other Time based properties within your actions. You can start, pause, and stop routines with a simple API, and chain them together to create complex sequences of events. SubRoutines also includes methods for waiting a specified amount of time, running an action for a specified amount of time or for a certain number of frames, waiting on a condition before running, etc.

    Here are some of the features of SubRoutines:
    • Public and static SubRoutines class with a collection of methods for starting and chaining routines:
      • SubRoutines.Always(Action action)
      • SubRoutines.Wait(float time, Action action)
      • SubRoutines.RunFor(float time, Action<float> action, Action callback = null)
      • SubRoutines.When(Func<bool> condition, Action action)
      • SubRoutines.While(Func<bool> condition, Action action, Action callback)
      • SubRoutines.RunNextFrame(Action action)
      • SubRoutines.RunAfterXFrames(int numFrames, Action action)
      • SubRoutines.RunForXFrames(int numFrames, Action<int> action, Action callback)
      • SubRoutines.Do(Action action)
      • SubRoutines.Repeat(int repeat, float interval, Action<int> action, Action callback)
      • SubRoutines.Chain(params SubRoutine[])
      • SubRoutines.GetInstance()
      • SubRoutines.RemoveSubRoutine(SubRoutine subRoutine)
      • SubRoutines.RemoveAllSubRoutines()
    • Easy to use API with clear and concise method names.
    • Ability to pause and resume sub routines.
    • Each sub routine will update at the same rate as all other game objects.
    SubRoutines includes several methods that allow you to run an action for a specified amount of time or number of runs, and pass the current progress or run count into the action itself. For example, the RunFor method passes the current progress as a value between 0 and 1, while the RunForXFrames method passes the current number of frames elapsed. Similarly, the Repeat method passes the current number of repeats. This can be useful if you want to perform an action that depends on the current progress or run count, such as updating a UI element or spawning a game objects. It allows you to easily create dynamic and responsive behaviors within your routines.

    SubRoutines also includes a Chain method that allows you to easily chain together a series of routines to create complex sequences of events. To use it, simply pass in a list of SubRoutine objects as arguments. The Chain method will wait for each routine to finish before moving on to the next one. This is useful for creating behaviors that depend on the completion of other routines, or simply chaining a list of timed events one after the other.

    I hope you find SubRoutines useful in your game development projects! You can check out the documentation and the asset down below.

    Thanks for reading, and happy game development!

    Link to asset: https://assetstore.unity.com/packages/tools/utilities/sub-routines-221831

    Link to documentation: https://mugheadstudios.com/files/SubRoutines_Documentation.pdf?2

    If you have any questions, feel free to post here or email me directly: zephni@hotmail.co.uk
     
    Last edited: Jan 9, 2023