Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- using System.Collections.Generic;
- using System.Text.RegularExpressions;
- public class DebugMessage {
- string message;
- LogType type;
- }
- public class Debugger : MonoBehaviour {
- GUIStyle textStyle = new GUIStyle();
- Rect window = new Rect(0,0, 640, 480);
- List<string> logs = new List<string>();
- int lastcount = 0;
- Vector2 pos = Vector2.zero;
- string input = "";
- void Start () {
- logs = new List<string>();
- window = new Rect(5, Adjust.orig.height-350, 320, 280);
- textStyle.wordWrap = true;
- textStyle.richText = true;
- logs.Add("<System>: <color=green>Welcome to the world of Saisen. Please enjoy your stay!</color>");
- }
- void OnEnable () {
- Application.RegisterLogCallbackThreaded(Log);
- }
- void Update() {
- }
- public void Log(string log, string stackTrace, LogType type) {
- string message = "";
- switch(type) {
- case LogType.Log:
- message = "<System>: <color=white>"+log+"</color>";
- break;
- case LogType.Exception:
- message = "<System>: <color=red>ERR - "+log+"</color>";
- break;
- default:
- return;
- break;
- }
- if (!Regex.Replace(logs[logs.Count-1], "\r\n", string.Empty).Equals(Regex.Replace(message, "\r\n", string.Empty))) {
- if (logs.Count != 0)
- logs.Add("\r\n"+message);
- else
- logs.Add(message);
- }
- }
- void OnGUI() {
- window = Adjust.Reverse(GUI.Window(0, Adjust.FitToScreen(window), DrawWindow, "System Console"));
- if (Event.current.type != EventType.Repaint)
- Debug.Log("<System>: <color=white>Focus Control='"+GUI.GetNameOfFocusedControl()+"'</color>");
- if (Event.current.type == EventType.KeyDown && Event.current.keyCode == KeyCode.Return) {
- if (GUI.GetNameOfFocusedControl().Equals("")) {
- GUI.FocusWindow(0);
- GUI.FocusControl("input");
- } else if (GUI.GetNameOfFocusedControl().Equals("input")) {
- if (!input.Equals("")) {
- logs.Add("<User>: <color=white>"+input+"</color>");
- }
- input = "";
- //GUI.BringWindowToBack(0);
- GUI.FocusControl("");
- GUI.UnfocusWindow();
- }
- }
- }
- void DrawWindow(int id) {
- //Rect size = new Rect(5, Adjust.orig.height-350, 320, 280);
- GUILayout.BeginHorizontal(GUI.skin.box);
- //GUI.Box(Adjust.FitToScreen(window), new Texture());
- pos = GUILayout.BeginScrollView(pos);
- foreach(string msg in logs) {
- GUILayout.Label(msg, textStyle);
- }
- GUILayout.EndScrollView();
- /*if (logs.Count != lastcount) {
- pos = new Vector2(0, GUILayoutUtility.GetLastRect().height);
- lastcount = logs.Count;
- }*/
- GUILayout.EndHorizontal();
- GUILayout.BeginHorizontal(GUI.skin.box);
- GUI.SetNextControlName("input");
- input = GUILayout.TextField(input);
- GUILayout.EndHorizontal();
- //input = GUI.TextField(Adjust.FitToScreen(5,window.y+window.height-30, window.width-100, 30), input);
- //GUI.Button(Adjust.FitToScreen(window.x+window.width-95,window.y+window.height-30, 90, 30), "Send");
- Rect dragzone = window;
- dragzone.width -= dragzone.x;
- dragzone.height = 15;
- GUI.DragWindow(dragzone);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment