纳金网
标题:
Unity的log信息记录到文本文件中
[打印本页]
作者:
狂风大尉
时间:
2014-12-30 00:35
标题:
Unity的log信息记录到文本文件中
using UnityEngine;
using System.Collections;
using System.IO;
public class LzhLog : MonoBehaviour
{
static int line = 0;
public static void print(string info)
{
line ++;
string path = Application.dataPath + “/LogFile.txt”;
StreamWriter sw;
//Debug.Log (path);
if (line == 1)
{
sw = new StreamWriter(path, false);
string fileTitle = “日志文件创建的时间 ” + System.DateTime.Now.ToString();
sw.WriteLine (fileTitle);
}
else
{
sw = new StreamWriter (path, true);
}
string lineInfo = line + “\t” + “时刻 ” + Time.time + “: ”;
sw.WriteLine (lineInfo);
sw.WriteLine (info);
Debug.Log (info);
sw.Flush ();
sw.Close ();
}
// Update is called once per frame
void Update ()
{
// test
if(Input.GetKeyDown(KeyCode.Space))
{
LexunLog.print (“测试信息”);
}
}
}
复制代码
欢迎光临 纳金网 (http://old.narkii.com/club/)
Powered by Discuz! X2.5