To create a build for the Web platform, go to File > Build Settings from Unity’s main menu. In the Platform list, select Web and then click Switch Platform.
When you have configured the Build Settings, choose from one the following options:
The Unity build system for Web supports the following settings:
设置 | 功能 | |
---|---|---|
Client Browser Type | Select the browser client that you want your application to launch at runtime. For example, if you choose System Default, then your application launches the default browser, and removes the Path to Client Browser setting. The available options are: | |
System Default | This is the default setting. Select this option to launch the application in the default browser. | |
Microsoft Edge | Select this option to launch the application in Edge browser. | |
Mozilla Firefox | Select this option to launch the application in Firefox. | |
Google Chrome | Select this option to launch the application in Chrome. | |
Safari | Select this option to launch the application in Safari. | |
Path to Client Browser | Specify the path to the browser client that you want your application to launch at runtime. Note: This option is only visible if the Client Browser Type isn’t set to the default browser. | |
Texture Compression | The texture compression format to use for the build. For more information, refer to Web texture compression. The available options are: | |
Use Player Settings | This is the default selection. It uses the texture compression format you set in the Player settings window. | |
ETC2 | Uses ETC2 format, which is widely supported on mobile devices. | |
ASTC | Uses ASTC format, which is widely supported on mobile devices. | |
DXT | Uses DXT format, which is widely supported on desktop devices. | |
Development Build | Enable this setting to include scripting debug symbols and the Profiler in your build. When you enable this, Unity sets the DEVELOPMENT_BUILD scripting define. Use this setting only when you want to test your application because development builds don’t minify content, they’re large to distribute. |
|
Code Optimization | Select the optimization mode to use for compiling the Web code. | |
Shorter Build Time | This is the default setting. Select this option to generate WebGL code that takes the least amount of time to build. | |
Runtime Speed | Select this option to generate WebGL code that’s optimized for runtime performance, at the expense of taking a longer time to build. | |
Runtime Speed with LTO | This is the same as Runtime Speed, but with an additional Link Time Optimizations (LTO) stage (sometimes called Whole Program Optimization). Enable LTO when compiling Master shipping builds for deployment to end users. | |
Disk Size | Select this option to favor optimizations that minimize build size, at the expense of taking a longer time to build. The recommended best practice is to select this option when targeting mobile web browsers, that may have limits on the size of WebAssembly files that can be loaded. Smaller disk sizes generally result in shorter page startup times. | |
Disk Size with LTO | This is the same as Disk Size, but enables additional Link Time Optimizations (LTO) stage (sometimes called Whole Program Optimization). Select this option when compiling Master shipping builds for deployment to end users. | |
Autoconnect Profiler | Typically, when enabled, this setting allows you to automatically connect the Unity Profiler to your build. However for Web, as you can’t connect the Profiler to a running build, use this option to connect the content to the Unity Editor instead. This is because the Profiler connection is handled using WebSockets on Web, but a web browser only allows outgoing connections from the content. For this setting to be available, you must enable the Development Build option. | |
Deep Profiling | Enable this setting to activate Deep Profiling in the Profiler. This makes the Profiler instrument every function call in your application and returns more detailed profiling data. When you enable Deep Profiling Support, it might slow down script execution. This option is only available if you enable the Development Build option. | |
Build | Use it to build your application. | |
Build And Run | Use it to view the Web Player locally. Unity uses a local web server to host your build, and opens it from a localhost URL. Alternatively, you can use a custom local web server with properly configured response headers. For more information, refer to Compressed builds and server configuration. |
For changing the settings for Asset Import Overrides, refer to Build Settings.
When you build your Web application, Unity creates a Build
folder with the name you specify in the Build Settings window. The Build
folder has the following files, where [ExampleBuild]
represents the name of the target build folder.
文件名 | 描述 |
---|---|
[ExampleBuild].loader.js |
The JavaScript code that the web page needs to load the Unity content. |
[ExampleBuild].framework.js |
JavaScript runtime and plug-ins. |
[ExampleBuild].wasm |
WebAssembly 二进制文件。 |
[ExampleBuild].mem |
A binary image to initialize the heap memory for your Player. Unity generates this file for multi-threaded WebAssembly builds only. |
[ExampleBuild].data |
资源数据和场景。 |
[ExampleBuild].symbols.json |
调试错误堆栈跟踪所需的调试符号名称。仅当启用 Debug Symbols 选项时 (File > Build Settings > Player Settings),才会为 Release 构建生成此文件。 |
[ExampleBuild].jpg |
A background image, which displays while the build is loading. This file is only generated when a Background Image is available in the Player Settings (File > Build Settings > Player Settings > Splash Image). For more information, refer to Splash Screen. |
If you enable a Compression Method for your build, Unity identifies the extension that corresponds with the compression method and adds this extension to the names of the files inside the Build sub folder. If you enable Decompression Fallback, Unity appends the extension .unityweb
to the build file names. Otherwise, Unity appends the extension .gz
for the Gzip compression method, or .br
for the Brotli compression method.
For more information, refer to Compressed builds and server configuration.
If you enable Name Files As Hashes in the Player Settings, Unity uses the hash of the file content instead of the default file name. This applies to each file in the build folder. This option allows you to upload updated versions of the game builds into the same folder on the server, and only upload the files which have changed between build iterations.
注意:在某些浏览器中可能无法直接从文件系统打开播放器。这是由于本地文件 URL 应用了安全限制。
Use Enable Exceptions to specify how to handle unexpected code behavior (also known as errors) at runtime.
To access Enable Exceptions, go to the Web Player Settings > Publishing Settings section.
In the Enable Exceptions option, choose from the following options:
None: Select this if you don’t need any exception support. This gives the best performance and smallest builds. With this option, any exception thrown causes your content to stop with an error.
Explicitly Thrown Exceptions Only (default): Select this to capture exceptions which are explicitly specified from a throw
statement in your scripts and to also to make sure finally
blocks are called. Note that selecting this option makes the generated JavaScript code from your scripts longer and slower; This might only be an issue if scripts are the main bottleneck in your project.
Full Without Stacktrace: Select this option to capture:
throw
statements in your scripts (the same as in the Explicitly Thrown Exceptions Only option)Full With Stacktrace: This option is similar to the earlier option, but it also captures Stack traces. Unity generates these exceptions by embedding checks for them in the code, so this option decreases performance and increases browser memory usage. Only use this for debugging, and always test in a 64-bit browser.