Last active
February 15, 2019 07:56
-
-
Save yangruihan/bfe3078421fd679ca5cc477e004f4b61 to your computer and use it in GitHub Desktop.
Debug util for unity
This file contains hidden or 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
| using UnityEngine; | |
| using System; | |
| public class DebugUtil | |
| { | |
| public enum Level | |
| { | |
| Log = 0, | |
| Warning, | |
| Error, | |
| None, | |
| }; | |
| private static Level _level = Level.Log; | |
| public static void SetLevel(Level l) | |
| { | |
| _level = l; | |
| } | |
| public static void Log(object obj = null) | |
| { | |
| if (_level <= Level.Log) | |
| { | |
| UnityEngine.Debug.Log("[" + Time.frameCount + "]" + obj); | |
| } | |
| } | |
| public static void LogWarning(object obj = null) | |
| { | |
| if (_level <= Level.Warning) | |
| { | |
| UnityEngine.Debug.LogWarning("[" + Time.frameCount + "]" + obj); | |
| } | |
| } | |
| public static void LogError(object obj = null) | |
| { | |
| if (_level <= Level.Error) | |
| { | |
| UnityEngine.Debug.LogError("[" + Time.frameCount + "]" + obj); | |
| } | |
| } | |
| public static void LogException(System.Exception obj = null) | |
| { | |
| if (_level <= Level.Error) | |
| { | |
| UnityEngine.Debug.LogException(obj); | |
| } | |
| } | |
| public static void LogFormat(string format, params object[] pars) | |
| { | |
| if (_level <= Level.Log) | |
| { | |
| UnityEngine.Debug.LogFormat(format, pars); | |
| } | |
| } | |
| public static void LogErrorFormat(string format, params object[] pars) | |
| { | |
| if (_level <= Level.Error) | |
| { | |
| UnityEngine.Debug.LogErrorFormat(format, pars); | |
| } | |
| } | |
| public static void Assert(bool expression) | |
| { | |
| if (!expression) | |
| throw new Exception("Assertion failed"); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment