Trying to host Unity WebGL on a .Net Core 2.0 application? Check out my demo at www.sebswebs.com/Game. It may seem like a rather simple ordeal, however, there are some road bumps you will encounter along the way. You can save yourself a lot of time and frustration by following the simple steps provided here.
Step 1: Build
First of all, ensure the application compiled by Unity works in the folder that was generated because compilation errors may prevent your application from running out the gate. As a result we should build by generating properly. File > Build & Run. Select WebGL player as your target output. Run the application and test for functionality. Easy.
Step 2: Provision
Furthermore we will want to serve up the files in a typical MVC configuration. You can use any model you prefer, however with the rampant popularity of all things MVC, we will design as so. Here we have an example of our required file structure.
We can see that our static files (those output by Unity) are served from our wwwroot folder (more on that later). Additionally, we have our typical MVC affair; a controller to return a view and a corresponding view that has the content from Index.html. My strategy was to return an Index.cshtml file that is basically a copy paste of the Index.html Unity provided after the WebGL build was completed. I encourage a more elaborate setup once you have a functioning prototype.
Step 3: Configure
Finally we have to configure our .Net Core application to properly serve up our static files and define our MIME types so that our application knows what to do with them. Our files are in the wwwroot folder as we will set up static file delivery. In our Startup.CS file we have to define from within the configuration method
Within public void Configure(IApplicationBuilder app, IHostingEnvironment env)
Now you can host your content locally or on your hosting service provider and enjoy the fruits of your labor. Testing your apps in the WebGL player is a great way to prototype and build test versions. All without the hassle of going through the App Store and Google Play. You can share you application with your friends and get some feedback right away.
If you have any questions or you want to get in touch. You can find me at www.sebswebs.com