Files
tysdk-intergration/sdk-intergration/LocalPackages/LeviathanVideo/Runtime/LeviathanLogConfig.cs
2026-03-24 11:43:22 +08:00

150 lines
4.0 KiB
C#

/*----------------------------------------------------------------
// Copyright (C) 2025 Beijing All rights reserved.
//
// Author: huachangmiao
// Create Date: 2025/10/29
// Module Describe: Leviathan日志配置类
//----------------------------------------------------------------*/
using System.Runtime.InteropServices;
using UnityEngine;
//******************************************************************
// 日志配置类
//******************************************************************
public static class LeviathanLogConfig
{
// 日志开关
private static bool _enableWorkerManagerLog = false;
private static bool _enableWorkerVideoLog = false;
private static bool _enableWorkerDecoderLog = false;
private static bool _enableSoftwareDecoderLog = false;
private static bool _enableVideoDecoderLog = false;
private static bool _enableAllLog = false;
// 公开属性
public static bool EnableWorkerManagerLog
{
get => _enableWorkerManagerLog;
set
{
_enableWorkerManagerLog = value;
UpdateJSLogConfig();
}
}
public static bool EnableWorkerVideoLog
{
get => _enableWorkerVideoLog;
set
{
_enableWorkerVideoLog = value;
UpdateJSLogConfig();
}
}
public static bool EnableWorkerDecoderLog
{
get => _enableWorkerDecoderLog;
set
{
_enableWorkerDecoderLog = value;
UpdateJSLogConfig();
}
}
public static bool EnableSoftwareDecoderLog
{
get => _enableSoftwareDecoderLog;
set => _enableSoftwareDecoderLog = value;
}
public static bool EnableVideoDecoderLog
{
get => _enableVideoDecoderLog;
set => _enableVideoDecoderLog = value;
}
public static bool EnableAllLog
{
get => _enableAllLog;
set
{
_enableAllLog = value;
UpdateJSLogConfig();
}
}
#if UNITY_WEBGL && !UNITY_EDITOR
[DllImport("__Internal")]
private static extern void SetLeviathanLogConfig(bool workerManager, bool workerVideo, bool workerDecoder, bool all);
#endif
// 更新JS端的日志配置
private static void UpdateJSLogConfig()
{
#if UNITY_WEBGL && !UNITY_EDITOR
try
{
SetLeviathanLogConfig(_enableWorkerManagerLog, _enableWorkerVideoLog, _enableWorkerDecoderLog, _enableAllLog);
}
catch (System.Exception e)
{
Debug.LogWarning($"[LeviathanLogConfig] 更新JS日志配置失败: {e.Message}");
}
#endif
}
// 便捷方法:开启所有日志
public static void EnableAll()
{
EnableAllLog = true;
}
// 便捷方法:关闭所有日志
public static void DisableAll()
{
EnableAllLog = false;
EnableWorkerManagerLog = false;
EnableWorkerVideoLog = false;
EnableWorkerDecoderLog = false;
EnableSoftwareDecoderLog = false;
EnableVideoDecoderLog = false;
}
// C#端日志辅助方法
public static void Log(string module, object message)
{
if (!ShouldLog(module)) return;
Debug.Log($"[Leviathan{module}] {message}");
}
public static void LogWarning(string module, object message)
{
if (!ShouldLog(module)) return;
Debug.LogWarning($"[Leviathan{module}] {message}");
}
public static void LogError(string module, object message)
{
if (!ShouldLog(module)) return;
Debug.LogError($"[Leviathan{module}] {message}");
}
private static bool ShouldLog(string module)
{
if (_enableAllLog) return true;
return module switch
{
"WorkerManager" => _enableWorkerManagerLog,
"WorkerVideo" => _enableWorkerVideoLog,
"WorkerDecoder" => _enableWorkerDecoderLog,
"SoftwareDecoder" => _enableSoftwareDecoderLog,
"VideoDecoder" => _enableVideoDecoderLog,
_ => false
};
}
}