- Home /
Moving all Debug information to a Custom Console
Hey Everyone
I'm having some trouble trying to find out how to send debug information to a custom console. I Whipped up a quick Script that uses unity 5s UI and a textbox. I've got this so far
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System;
using UnityEngine.SceneManagement;
public class Dev_Console : MonoBehaviour {
//This Script is a Simple Dev Console Script it will allow Commands to be entered and important dev information to be seen in game and build versions
//This script is being designed with Reusability in mind
public Text ConsoleTextFeild;
public GameObject TextInput;
public GameObject Console_Overlay;
public bool Console_open = false;
public Animator Anim;
public GameObject SelectedDevObject;
public string Cur_Input;
string CommandText;
public List<string> data;
void Start () {
Anim = Console_Overlay.GetComponent<Animator>();
Anim.Play("Offscreen"); //Open console
data = new List<string>();
//Add Build Information here
Message("Build 2.0.0");
Message("Build Title| AI OverHaul");
Message("Type help to bring up options");
}
// Update is called once per frame
void Update () {
if (Input.GetKeyDown(KeyCode.BackQuote)) //quick quit game
{
OpenOrClose_Console(); //open or Close the Console
}
}
public void checkInput () //Input Commands here
{
Cur_Input = TextInput.GetComponent<InputField>().text;
Message(Cur_Input); //Send input to console
Message(""); // an Empty Space-er
CommandText = Cur_Input.ToLower(); //convert all the characters to lower case
switch (CommandText)
{
case "help":
Message("A list of Commands are presented here");
Line();
BR();
Message("clear -- Clears the console");
Message("exit -- Exits the game");
Message("reset -- Reset current level");
Message("help -- prints a helpfull list of options");
Message("show_stats -- prints a helpfull information about the currently selected object");
Message("display_BuildInfo -- Prints a helpfull list of Information about the current build what was added or changed");
break;
case "exit":
Message("Quiting Application");
Application.Quit();
break;
case "reset":
Message("Scene was Reset");
int scene = SceneManager.GetActiveScene().buildIndex;
SceneManager.LoadScene(scene, LoadSceneMode.Single);
break;
case "show_stats":
if(SelectedDevObject != null) //Cheack if a object is avalable
{
Message("Displaying stats for " + SelectedDevObject);
Line();
BR();
PopulateStats();
}
else
{
Message("Error no Object Selected, (Please Select an object by clicking on it)");
BR();
}
break;
case "clear": //clear the console
ConsoleTextFeild.text = "";
Message("Build 2.0.0");
Message("Build Title| AI OverHaul");
Message("Type help to bring up options");
break;
//*****************************************BUILD INFO******************************************************************************
case "display_buildinfo":
// I removed the build info to save time on reading theres no errors here
break;
//*****************************************BUILD INFO******************************************************************************
//Defualt if there is no command relateing to the allowed list
default:
Message("Error!!");
Message("Unrecognized command Type help for command list");
Debug.Log("Unrecognized command Type help for command list");
BR();
break;
}
TextInput.GetComponent<InputField>().text = ""; //Clear Input Field
}
public void Message (string message) // a custom debug call
{
ConsoleTextFeild.text += "\n" +"> "+ message; //add a new line with the messege
}
void BR ()// Break
{
Message("");
}
void Line() //Add a Line to the Text
{
Message("___________________________________");
}
public void PopulateStats ()
{
for (int i = 0; i < data.Count; i++)
{
Message(data[i]);
}
Message(""); // an Empty Space-er
}
void OpenOrClose_Console ()
{
if(Console_open == false)
{// Open console
Anim.Play("Dev_Console_Open"); //Open console
Console_open = true;
}
else
{//close Console
Anim.Play("Dev_Console_Close"); //close console
Console_open = false;
}
}
}
As you can see I have some commands and a way to send log messeges to the console "Messege("my messege");" what Im trying to do is send Unity Errors and warnings here aswell and im just stumped as to how to do this I took a look around online and found a few things, but it just ended up crashing the Unity editor It was something to do with the Logger https://docs.unity3d.com/ScriptReference/Logger.html.
Any help or any direction I could get on this whould be much appreciated.
Thanks.
Answer by JVLVince · Dec 20, 2017 at 09:31 AM
Checkout LogCallback and logMessageReceived. Maybe it's what you are trying to implement
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Get the last Debug messeage 1 Answer
Input Button is not setup Error 1 Answer
Why am I seeing: error CS0117: `Debug' does not contain a definition for `LogWarning' 1 Answer