IT 이모저모

Unity 로그 출력안하기

exien 2018. 5. 9. 16:56

유니티를 사용하여 게임을 런칭할때 개발하는 동안 출력했던 로그를 릴리즈 환경에서는 출력이 필요 없습니다. 이때 사용하면 유용한 방법을 소개합니다. 


릴리즈 빌드를할때 아래의 코드를 추가하면 유니티 C#의 Contitional 에 의해 유니티 로그 함수가 빈함수로 대체되어 아무 행동도 하지 않게 됩니다.


//#if UNITY_EDITOR
//#define DEBUG
//#endif
using UnityEngine;
using System.Collections;
using System;
using System.IO;
using System.Text.RegularExpressions;
using UnityEngineInternal;
///
/// 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
///
public static class Debug
{
public static bool isDebugBuild
{
get { return UnityEngine.Debug.isDebugBuild; }
}
[System.Diagnostics.Conditional("UNITY_EDITOR")]
public static void Log (object message)
{
UnityEngine.Debug.Log (message);
}
[System.Diagnostics.Conditional("UNITY_EDITOR")]
public static void Log (object message, UnityEngine.Object context)
{
UnityEngine.Debug.Log (message, context);
}
[System.Diagnostics.Conditional("UNITY_EDITOR")]
public static void LogError (object message)
{
UnityEngine.Debug.LogError (message);
}
[System.Diagnostics.Conditional("UNITY_EDITOR")]
public static void LogError (object message, UnityEngine.Object context)
{
UnityEngine.Debug.LogError (message, context);
}
[System.Diagnostics.Conditional("UNITY_EDITOR")]
public static void LogWarning (object message)
{
UnityEngine.Debug.LogWarning (message.ToString ());
}
[System.Diagnostics.Conditional("UNITY_EDITOR")]
public static void LogWarning (object message, UnityEngine.Object context)
{
UnityEngine.Debug.LogWarning (message.ToString (), context);
}
[System.Diagnostics.Conditional("UNITY_EDITOR")]
public static void DrawLine(Vector3 start, Vector3 end, Color color = default(Color), float duration = 0.0f, bool depthTest = true)
{
UnityEngine.Debug.DrawLine(start, end, color, duration, depthTest);
}
[System.Diagnostics.Conditional("UNITY_EDITOR")]
public static void DrawRay(Vector3 start, Vector3 dir, Color color = default(Color), float duration = 0.0f, bool depthTest = true)
{
UnityEngine.Debug.DrawRay(start, dir, color, duration, depthTest);
}
[System.Diagnostics.Conditional("UNITY_EDITOR")]
public static void Assert(bool condition)
{
if (!condition) throw new Exception();
}
}