单例

申明了一个CanvasUpdateRegistry类型的instance单例类

/// <summary>
/// Get the singleton registry instance.
/// </summary>
public static CanvasUpdateRegistry instance
{
    get
    {
        if (s_Instance == null)
            s_Instance = new CanvasUpdateRegistry();
        return s_Instance;
    }
}

跟踪

m_LayoutRebuildQueue

private readonly IndexedSet<ICanvasElement> m_LayoutRebuildQueue = new IndexedSet<ICanvasElement>();
  1. 通过 InternalRegisterCanvasElementForLayoutRebuild接口将 ICanvasElement 加入m_LayoutRebuildQueue,不会重复添加,外界通过调用静态函数RegisterCanvasElementForLayoutRebuildICanvasElement加入队列

  2. 关于 IndexedSet

  3. 外部添加途径

    1. Scrollbar的OnValidate接口, ScrollRect的OnEnable、SetDirtyCaching接口,Slider的OnValidate接口,Toggle的OnValidate接口:调用RegisterCanvasElementForLayoutRebuild注册
    2. LayoutRebuild的MarkLayoutRootForRebuild静态方法调用TryRegisterCanvasElementForLayoutRebuild注册,MarkLayoutRootForRebuild又只在其MarkLayoutForRebuild接口中调用。而
    LayoutRebuilder.MarkLayoutForRebuild(rectTransform);
    

    在需要更新位置、大小的组件里被调用(通常在onenable、setdirty中)

m_GraphicRebuildQueue

private readonly IndexedSet<ICanvasElement> m_GraphicRebuildQueue = new IndexedSet<ICanvasElement>();
  1. 同1,不同的是:不会根据是否添加过返回false
  2. 同上2
  3. 增加了m_PerformingGraphicUpdate参数,控制添加元素,正在执行m_GraphicRebuildQueue中元素的rebuild时,不允许添加/移除新的元素
  4. 外部添加途径:只有Graphic中几个设置dirty的地方主动调用了:SetVerticesDirty、SetMaterialDirty、OnCullingChanged、MarkGeometryAsDirty
CanvasUpdateRegistry.RegisterCanvasElementForGraphicRebuild(this);