小编Ora*_*n C的帖子

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

不确定我在 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";
                } …
Run Code Online (Sandbox Code Playgroud)

unity-game-engine webgl unity-webgl

4
推荐指数
1
解决办法
986
查看次数

标签 统计

unity-game-engine ×1

unity-webgl ×1

webgl ×1