监听Unity的打印事件,如常规打印,报错等等。
如下代码为自制的打印日志:
List
void OnEnable()
{
Application.logMessageReceived += HandleLog;
}
void OnDisable()
{
Application.logMessageReceived -= HandleLog;
}
void HandleLog(string logString, string stackTrace, LogType type)
{
mWriteTxt.Add(logString);
}
private void Start()
{
if (File.Exists(Application.dataPath + "/Log/12.txt"))
{
File.Delete(Application.dataPath + "/Log/12.txt");
}
for (int i = 0; i < 3; i++)
{
Debug.Log("aaa");
}
Debug.LogError("cuowu "); -->正常打印事件
int[] str = new int[2] {1,2 };
for (int i = 0; i < 3; i++)
{
Debug.Log(str[i]); -->写一个数组溢出来引发报错}
写入本地的txt文件如下: