Skip to content

Instantly share code, notes, and snippets.

@seibe
Created December 9, 2018 12:48
Show Gist options
  • Save seibe/da19ff30396fe0493f5757aee6ac70d6 to your computer and use it in GitHub Desktop.
Save seibe/da19ff30396fe0493f5757aee6ac70d6 to your computer and use it in GitHub Desktop.
ログごとにスタックトレースの有無を切り替えられる Debug.cs
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