From 2b4f4bc343cb63832dd26597489e487b4967b813 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Tue, 16 Jul 2024 16:18:26 +0900 Subject: [PATCH] =?UTF-8?q?=E3=81=A8=E3=82=8A=E3=81=82=E3=81=88=E3=81=9A?= =?UTF-8?q?=E3=80=80ILogHandler=E3=80=80=E3=81=AB=E5=AF=BE=E5=BF=9C?= =?UTF-8?q?=E3=80=82=E6=9B=B4=E3=81=AA=E3=82=8B=E6=8B=A1=E5=BC=B5=E3=81=AF?= =?UTF-8?q?=E4=BD=BF=E3=81=86=E3=81=A8=E3=81=8D=E3=81=AB=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/UniGLTF/Runtime/Utils/UniGLTFLogger.cs | 49 ++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) 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