switch (update) { case CanvasUpdate.PreRender: //顶点被标记为脏(true) if (m_VertsDirty) { //更新网格 UpdateGeometry(); m_VertsDirty = false; } if (m_MaterialDirty) { //更新材质 UpdateMaterial(); m_MaterialDirty = false; } break; } }
//网格刷新方法 privatevoidDoMeshGeneration() { if (rectTransform != null && rectTransform.rect.width >= 0 && rectTransform.rect.height >= 0) //更新网格数据 OnPopulateMesh(s_VertexHelper); else //清除网格数据 s_VertexHelper.Clear(); // clear the vertex helper so invalid graphics dont draw.
var components = ListPool<Component>.Get(); GetComponents(typeof(IMeshModifier), components); //https://zhuanlan.zhihu.com/p/340601601 可以看该链接去看这方法的作用 //简介就是继承该接口的组件(Shadow Outline)也行进行刷新网格信息 for (var i = 0; i < components.Count; i++) ((IMeshModifier)components[i]).ModifyMesh(s_VertexHelper);
// now layout is complete do culling... UnityEngine.Profiling.Profiler.BeginSample(m_CullingUpdateProfilerString); ClipperRegistry.instance.Cull(); UnityEngine.Profiling.Profiler.EndSample();
m_PerformingGraphicUpdate = true;
var graphicRebuildQueueCount = m_GraphicRebuildQueue.Count; for (var i = (int)CanvasUpdate.PreRender; i < (int)CanvasUpdate.MaxUpdateValue; i++) { UnityEngine.Profiling.Profiler.BeginSample(m_CanvasUpdateProfilerStrings[i]); for (var k = 0; k < graphicRebuildQueueCount; k++) { try { var element = m_GraphicRebuildQueue[k]; if (ObjectValidForUpdate(element)) //重建图形元素 element.Rebuild((CanvasUpdate)i); } catch (Exception e) { Debug.LogException(e, m_GraphicRebuildQueue[k].transform); } } UnityEngine.Profiling.Profiler.EndSample(); }
for (int i = 0; i < graphicRebuildQueueCount; ++i) m_GraphicRebuildQueue[i].GraphicUpdateComplete();