WebGL Player 设置
This page details the Player settings specific to the WebGL platform. For a description of the general Player settings, see Player settings.
WebGL Player 设置您可以在以下部分找到这些属性的文档:
Note: Although the Icon panel appears on the WebGL Player settings, there are no icon settings because WebGL games do not use icons.
For more information about WebGL Publishing Settings, see WebGL Building and Running.
Resolution and Presentation
此部分可以自定义屏幕模式和默认大小。
Resolution section for the WebGL Player platform分辨率
设置 | 功能 |
---|---|
Default Canvas Width | 设置 WebGL 画布元素的宽度。 |
Default Canvas Height | 设置 WebGL 画布元素的高度。 |
Run In Background | 启用此选项将允许您的内容将在画布或浏览器窗口失去焦点时继续运行。 |
WebGL Template
选择要用于 WebGL 项目的模板:
- Default 页面是一个简单的白色页面,其中的灰色画布上有一个加载进度条。
- Minimal 页面只有必要的样板代码来运行 WebGL 内容。
您可以指定自己的模板,以便在与之前完成的游戏类似的环境中运行游戏。遵循使用 WebGL 模板中的说明。
Splash Image
Use the Virtual Reality Splash Image setting to select a custom splash image for XR displays. For information on common Splash Screen settings, see Splash Screen.
Splash screen settings for virtual reality.Other Settings
此部分可以自定义一系列选项,这些选项分为以下几组:
Rendering
使用这些设置可自定义 Unity 针对 WebGL 平台渲染游戏的方式。
WebGL 平台的 Rendering Player 设置Property | Description | |
---|---|---|
Color Space | Choose which color space Unity uses for rendering: Gamma or Linear. See the Linear rendering overviewfor an explanation of the difference between the two. • Gamma: Gamma color space is typically used for calculating lighting on older hardware restricted to 8 bits per channel for the framebuffer format. Even though monitors today are digital, they might still take a gamma-encoded signal as input. • Linear: Linear color space rendering gives more precise results. When you select to work in linear color space, the Editor defaults to using sRGB sampling. If your Textures are in linear color space, you need to work in linear color space and disable sRGB sampling for each Texture. |
|
Auto Graphics API | Disable this option to manually pick and reorder the graphics APIs. By default this option is enabled, and Unity includes WebGL2.0, with WebGL1.0 as a fallback for devices where WebGL2.0 is not supported. | |
Static Batching | Enable this option to use Static batching. | |
Dynamic Batching | Enable this option to use Dynamic Batching on your build (enabled by default). Note: Dynamic batching has no effect when a Scriptable Render Pipeline is active, so this setting is only visible when nothing is set in the Scriptable Render Pipeline Asset Graphics setting. |
|
Graphics Jobs | Enable this option to instruct Unity to offload graphics tasks (render loops) to worker threads running on other CPU cores. This is intended to reduce the time spent in Camera.Render on the main thread, which is often a bottleneck. |
|
Lightmap Encoding | Choose Normal Quality or High Quality to set the lightmap encoding. This setting affects the encoding scheme and compression format of the lightmaps. | |
Lightmap Streaming | Whether to use Mipmap Streaming for lightmaps. Unity applies this setting to all lightmaps when it generates them. Note: To use this setting, you must enable the Texture Streaming Quality setting. |
|
Streaming Priority | Set the priority for all lightmaps in the Mipmap Streaming system. Unity applies this setting to all lightmaps when it generates them. Positive numbers give higher priority. Valid values range from –128 to 127. |
|
Frame Timing Stats | Enable this property to gather CPU and GPU frame time statistics. Use this together with the Dynamic Resolution camera setting to determine if your application is CPU or GPU bound. | |
Virtual Texturing | Indicates whether to enable Virtual Texturing. Note: The Unity Editor requires a restart for this setting to take effect. |
|
Shader precision model | Controls the default precision of samplers used in shaders. See Shader data types and precision for more details. | |
360 Stereo Capture | Indicates whether Unity can capture stereoscopic 360 images and videos. When enabled, Unity compiles additional shader variants to support 360 capture (currently only on Windows/OSX). When enabled, enable_360_capture keyword is added during the Stereo RenderCubemap call. Note that this keyword is not triggered outside the Stereo RenderCubemap function. For more information, see Stereo 360 Image and Video Capture. |
配置
WebGL 平台的 Configuration 设置设置 | 功能 | ||
---|---|---|---|
Scripting Backend | 选择要使用的脚本后端。脚本后端确定 Unity 如何在项目中编译和执行 C# 代码。 | ||
Mono | 将 C# 代码编译为 .NET 公共中间语言 (CIL) 并使用公共语言运行时执行该 CIL。有关更多信息,请参阅 Mono Project 网站。 | ||
IL2CPP | 将 C# 代码编译为 CIL,将 CIL 转换为 C++,然后将该 C++ 编译为本机机器代码,该代码在运行时直接执行。请参阅 IL2CPP 以了解更多信息。 | ||
API Compatibility Level | 选择可以在项目中使用的 .NET API 运行时。此设置可能会影响与第三方库的兼容性。 提示:如果您遇到第三方程序集的问题,可以尝试下文的 API Compatibility Level 部分中的建议。 |
||
.Net Standard | 兼容 .NET Standard 2.0。生成较小的构建并具有完整的跨平台支持。 | ||
.Net Framework | 兼容 .NET Framework 4(包括 .NET Standard 2.0 配置文件中的所有内容以及其他 API)。如果使用的库需要访问 .NET Standard 2.0 中未包含的 API,请选择此选项。生成更大的构建,并且任何可用的其他 API 不一定在所有平台上都受支持。有关更多信息,请参阅引用其他类库程序集。 | ||
C++ Compiler Configuration | 选择在编译 IL2CPP 生成的代码时使用的 C++ 编译器配置。 注意:除非 Scripting Backend 设置为 IL2CPP_,否则此属性被禁用。| |Use incremental GC|| Enable this to use the incremental garbage collector, which spreads garbage collection over several frames to reduce gc-related spikes in frame duration.| |Active Input Handling|| 选择您希望如何处理来自用户的输入。 | ||Input Manager (old)| Use the default Input window. | ||Input System (Preview)| 使用较新的输入系统。输入系统作为此版本的预览包提供。要试用输入系统的预览版,请安装 InputSystem 包。| ||Both_ |
并排使用两个系统。 |
API Compatibility Level
You can choose your mono API compatibility level for all targets. Sometimes a 3rd-party .NET library uses functionality that’s outside of your .NET compatibility level. To understand what’s going on in such cases, and how to best fix it, try following these suggestions:
- Install ILSpy for Windows.
- Drag the .NET assemblies for the API compatilibity level that you are having issues with into ILSpy. You can find these under
Frameworks/Mono/lib/mono/YOURSUBSET/
. 3.拖入第三方程序集。 4.右键单击第三方程序集并选择 Analyze。 5.在分析报告中,检查 Depends on 部分。此报告以红色突出显示第三方程序集所依赖的但在您选择的 .NET 兼容性级别中不可用的任何内容。
Script Compilation
WebGL 平台的脚本编译设置设置 | 功能 | |
---|---|---|
Scripting Define Symbols | Set custom compilation flags. For more details, see the documentation on Platform dependent compilation. | |
Additional Compiler Arguments | Add entries to this list to pass additional arguments to the Roslyn compiler. Use one new entry for each additional argument. To create a new entry, press the ‘+’ button. To remove an entry, press the ‘-’ button. When you have added all desired arguments, click the Apply button to include your additional arguments in future compilations.The Revert button resets this list to the most recent applied state. |
|
Suppress Common Warnings | Disable this setting to display the C# warnings CS0169 and CS0649. | |
Allow ‘unsafe’ Code | 允许在预定义的程序集(例如,Assembly-CSharp.dll )中编译“不安全”的 C# 代码。对于程序集定义文件 ( .asmdef ),请单击其中一个 .asmdef 文件,并在出现的 Inspector 窗口中启用该选项。 |
|
Use Deterministic Compilation | Disable this setting to prevent compilation with the -deterministic C# flag. With this setting enabled, compiled assemblies are byte-for-byte identical each time they are compiled. For more information, see Microsoft’s deterministic compiler option documentation. |
|
Enable Roslyn Analyzers | Disable this setting to compile user-written scripts without Roslyn analyzer DLLs that might be present in your project. | |
Use Roslyn Reference Assemblies | Disable this setting to the compiler not to skip compilation reference assemblies when the metadata of the assembly does not change. |
Optimization
WebGL 平台的 Optimization 设置Property | Description | |
---|---|---|
Prebake Collision Meshes | Enable this option to add collision data to Meshes at build time. | |
Keep Loaded Shaders Alive | When enabled, you cannot unload a shader. See Shader Loading for more information. | |
Preloaded Assets | Set an array of Assets for the player to load on startup. To add new Assets, increase the value of the Size property, then set a reference to the Asset to load in the new Element box that appears. |
|
AOT compilation options | Additional options for Ahead of Time (AOT) compilation. This helps optimize the size of the built iOS player. | |
Strip Engine Code | Enable this option if you want the Unity Linker tool to remove code for Unity Engine features that your Project doesn’t use. This setting is only available with the IL2CPP scripting backend. Most apps don’t use every available DLL. This option strips out DLLs that your app doesn’t use to reduce the size of the built Player. If your app is using one or more classes that would normally be stripped out under your current settings, Unity displays a debug message when you try to build the app. |
|
Managed Stripping Level | Choose how Unity strips unused managed (C#) code.The options are Disabled Low, Medium, and High. When Unity builds your app, the Unity Linker process can strip unused code from the managed DLLs your Project uses. Stripping code can make the resulting executable significantly smaller, but can sometimes accidentally remove code that is in use. For more information about these options, see documentation on Managed code stripping. For information about bytecode stripping with IL2CPP, see documentation on Managed bytecode stripping with IL2CPP. |
|
Vertex Compression | Choose the channel that you want to set for compressing meshes under the vertex compression method, which by default, is set to Mixed. This affects all the meshes in your project. Typically, Vertex Compression is used to reduce the size of mesh data in memory, reduce file size, and improve GPU performance. For information on how to configure vertex compression and limitations of this setting, see [compressing meshes]. | |
Optimize Mesh Data | Selecting this option enables stripping of unused vertex attributes from the mesh used in a build. This reduces the amount of data in the mesh, which might help reduce build size, loading times, and runtime memory usage. However, you must remember to not change material or shader settings at runtime, if you have this setting enabled. See PlayerSettings.stripUnusedMeshComponents for more information. |
|
Texture MipMap Stripping | Enable this option to enable mipmap stripping for all platforms, which strips unused mipmaps from Textures at build time. Unity determines unused mipmaps by comparing the value of the mipmap against the Quality Settings for the current platform. If a mipmap value is excluded from every Quality Setting for the current platform, then Unity strips those mipmaps from the build at build time. If QualitySettings.masterTextureLimit is set to a mipmap value that has been stripped, Unity will set the value to the closest mipmap value that has not been stripped. |
Logging
选择在特定上下文中允许的日志记录类型。
WebGL 平台的 Logging 设置-
Select your preferred logging method from the available options.
- Check a box that corresponds to each Log Type (Error, Assert, Warning, Log, and Exception) based on the type of logging you require. For example:
- ScriptOnly: Logs only when running scripts.
- Full: Logs all the time.
- None: No logs are ever recorded.
See stack trace logging for more information.
Legacy
Enable the Clamp BlendShapes (Deprecated) option to clamp the range of blend shape weights in Skinned Mesh Renderers.
WebGL 平台的 Legacy 设置Publishing settings
Use the Publishing Settings to configure how Unity builds your WebGL app. For example, you can choose to enable the browser cache to store its files in your build.
WebGL 平台的 Publishing settings设置 | 功能 |
---|---|
Enable Exceptions | 选择在运行时如何处理意外的代码行为(通常视为错误)。选项包括:_None、Explicitly Thrown Exceptions Only、Full Without Stacktrace_ 和 Full With Stacktrace。有关详细信息,请参阅构建和运行 WebGL 项目页面。 |
Compression Format | 选择要用于发布版本文件的压缩格式。选项包括:_Gzip、Brotli_ 或 _Disabled_(无)。请注意,此选项不会影响开发版本。 |
Name Files As Hashes | 启用此选项可使用未压缩文件内容的 MD5 哈希作为构建中每个文件的文件名。 |
Data caching | 启用此选项可自动将内容资源数据缓存在用户计算机上,这样就不必在后续运行中重新下载(除非内容已更改)。 缓存是使用浏览器提供的 IndexedDB API 实现的。有些浏览器可能会对此实施限制,例如要求用户进行授权才能缓存超过特定大小的数据。 |
Debug Symbols | 启用此选项可在发生错误时保留调试符号并执行堆栈跟踪的恢复(显示原始函数名称)。对于发布版本,所有调试信息都存储在单独的文件中;发生错误时将根据需要从服务器下载该文件。开发版本始终具有嵌入在主模块中的恢复支持,因此不受此选项的影响。 |
Decompression Fallback | Include decompression fallback code for build files in the loader. Use this option if you are not able to configure server response headers according to the selected compression method. |