A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/Wenzil/UnityConsole below:

Wenzil/UnityConsole: Easy-to-use developer console for Unity 5

Welcome to UnityConsole, an easy-to-use developer console for Unity 5!

  1. Import the UnityConsole package into your project (or clone the UnityConsole repository into your Assets folder)
  2. Add a UI canvas to your scene if you don't already have one (GameObject > UI > Canvas)
  3. Drag-and-Drop the Console prefab onto the canvas in the Hierarchy
  4. Run your scene and press TAB to toggle the console

Anywhere in your code, simply use Console.Log() to output to the console

The console comes with three commands by default.

Use the ConsoleCommandsDatabase.RegisterCommand() method to register your own commands. Here's an example.

public class MyCommands : MonoBehaviour
{
    void Start()
    {
        ConsoleCommandsDatabase.RegisterCommand("TAKE", MyCommands.Take,
            description: "Partake in a great adventure alone.",
            usage: "TAKE");
            
        ConsoleCommandsDatabase.RegisterCommand("RANDOM", MyCommands.Random,
            description: "Display a random number between a and b using an optional seed.",
            usage: "RANDOM a b [seed]");
    }

    private static string Take(params string[] args)
    {
        return "It is dangerous to go alone! Take this."
    }

    private static string Random(params string[] args)
    {
        if (args.Length < 2)
        {
            return "Missing range bounds.";
        }

        if (args.Length >= 3)
        {
            int seed = 0;
            if (int.TryParse(args[2], out seed))
            {
                UnityEngine.Random.seed = seed;
            }
            else
            {
                return "Invalid seed.";
            }
        }

        float a = 0;
        float b = 0;
        if (float.TryParse(args[0], out a) &&
            float.TryParse(args[1], out b) &&
            a <= b)
        {
            return Convert.ToString(UnityEngine.Random.Range(a, b));
        }
        else
        {
            return "Invalid range bounds.";
        }
    }

Attaching this script to the console will extend it with the two commands at the start of the game. Registered commands can be overwritten and persist between scenes but don't persist between multiple application executions.

You can use UnityConsole in world space. Simply set your canvas Render Mode to World Space and you're good to go. You may need to scale down the canvas.

You can easily change the appearance of the console by changing the image sources, font styles and state transitions of the various UI components. It is also possible to anchor the console differently as needed.

Feel free to create pull requests or report any issues you may find. I'll be taking your feedback!

@Syncopath1 on Twitter


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4