Store a link between the given canvas and graphic in the registry.
public static void RegisterGraphicForCanvas(Canvas c, Graphic graphic) { if (c != null) { IndexedSet<Graphic> set; instance.m_Graphics.TryGetValue(c, out set); if (set != null) { set.AddUnique(graphic); } else { set = new IndexedSet<Graphic> { graphic }; instance.m_Graphics.Add(c, set); } } }
/// <summary> /// 17/6 2020 Graphic学习 /// 主要是Canvas显示隐藏或者canvas控件OnEnable、Disable的时候调用 /// 主要是检测Canvas控件的 /// </summary> protected override void OnCanvasHierarchyChanged() { // Debug.Log("OnCanvasHierarchyChanged"); // Use m_Cavas so we dont auto call CacheCanvas Canvas currentCanvas = m_Canvas; // Clear the cached canvas. Will be fetched below if active. m_Canvas = null; if (!IsActive()) { return; } CacheCanvas(); if (currentCanvas != m_Canvas) { //currentCanvas != m_Canvas时,说明UI更换了canvas,需要与之前的Canvas解除关联 GraphicRegistry.UnregisterGraphicForCanvas(currentCanvas, this); // Only register if we are active and enabled as OnCanvasHierarchyChanged can get called // during object destruction and we dont want to register ourself and then become null. if (IsActive()) { //如果当前组件还是在激活状态下的话,就将当前UI和新的canvas进行注册绑定 GraphicRegistry.RegisterGraphicForCanvas(canvas, this); } } }