相关文章推荐
好帅的扁豆  ·  Unity 性能规范·  3 月前    · 
火星上的烤地瓜  ·  使用 html2canvas + ...·  2 月前    · 
帅气的单杠  ·  HUAWEI Mate 50 Pro - ...·  1 年前    · 
睿智的酸菜鱼  ·  海通证券·  1 年前    · 

Unity’s UI optimization tutorial mentions that one way to optimize hiding parts of the UI would be by Disabling Canvas Renderers .

However, they don’t exactly say how this should be done, and I haven’t found that on the current documentation for Canvas Renderers or the legacy one (since this tutorial was checked with Unity 5.3).

The only thing they say is that what should be done is to

[…] place the UI to be shown/hidden onto its own Canvas or Sub-canvas and then to merely enable/disable the Canvas Renderer component attached to that Canvas or Sub-canvas.

Is there a way to actually enable/disable the Canvas Renderer component or is there another optimized way to stop rendering UI Graphic components from a Sub-canvas without discarding VBO data?

I know that I can hide the UI objects by disabling the Canvas, disabling the GameObject or setting the Canvas Group alpha to 0, but I really need to make a WebGL build as optimized as possible, since the client needs it to run on an iPad, so please help me if you can.

Thanks.

It’s as simple as disabling the Canvas component, as it’s the thing that’s handling all the rendering of the UI.

Did a test with thousands of Canvas objects, and it did increase the render time by around 1ms for me, and disabling the Canvas component removed that delay.

I don’t think exist a way to disable “Canvas Renderer”.

you can log the dirty state change by call “RegisterDirtyLayoutCallBack” or “RegisterDirtyVerticesCallBack” on Awake

and you can find out that
“CanvasRenderer.cull = false” or “CanvasRenderer.SetAlpha(0)”
still cause a dirty.

The UI optimization tutorial said that

“One possible, but hacky, workaround
is to place the UI to be shown/hidden
onto its own Canvas or Sub-canvas and
then to merely enable/disable the
Canvas component on this object.”

So the poper way to do that is create a Canvas Component and disable it.