ASP.NET Core MVC项目无法显示Unity WebGL内容。

3
我正在开发一个ASP.NET Core MVC项目,需要将Unity WebGL游戏嵌入到其中一个页面中。我在网上搜索了很多地方,但它们都使用较旧版本的Unity,因此WebGL构建的内容看起来不同。
当我按下Unity中的“Build and Run”时,WebGL构建本身可以正常工作,但是当我尝试将其放入我的MVC中时无法正常工作。
到目前为止,我尝试过以下内容:
将Configure方法更改为使用静态内容:
public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { 
    if (env.IsDevelopment()) { 
        app.UseDeveloperExceptionPage(); 
    } else { 
        app.UseExceptionHandler("/Home/Error"); 
        // The default HSTS value is 30 days. You may want to change this for production scenarios, see https:// 
        app.UseHsts(); 
    }
    
    app.UseHttpsRedirection();

    app.UseDefaultFiles(); 
    app.UseFileServer(); 
    StaticFileOptions options = new StaticFileOptions(); 
    FileExtensionContentTypeProvider contentTypeProvider = (FileExtensionContentTypeProvider)options.ContentTypeProvider ?? new FileExtensionContentTypeProvider(); 
    contentTypeProvider.Mappings.Add(".unityweb", "application/octet—stream"); 
    options.ContentTypeProvider = contentTypeProvider; app. UseStaticFiles(options); 

    app.UseRouting(); 
}

配置方法:

配置方法

添加 web.config 文件

<system.webServer>
    <staticContent>
        <remove fileExtension=".unityweb" I>
        <mimeMap fileExtension=".unityweb" mimeType="application/octet—stream" />
    </staticContent>
</system.webServer> 

web.config文件:

web.config file

将WebGL构建的Build和index.html放置在wwwroot中:

directory

当我构建时,打开index.html文件,但游戏应该播放的框中没有任何内容:Build screen

控制台中的错误显示文件未找到,尽管它在Build文件夹中: errors directory

index.html文件: index.html

希望能得到帮助!

谢谢!


浏览器控制台中有任何错误吗? - MaartenDev
@MaartenDev 抱歉,忘记放进去了。它说找不到文件。 - user16626982
你能添加 index.html 的内容吗? - MaartenDev
你是否将 Build 文件夹添加到了 wwwroot 中? - MaartenDev
@MaartenDev 是的,我做了,index.html 也做了。 - user16626982
1个回答

0

对于任何想知道的人,这个问题已经通过将Unity降级到2019年版本得到解决。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接