Web template build configuration and interaction
Learn how to configure and interact with Web templates.
阅读时间3 分钟最后更新于 1 个月前
Configure and interact with Web builds using Web templates.
For information about template variables, JavaScript macros, and conditional directives, refer to Web template variables.
Build configuration
The configuration object contains the build configuration, which consists of code and data URLs, product name, company name, and version. You can define it using the following code:
var buildUrl = "Build";var config = { dataUrl: buildUrl + "/{{{ DATA_FILENAME }}}", frameworkUrl: buildUrl + "/{{{ FRAMEWORK_FILENAME }}}", codeUrl: buildUrl + "/{{{ CODE_FILENAME }}}",#if MEMORY_FILENAME memoryUrl: buildUrl + "/{{{ MEMORY_FILENAME }}}",#endif#if SYMBOLS_FILENAME symbolsUrl: buildUrl + "/{{{ SYMBOLS_FILENAME }}}",#endif streamingAssetsUrl: "StreamingAssets", companyName: "{{{ COMPANY_NAME }}}", productName: "{{{ PRODUCT_NAME }}}", productVersion: "{{{ PRODUCT_VERSION }}}", // additional options can go here, see below};
In the example above, the build folder URL is stored as a separate variable called . This is useful in cases where you don't know the relationship between the embedding page and build folder on the hosting server. It enables you to reuse the embedding code in other HTML documents. An example of when to use this is if you move the folder to another location on your server. You can adjust the value of the variable on the embedding page, and you can use the same embedding code. This also applies to the folder ().
buildUrlBuildbuildUrlStreamingAssetsstreamingAssetsUrlIn addition to setting the URL and field names on the build, you can set the following properties on the object.
configProperty | Use |
|---|---|
| By default (if set to true or unset), Unity synchronizes the WebGL canvas render target size with the Document Object Model (DOM) size of the canvas element (scaled by |
| This field enables forcing the DPI scaling ratio for the rendered page. Set to 1 to force rendering to "standard DPI" (or non-Retina DPI), which can help performance on lower-end mobile devices. By default, this field is unset, meaning the rendered page uses the browser DPR scaling ratio, resulting in High DPI rendering. |
| If set to true, all file writes inside the Unity |
Build interaction
After the build has successfully instantiated, the fulfillment handler callback of the Promise object receives the newly created Unity instance object as an argument. To interact with the build, call the following methods of the Unity instance:
Method | Use |
|---|---|
| The - To activate Full screen mode, set the - To exit Full screen mode, set the |
| The - - - |
| Use the - |