Skip to content

Conversation

bobroberts177
Copy link

  • If there is more than one completion, complete to the longest common substring and print completions
  • Autocomplete GameObject name parameters in the same way
  • Allow user to specify new types that can be parsed internally via ConsoleTypeParse function attribute
  • Allow user to specify autocomplete suggestions for new types via ConsoleTypeSuggest function attribute

Here's an example for testing out these features:

using System;
using System.Collections.Generic;
using UnityEngine;
using IngameDebugConsole;

public class ConsoleTest : MonoBehaviour {
  [ConsoleMethod("cube", "Creates a cube at specified position")]
  public static void CreateCubeAt(Vector3 position) {
    GameObject.CreatePrimitive(PrimitiveType.Cube).transform.position = position;
  }

  [ConsoleMethod("cub3", "Creates a cube at specified position")]
  public static void CreateCub3At(Vector3 position) {
    GameObject.CreatePrimitive(PrimitiveType.Cube).transform.position = position;
  }

  [ConsoleMethod("destroy", "Destroy a GameObject")]
  public static void DestroyGameObject(GameObject go) {
    GameObject.Destroy(go);
  }

  [ConsoleTypeParse(typeof(PrimitiveType))]
  public static bool ParsePrimitiveType(string input, out object output) {
    foreach(PrimitiveType primitiveType in (PrimitiveType[])Enum.GetValues(typeof(PrimitiveType))) {
      if (input == primitiveType.ToString()) {
        output = primitiveType;
        return true;
      }
    }
    output = null;
    return false;
  }

  [ConsoleTypeSuggest(typeof(PrimitiveType))]
  public static bool SuggestPrimitiveType(string input, out List<string> suggestions) {
    suggestions = new List<string>();
    foreach(PrimitiveType primitiveType in (PrimitiveType[])Enum.GetValues(typeof(PrimitiveType))) {
      string primitiveString = primitiveType.ToString();
      if (primitiveString.StartsWith(input))
        suggestions.Add(primitiveType.ToString());
    }
    return true;
  }

  [ConsoleMethod("create_primitive", "Create a primitive")]
  public static void CreateEntity(PrimitiveType primitiveType, Vector3 position) {
    GameObject.CreatePrimitive(primitiveType).transform.position = position;
  }
}

- If there is more than one completion, complete to the longest common substring and print completions
- Autocomplete GameObject name parameters in the same way
- Allow user to specify new types that can be parsed internally via ConsoleTypeParse function attribute
- Allow user to specify autocomplete suggestions for new types via ConsoleTypeSuggest function attribute
@yasirkula
Copy link
Owner

Thank you for the PR! In the future, I may change the autocomplete behaviour as you suggested, so I'll keep this PR open. But I'm not planning to change it now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants