[Unity] IL2CPP WebGL 出现错误信息 FS.syncfs

loader.js:1 warning: 2 FS.syncfs operations in flight at once, probably just doing extra work

在Google浏览器中运行WebGL出现的错误

是因为写了加载和反序列化本地 JSON 文件(如下所示),则会输出上述警告

public T LoadLocalData(string path) where T : class
{
    try
    {
        using (var sw = new StreamReader(path))
        {
            var json = sw.ReadToEnd();
            return JsonUtility.FromJson<T>(json);
        }
    }
    catch (System.Exception e)
    {
        Debug.LogError($"Error: {path} | {e.Message}");
    }
    return null;
}

WebGL中不允许使用文件操作

public T LoadLocalData(string path) where T : class
{
#if UNITY_WEBGL
    // WebGL用其他代替处理
    return null;
#else
    try
    {
        using (var sw = new StreamReader(path))
        {
            var json = sw.ReadToEnd();
            return JsonUtility.FromJson<T>(json);
        }
    }
    catch (System.Exception e)
    {
        Debug.LogError($"Error: {path} | {e.Message}");
    }
    return null;
#endif
}

猜你喜欢

转载自blog.csdn.net/dj1232090/article/details/134619673