U3D导出到安卓apk的日志打印管理
2014-08-30 16:56
465 查看
虽然U3D提供真机调试,但是由于内外网的隔离,使得这个流程比较麻烦和不太靠谱。真机调试的另一个方法是查看游戏运行导出的Log日志(U3D的Application.persistentDataPath路径下),下面是一个常用的log日志类
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Text;
public class OutputLog : MonoBehaviour
{
public static OutputLog instance = null;
private string err;
private string log;
private string filePath;
private bool isDebugMode = false;
void Awake()
{
filePath = Application.persistentDataPath + "/P1_log.txt";
if (System.IO.File.Exists(filePath))
{
File.Delete(filePath);
}
instance = this;
Application.RegisterLogCallback(HandleLog);
Debug.Log(filePath);
}
void OnDestroy()
{
instance = null;
Application.RegisterLogCallback(null);
}
private List<string> writeTxt = new List<string>();
private void HandleLog(string logString, string stackTrace, LogType type)
{
if (type == LogType.Error)
{
err += "\n";
err += logString;
err += "\n";
err += stackTrace;
writeTxt.Add("[Err]" + logString);
writeTxt.Add(stackTrace);
}
else
{
log += "\n";
log += logString;
writeTxt.Add("[log]" + logString);
writeTxt.Add(stackTrace);
}
}
void Start ()
{
GameObject.Find("Cube").AddComponent<T1>();
}
void Update ()
{
if (writeTxt.Count <= 0)
{
return;
}
string[] temp = writeTxt.ToArray();
writeTxt.Clear();
using (StreamWriter writer = new StreamWriter(filePath, true, Encoding.UTF8))
{
foreach (string t in temp)
{
writer.WriteLine(t);
}
}
}
}
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Text;
public class OutputLog : MonoBehaviour
{
public static OutputLog instance = null;
private string err;
private string log;
private string filePath;
private bool isDebugMode = false;
void Awake()
{
filePath = Application.persistentDataPath + "/P1_log.txt";
if (System.IO.File.Exists(filePath))
{
File.Delete(filePath);
}
instance = this;
Application.RegisterLogCallback(HandleLog);
Debug.Log(filePath);
}
void OnDestroy()
{
instance = null;
Application.RegisterLogCallback(null);
}
private List<string> writeTxt = new List<string>();
private void HandleLog(string logString, string stackTrace, LogType type)
{
if (type == LogType.Error)
{
err += "\n";
err += logString;
err += "\n";
err += stackTrace;
writeTxt.Add("[Err]" + logString);
writeTxt.Add(stackTrace);
}
else
{
log += "\n";
log += logString;
writeTxt.Add("[log]" + logString);
writeTxt.Add(stackTrace);
}
}
void Start ()
{
GameObject.Find("Cube").AddComponent<T1>();
}
void Update ()
{
if (writeTxt.Count <= 0)
{
return;
}
string[] temp = writeTxt.ToArray();
writeTxt.Clear();
using (StreamWriter writer = new StreamWriter(filePath, true, Encoding.UTF8))
{
foreach (string t in temp)
{
writer.WriteLine(t);
}
}
}
}
相关文章推荐
- [安卓开发]C4Droid:在手机上直接编程,然后导出为apk
- 教你用Cocosdx导出安卓安装文件(.apk)(一)
- 模块管理常规功能自己定义系统的设计与实现(16--模块数据的导出和打印[1])
- vs的lua项目,导出release版本在win上打印日志
- 安卓开发——如何查看Androidstudio和Eclipse导出的APK文件
- 学习的过程之一==关于log4j日志管理看到的自己之二=log4j后台打印日志看解决问题
- unity手游开发--开发安卓项目调试打印日志工具
- android的Log日志打印管理工具类(一)
- 安卓程序运行中突然崩溃的时候打印日志到本地
- android轻松管理安卓应用中的log日志 发布应用时log日志全部去掉的方法
- 教你用Cocosdx导出安卓安装文件(.apk)(二)
- 在安卓开发时用酷派手机无法打印出应用内的日志的解决方法
- 【小超_U3D】Android环境的配置和Unity导出APK
- 批处理导出安卓手机日志文件,压缩,修改文件名以当前时间点
- unity 3d 程序导出为安卓(.apk)的步骤
- android轻松管理安卓应用中的log日志 发布应用时log日志全部去掉的方法
- 教你用Cocosdx导出安卓安装文件(.apk)(一)
- 日志管理系统安卓项目阶段总结安卓
- 现场打印智能无线PDA安卓POS 条码识别、打印、数据采集销售开单收银管理软件
- 轻松管理安卓应用中的log打印信息