Creating custom tasks

You can easily write your own tasks. This allows you to create highly customizable tasks that are specific to your game's unique requirements.

Example: Log Message Task

In this example we will write a simple task that will log a message to the console. Create a new Script called LogMessageTask.cs and paste the following content:

using Ilumisoft.GameActionSystem;
using UnityEngine;

/// <summary>
/// Logs the given message when being executed
/// </summary>
[AddComponentMenu("Game Action System/Tasks/Debug/Log Message (Task)")]
public class LogMessageTask : GameActionTask
{
    /// <summary>
    /// A message that can be defined in the inspector
    /// </summary>
    public string message = string.Empty;

    /// <summary>
    /// This will be invoked when the task is executed
    /// </summary>
    /// <returns></returns>
    protected override StatusCode OnExecute()
    {
        // Log the message
        Debug.Log(message);

        // As the task is completed, when return the completed status code
        return StatusCode.Completed;
    }
}

Example: Wait Until Key Pressed Task

You can also write tasks that are running over multile frames before they are completed. The following task will be running until a specific key is pressed. This could be used for example on a sequential Game Action to delay a timeline from being played until the player pressed a key.

using Ilumisoft.GameActionSystem;
using UnityEngine;

/// <summary>
/// When added to a Game Action set to Sequential, this task will block any later task from being executed until the given key is pressed
/// </summary>
[AddComponentMenu("Game Action System/Tasks/Time/Wait Until Key Pressed (Task)")]
public class WaitUntilKeyPressedTask : GameActionTask
{
    /// <summary>
    /// The key that should be waited on
    /// </summary>
    public KeyCode keyCode = KeyCode.Space;

    /// <summary>
    /// This will be invoked when the task is executed
    /// </summary>
    /// <returns></returns>
    protected override StatusCode OnExecute()
    {
        // The task is completed, when the given key is pressed
        if (Input.GetKeyDown(keyCode))
        {
            return StatusCode.Completed;
        }

        // Otherwise the task is still being executed
        return StatusCode.Running;
    }
}

Last updated