This repository is a small example of how Unity WebGL build could be incorporated and used within ASP.NET Core web application with MVC framework.
Goal was to create minimum viable product of a ASP.NET Core web application, with bare minimum configuration and simple, straight to the point project structure.
Using Visual Studio 2022, I've picked ASP.NET Core Web App (Model-View-Controller) as the template for this project.
At the time of writing this, using Unity Hub (3.10.0) and Unity Editor (6000.0.25f1), I've picked '2D Platformer Microgame' free project template, available during project creation in Unity Hub. Simple, lightweight sample project, which can be built into a WebGL.
The only settings that were adjusted during creation of the actual WebGL builds were the following (Read more here):
- Decompression Fallback (Determines how Unity processes downloaded files when the build runs in the browser) - ENABLED for all three builds.
- Compression Format - I've built the project with all three available compression formats - 'No compression', 'Brotli compression' and 'Gzip compression'.
- .NET 9 SDK
- Docker
- IDE of your choice. I use Visual Studio / Visual Studio Code
- Git (Optional, if you want to use it to clone the repository)
There are multiple ways of doing this. Here's two:
-
Method 1 - run the following command using a CMD terminal in an empty directory:
git clone https://github.com/synboxdev/AspNetCore-Unity-WebGL.git
Afterwards, the project's repository will be downloaded to the directory inside of which you've ran this command.
- Method 2 - Downloading zipped repository and extracting it locally. Download zipped repository, and extract the files to a folder of your choosing.
Once you've retrieved the repository to your local machine, before running the following, do the following:
- Build the solution to restore dependencies.
- Start the project with one of the methods described below
You start the project locally, by executing the following command in the root directory of the solution
dotnet run Bacchus
And then open the following URL in your browser - https://localhost:7185
or http://localhost:5288
If you are using Visual Studio - you can simply start the project with the GUI interface - navigate to 'Debug' tab -> 'Start without debugging'. Or use the default shortcut of CTRL + F5.
Open up a command-line terminal in the root directory of the solution, and run the two following commands:
docker build -t bacchus .
docker run -p 443:8080 bacchus
Once that's done - the project should be up and running in a newly created docker container, accessible via browser on http://localhost:443
This project is licensed under the MIT License.
For any and all inquires, feel free to contact me.