Giter Site home page Giter Site logo

net.peeweek.console's Introduction

Console

openupm

A (Idtech-like) console for use at runtime in your Unity Projects. The goal is to keep it as simple as possible. The console can register console commands to extend its possibilities. Console commands are easy to write and implement. There are some examples shipped with the base package.

Oh, and the console catches unity Logs.

Console Screenshot

Install

OpenUPM Scoped Registry (2020.1 and newer)

Open Project Preferences and go to Package manager Window.

If not present, add this scoped registry:

  • Name: OpenUPM
  • URL : https://package.openupm.com
  • Scopes : net.peeweek

Once added, you can close the project settings window.

Open Package manager (Window/Package Manager), select the Console package, and click the install button.

Local Package Install

Either Clone the repository and reference the package.json in the Package Manager UI, or add directly this line to the Packages/manifest.json under dependencies :

"net.peeweek.console": "https://github.com/peeweek/net.peeweek.console.git#1.4.0",

How to use

  • By default, a default console is spawned from the prefab when playing.
  • Press the Backslash \ key at runtime to toggle the Console (Can be customized if you use the package as local package)
  • Use the input field to input commands and execute button or return key to execute.

Customizing the Console Prefab

If you want to customize the console prefab, you can create a copy of the default prefabs into your Assets/Resources directory from your Project View's Packages/Console/Resources directory. There are two diffent prefabs, based on the input system you are currently using:

  • Default_Console_LegacyInput.prefab : Legacy Input System
  • Default_Console_NewInputSystem.prefab : New Input System Package

After creating the copy, just rename the newly created asset, and remove the Default_ prefix.

Navigation (Defaults)

  • Backslash to Open/Close console
  • Up/Down arrows to access type command history
  • PageUp/PageDown to scroll console log history

Built-in Commands

  • help : displays a list of all registered commands with summary
  • help [command] displays the GetHelp() string of given command.
  • clear clears the console output.

API Summary

  • using ConsoleUtility;
  • Console.Log("Module", "Message", LogType.Warning);for a detailed log and coloration.
  • Console.Log("Module", "Message");shortcut with LogType.Log.
  • Console.Log("Message");Simplest one, without module.
  • Console.AddCommand(command)Registers one new command.

Writing Console Commands

Writing console commands requires writing a Class that implements IConsoleCommand interface.

  • To manually register a console command use Console.AddCommand(IConsoleCommand command)
  • To set a console command to register itself automatically use the [AutoRegisterConsoleCommand] class attribute

Console Command structure

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

namespace ConsoleUtility
{
    [AutoRegisterConsoleCommand]
    public class MyConsoleCommand : IConsoleCommand
    {
        public void Execute(string[] args)
        {
	     //use args array to parse command. args[] do not include the base command so in
             // command 'mycommand foo bar' args[0] is foo and args[1] is bar
        }

        public string name => "mycommand"; 		// the actual command key
        public string summary => "Does soemthing";	// summary displayed when typing 'help'
        public string help => "usage: mycommand"; 	// help displayed when typing 'help mycommand'

        public IEnumerable<Console.Alias> aliases
        {
	    get
	    {
                yield return Console.Alias.Get("myalias", "mycommand foo bar");
                // yield return any console alias you need, for ease of use purposes
	    }
        }
    }

}

net.peeweek.console's People

Contributors

peeweek avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

net.peeweek.console's Issues

The prefab "Console" is broken.

image

Renaming the root namespace from Console to Peeweek could fix the error in the image above. But it will also break the prefab, because script connections to the gameobjects in the prefab are lost after changing the namespace, I think.

Please provide a Unity scene with a correct hierarchy of the console instead of a single prefab file. A working sample scene is also helpful.

PS:
Before renaming the Console namespace, when I removed and then tried to re-add the Console script component to the "Console" prefab, an error occurred: Can't add script behaviour TMP_CoroutineTween. The script needs to derive from MonoBehaviour!. (The name TMP_CoroutineTween seems to be a random name.) It seems a bug in Unity: https://forum.unity.com/threads/cant-add-script-behaviour-tmp_coroutinetween-the-script-needs-to-derive-from-monobehaviour.550183/
1

Environtment: Win10, Unity 2018.2.4f1

Get Console visible

Is there a way to get console status if it's opened or closed?
i would like to disable player control when console are active

Incompatible with new Input System

Hi,

First of all, thanks for this great tool! At the moment it currently isn't working with the new Input System. Are there plans to support both input systems? The culprit is the prefab (see image below)

Prefab_Issue

I am using this as a upm package, otherwise I could of course just change the prefab.

Thanks in advance and kind regards :)

Inactive event system prevents the console from working

Replicate: Create a blank new 3D project (2020.3.14f1 in my case) and add the Console package.

\ works to bring the console up, but the input field is inactive and non interactable because the EventSystem is disabled. Enabling the EventSystem allows the console to function.

tab or down arrow to autocomplete

Hey, this is an awesome tool! Thanks for making it :) The only thing I wish it had was tab or down key to autocomplete whatever is at the top of the autopanel list

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.