디바이스에서 Debug.Log 메시지 출력하지 않도록 하기
[추가] 2024-04-17
#define으로 Editor, Device등 원하는 곳에 띄울 수 있게 약간 변형함
#if UNITY_EDITOR
#define MY_DEBUG
#endif
using UnityEngine;
using System.Collections;
using System;
using UnityEngine.Internal;
///
/// It overrides UnityEngine.Debug to mute debug messages completely on a platform-specific basis.
///
/// Putting this inside of 'Plugins' foloder is ok.
///
/// Important:
/// Other preprocessor directives than 'UNITY_EDITOR' does not correctly work.
///
/// Note:
/// [Conditional] attribute indicates to compilers that a method call or attribute should be
/// ignored unless a specified conditional compilation symbol is defined.
///
/// See Also:
/// http://msdn.microsoft.com/en-us/library/system.diagnostics.conditionalattribute.aspx
///
/// 2012.11. @kimsama
///
/// - Unity 5.x 대응(5.x에 추가된 Debug 함수 추가)
/// - isDebugBuild("Development Build") 시 return.
/// 2016-07-25 by blueasa
public static class Debug
{
public static bool developerConsoleVisible
{
get { return UnityEngine.Debug.developerConsoleVisible; }
}
public static bool isDebugBuild
{
//get { return UnityEngine.Debug.isDebugBuild; }
#if MY_DEBUG
get { return true; }
#else
get { return false; }
#endif
}
public static ILogger logger
{
get { return UnityEngine.Debug.unityLogger; }
}
public static void Assert(bool condition)
{
if (false == isDebugBuild)
return;
UnityEngine.Debug.Assert(condition);
}
public static void Assert(bool condition, string message)
{
if (false == isDebugBuild)
return;
UnityEngine.Debug.Assert(condition, message);
}
public static void Assert(bool condition, object message)
{
if (false == isDebugBuild)
return;
UnityEngine.Debug.Assert(condition, message);
}
public static void Assert(bool condition, UnityEngine.Object context)
{
if (false == isDebugBuild)
return;
UnityEngine.Debug.Assert(condition, context);
}
public static void Assert(bool condition, string message, UnityEngine.Object context)
{
if (false == isDebugBuild)
return;
UnityEngine.Debug.Assert(condition, message, context);
}
public static void Assert(bool condition, object message, UnityEngine.Object context)
{
if (false == isDebugBuild)
return;
UnityEngine.Debug.Assert(condition, message, context);
}
public static void AssertFormat(bool condition, string format, params object[] args)
{
if (false == isDebugBuild)
return;
UnityEngine.Debug.AssertFormat(condition, format, args);
}
public static void AssertFormat(bool condition, UnityEngine.Object context, string format, params object[] args)
{
if (false == isDebugBuild)
return;
UnityEngine.Debug.AssertFormat(condition, context, format, args);
}
public static void Break()
{
if (false == isDebugBuild)
return;
UnityEngine.Debug.Break();
}
public static void ClearDeveloperConsole()
{
if (false == isDebugBuild)
return;
UnityEngine.Debug.ClearDeveloperConsole();
}
public static void DebugBreak()
{
if (false == isDebugBuild)
return;
UnityEngine.Debug.DebugBreak();
}
public static void DrawLine(Vector3 start, Vector3 end)
{
if (false == isDebugBuild)
return;
UnityEngine.Debug.DrawLine(start, end);
}
public static void DrawLine(Vector3 start, Vector3 end, Color color)
{
if (false == isDebugBuild)
return;
UnityEngine.Debug.DrawLine(start, end, color);
}
public static void DrawLine(Vector3 start, Vector3 end, Color color, float duration)
{
if (false == isDebugBuild)
return;
UnityEngine.Debug.DrawLine(start, end, color, duration);
}
public static void DrawLine(Vector3 start, Vector3 end, [DefaultValue("Color.white")] Color color, [DefaultValue("0.0f")] float duration, [DefaultValue("true")] bool depthTest)
{
if (false == isDebugBuild)
return;
UnityEngine.Debug.DrawLine(start, end, color, duration, depthTest);
}
public static void DrawRay(Vector3 start, Vector3 dir)
{
if (false == isDebugBuild)
return;
UnityEngine.Debug.DrawRay(start, dir);
}
public static void DrawRay(Vector3 start, Vector3 dir, Color color)
{
if (false == isDebugBuild)
return;
UnityEngine.Debug.DrawRay(start, dir, color);
}
public static void DrawRay(Vector3 start, Vector3 dir, Color color, float duration)
{
if (false == isDebugBuild)
return;
UnityEngine.Debug.DrawRay(start, dir, color, duration);
}
public static void DrawRay(Vector3 start, Vector3 dir, [DefaultValue("Color.white")] Color color, [DefaultValue("0.0f")] float duration, [DefaultValue("true")] bool depthTest)
{
if (false == isDebugBuild)
return;
UnityEngine.Debug.DrawRay(start, dir, color, duration, depthTest);
}
public static void Log(object message)
{
if (false == isDebugBuild)
return;
UnityEngine.Debug.Log(message);
}
public static void Log(object message, UnityEngine.Object context)
{
if (false == isDebugBuild)
return;
UnityEngine.Debug.Log(message, context);
}
public static void LogAssertion(object message)
{
//if (false == isDebugBuild)
// return;
UnityEngine.Debug.LogAssertion(message);
}
public static void LogAssertion(object message, UnityEngine.Object context)
{
//if (false == isDebugBuild)
// return;
UnityEngine.Debug.LogAssertion(message, context);
}
public static void LogAssertionFormat(string format, params object[] args)
{
//if (false == isDebugBuild)
// return;
UnityEngine.Debug.LogAssertionFormat(format, args);
}
public static void LogAssertionFormat(UnityEngine.Object context, string format, params object[] args)
{
//if (false == isDebugBuild)
// return;
UnityEngine.Debug.LogAssertionFormat(context, format, args);
}
public static void LogError(object message)
{
//if (false == isDebugBuild)
// return;
UnityEngine.Debug.LogError(message);
}
public static void LogError(object message, UnityEngine.Object context)
{
//if (false == isDebugBuild)
// return;
UnityEngine.Debug.LogError(message, context);
}
public static void LogErrorFormat(string format, params object[] args)
{
//if (false == isDebugBuild)
// return;
UnityEngine.Debug.LogErrorFormat(format, args);
}
public static void LogErrorFormat(UnityEngine.Object context, string format, params object[] args)
{
//if (false == isDebugBuild)
// return;
UnityEngine.Debug.LogErrorFormat(context, format, args);
}
public static void LogException(Exception exception)
{
//if (false == isDebugBuild)
// return;
UnityEngine.Debug.LogException(exception);
}
public static void LogException(string exception)
{
Exception ex = new Exception(exception);
UnityEngine.Debug.LogException(ex);
}
public static void LogException(Exception exception, UnityEngine.Object context)
{
//if (false == isDebugBuild)
// return;
UnityEngine.Debug.LogException(exception, context);
}
public static void LogFormat(string format, params object[] args)
{
if (false == isDebugBuild)
return;
UnityEngine.Debug.LogFormat(format, args);
}
public static void LogFormat(UnityEngine.Object context, string format, params object[] args)
{
if (false == isDebugBuild)
return;
UnityEngine.Debug.LogFormat(context, format, args);
}
public static void LogWarning(object message)
{
if (false == isDebugBuild)
return;
UnityEngine.Debug.LogWarning(message);
}
public static void LogWarning(object message, UnityEngine.Object context)
{
if (false == isDebugBuild)
return;
UnityEngine.Debug.LogWarning(message, context);
}
public static void LogWarningFormat(string format, params object[] args)
{
if (false == isDebugBuild)
return;
UnityEngine.Debug.LogWarningFormat(format, args);
}
public static void LogWarningFormat(UnityEngine.Object context, string format, params object[] args)
{
if (false == isDebugBuild)
return;
UnityEngine.Debug.LogWarningFormat(context, format, args);
}
}
----
[추가][Unity 5.3 이상]
It works. And, Unity 5.3 provides an easier solution: Debug.logger.logEnabled=false to disable it. [출처] https://gist.github.com/kimsama/4123043 |
'Unity3D > Tips' 카테고리의 다른 글
하이어라키(Hierarchy)에서 GameObject Active/InActive HotKey for NGUI (2) | 2013.10.28 |
---|---|
iOS Player 빌드 사이즈 최적화 하기 (0) | 2013.08.19 |
유니티 안드로이드 플러그인 만들기 (0) | 2013.07.24 |
Unity3d Texture 레퍼런스정리 (0) | 2013.07.03 |
유니티 메모리 최적화 (0) | 2013.07.03 |
zhangzhibin commented on 6 Nov 2016