纳金网

标题: Unity的log信息记录到文本文件中 [打印本页]

作者: 狂风大尉    时间: 2014-12-30 00:35
标题: Unity的log信息记录到文本文件中
  1. using UnityEngine;

  2. using System.Collections;

  3. using System.IO;

  4. public class LzhLog : MonoBehaviour

  5. {

  6. static int line = 0;

  7. public static void print(string info)

  8. {

  9. line ++;

  10. string path = Application.dataPath + “/LogFile.txt”;

  11. StreamWriter sw;

  12. //Debug.Log (path);

  13. if (line == 1)

  14. {

  15. sw = new StreamWriter(path, false);

  16. string fileTitle = “日志文件创建的时间  ” + System.DateTime.Now.ToString();

  17. sw.WriteLine (fileTitle);

  18. }

  19. else

  20. {

  21. sw = new StreamWriter (path, true);

  22. }

  23. string lineInfo = line + “\t” + “时刻 ” + Time.time + “: ”;

  24. sw.WriteLine (lineInfo);

  25. sw.WriteLine (info);

  26. Debug.Log (info);

  27. sw.Flush ();

  28. sw.Close ();

  29. }

  30. // Update is called once per frame

  31. void Update ()

  32. {

  33. // test

  34. if(Input.GetKeyDown(KeyCode.Space))

  35. {

  36. LexunLog.print (“测试信息”);

  37. }

  38. }

  39. }
复制代码





欢迎光临 纳金网 (http://old.narkii.com/club/) Powered by Discuz! X2.5