RangeError:为函数调用 createUnityInstance 提供了太多参数

Ora*_*n C 4 unity-game-engine webgl unity-webgl

不确定我在 Unity 中构建 WebGl 时做错了什么,或者是否需要添加更多内容。

在我们的 web 应用程序的 wwwroot 中设置一个路径以放入 WebGL 构建。当我在本地运行它时,页面将加载,并且出现 Unity 徽标,进度条达到 90% 就这样了。

在 Firefox 中运行时,页面加载并生成 RangeError 弹出窗口 如何查看传递的参数?

最初我出现了解析错误,但设法解决了该问题。

无法解析/MyApp/Build/Builds.framework.js.gz!如果启用了构建压缩,但托管内容的 Web 服务器配置错误,无法提供存在 HTTP 响应标头“Content-Encoding: gzip”的文件,则可能会发生这种情况。检查浏览器控制台和 Devtools Network 选项卡进行调试。

添加以下代码已解决解析错误。

    public static IApplicationBuilder UseStaticFilesExtendedTypes(this IApplicationBuilder app)
    {
        var provider = new FileExtensionContentTypeProvider();
        provider.Mappings[".glb"] = "model/gltf-binary";
        provider.Mappings[".env"] = "application/octet-stream";

        // app.UseStaticFiles(new StaticFileOptions { ContentTypeProvider = provider });

        app.UseStaticFiles(new StaticFileOptions
        {
            ContentTypeProvider = provider,
            OnPrepareResponse = content =>
            {
                if (content.File.Name.EndsWith(".js.gz"))
                {
                    content.Context.Response.Headers["Content-Type"] = "text/javascript";
                    content.Context.Response.Headers["Content-Encoding"] = "gzip";
                }
                if (content.File.Name.EndsWith(".wasm.gz"))
                {
                    content.Context.Response.Headers["Content-Type"] = "application/wasm";
                    content.Context.Response.Headers["Content-Encoding"] = "gzip";
                }
            }
        });

        return app;
    }
Run Code Online (Sandbox Code Playgroud)

这是本地主机网页上显示的内容。

在此输入图像描述

RangeError: too many arguments provided for a function call
createUnityInstance/l/</<@https://localhost:5001/MyApp/Build/Builds.loader.js:1:5770

promise callback*createUnityInstance/l/<@https://localhost:5001/MyApp/Build/Builds.loader.js:1:5417

callRuntimeCallbacks@https://localhost:5001/MyApp/Build/Builds.framework.js.gz:3:19279

preRun@https://localhost:5001/MyApp/Build/Builds.framework.js.gz:3:14671
run@https://localhost:5001/MyApp/Build/Builds.framework.js.gz:3:359513
runCaller@https://localhost:5001/MyApp/Build/Builds.framework.js.gz:3:358850

removeRunDependency@https://localhost:5001/MyApp/Build/Builds.framework.js.gz:3:15974

receiveInstance@https://localhost:5001/MyApp/Build/Builds.framework.js.gz:3:17723

receiveInstantiationResult@https://localhost:5001/MyApp/Build/Builds.framework.js.gz:3:17840

promise callback*unityFramework/createWasm/instantiateAsync/<@https://localhost:5001/MyApp/Build/Builds.framework.js.gz:3:18451

promise callback*instantiateAsync@https://localhost:5001/MyApp/Build/Builds.framework.js.gz:3:18354

createWasm@https://localhost:5001/MyApp/Build/Builds.framework.js.gz:3:18914

unityFramework@https://localhost:5001/MyApp/Build/Builds.framework.js.gz:3:293288

createUnityInstance/l/<@https://localhost:5001/MyApp/Build/Builds.loader.js:1:5335

promise callback*l@https://localhost:5001/MyApp/Build/Builds.loader.js:1:5317

createUnityInstance/<@https://localhost:5001/MyApp/Build/Builds.loader.js:1:18860

createUnityInstance@https://localhost:5001/MyApp/Build/Builds.loader.js:1:18452

script.onload@https://localhost:5001/lib/unity-loader.js:64:24
EventHandlerNonNull*@https://localhost:5001/lib/unity-loader.js:63:1
Run Code Online (Sandbox Code Playgroud)

构建设置:

在此输入图像描述

Ora*_*n C 6

我已经成功解决了这个问题。

我不清楚我是如何提出这个问题的,但当时我很绝望。

这是一个缓存问题。

在 Firefox 中,按 F12 打开控制台并选择“存储”选项卡。展开Indexed DB,在 localhost 内删除UnityCache并刷新页面。

在此输入图像描述

我已经进行了多个构建并替换了新的构建并尝试再次运行,这似乎导致了错误。Unity 在构建 WebGl 时生成的 Builds.loader.js 似乎存在缓存/旧缓存问题。

希望这会有所帮助!