Skip to content

Console

chaolun edited this page Aug 14, 2019 · 2 revisions

Quick Start

  • Add submodule $ git submodule add git@github.com:chaolunner/UnityFrameworkStreamingAssets.git Assets/StreamingAssets

  • Use the ~ key switch console system, Use the esc key turn off console system

  • Find the Plugins/UniEasy/Resources/Kernel/Console.prefab and select Server component

  • Set the port on the Server component (default value is 55055)

  • Add the UniEasy.Console.Command attribute to your code

  • Run the game and connect to http://localhost:55055 with your browser

How To Register Commands

[Command ("Quit", "Quit the application.", "Quit")]
public static string Execute (params string[] args)
{
    Application.Quit ();
    #if UNITY_EDITOR
    UnityEditor.EditorApplication.isPlaying = false;
    #endif
    return "Quitting...";
}
Console.RegisterCommand ("Quit", "Quit the application.", "Quit", (args) =>
{
    Application.Quit ();
    #if UNITY_EDITOR
    UnityEditor.EditorApplication.isPlaying = false;
    #endif
    return "Quitting...";
});

Deregister Commands

public class QuitSystem : SystemBehaviour
{
    public override void Initialize (IEventSystem eventSystem, IPoolManager poolManager, GroupFactory groupFactory, PrefabFactory prefabFactory)
    {
        base.Initialize (eventSystem, poolManager, groupFactory, prefabFactory);

        UniEasy.Console.Console.RegisterCommand ("Quit", "Quit the application.", "Quit", (args) =>
        {
            Application.Quit ();
            #if UNITY_EDITOR
            UnityEditor.EditorApplication.isPlaying = false;
            #endif
            return "Quitting...";
        }).AddTo (this.Disposer);
    }
}

Logging

public class ConsoleSystem : SystemBehaviour
{
    void Start ()
    {
        Console.Log ("output");
    }

    public override void OnEnable ()
    {
        base.OnEnable ();

        Console.RegisterLog (OnLog);
    }

    public override void OnDisable ()
    {
        base.OnDisable ();

        Console.DeregisterLog (OnLog);
    }

    void OnLog (string[] args)
    {
        Debug.Log (args.FirstOrDefault ());
    }
}

Default Commands

The console comes with some commands by default

  • HELP - Display the list of available commands or details about a specific command

  • LOADSCENE - Load the specified scene by name. Before you load scene you have to add it to the scenes in build Use File -> Build Settings... in Unity and add the .scene to the scenes in build

  • DEREGISTER - Deregister a specific command.

  • CLEAR - Clear console output.

  • Debug - Open or Close console by input debug on or debug off.

  • QUIT - Quit the application.

Shortcut key

  • Tab - Fast completion command

  • Arrow Up/Down - Input commands history

  • Enter - Execute command

  • ~ - Switch console open or colse

  • Esc - Close console

  • Click 20 times(Android/iOS) - Open console

Debugger

using UniEasy.Console;

public class Example : MonoBehaviour
{
    void Start ()
    {
        Debugger.Log ("white context", "Layer 0");
        Debugger.LogWarnning ("yellow context", "Layer 1");
        Debugger.LogError ("red context", "Layer 2");
    }
}
  • Debug System Prefab Path : Assets/UniEasy/Resources/Kernel/...

  • Prefabs under the Kernel folder will auto be create when playing and Add to DontDestoryOnLoad scene

  • Debug Config File Path : Assets/UniEasy/Preferences/DebugSetting.asset

  • Selected DebugSetting you can see a IsLogEnable toggle in Inspector Window, if you select IsLogEnable for False, nothing will output on Console Window

  • You can see a ShowOnUGUI toggle in Inspector Window, It mean if you select it for true, Debug Canvas will turn on

  • You can see a DebugView List in Inspector Window, It Include Collapse, Log, Warning, Error same as unity console (click to show/hide corresponding content)

  • You can see a DebugMask List in Inspector Window, it include all you setted layer name (eg. If set Layer 0 for false white context will not be output on Console Window)

  • The new layer will auto add to DebugMask List when you do Debugger.Log (content, layer name) in editor playing

  • If you want to open the Debug Canvas in the scene, you just need to press the ~ key and input debug on or debug true then press the enter key

Clone this wiki locally