diff --git a/Assets/UniGLTF/Runtime/Utils/UniGLTFLogger.cs b/Assets/UniGLTF/Runtime/Utils/UniGLTFLogger.cs index 98bcebf9b..594636d4a 100644 --- a/Assets/UniGLTF/Runtime/Utils/UniGLTFLogger.cs +++ b/Assets/UniGLTF/Runtime/Utils/UniGLTFLogger.cs @@ -4,8 +4,55 @@ namespace UniGLTF { public static class UniGLTFLogger { + class DefaultUnityLogger : ILogHandler + { + public void LogException(System.Exception exception, UnityEngine.Object context) + { + Debug.LogException(exception, context); + } + + public void LogFormat(LogType logType, UnityEngine.Object context, string format, params object[] args) + { + switch (logType) + { + case LogType.Error: + Debug.LogError(string.Format(format, args), context); + break; + case LogType.Assert: + Debug.LogAssertion(string.Format(format, args), context); + break; + case LogType.Warning: + Debug.LogWarning(string.Format(format, args), context); + break; + case LogType.Log: + Debug.Log(string.Format(format, args), context); + break; + case LogType.Exception: + // where exception ? + Debug.LogError(string.Format(format, args), context); + break; + default: + throw new System.NotImplementedException(); + } + } + } + + static ILogHandler s_logger = new DefaultUnityLogger(); + + public static void SetLogger(ILogHandler logger) + { + if (logger != null) + { + s_logger = logger; + } + else + { + s_logger = new DefaultUnityLogger(); + } + } + [System.Diagnostics.Conditional("VRM_DEVELOP")] [HideInCallstack] - public static void Log(string msg) => Debug.Log(msg); + public static void Log(string msg, UnityEngine.Object context = null) => s_logger.LogFormat(LogType.Log, context, msg); } } \ No newline at end of file