【问题标题】:Is it possible to show whatever is printed in the Debug.Log into the scene using a text?是否可以使用文本将 Debug.Log 中打印的任何内容显示到场景中?
【发布时间】:2021-09-05 23:27:29
【问题描述】:

我正在尝试将统一控制台中出现的消息转换为场景中的文本。

你有什么建议吗?

【问题讨论】:

标签: unity3d


【解决方案1】:

是的,在 Debug.Log() 中,您已经为其提供了一个值或要在控制台中显示的文本,因此您可以获取该值并将其显示在文本对象中。

【讨论】:

  • 在我的情况下有点不同,因为我需要在 UI 界面中显示的文本与有关 BLE 连接过程的指令和反馈有关,因此最好直接阅读控制台并显示信息界面
  • 我明白了,您在问题中没有提到这一点,
【解决方案2】:

此代码部分工作,因为现在它向我显示出现在控制台中的文本,但只获取第一个文本,然后其他句子排队显示,但这永远不会发生,因为只显示第一个句子。

enter code here

void OnEnable()
{
    Application.logMessageReceivedThreaded += HandleLog;
}

void OnDisable()
{
    Application.logMessageReceivedThreaded -= HandleLog;
}

void HandleLog(string logString, string stackTrace, LogType type)
{
    if (type == LogType.Log){
        string[] splitString = logString.Split(char.Parse(":"));
        string debugKey = splitString[0];
        string debugValue = splitString.Length > 1 ? splitString[1] :"";

        if (debugLogs.ContainsKey(debugKey))
            debugLogs[debugKey] = debugValue;
             else
             debugLogs.Add(debugKey, debugValue);

             
  }

  string displayText = "";
  foreach ( KeyValuePair<string, string> log in debugLogs)
  {
      if(log.Value ==""){
      displayText += log.Key + "\n ";
      }


      else{
       displayText += log.Key + ": " + log.Value + "\n";
       }

    }
            
    display.text = displayText;

}

【讨论】:

  • 请在您的回答中提供更多详细信息。正如目前所写的那样,很难理解您的解决方案。
猜你喜欢
  • 2012-08-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-09-23
  • 1970-01-01
  • 1970-01-01
  • 2018-07-03
  • 1970-01-01
相关资源
最近更新 更多