Unity抓取程序报错log
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.Text;
public class LogEvent : MonoBehaviour
{
StringBuilder logBuilder = new StringBuilder ();
void Awake ()
{
Application.logMessageReceived += HandleLog;
}
// Use this for initialization
void Start ()
{
Debug.LogError ("Test...");
}
// Update is called once per frame
void Update ()
{
}
void OnGUI ()
{
GUILayout.Label (logBuilder.ToString ());
}
void HandleLog (string condition, string stackTrace, LogType type)
{
if (type == LogType.Error || type == LogType.Exception) {
string message = string.Format ("condition = {0} \n stackTrace = {1} \n type = {2}", condition, stackTrace, type);
SendLog (message);
}
}
void SendLog (string message)
{
logBuilder.Append (message);
}
}