Skip to content

Commit 7d189bb

Browse files
authored
TestConsole 在屏幕上输出Log
1 parent 1a10038 commit 7d189bb

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

SomeTest/TestConsole.cs

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using UnityEngine;
2+
using UnityEngine.UI;
3+
4+
class TestConsole : MonoBehaviour
5+
{
6+
public Text TestTxt;
7+
private string mContent;
8+
9+
void OnEnable()
10+
{
11+
Application.logMessageReceived += HandleLog;
12+
}
13+
14+
void OnDisable()
15+
{
16+
Application.logMessageReceived -= HandleLog;
17+
}
18+
19+
void OnDestroy()
20+
{
21+
Application.logMessageReceived -= HandleLog;
22+
}
23+
24+
/// <summary>
25+
/// Records a log from the log callback.
26+
/// </summary>
27+
/// <param name="message">Message.</param>
28+
/// <param name="stackTrace">Trace of where the message came from.</param>
29+
/// <param name="type">Type of message (error, exception, warning, assert).</param>
30+
void HandleLog(string message, string stackTrace, LogType type)
31+
{
32+
if (type == LogType.Exception || type == LogType.Error)
33+
{
34+
mContent += message + "\n" + stackTrace + "\n";
35+
show();
36+
}
37+
}
38+
39+
private void show()
40+
{
41+
TestTxt.text = mContent;
42+
}
43+
}

0 commit comments

Comments
 (0)