반응형

아무 게임오브젝트에 해당 스크립트를 붙이면 Debug가 출력 될 때 화면에 똑같이 출력해준다.

에디터에서는 필요없겠지만 기기에서 테스트할 때 편리하다.

 

using System.Collections;
using UnityEngine;

public class DebugToScreen : MonoBehaviour {
 	string myLog;
 	Queue myLogQueue = new Queue ();

 	void OnEnable () {
 		Application.logMessageReceived += HandleLog;
 	}

 	void OnDisable () {
 		Application.logMessageReceived -= HandleLog;
 	}

 	void HandleLog (string logString, string stackTrace, LogType type) {
 		myLog = logString;
 		string newString = "\n [" + type + "] : " + myLog;
 		myLogQueue.Enqueue (newString);
 		if (type == LogType.Exception) {
 			newString = "\n" + stackTrace;
 			myLogQueue.Enqueue (newString);
 		}
 		myLog = string.Empty;
 		foreach (string mylog in myLogQueue) {
 			myLog += mylog;
 		}
 	}

 	void OnGUI () {
 		GUILayout.Label (myLog);
	}
}

 

반응형

+ Recent posts