Komak57

FocusToggleError

Apr 6th, 2014
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.02 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Text.RegularExpressions;
  5.  
  6. public class DebugMessage {
  7.     string message;
  8.     LogType type;
  9. }
  10. public class Debugger : MonoBehaviour {
  11.     GUIStyle textStyle = new GUIStyle();
  12.     Rect window = new Rect(0,0, 640, 480);
  13.     List<string> logs = new List<string>();
  14.     int lastcount = 0;
  15.     Vector2 pos = Vector2.zero;
  16.     string input = "";
  17.     void Start () {
  18.         logs = new List<string>();
  19.         window = new Rect(5, Adjust.orig.height-350, 320, 280);
  20.         textStyle.wordWrap = true;
  21.         textStyle.richText = true;
  22.         logs.Add("<System>: <color=green>Welcome to the world of Saisen. Please enjoy your stay!</color>");
  23.     }
  24.  
  25.     void OnEnable () {
  26.         Application.RegisterLogCallbackThreaded(Log);
  27.     }
  28.  
  29.     void Update() {
  30.     }
  31.  
  32.     public void Log(string log, string stackTrace, LogType type) {
  33.         string message = "";
  34.         switch(type) {
  35.         case LogType.Log:
  36.             message = "<System>: <color=white>"+log+"</color>";
  37.             break;
  38.         case LogType.Exception:
  39.             message = "<System>: <color=red>ERR - "+log+"</color>";
  40.             break;
  41.         default:
  42.             return;
  43.             break;
  44.         }
  45.  
  46.  
  47.         if (!Regex.Replace(logs[logs.Count-1], "\r\n", string.Empty).Equals(Regex.Replace(message, "\r\n", string.Empty))) {
  48.             if (logs.Count != 0)
  49.                 logs.Add("\r\n"+message);
  50.             else
  51.                 logs.Add(message);
  52.         }
  53.     }
  54.  
  55.     void OnGUI() {
  56.         window = Adjust.Reverse(GUI.Window(0, Adjust.FitToScreen(window), DrawWindow, "System Console"));
  57.         if (Event.current.type != EventType.Repaint)
  58.             Debug.Log("<System>: <color=white>Focus Control='"+GUI.GetNameOfFocusedControl()+"'</color>");
  59.         if (Event.current.type == EventType.KeyDown && Event.current.keyCode == KeyCode.Return) {
  60.             if (GUI.GetNameOfFocusedControl().Equals("")) {
  61.                 GUI.FocusWindow(0);
  62.                 GUI.FocusControl("input");
  63.             } else if (GUI.GetNameOfFocusedControl().Equals("input")) {
  64.                 if (!input.Equals("")) {
  65.                     logs.Add("<User>: <color=white>"+input+"</color>");
  66.                 }
  67.                 input = "";
  68.                 //GUI.BringWindowToBack(0);
  69.                 GUI.FocusControl("");
  70.                 GUI.UnfocusWindow();
  71.             }
  72.         }
  73.     }
  74.     void DrawWindow(int id) {
  75.         //Rect size = new Rect(5, Adjust.orig.height-350, 320, 280);
  76.         GUILayout.BeginHorizontal(GUI.skin.box);
  77.         //GUI.Box(Adjust.FitToScreen(window), new Texture());
  78.         pos = GUILayout.BeginScrollView(pos);
  79.         foreach(string msg in logs) {
  80.             GUILayout.Label(msg, textStyle);
  81.         }
  82.         GUILayout.EndScrollView();
  83.         /*if (logs.Count != lastcount) {
  84.             pos = new Vector2(0, GUILayoutUtility.GetLastRect().height);
  85.             lastcount = logs.Count;
  86.         }*/
  87.         GUILayout.EndHorizontal();
  88.         GUILayout.BeginHorizontal(GUI.skin.box);
  89.         GUI.SetNextControlName("input");
  90.         input = GUILayout.TextField(input);
  91.         GUILayout.EndHorizontal();
  92.  
  93.         //input = GUI.TextField(Adjust.FitToScreen(5,window.y+window.height-30, window.width-100, 30), input);
  94.         //GUI.Button(Adjust.FitToScreen(window.x+window.width-95,window.y+window.height-30, 90, 30), "Send");
  95.  
  96.         Rect dragzone = window;
  97.         dragzone.width -= dragzone.x;
  98.         dragzone.height = 15;
  99.         GUI.DragWindow(dragzone);
  100.     }
  101. }
Advertisement
Add Comment
Please, Sign In to add comment