├── .gitignore ├── Assets ├── Console.meta └── Console │ ├── Font.meta │ ├── Font │ ├── monofonto.ttf │ └── monofonto.ttf.meta │ ├── Prefabs.meta │ ├── Prefabs │ ├── ConsoleCanvas.prefab │ └── ConsoleCanvas.prefab.meta │ ├── Scenes.meta │ ├── Scenes │ ├── Main.unity │ └── Main.unity.meta │ ├── Scripts.meta │ └── Scripts │ ├── GameConsole.cs │ ├── GameConsole.cs.meta │ ├── Test.cs │ └── Test.cs.meta ├── ProjectSettings ├── AudioManager.asset ├── ClusterInputManager.asset ├── DynamicsManager.asset ├── EditorBuildSettings.asset ├── EditorSettings.asset ├── GraphicsSettings.asset ├── InputManager.asset ├── NavMeshAreas.asset ├── NetworkManager.asset ├── Physics2DSettings.asset ├── ProjectSettings.asset ├── ProjectVersion.txt ├── QualitySettings.asset ├── TagManager.asset ├── TimeManager.asset ├── UnityAdsSettings.asset └── UnityConnectSettings.asset ├── README.md ├── UnityConsole.gif └── UnityConsole.unitypackage /.gitignore: -------------------------------------------------------------------------------- 1 | /[Ll]ibrary/ 2 | /[Tt]emp/ 3 | /[Oo]bj/ 4 | /[Bb]uild/ 5 | /[Bb]uilds/ 6 | /Assets/AssetStoreTools* 7 | 8 | # Autogenerated VS/MD solution and project files 9 | ExportedObj/ 10 | *.csproj 11 | *.unityproj 12 | *.sln 13 | *.suo 14 | *.tmp 15 | *.user 16 | *.userprefs 17 | *.pidb 18 | *.booproj 19 | *.svd 20 | 21 | 22 | # Unity3D generated meta files 23 | *.pidb.meta 24 | 25 | # Unity3D Generated File On Crash Reports 26 | sysinfo.txt 27 | 28 | # Builds 29 | *.apk 30 | -------------------------------------------------------------------------------- /Assets/Console.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a96b5b5b48308c94da849eee191440a4 3 | folderAsset: yes 4 | timeCreated: 1468287074 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Console/Font.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 453fccf05804e764eb22696dc1e61423 3 | folderAsset: yes 4 | timeCreated: 1467328265 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Console/Font/monofonto.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LorenzGit/UnityConsole/67ff08ea5fd9204b8dc5969a1a68fefbb5dcc75d/Assets/Console/Font/monofonto.ttf -------------------------------------------------------------------------------- /Assets/Console/Font/monofonto.ttf.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c63c570767883db4ab91b77c18e5cb0a 3 | timeCreated: 1467329586 4 | licenseType: Pro 5 | TrueTypeFontImporter: 6 | serializedVersion: 3 7 | fontSize: 16 8 | forceTextureCase: -2 9 | characterSpacing: 1 10 | characterPadding: 0 11 | includeFontData: 1 12 | fontNames: [] 13 | fallbackFontReferences: [] 14 | customCharacters: 15 | fontRenderingMode: 0 16 | ascentCalculationMode: 1 17 | userData: 18 | assetBundleName: 19 | assetBundleVariant: 20 | -------------------------------------------------------------------------------- /Assets/Console/Prefabs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6c99f0c0359c2461892979f8472fe19f 3 | folderAsset: yes 4 | timeCreated: 1467338075 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Console/Prefabs/ConsoleCanvas.prefab: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LorenzGit/UnityConsole/67ff08ea5fd9204b8dc5969a1a68fefbb5dcc75d/Assets/Console/Prefabs/ConsoleCanvas.prefab -------------------------------------------------------------------------------- /Assets/Console/Prefabs/ConsoleCanvas.prefab.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c19346f9d5c484f09b6f80dc774415d5 3 | timeCreated: 1467338078 4 | licenseType: Free 5 | NativeFormatImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Console/Scenes.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: fd0575b14242002468e89cad13d2cd88 3 | folderAsset: yes 4 | timeCreated: 1466805056 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Console/Scenes/Main.unity: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LorenzGit/UnityConsole/67ff08ea5fd9204b8dc5969a1a68fefbb5dcc75d/Assets/Console/Scenes/Main.unity -------------------------------------------------------------------------------- /Assets/Console/Scenes/Main.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f4e8d958809cc714b93f8f4bead82d7b 3 | timeCreated: 1466805081 4 | licenseType: Pro 5 | DefaultImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Console/Scripts.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ffd0f924ada4eac4f8f723485f6f8cdf 3 | folderAsset: yes 4 | timeCreated: 1466805071 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Console/Scripts/GameConsole.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text.RegularExpressions; 4 | using UnityEngine; 5 | using UnityEngine.UI; 6 | 7 | public class GameConsole : MonoBehaviour 8 | { 9 | #region Constants 10 | 11 | /// 12 | /// Amount of visible lines on the screen 13 | /// 14 | private const int MaxNumberOfLines = 14; 15 | 16 | /// 17 | /// Amount of characters per line 18 | /// 19 | private const float CharacterWidth = 40f; 20 | 21 | /// 22 | /// Height of each line 23 | /// 24 | private const float LineHeight = 40f; 25 | 26 | #endregion 27 | 28 | 29 | #region Singleton 30 | 31 | /// 32 | /// Singleton instance for the MonoBehavior 33 | /// 34 | private static GameConsole _instance; 35 | 36 | #endregion 37 | 38 | 39 | #region Structs 40 | 41 | /// 42 | /// Struct that holds the info of each line 43 | /// 44 | private struct ConsoleString 45 | { 46 | /// 47 | /// Text on the line 48 | /// 49 | public string text; 50 | 51 | /// 52 | /// Color of the line 53 | /// 54 | public Color color; 55 | 56 | 57 | /// 58 | /// Initializes a new instance of the struct. 59 | /// 60 | /// Text. 61 | /// Color. 62 | public ConsoleString (string text, Color color) 63 | { 64 | this.text = text; 65 | this.color = color; 66 | } 67 | } 68 | 69 | 70 | /// 71 | /// Struct that holds the callback and description for a console command 72 | /// 73 | private struct ConsoleCallback 74 | { 75 | /// 76 | /// Action to execute 77 | /// 78 | public Delegate callback; 79 | 80 | /// 81 | /// Description of the command 82 | /// 83 | public string description; 84 | } 85 | 86 | #endregion 87 | 88 | 89 | #region Fields 90 | 91 | /// 92 | /// Holds MaxNumberOfLines in Text. 93 | /// 94 | private readonly List _textGameObjects = new List (); 95 | 96 | /// 97 | /// List of colors to alternate through for easier line reading 98 | /// 99 | private Color[] _colors = new Color[2]{ Color.white, Color.cyan }; 100 | 101 | /// 102 | /// Current index into the colors array 103 | /// 104 | private int _currentColor = 0; 105 | 106 | //Current line color 107 | /// 108 | /// Holds list of all strings ever logged 109 | /// 110 | private List _consoleStrings = new List (); 111 | 112 | /// 113 | /// Index of the current line at the top 114 | /// 115 | private int _currentLine = 0; 116 | 117 | /// 118 | /// Transform that holds the content 119 | /// 120 | private RectTransform _contentRectTranform; 121 | 122 | /// 123 | /// Scrolling instance 124 | /// 125 | private ScrollRect _scrollRect; 126 | 127 | /// 128 | /// Input text instance 129 | /// 130 | private InputField _inputTextField; 131 | 132 | /// 133 | /// Dictionary that holds all callbacks 134 | /// 135 | private Dictionary _callbacks = new Dictionary (); 136 | 137 | /// 138 | /// True if we have initialized the console 139 | /// 140 | private bool _isInitialized; 141 | 142 | /// 143 | /// RectTransform of the console 144 | /// 145 | private RectTransform _rectTransform; 146 | 147 | /// 148 | /// Calculated maximum number of characters per line 149 | /// 150 | private int _maxCharsPerLine; 151 | 152 | #endregion 153 | 154 | 155 | #region Public methods 156 | 157 | /// 158 | /// Opens or Closes the console 159 | /// 160 | public static void ToggleConsole() 161 | { 162 | if (_instance != null ) 163 | { 164 | if (_instance.gameObject.activeSelf == false) 165 | { 166 | OpenConsole(); 167 | } 168 | else 169 | { 170 | CloseConsole(); 171 | } 172 | } 173 | } 174 | 175 | 176 | /// 177 | /// Opens the console 178 | /// 179 | public static void OpenConsole () 180 | { 181 | if (_instance != null && _instance.gameObject.activeSelf == false) { 182 | _instance.CalculateMaxCharsPerLine (); 183 | _instance.gameObject.SetActive (true); 184 | _instance._scrollRect.verticalScrollbar.value = 0f; 185 | _instance.SetContentPosition (); 186 | } 187 | } 188 | 189 | 190 | /// 191 | /// Closes the console 192 | /// 193 | public static void CloseConsole () 194 | { 195 | if (_instance != null) { 196 | _instance.gameObject.SetActive (false); 197 | } 198 | } 199 | 200 | 201 | /// 202 | /// Adds a callback for the console. Callback method signature can either be empty or contain all strings 203 | /// 204 | /// Name of the console command. 205 | /// Callback. 206 | /// Description. 207 | public static void AddCallback (string s, Delegate callback, string description = "") 208 | { 209 | if (_instance != null) { 210 | _instance._callbacks [s] = new ConsoleCallback { 211 | callback = callback, 212 | description = description 213 | }; 214 | } 215 | } 216 | 217 | /// 218 | /// Adds a callback for the console. Callback method signature can either be empty or contain all strings 219 | /// 220 | /// Name of the console command. 221 | /// Callback. 222 | /// Description. 223 | public static void AddCallback(string s, Action callback, string description = "") 224 | { 225 | AddCallback(s, (Delegate)callback, description); 226 | } 227 | 228 | /// 229 | /// Adds a callback for the console. Callback method signature can either be empty or contain all strings 230 | /// 231 | /// Name of the console command. 232 | /// Callback. 233 | /// Description. 234 | public static void AddCallback(string s, Action callback, string description = "") 235 | { 236 | AddCallback(s, (Delegate)callback, description); 237 | } 238 | 239 | /// 240 | /// Removes a callback 241 | /// 242 | /// S. 243 | public static void RemoveCallback (string s) 244 | { 245 | if (_instance != null) { 246 | _instance._callbacks.Remove (s); 247 | } 248 | } 249 | 250 | #endregion 251 | 252 | #region Initialization 253 | 254 | /// 255 | /// Initializes the GameObject 256 | /// 257 | public void Initialize () 258 | { 259 | if (_isInitialized == false) { 260 | _isInitialized = true; 261 | _instance = this; 262 | 263 | InitializeTextObjects (); 264 | 265 | _rectTransform = this.gameObject.GetComponent (); 266 | CalculateMaxCharsPerLine (); 267 | 268 | _contentRectTranform = this.transform.Find ("ScrollView/Viewport/Content").GetComponent (); 269 | 270 | _scrollRect = this.transform.Find ("ScrollView").GetComponent (); 271 | _scrollRect.onValueChanged.AddListener (delegate { 272 | UpdateScroller (); 273 | }); 274 | 275 | _inputTextField = this.gameObject.transform.Find ("InputField").GetComponent (); 276 | 277 | InitButtons (); 278 | 279 | Application.logMessageReceived += HandleLog; //Everytime you write Debug.Log somewhere this handles it. 280 | AddCallbacks (); 281 | Debug.Log ("Write 'help' for a list of commands..."); 282 | 283 | UpdateScroller (); 284 | } 285 | } 286 | 287 | 288 | /// 289 | /// Initialize all the Text GameObjects to pool 290 | /// 291 | private void InitializeTextObjects () 292 | { 293 | // Get the text GameObject from the chain 294 | GameObject textObject = transform.Find ("ScrollView/Viewport/Content/Text").gameObject; 295 | 296 | // Add it to our list 297 | _textGameObjects.Add (textObject.GetComponent ()); 298 | 299 | // Clone the prefab and add the remaining lines 300 | for (int i = 1; i < MaxNumberOfLines; i++) { 301 | GameObject textObjectClone = Instantiate (textObject); 302 | textObjectClone.transform.SetParent (textObject.transform.parent, false); 303 | textObjectClone.transform.localPosition = new Vector3 (5f, -LineHeight * i, 0f); 304 | 305 | _textGameObjects.Add (textObjectClone.GetComponent ()); 306 | } 307 | } 308 | 309 | 310 | /// 311 | /// Add event handlers for the buttons 312 | /// 313 | private void InitButtons () 314 | { 315 | this.gameObject.transform.Find ("SendButton").GetComponent