第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

從代碼獲取控制臺(tái)記錄的消息

從代碼獲取控制臺(tái)記錄的消息

C#
繁星淼淼 2023-08-13 16:02:33
我想知道是否有任何方法可以從代碼中檢索運(yùn)行時(shí)在控制臺(tái)中記錄的消息。我正在 Android 上部署一個(gè)應(yīng)用程序,據(jù)我所知,控制臺(tái)只能在開(kāi)發(fā)版本下打印,而我希望它在穩(wěn)定版本下打印。
查看完整描述

1 回答

?
幕布斯7119047

TA貢獻(xiàn)1794條經(jīng)驗(yàn) 獲得超8個(gè)贊

LogCallback您可以使用一個(gè)類并添加帶有簽名的回調(diào)方法Application.logMessageReceived和/或Application.logMessageReceivedThreaded

并使用初始化類[RuntimeInitializeOnLoadMethod]

例如,用于在運(yùn)行時(shí)收集所有日志輸出

public static class DebugListener

{

? ? public static List<LogEntry> logs = new List<LogEntry>();


? ? [RuntimeInitializeOnLoadMethod]

? ? private static void InitializeOnLoad()

? ? {

? ? ? ? // removing the callback first makes sure it is only added once

? ? ? ? Application.logMessageReceived -= HandleLog;

? ? ? ? Application.logMessageReceived += HandleLog;

? ? }


? ? private static void HandleLog(string logString, string stackTrace, LogType type)

? ? {

? ? ? ? logs.Add(new LogEntry(logString, stackTrace, type));

? ? }

}


[Serializable]

public class LogEntry

{

? ? public string Message;

? ? public string StackTrace;

? ? public LogType Type;


? ? // default constructor is required for serialization

? ? public LogEntry() { }


? ? public LogEntry(string message, string stackTrace, LogType type)

? ? {

? ? ? ? Message = message;

? ? ? ? StackTrace = stackTrace;

? ? ? ? Type = type;

? ? }

}

當(dāng)然,您不僅可以將它們收集在列表中,HandleLog還可以使用接收到的日志數(shù)據(jù),例如將其添加到組件UI.Text


或者,直接顯示文本的最簡(jiǎn)單解決方案也是使用之前的方法,但在 MonoBehaviour 組件中,并使用和顯示OnGUI文本GUI.Label

public class DebugListener : MonoBehaviour

{

? ? private string lastMessage;

? ? private string lastStackTrace;

? ? private LogType lastType;


? ? private void OnEnable()

? ? {

? ? ? ? Application.logMessageReceived += HandleLog;

? ? }


? ? private void OnDisable()

? ? {

? ? ? ? Application.logMessageReceived -= HandleLog;

? ? }


? ? private void HandleLog(string message, string stack, LogType type)

? ? {

? ? ? ? lastMessage = message;

? ? ? ? lastStackTrace = stack;

? ? ? ? lastType = type;

? ? }


? ? private void OnGUI()

? ? {

? ? ? ? if(string.IsNullOrEmpty(lastMessage)) return;


? ? ? ? // show text at certain offset from left top corner

? ? ? ? // and certain size

? ? ? ? // e.g. simply place it in the center of the screen?

? ? ? ? // and make it overlay the entire screen

? ? ? ? GUI.Label(new Rect(Screen.width / 2f, Screen.height / 2f, Screen.width, Screen.height), $"{lastType}\n{lastMessage}\n{lastStackTrace}");

? ? }

}


查看完整回答
反對(duì) 回復(fù) 2023-08-13
  • 1 回答
  • 0 關(guān)注
  • 128 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)