yyl
2026-03-31 0fa617a09eedf6bdb25eda55fac1d3344859fd93
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
using UnityEngine;
 
/// <summary>
/// WebGL 环境下直接调用浏览器 console.error,不受 Unity Release Build 日志抑制影响。
/// 非 WebGL 平台回退到 Debug.LogError。
/// </summary>
public static class WebGLDebug
{
    public static void LogError(string msg)
    {
#if UNITY_WEBGL && !UNITY_EDITOR
        string escaped = msg.Replace("\\", "\\\\").Replace("'", "\\'").Replace("\n", "\\n").Replace("\r", "");
        Application.ExternalEval("console.error('" + escaped + "')");
#else
        Debug.LogError(msg);
#endif
    }
}