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.
Select SpaceType: Space or Underline _
➕ You can add new part (or remove e excess part) and customize it. We need 2 parts.
Select PartTypefor each part and our formula should look like this:
2. Create a method that will be called when executing the command
CmdInputResult 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:
using TIM;
using UnityEngine;
public class DemoScript : MonoBehaviour
{
public CmdFormula SpawnBallsFormula;
}
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);
}
}
}
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);
}
}
}