Skip to content

Instantly share code, notes, and snippets.

@leegoonz
Forked from kimsama/Debug.cs
Created August 31, 2016 17:50
Show Gist options
  • Save leegoonz/4106007b60aed081ddf9ea2de2ef34ba to your computer and use it in GitHub Desktop.
Save leegoonz/4106007b60aed081ddf9ea2de2ef34ba to your computer and use it in GitHub Desktop.
It overrides UnityEngine.Debug to mute debug messages completely on a platform-specific basis. [Edit] Added isDebugBuild property.
//#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();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment