Sub Routines

$4
Publisher Craig Dennis
File size 300.69kB
Number of files 8
Latest version 1
Latest release date 2023-01-05 08:25:09
First release date 2022-05-30 09:40:21
Supported Unity versions 2018.4.2 or higher

SubRoutines

--------------------------------------------------

What are SubRoutines and why would I need them?

To put it simply once created, a sub routine will run in the background performing an action until a condition is met. Fleshing this idea out further we can build many complex tasks that can run concurrently or within a chain of events, while adding features that makes awkward development much easier to write and code that is easier to read at a glance.

Another handy feature is the ability to pause a routine at any time, and chain routines together. This allows for great flexibilty and can act (or be further extended to act) as a very customisable event system for your game. You have full control of how a routine is run.


How does it work?

Many varieties of tasks can be defined by 2 simple things: a condition and an action. This package provides all of the background work by testing and running these tasks according to the current frame rate while giving a simple interface to create them. The package comes with a static class named SubRoutines which contains a variety of common understandable methods to easily interface with such as “Wait”, “While” and “RunFor”, which act as a great foundation for any type of time / condition based task.


See the documentation for more information on how to use the SubRoutines package and what it can be used for.


Public static methods (Called with SubRoutines.MethodName)

--------------------------------------------------

  • While: The foundational sub routine, use this to create further static routine methods. If condition is true then invoke action, otherwise invoke callback, then the sub routine will be automatically disposed of.
  • Always: Creates a sub routine that invokes action every frame.
  • When: Waits until condition is true and then invokes action.
  • Wait: Waits for the specified time and then invokes action.
  • RunFor: Invokes action every frame until the specified time is met, then finally invokes callback.
  • Repeat: Repeats action a certain number of times (or infinitely) every interval seconds.
  • RunNextFrame: Waits one frame and then calls action.
  • RunAfterXFrames: Waits numFrames frames and then calls action.
  • RunForXFrames: Invoke action for a specified number of frames (numFrames), passing the current number of frames elapsed into action (f), then invokes callback on the last frame.
  • Do: Call action immediately. Note that this is only ever useful within a chain of events.
  • Chain: Invoke a chain of SubRoutines, waiting for one to finish before moving on to the next. Note that Chains can be nested, which will be run concurrently by default.
  • GetInstance: Get game object instance.
  • RemoveSubRoutine: Remove a SubRoutine.
  • RemoveAllSubRoutines: Remove all SubRoutines.

--------------------------------------------------

Documentation:


SubRoutines Documentation.pdf


Contact:


Email, Discord


Top Publisher Assets