Last active
October 7, 2017 19:36
-
-
Save Democide/a9621059afc8979f41fce694f0ea7bb1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* To avoid performance issues caused by string constructions when logging stuff | |
* to the console, this script uses the custom DEBUG_LOGGING define to disable logging | |
* | |
* Replace all calls to Debug.Log etc with calls to DebugSafe.Log. | |
* | |
* When creating a non-debug build or testing the game for performance, you can disable | |
* the debug messages by disabling the custom define. | |
*/ | |
using UnityEngine; | |
public static class DebugSafe { | |
public static void Log(object message) { | |
#if DEBUG_LOGGING | |
Debug.Log(message); | |
#endif | |
} | |
public static void Log(object message, Object context) { | |
#if DEBUG_LOGGING | |
Debug.Log(message, context); | |
#endif | |
} | |
public static void LogFormat(string format, params object[] args) { | |
#if DEBUG_LOGGING | |
Debug.LogFormat(format, args); | |
#endif | |
} | |
public static void LogFormat(Object context, string format, params object[] args) { | |
#if DEBUG_LOGGING | |
Debug.LogFormat(context, format, args); | |
#endif | |
} | |
public static void LogAssertion(Object message) { | |
#if DEBUG_LOGGING | |
Debug.LogAssertion(message); | |
#endif | |
} | |
public static void LogAssertion(Object message, Object context) { | |
#if DEBUG_LOGGING | |
Debug.LogAssertion(message, context); | |
#endif | |
} | |
public static void LogAssertionFormat(Object message, Object context) { | |
#if DEBUG_LOGGING | |
Debug.LogAssertion(message, context); | |
#endif | |
} | |
public static void LogAssertionFormat(string format, params object[] args) { | |
#if DEBUG_LOGGING | |
Debug.LogAssertionFormat(format, args); | |
#endif | |
} | |
public static void LogAssertionFormat(Object context, string format, params object[] args) { | |
#if DEBUG_LOGGING | |
Debug.LogAssertionFormat(context, format, args); | |
#endif | |
} | |
public static void LogError(object message) { | |
#if DEBUG_LOGGING | |
Debug.LogError(message); | |
#endif | |
} | |
public static void LogError(object message, Object context) { | |
#if DEBUG_LOGGING | |
Debug.LogError(message, context); | |
#endif | |
} | |
public static void LogErrorFormat(string format, params object[] args) { | |
#if DEBUG_LOGGING | |
Debug.LogErrorFormat(format, args); | |
#endif | |
} | |
public static void LogErrorFormat(Object context, string format, params object[] args) { | |
#if DEBUG_LOGGING | |
Debug.LogErrorFormat(context, format, args); | |
#endif | |
} | |
public static void LogWarning(object message) { | |
#if DEBUG_LOGGING | |
Debug.LogWarning(message); | |
#endif | |
} | |
public static void LogWarning(object message, Object context) { | |
#if DEBUG_LOGGING | |
Debug.LogWarning(message, context); | |
#endif | |
} | |
public static void LogWarningFormat(string format, params object[] args) { | |
#if DEBUG_LOGGING | |
Debug.LogWarningFormat(format, args); | |
#endif | |
} | |
public static void LogWarningFormat(Object context, string format, params object[] args) { | |
#if DEBUG_LOGGING | |
Debug.LogWarningFormat(context, format, args); | |
#endif | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment