TIM.Console
  • Quick start
  • User Interface
  • Log
  • Commands
    • PartType C#
    • CmdFormula C#
    • CmdInputResult C#
  • Support
Powered by GitBook
On this page
  • How to create command
  • 1. Create CmdFormula
  • 2. Create a method that will be called when executing the command
  • 3. Register your command
  • ✅ All done!

Commands

PreviousLogNextPartType C#

Last updated 1 year ago

You can create your own commands.

Every command has its formula!

You create formulas by your self. Commands can be of any complexity and structure!

How to create command

For example we want to create command that will spawn balls in our scene.

It contains 2 parts: sentence "Spawn_balls" + Integer "count"

Spawn_balls [int: count]

1. Create CmdFormula

Create CmdFormula field in your script.

using TIM;
using UnityEngine;

public class DemoScript : MonoBehaviour
{
    public CmdFormula SpawnBallsFormula;
}

Select SpaceType: Space or Underline _

âž• You can add new part (or remove e excess part) and customize it. We need 2 parts.

2. Create a method that will be called when executing the command

using TIM;
using UnityEngine;

public class DemoScript : MonoBehaviour
{
    public CmdFormula SpawnBallsFormula;

    private void OnSpawnBallsCommand(CmdInputResult result)
    {
        
    }
}
using TIM;
using UnityEngine;

public class DemoScript : MonoBehaviour
{
    public CmdFormula SpawnBallsFormula;
    public GameObject BallPrefab;

    private void OnSpawnBallsCommand(CmdInputResult result)
    {
        int ballsCount = result.Parts[1].Integer;
        
        for (int i = 0; i < ballsCount; i++)
        {
            Instantiate(BallPrefab);
        }
    }
}

3. Register your command

You need to register your command in Console

using System;
using TIM;
using UnityEngine;

public class DemoScript : MonoBehaviour
{
    public CmdFormula SpawnBallsFormula;
    public GameObject BallPrefab;

    private void Start()
    {
        TIM.Console.RegisterCommand(SpawnBallsFormula, OnSpawnBallsCommand);
    }

    private void OnSpawnBallsCommand(CmdInputResult result)
    {
        int ballsCount = result.Parts[1].Integer;
        
        for (int i = 0; i < ballsCount; i++)
        {
            Instantiate(BallPrefab);
        }
    }
}

✅ All done!

Select for each part and our formula should look like this:

contains user's input string already separated in parts and parsed to necessary types! So to get balls count you just need to get value from Part that contains balls count value:

PartType
CmdInputResult
Write console command
spawned balls