using UnityEngine; /// <summary> /// An example of a script for a Unity scene that uses ConsoleInGame to make a debug log console. /// </summary> /// <remarks> /// Forked by Joseph Cassano (jplc.ca) from Matthew Miner (www.matthewminer.com)'s Console.cs. /// Fork splits Console.cs into ConsoleInGame.cs for the main console code and ExampleSceneScript /// to show how one would use ConsoleInGame from another script. /// Permission is given to use this script however you please with absolutely no restrictions. /// </remarks> public class ExampleSceneScript : MonoBehaviour { // Variables for use with the console. KeyCode consoleToggleKey; int consoleMargin; Rect consoleWindowRect; bool consoleShow; void OnEnable() { // Tying the Log messages to the console. Application.RegisterLogCallback(ConsoleInGame.HandleLog); } void OnDisable() { // Removing the link between the Log and the console. Application.RegisterLogCallback(null); } // Use this for initialization void Start() { consoleToggleKey = KeyCode.BackQuote; consoleMargin = 20; consoleWindowRect = new Rect(consoleMargin, consoleMargin, Screen.width - (2 * consoleMargin), Screen.height - (2 * consoleMargin)); // Example of Log message created before Update() still being shown in the console Debug.Log("Start Log message."); } // Update is called once per frame void Update() { // Input for displaying/dismissing the console. if (Input.GetKeyDown(consoleToggleKey)) { consoleShow = !consoleShow; } // Creating a Log message to show that the console works. if (Input.GetKeyDown(KeyCode.Space)) { Debug.Log("Example Log message."); } // Insert the code for your scene below. // Also add to any other methods as necessary (like Start()). // ... } void OnGUI() { // Displaying/dismissing the console. if (!consoleShow) { return; } consoleWindowRect = GUILayout.Window(123456, consoleWindowRect, ConsoleInGame.ConsoleWindow, "Console"); } }