Skip to content

Instantly share code, notes, and snippets.

@MBehtemam
Forked from onevcat/D.cs
Last active August 29, 2015 14:17
Show Gist options
  • Save MBehtemam/6cce4973759a8feb8a4c to your computer and use it in GitHub Desktop.
Save MBehtemam/6cce4973759a8feb8a4c to your computer and use it in GitHub Desktop.
#define DEBUG_LEVEL_LOG
#define DEBUG_LEVEL_WARN
#define DEBUG_LEVEL_ERROR
using UnityEngine;
using System.Collections;
// setting the conditional to the platform of choice will only compile the method for that platform
// alternatively, use the #defines at the top of this file
public class D
{
[System.Diagnostics.Conditional( "DEBUG_LEVEL_LOG" )]
[System.Diagnostics.Conditional( "DEBUG_LEVEL_WARN" )]
[System.Diagnostics.Conditional( "DEBUG_LEVEL_ERROR" )]
public static void log( object format, params object[] paramList )
{
if( format is string )
Debug.Log( string.Format( format as string, paramList ) );
else
Debug.Log( format );
}
[System.Diagnostics.Conditional( "DEBUG_LEVEL_WARN" )]
[System.Diagnostics.Conditional( "DEBUG_LEVEL_ERROR" )]
public static void warn( object format, params object[] paramList )
{
if( format is string )
Debug.LogWarning( string.Format( format as string, paramList ) );
else
Debug.LogWarning( format );
}
[System.Diagnostics.Conditional( "DEBUG_LEVEL_ERROR" )]
public static void error( object format, params object[] paramList )
{
if( format is string )
Debug.LogError( string.Format( format as string, paramList ) );
else
Debug.LogError( format );
}
[System.Diagnostics.Conditional( "UNITY_EDITOR" )]
[System.Diagnostics.Conditional( "DEBUG_LEVEL_LOG" )]
public static void assert( bool condition )
{
assert( condition, string.Empty, true );
}
[System.Diagnostics.Conditional( "UNITY_EDITOR" )]
[System.Diagnostics.Conditional( "DEBUG_LEVEL_LOG" )]
public static void assert( bool condition, string assertString )
{
assert( condition, assertString, false );
}
[System.Diagnostics.Conditional( "UNITY_EDITOR" )]
[System.Diagnostics.Conditional( "DEBUG_LEVEL_LOG" )]
public static void assert( bool condition, string assertString, bool pauseOnFail )
{
if( !condition )
{
Debug.LogError( "assert failed! " + assertString );
if( pauseOnFail )
Debug.Break();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment