A task system in Unity to create a sequence of tasks to execute and manage them.
Executing a sequence looks like... Task1 : Enable a gameobject Task2 : Move the gameobject Task3 : Wait for 10 seconds Task4 : Log "I waited for 10 seconds" Task5 : Disable the gameobject
You can create different types of these tasks and execute them when you want through code. You can create as many task lists as you need and set the task list you want to use at that time as the 'current task list'. Start, stop and manage your system. I have used this system in a previously published game and created multiple of these task types as needed by game designers. These work similar to story graphs and can be used by non-technical staff. The system is built upon reusing of objects (tasks and sequence) by pooling them, so that at any instance there aren't many unused objects.
- Open the 'Example' scene
- In the toolbar there exists an option 'Task System'->'Manager'. This opens the 'Manager' window to create tasklists or run sequences at runtime for debugging.
- 'Task List XML Source Path' is the directory of the folder that includes all the task lists. A Task List is an XML list that includes your sequences and tasks. You can have as many of these task lists as you desire.
- When you edit a task list it needs to be turned into a Unity Asset. You can do this by clicking 'Create All Scriptable Objects'. These newly created Unity Assets are then placed into the folder in the directory 'Task List Asset Destination Path'
- Once the game begins, add/remove the task lists you need at that moment AddTaskList(a_strAssetPath), RemoveTaskList(a_strTaskListName) and you can select a single task list to be used as the current to refer to by executing 'SetCurrentTaskList(TaskListName)'. This task list is the one you refer to when wish to execute a sequence i.e. the sequence you run should be found in this task list.
- Currently there exist 2 example tasks: TaskWait and TaskLog. To create more types of tasks, replicate the TaskWait.cs code and add your new task relevant code in place of the inherited code.
- onInitialize() is called when the sequence begins executing.
- onExecute() Called when that task is executed.
- onUpdate() Called while the task is ongoing similar to the update function but for that task specifically.
- onComplete() Called when the task is completed. This needs to be called by you specifying that this task is completed. For example: TaskWait waits for some time and after that specified time calls onComplete().
- The TaskManager manages all execution and management of tasks, call TaskManagerExecuteSequence(SequenceName) to start a sequence and a sequence can also be stopped etc.