gpt4 book ai didi

How can I get the error message that the mouse is hovering over?(如何获得鼠标悬停的错误信息?)

翻译 作者:bug小助手 更新时间:2023-10-26 22:34:07 26 4
gpt4 key购买 nike



I'm trying to write an editor related to debugging. I believe there isn't any function in Unity that allows me to retrieve debug messages. Is it possible to access the error message I select in the Debug window?

我正在尝试编写一个与调试相关的编辑器。我相信在Unity中没有任何函数可以让我检索调试消息。是否可以访问我在调试窗口中选择的错误消息?


enter image description here


I tried the Application.logMessageReceived function, but it doesn't work in the editor.

我尝试了Application.logMessageReceided函数,但它在编辑器中不起作用。


更多回答

I dont believe it works that way. I believe you have to trap the debug messages as they are made, then you can do something with them if you control the window etc.

我不相信事情会是这样的。我相信你必须在生成调试消息时捕获它们,然后如果你控制了窗口等,你就可以对它们做些什么。

docs.unity3d.com/ScriptReference/ILogger.html

Docs.unity3d.com/ScriptReference/ILogger.html

优秀答案推荐

You can certainly achieve this using reflection. I'll provide you with an example.

当然,您可以使用反射来实现这一点。我将为您提供一个例子。


        // Get the Assembly of Unity
var assembly = typeof(EditorWindow).Assembly;

// Get the type UnityEditor.ConsoleWindow
var consoleWindowType = assembly.GetType("UnityEditor.ConsoleWindow");

// Retrieve the ms_ConsoleWindow field
var ms_ConsoleWindowField = consoleWindowType.GetField("ms_ConsoleWindow", BindingFlags.Static | BindingFlags.NonPublic);

// Get the value of ms_ConsoleWindow to obtain the ConsoleWindow object
var consoleWindow = (EditorWindow)ms_ConsoleWindowField.GetValue(null);

// Retrieve the m_SelectedLogEntry field
var m_SelectedLogEntryField = consoleWindowType.GetField("m_ActiveText", BindingFlags.Instance | BindingFlags.NonPublic);

// Get the value of m_SelectedLogEntry from the ConsoleWindow object
var selectedLogEntry = m_SelectedLogEntryField.GetValue(consoleWindow);

// Extract the log message from selectedLogEntry
var selectedLog = selectedLogEntry?.ToString();


Github Gist example link

GitHub Gist示例链接


更多回答

This is incredible. It worked perfectly for me. Thank you, my friend.

这太不可思议了。它对我来说非常有效。谢谢你,我的朋友。

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com