一、CanvasUpdateRegistry实现 的功能
主要的实现功能是对所有的graphic对象和layout对象进行注册管理【组件需要是ICanvasElement类型】,根据canvas的事件,调用ui对象的Rebuild函数进行重建。
二、源码分析
1、 private static CanvasUpdateRegistry s_Instance;表示当前的CanvasUpdateRegistry是一个单例。
2、//布局刷新队列
private readonly IndexedSet<ICanvasElement> m_LayoutRebuildQueue = new IndexedSet<ICanvasElement> ();
//图片类的刷新队列
private readonly IndexedSet<ICanvasElement> m_GraphicRebuildQueue = new IndexedSet<ICanvasElement> ();
m_LayoutRebuildQueue通过调用InternalRegisterCanvasElementForLayoutRebuild进行元素增加。RegisterCanvasElementForLayoutRebuild和TryRegisterCanvasElementForLayoutRebuild进行调用,两个函数就差是否有一个返回结果。返回结果是true表示成功添加到重建的layoutQueue当中,false表示添加失败或者是已经在LayoutRebuildQueue队列中,使用脏标记进行控制是否可以添加。InternalUnRegisterCanvasElementForLayoutRebuild进行元素对象删除,m_PerformingLayoutUpdate作为脏标记
m_GraphicRebuildQueue功能类似。只是存放的是graphic对象,操作的对象是graphic