Custom Commands

Simple Example: Get the position of a gameObject by name.

Define a new command GetPosition to take the name of the gameObject as an argument and return its position.

public static class MyCommands
{
    [ProximaCommand("My", "gp")]
    public static Vector3 GetPosition(string name)
    {
        var go = GameObject.Find(name);
        if (go == null) throw new Exception("GameObject not found.");
        return go.transform.position;
    }
}

The first argument to ProximaCommand is the category which will appear when the user types "?". The second argument is an alias, or shortcut you can use instead of the full command name.

In order for Proxima to find your command, you need to register its class. For example, you can do this in Awake() of one of your components:

void Awake()
{
    ProximaInspector.RegisterCommands<MyComands>();
}

Now you can invoke your command in the Console by typing:

> GetPosition "Main Camera"
[0,1,-10]

or

> gp "Main Camera"
[0,1,-10]

Pattern matching gameObjects

Often, scenes have multiple gameObjects with the same name. Sometimes, the user doesn't know or doesn't want to type the full name. Instead of GameObject.Find, you can use ProximaCommandHelpers.FindGameObject to pattern match the user input.

[ProximaCommand("My", "gp")]
public static string GetPosition(string name)
{
    var gameObjects = ProximaCommandHelpers.FindGameObjects(name);
    if (gameObjects.Count == 0)
    {
        throw new Exception($"No game object found with name '{name}'");
    }

    var sb = new StringBuilder();
    foreach (var go in gameObjects)
    {
        sb.AppendLine(go.name +
            " [" + go.GetInstanceID() + "] " +
            ProximaSerialization.Serialize(                 go.transform.position, true));
    }

    return sb.ToString();
}
> gp *camera
Main Camera [23162] [0, 1, -10]

Command Parameters

Add parameters to your command by adding arguments to your method.

[ProximaCommand("My", "addv")]
public static Vector3 AddVectors(Vector3 lhs, Vector3 rhs)
{
    return lhs + rhs;
}
> addv [1, 2, 3] [4, 5, 6]
[5,7,9]

Pattern matching parameters

Instead of explicitly taking a Vector3 as an argument, you can use the PropertyOrValue wrapper to accept either a Vector3 or a property.

[ProximaCommand("My", "addv")]
public static Vector3 AddVectors(PropertyOrValue<Vector3> lhs, PropertyOrValue<Vector3> rhs)
{
    return lhs.Get() + rhs.Get();
}
> addv *camera.transform.position panel.transform.position
[474.5,1,-10]