Skip to content
This repository was archived by the owner on Apr 29, 2021. It is now read-only.

Commit 01fc2eb

Browse files
authored
Merge pull request #130 from UnityTech/yczhang
Update README for webgl plugin.
2 parents d841bc4 + 433cd76 commit 01fc2eb

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

README-ZH.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,26 @@ UIWidgets也支持Gif!
184184
默认的逻辑是在界面静止时将帧率降低为15,在界面变动时将帧率提高至60。
185185
如果您需要修改帧率升高或降低时的行为,请将`Window.onFrameRateSpeedUp`和/或`Window.onFrameRateCoolDown`设置为您自己的函数。
186186

187+
#### 八、WebGL Canvas分辨率调整插件
188+
因为浏览器中Canvas的宽高和其在显示器上的像素数可能不一致,所以构建出的WebGL程序中画面可能会模糊。
189+
插件`Plugins/platform/webgl/UIWidgetsCanvasDevicePixelRatio.jslib`解决了这个问题。
190+
如果您因为任何原因需要禁止此插件,请在Project面板中选中该插件,在Inspector面板中的Define Constraints参数中,输入`ENABLE_CANVAS_DEVICE_PIXEL_RATIO_PLUGIN`(该宏默认没有被定义,从而使得此插件被禁用)。
191+
192+
此插件覆盖了Unity WebGL构建模块中的如下参数:
193+
```
194+
JS_SystemInfo_GetWidth
195+
JS_SystemInfo_GetHeight
196+
JS_SystemInfo_GetCurrentCanvasWidth
197+
JS_SystemInfo_GetCurrentCanvasHeight
198+
$Browser
199+
$JSEvents
200+
```
201+
如果您需要实现自己的WebGL插件,并且您的插件覆盖了这些参数中的至少一种,您需要采用上文中提到的方法禁用`UIWidgetsCanvasDevicePixelRatio`插件,以防止可能的冲突。
202+
如果您仍然需要此插件所提供的功能,您可以手动将此插件对Unity WebGL构建模块的修改应用到您的插件中。
203+
`UIWidgetsCanvasDevicePixelRatio`插件中所有的修改之处都以`////////// Modification Start ////////////``////////// Modification End ////////////`标识。
204+
在被标识的代码中,所有乘/除以`devicePixelRatio`都来自于我们的修改。
205+
若您需要详细了解此插件所修改的脚本,请参考您的Unity Editor安装目录下的`PlaybackEngines/WebGLSupport/BuildTools/lib`文件夹中的`SystemInfo.js``UnityNativeJS/UnityNative.js`
206+
187207
## 调试UIWidgets应用程序
188208

189209
#### 定义UIWidgets_DEBUG

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,27 @@ Status bar is always hidden by default when an Unity project is running on an An
215215
To build an App that is able to adjust the frame rate automatically, please open Project Settings, and in the Quality tab, set the "V Sync Count" option of the target platform to "Don't Sync".
216216
The default logic is to set the frame rate to 15 when the screen is static, and change the frame rate to 60 whenever the screen changes.
217217
If you would like to modify the behavior of speeding up or cooling down the frame rate, please set `Window.onFrameRateSpeedUp` and/or `Window.onFrameRateCoolDown` to your own functions.
218+
219+
#### WebGL Canvas Device Pixel Ratio Plugin
220+
The width and height of the Canvas in browser may differ from the number of pixels the Canvas occupies on the screen.
221+
Therefore, the image may blur in the builded WebGL program.
222+
The Plugin `Plugins/platform/webgl/UIWidgetsCanvasDevicePixelRatio.jslib` solves this issue.
223+
If you need to disable this plugin for any reason, please select this plugin in the **Project** panel, and put `ENABLE_CANVAS_DEVICE_PIXEL_RATIO_PLUGIN` (this is not defined by default, which renders this plugin disabled) in the **Define Constraints** field in the **Inspector** panel.
224+
225+
This plugin overrides the following parameters in the Unity WebGL building module:
226+
```
227+
JS_SystemInfo_GetWidth
228+
JS_SystemInfo_GetHeight
229+
JS_SystemInfo_GetCurrentCanvasWidth
230+
JS_SystemInfo_GetCurrentCanvasHeight
231+
$Browser
232+
$JSEvents
233+
```
234+
If you would like to implement your own WebGL plugin, and your plugin overrides at least one of the above parameters, you need to disable the `UIWidgetsCanvasDevicePixelRatio` plugin in the above mentioned way to avoid possible conflicts.
235+
If you still need the function provided by this plugin, you can mannually apply the modification to Unity WebGL building module introduced in this plugin.
236+
All the modifications introduced in `UIWidgetsCanvasDevicePixelRatio` are marked by `////////// Modifcation Start ////////////` and `////////// Modifcation End ////////////`.
237+
In the marked codes, all the multiplications and divisions with `devicePixelRatio` are introduced by our modification.
238+
To learn about the original script in detail, please refer to `SystemInfo.js` and `UnityNativeJS/UnityNative.js` in `PlaybackEngines/WebGLSupport/BuildTools/lib` in your Unity Editor installation.
218239

219240
## Debug UIWidgets Application
220241

Runtime/Plugins/platform/webgl/UIWidgetsCanvasDevicePixelRatio.jslib

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,26 @@
11
mergeInto(LibraryManager.library, {
22
JS_SystemInfo_GetWidth: function () {
3+
//////////// Modification Start ////////////////////
34
return UnityLoader.SystemInfo.width * window.devicePixelRatio;
5+
//////////// Modification End ////////////////////
46
},
57

68
JS_SystemInfo_GetHeight: function () {
9+
//////////// Modification Start ////////////////////
710
return UnityLoader.SystemInfo.height * window.devicePixelRatio;
11+
//////////// Modification End ////////////////////
812
},
913

1014
JS_SystemInfo_GetCurrentCanvasWidth: function () {
15+
//////////// Modification Start ////////////////////
1116
return Module['canvas'].clientWidth * window.devicePixelRatio;
17+
//////////// Modification End ////////////////////
1218
},
1319

1420
JS_SystemInfo_GetCurrentCanvasHeight: function () {
21+
//////////// Modification Start ////////////////////
1522
return Module['canvas'].clientHeight * window.devicePixelRatio;
23+
//////////// Modification End ////////////////////
1624
},
1725
$Browser : {
1826
mainLoop: {

0 commit comments

Comments
 (0)