Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve autocomplete #22

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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