先修复一下,错误的场景 删除不必要的钓场资产 修复into场景 update:更新meta文件,修复报错 update:修复资源 修复第一章节建造 修复建造第三章 update:删除多余内容 update:更新README.md update:还原图标 update:更新README update:更新配置
44 lines
1.2 KiB
C#
44 lines
1.2 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using UnityEngine;
|
|
|
|
public class FileLogger : MonoBehaviour
|
|
{
|
|
private string logFilePath;
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
// 定义日志文件路径
|
|
logFilePath = Application.persistentDataPath + "/game_log.txt";
|
|
|
|
// 删除旧日志文件(如果存在)
|
|
if (File.Exists(logFilePath))
|
|
{
|
|
File.Delete(logFilePath);
|
|
}
|
|
|
|
// 注册自定义日志处理器
|
|
Application.logMessageReceived += HandleLog;
|
|
}
|
|
|
|
void OnDestroy()
|
|
{
|
|
// 注销自定义日志处理器
|
|
Application.logMessageReceived -= HandleLog;
|
|
}
|
|
|
|
void HandleLog(string logString, string stackTrace, LogType type)
|
|
{
|
|
// 将日志信息写入文件
|
|
using (StreamWriter writer = new StreamWriter(logFilePath, true))
|
|
{
|
|
writer.WriteLine($"[{type}] {logString}");
|
|
if (type == LogType.Error || type == LogType.Exception)
|
|
{
|
|
writer.WriteLine(stackTrace); // 如果是错误或异常,写入堆栈跟踪
|
|
}
|
|
}
|
|
}
|
|
}
|