1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using System.IO;
- using System.Text;
- public class DebugOutputManager{
- private string outpathLog;
- private string outpathError;
- private string outpathWarning;
- public DebugOutputManager ()
- {
- #if UNITY_EDITOR
- outpathLog = Application.dataPath + "/StreamingAssets" + "/outLog.txt";
- outpathError = Application.dataPath + "/StreamingAssets" + "/outLogError.txt";
- outpathWarning = Application.dataPath + "/StreamingAssets" + "/outLogWarining.txt";
- #elif UNITY_IPHONE
- outpathLog = Application.dataPath +"/Raw"+"/outLog.txt";
- outpathError = Application.dataPath +"/Raw"+"/outLogError.txt";
- outpathWarning = Application.dataPath +"/Raw"+"/outLogWarining.txt";
- #elif UNITY_ANDROID
- outpathLog = Application.persistentDataPath + "/outLog.txt";
- outpathError = Application.persistentDataPath + "/outLogError.txt";
- outpathWarning = Application.persistentDataPath + "/outLogWarining.txt";
- #endif
- //每次启动客户端删除之前保存的Log
- if (System.IO.File.Exists(outpathLog))
- {
- File.Delete(outpathLog);
- }
- if (System.IO.File.Exists(outpathError))
- {
- File.Delete(outpathError);
- }
- if (System.IO.File.Exists(outpathWarning))
- {
- File.Delete(outpathWarning);
- }
- }
-
- public void WriteLog (string log, string trace, LogType lType) {
- switch (lType) {
- case LogType.Log:
- using (StreamWriter writer = new StreamWriter(outpathLog, true, Encoding.UTF8)) { writer.WriteLine(log); }
- break;
- case LogType.Warning:
- using (StreamWriter writer = new StreamWriter(outpathWarning, true, Encoding.UTF8)) { writer.WriteLine(log); }
- break;
- case LogType.Error:
- using (StreamWriter writer = new StreamWriter(outpathError, true, Encoding.UTF8)) { writer.WriteLine(log); }
- break;
- }
- }
- }
|