Unity管理Debug.log输出的Log
2015-07-02 14:10
453 查看
<p><span style="color: rgb(69, 69, 69); font-family: Verdana, 'Microsoft YaHei'; font-size: 16px; line-height: 30px;">在开发Unity的时候,在输出log的时候大家都会采用Debug.log()的方式来输出Log,但是游戏发布的时候这样的Log是不能关闭的,在用户手机运行产生一堆LOG也不是啥好事,一定要关闭才行、主要是unity官方也没有提供直接关闭的方法。</span></p><p><span style="color: rgb(69, 69, 69); font-family: Verdana, 'Microsoft YaHei'; font-size: 16px; line-height: 30px;">参考文章:http://www.xuanyusong.com/archives/2782</span></p>
using System; using System.Collections.Generic; using System.Text; using UnityEngine; namespace TDebugger { public class TDebug { // 摘要: // Opens or closes developer console. public static bool developerConsoleVisible { get { return Debug.developerConsoleVisible; } set { Debug.developerConsoleVisible = value; } } // // 摘要: // In the Build Settings dialog there is a check box called "Development Build". public static bool isDebugBuild { get { return Debug.isDebugBuild; } } public static void Break() { Debug.Break(); } public static void ClearDeveloperConsole() { Debug.ClearDeveloperConsole(); } public static void DebugBreak() { Debug.DebugBreak(); } // // 摘要: // Draws a line from the point start to end with color for a duration of time // and with or without depth testing. If duration is 0 then the line is rendered // 1 frame. public static void DrawLine(Vector3 start, Vector3 end) { if (s_TDebugToggle) { Debug.DrawLine(start, end); } } // // 摘要: // Draws a line from the point start to end with color for a duration of time // and with or without depth testing. If duration is 0 then the line is rendered // 1 frame. public static void DrawLine(Vector3 start, Vector3 end, Color color) { if (s_TDebugToggle) { Debug.DrawLine(start, end, color); } } // // 摘要: // Draws a line from the point start to end with color for a duration of time // and with or without depth testing. If duration is 0 then the line is rendered // 1 frame. public static void DrawLine(Vector3 start, Vector3 end, Color color, float duration) { if (s_TDebugToggle) { Debug.DrawLine(start, end, color, duration); } } // // 摘要: // Draws a line from the point start to end with color for a duration of time // and with or without depth testing. If duration is 0 then the line is rendered // 1 frame. public static void DrawLine(Vector3 start, Vector3 end, Color color, float duration, bool depthTest) { if (s_TDebugToggle) { Debug.DrawLine(start, end, color, duration, depthTest); } } // // 摘要: // Draws a line from start to start + dir with color for a duration of time // and with or without depth testing. If duration is 0 then the line is rendered // 1 frame. public static void DrawRay(Vector3 start, Vector3 dir) { if (s_TDebugToggle) { Debug.DrawRay(start, dir); } } // // 摘要: // Draws a line from start to start + dir with color for a duration of time // and with or without depth testing. If duration is 0 then the line is rendered // 1 frame. public static void DrawRay(Vector3 start, Vector3 dir, Color color) { if (s_TDebugToggle) { Debug.DrawRay(start, dir, color); } } // // 摘要: // Draws a line from start to start + dir with color for a duration of time // and with or without depth testing. If duration is 0 then the line is rendered // 1 frame. public static void DrawRay(Vector3 start, Vector3 dir, Color color, float duration) { if (s_TDebugToggle) { Debug.DrawRay(start, dir, color, duration); } } // // 摘要: // Draws a line from start to start + dir with color for a duration of time // and with or without depth testing. If duration is 0 then the line is rendered // 1 frame. public static void DrawRay(Vector3 start, Vector3 dir, Color color, float duration, bool depthTest) { if (s_TDebugToggle) { Debug.DrawRay(start, dir, color, duration, depthTest); } } // // 摘要: // Logs message to the Unity Console. public static void Log(object message) { if (s_TDebugToggle) { Debug.Log(message); } } // // 摘要: // Logs message to the Unity Console. public static void Log(object message, UnityEngine.Object context) { if (s_TDebugToggle) { Debug.Log(message, context); } } // // 摘要: // A variant of Debug.Log that logs an error message to the console. public static void LogError(object message) { if (s_TDebugToggle) { Debug.LogError(message); } } // // 摘要: // A variant of Debug.Log that logs an error message to the console. public static void LogError(object message, UnityEngine.Object context) { if (s_TDebugToggle) { Debug.LogError(message, context); } } // // 摘要: // A variant of Debug.Log that logs an error message from an exception to the // console. public static void LogException(Exception exception) { if (s_TDebugToggle) { Debug.LogException(exception); } } // // 摘要: // A variant of Debug.Log that logs an error message from an exception to the // console. public static void LogException(Exception exception, UnityEngine.Object context) { if (s_TDebugToggle) { Debug.LogException(exception, context); } } // // 摘要: // A variant of Debug.Log that logs a warning message to the console. public static void LogWarning(object message) { if (s_TDebugToggle) { Debug.LogWarning(message); } } // // 摘要: // A variant of Debug.Log that logs a warning message to the console. public static void LogWarning(object message, UnityEngine.Object context) { if (s_TDebugToggle) { Debug.LogWarning(message, context); } } /// <summary> /// Debug 开关 /// 默认为开启状态true,false则不输出Debug /// </summary> public static bool Toggle { get { return s_TDebugToggle; } set { s_TDebugToggle = value; } } private static bool s_TDebugToggle = true; } }
将上面的代码打包成DLL,在Unity项目中测试证明可行,下面分享下这个测试包:http://pan.baidu.com/s/1dDq9qpF
相关文章推荐
- Unity3D常用插件下载及使用方法
- Unity导出的Android项目按钮无法点击问题
- Intermediate Unity 3D for iOS: Part 3/3
- UnityShader实例05:Toon(卡通)材质
- [Unity3D]引擎崩溃、异常、警告、BUG与提示总结及解决方法
- Unity学习 - C#委托的介绍(delegate、Action、Func、predicate)
- 【风宇冲】Unity3D教程宝典之两步实现超实用的XML存档
- Unity学习 - C#委托的介绍(delegate、Action、Func、predicate)
- unity多人开发,更新svn后材质丢失(模型贴图全变紫)的问题
- Unity3D游戏开发之从Unity3D项目版本控制说起
- Unity3D实践系列11, 组件的添加和访问
- Unity使用JsonFX插件进行序列化
- 学习笔记:Unity战斗卡牌游戏(三)-----代码加载预设 及 Tween动画使用及播放回掉
- unity 随笔
- Unity3D中使用委托和事件
- unity, GetComponent<Renderer>().bounds.size vs GetComponent<MeshFilter>().sharedMesh.bounds.size
- [Unity3D]Unity3D圣骑士模仿游戏开发传仙灵达到当局岛
- unity里面查找所有物体
- 如何使用Eclipse来打包unity3d工程
- 【Unity3D】学习第一天