我正在开发一个ASP.NET Core MVC项目,需要将Unity WebGL游戏嵌入到其中一个页面中。我在网上搜索了很多地方,但它们都使用较旧版本的Unity,因此WebGL构建的内容看起来不同。
当我按下Unity中的“Build and Run”时,WebGL构建本身可以正常工作,但是当我尝试将其放入我的MVC中时无法正常工作。
到目前为止,我尝试过以下内容:
将Configure方法更改为使用静态内容:
当我按下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
文件:
将WebGL构建的Build和index.html放置在wwwroot中:
当我构建时,打开index.html文件,但游戏应该播放的框中没有任何内容:
控制台中的错误显示文件未找到,尽管它在Build文件夹中: errors directory
index.html文件: index.html
希望能得到帮助!
谢谢!
Build
文件夹添加到了wwwroot
中? - MaartenDev