// Use this for initialization
void Start()
{
textLog = gameObject.GetComponentInChildren<Text>();
}
void OnEnable()
{
Application.logMessageReceived += LogMessage;
}
void OnDisable()
{
Application.logMessageReceived -= LogMessage;
}
public void LogMessage(string message, string stackTrace, LogType type)
{
totalString += $"\n 第{index}条: \n {type} \n {message} \n {stackTrace}";
if (textLog != null)
{
textLog.text = totalString;
}
index++;
}
private void OnDestroy()
{
var path = "";
var now = System.DateTime.Now.ToString().Replace(":","_").Replace("/","-");
path = @$"D:/Unity日志文件{now}.txt";
System.IO.File.WriteAllText(path,totalString);
}
Unity Debug信息如何保存到一个文件中并输出
最新推荐文章于 2024-04-26 18:05:13 发布