Created
December 9, 2018 12:48
-
-
Save seibe/da19ff30396fe0493f5757aee6ac70d6 to your computer and use it in GitHub Desktop.
ログごとにスタックトレースの有無を切り替えられる Debug.cs
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
public static class Debug | |
{ | |
public static void LogError(object message, UnityEngine.StackTraceLogType stackTraceType = UnityEngine.StackTraceLogType.ScriptOnly) | |
{ | |
LogInternal(UnityEngine.LogType.Error, message, stackTraceType); | |
} | |
public static void LogWarning(object message, UnityEngine.StackTraceLogType stackTraceType = UnityEngine.StackTraceLogType.ScriptOnly) | |
{ | |
LogInternal(UnityEngine.LogType.Warning, message, stackTraceType); | |
} | |
public static void Log(object message, UnityEngine.StackTraceLogType stackTraceType = UnityEngine.StackTraceLogType.ScriptOnly) | |
{ | |
LogInternal(UnityEngine.LogType.Log, message, stackTraceType); | |
} | |
private static void LogInternal(UnityEngine.LogType logType, object message, UnityEngine.StackTraceLogType stackTraceType) | |
{ | |
var currentStackTraceType = UnityEngine.Application.GetStackTraceLogType(logType); | |
if (currentStackTraceType != stackTraceType) | |
{ | |
UnityEngine.Application.SetStackTraceLogType(logType, stackTraceType); | |
} | |
switch (logType) | |
{ | |
case UnityEngine.LogType.Error: | |
UnityEngine.Debug.LogError(message); | |
break; | |
case UnityEngine.LogType.Warning: | |
UnityEngine.Debug.LogWarning(message); | |
break; | |
case UnityEngine.LogType.Log: | |
UnityEngine.Debug.Log(message); | |
break; | |
} | |
if (currentStackTraceType != stackTraceType) | |
{ | |
UnityEngine.Application.SetStackTraceLogType(logType, currentStackTraceType); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment