Siki_Unity_3_UGUI整体解决方案-优化篇

UGUI整体解决方案-优化篇

任务2:简介

主要两个方面:合批(batching) 和 重建(rebuild)

目录:
1. UI相关基础
2. UI主要组件
3. UI渲染规则
4. 重建
5. 批处理
6. 事件响应与射线
7. 填充率、overdraw
8. 具体UI组件的优化

任务3:基本概念

网格 -- Mesh:

无论是3D物体还是2D物体,都是由网格mesh绘制的

比如一个image,是由两个面片构成的

可以在Scene视图面板中选择Wireframe进行查看当前网格

填充率 -- Overdraw

表示重叠的部分

可以在Scene视图面板中选择OverDraw进行查看填充率情况

DrawCall

在GPU进行绘制之前,CPU需要计算并提供比如顶点位置纹理等信息,并调用图形接口API进行绘制渲染,每一次调用被称为一次Drawcall

Batching -- 批处理:

将可以合并的mesh进行合并,目的是减少drawcall

任务4:Canvas与Graphics

Canvas:负责将所有子物体组件进行合批,并进行绘制渲染
  需要被绘制的物体上都挂载有CanvasRenderer组件,Canvas是通过该组件查找需要绘制的物体的

Graphics:需要渲染的组件都是继承自Graphics类的
  Graphics实现了ICanvasElement接口,该接口表示需要显示在Canvas下
  ICanvasElement接口中有一个void Rebuild(CanvasUpdate executing);方法,即平时所说的UI重建

Rebuild:在进行合批操作后,所有被脏标记的元素都会进行重建

脏标记:有修改的组件会被进行脏标记
  在Graphics下有public virtual void SetAllDirty()
  SetAllDirty里执行了SetLayoutDirty(); SetMaterialDirty(); SetVerticesDirty();
  优化需要注意的也主要是这三个方面:Layout、材质、顶点

任务5:Rebuild 重建

// A Graphic that is capable of being masked out 可被遮挡的组件
MaskableGraphic
: Graphic, IClippable, IMaskable, IMaterialModifier
  实现了IMaskable接口的类,表示可被遮罩遮挡

Text、Image等组件都继承了MaskableGraphics

// Wrapper class for managing layout rebuilding of CanvasElement 管理Layout的重建
LayoutRebuilder: ICanvasElement

// A component is treated as a layout element by the auto layout system if it implements ILayoutElement
ILayoutElement
  所有能被排序的组件都继承自该接口,比如Image、Text等

// A place where CanvasElements can register themselves for rebuilding.
CanvasUpdateRegistry: 
  注册了Canvas.willRenderCanvases事件
  Canvas.willRenderCanvases += PerformUpdate;
  在PerformUpdate中实现了重建的操作,比如对m_LayoutRebuildQueue进行操作

 

 

 

 

 

 

 

 

 

 

 

 

 

 

原文地址:https://www.cnblogs.com/FudgeBear/p/14342632.html