Registry which maps a Graphic to the canvas it belongs to.
/// <summary> /// 8/6 2020 Graphic源码学习 /// 在更换父节点之前调用方法 /// 之所以在更换父节点的情况下进行Canvas的撤销和注册,主要是防止Canvas间切换父节点的情况 /// </summary> protected override void OnBeforeTransformParentChanged() { // Debug.Log("OnBeforeTransformParentChanged"); //先撤销组件和canvas的关联 GraphicRegistry.UnregisterGraphicForCanvas(canvas, this); LayoutRebuilder.MarkLayoutForRebuild(rectTransform); }
private static void Raycast(Canvas canvas, Camera eventCamera, Vector2 pointerPosition, List <GameObject> results) { // Necessary for the event system var foundGraphics = GraphicRegistry.GetGraphicsForCanvas(canvas); s_SortedGraphics.Clear(); for (int i = 0; i < foundGraphics.Count; ++i) { Graphic graphic = foundGraphics[i]; // -1 means it hasn't been processed by the canvas, which means it isn't actually drawn if (graphic.depth == -1) { continue; } if (!RectTransformUtility.PointInRectangle(pointerPosition, graphic.rectTransform, eventCamera)) { continue; } if (graphic.Raycast(pointerPosition, eventCamera)) { s_SortedGraphics.Add(graphic); } } s_SortedGraphics.Sort((g1, g2) => g2.depth.CompareTo(g1.depth)); for (int i = 0; i < s_SortedGraphics.Count; ++i) { results.Add(s_SortedGraphics[i].gameObject); } }
protected override void OnBeforeTransformParentChanged() { //Deregister the given Graphic from a Canvas. GraphicRegistry.UnregisterGraphicForCanvas(canvas, this); //Mark the given RectTransform as needing it's layout to be recalculated during the next layout pass. LayoutRebuilder.MarkLayoutForRebuild(rectTransform); }
/// <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); } } }
private static void Raycast(Canvas canvas, Camera eventCamera, Vector2 pointerPosition, List <Graphic> results) { IList <Graphic> graphicsForCanvas = GraphicRegistry.GetGraphicsForCanvas(canvas); for (int i = 0; i < graphicsForCanvas.Count; i++) { Graphic graphic = graphicsForCanvas[i]; if (!graphic.canvasRenderer.cull) { if (graphic.depth != -1 && graphic.raycastTarget) { if (RectTransformUtility.RectangleContainsScreenPoint(graphic.rectTransform, pointerPosition, eventCamera)) { if (graphic.Raycast(pointerPosition, eventCamera)) { GraphicRaycaster.s_SortedGraphics.Add(graphic); } } } } } GraphicRaycaster.s_SortedGraphics.Sort((Graphic g1, Graphic g2) => g2.depth.CompareTo(g1.depth)); for (int j = 0; j < GraphicRaycaster.s_SortedGraphics.Count; j++) { results.Add(GraphicRaycaster.s_SortedGraphics[j]); } GraphicRaycaster.s_SortedGraphics.Clear(); }
protected override void 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) { 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()) { GraphicRegistry.RegisterGraphicForCanvas(canvas, this); } } }
protected override void OnBeforeTransformParentChanged() { if (raycastTarget) { GraphicRegistry.UnregisterGraphicForCanvas(canvas, this); } LayoutRebuilder.MarkLayoutForRebuild(rectTransform); }
protected override void OnTransformParentChanged() { if (this.IsActive()) { this.CacheCanvas(); GraphicRegistry.RegisterGraphicForCanvas(this.canvas, this); this.SetAllDirty(); } }
protected override void OnTransformParentChanged() { base.OnTransformParentChanged(); if (IsActive()) { CacheCanvas(); GraphicRegistry.RegisterGraphicForCanvas(canvas, this); SetAllDirty(); } }
/// <summary> /// Mark the Graphic and the canvas as having been changed. /// </summary> protected override void OnEnable() { base.OnEnable(); CacheCanvas(); GraphicRegistry.RegisterGraphicForCanvas(canvas, this); #if UNITY_EDITOR GraphicRebuildTracker.TrackGraphic(this); #endif SetAllDirty(); }
protected override void OnDisable() { GraphicRegistry.UnregisterGraphicForCanvas(this.canvas, this); CanvasUpdateRegistry.UnRegisterCanvasElementForRebuild(this); if (this.canvasRenderer != null) { this.canvasRenderer.Clear(); } LayoutRebuilder.MarkLayoutForRebuild(this.rectTransform); base.OnDisable(); }
protected override void OnEnable() { base.OnEnable(); this.CacheCanvas(); GraphicRegistry.RegisterGraphicForCanvas(this.canvas, this); if (Graphic.s_WhiteTexture == null) { Graphic.s_WhiteTexture = Texture2D.whiteTexture; } this.SetAllDirty(); }
protected override void OnCanvasHierarchyChanged() { Canvas c = this.m_Canvas; this.CacheCanvas(); if (c != this.m_Canvas) { GraphicRegistry.UnregisterGraphicForCanvas(c, this); GraphicRegistry.RegisterGraphicForCanvas(this.canvas, this); } }
protected override void OnCanvasHierarchyChanged() { Canvas c = this.m_Canvas; this.CacheCanvas(); if (!((UnityEngine.Object)c != (UnityEngine.Object) this.m_Canvas)) { return; } GraphicRegistry.UnregisterGraphicForCanvas(c, this); GraphicRegistry.RegisterGraphicForCanvas(this.canvas, this); }
protected override void OnTransformParentChanged() { base.OnTransformParentChanged(); this.m_Canvas = (Canvas)null; if (!this.IsActive()) { return; } this.CacheCanvas(); GraphicRegistry.RegisterGraphicForCanvas(this.canvas, this); this.SetAllDirty(); }
protected override void OnEnable() { base.OnEnable(); this.CacheCanvas(); GraphicRegistry.RegisterGraphicForCanvas(this.canvas, this); GraphicRebuildTracker.TrackGraphic(this); if ((UnityEngine.Object)Graphic.s_WhiteTexture == (UnityEngine.Object)null) { Graphic.s_WhiteTexture = Texture2D.whiteTexture; } this.SetAllDirty(); }
/// <summary> /// /// <para> /// See MonoBehaviour.OnDisable. /// </para> /// /// </summary> protected override void OnDisable() { GraphicRebuildTracker.UnTrackGraphic(this); GraphicRegistry.UnregisterGraphicForCanvas(this.canvas, this); CanvasUpdateRegistry.UnRegisterCanvasElementForRebuild((ICanvasElement)this); if ((UnityEngine.Object) this.canvasRenderer != (UnityEngine.Object)null) { this.canvasRenderer.Clear(); } LayoutRebuilder.MarkLayoutForRebuild(this.rectTransform); base.OnDisable(); }
protected override void OnCanvasHierarchyChanged() { // Use m_Cavas so we dont auto call CacheCanvas Canvas currentCanvas = m_Canvas; CacheCanvas(); if (currentCanvas != m_Canvas) { GraphicRegistry.UnregisterGraphicForCanvas(currentCanvas, this); GraphicRegistry.RegisterGraphicForCanvas(canvas, this); } }
private static void Raycast(Canvas canvas, Camera eventCamera, Vector2 pointerPosition, List <Graphic> results) { IList <Graphic> graphicsForCanvas = GraphicRegistry.GetGraphicsForCanvas(canvas); for (int i = 0; i < graphicsForCanvas.Count; i++) { Graphic item = graphicsForCanvas[i]; if ((!item.canvasRenderer.cull && (item.depth != -1)) && ((item.raycastTarget && RectTransformUtility.RectangleContainsScreenPoint(item.rectTransform, pointerPosition, eventCamera)) && item.Raycast(pointerPosition, eventCamera))) { s_SortedGraphics.Add(item); } } if (< > f__am$cache0 == null) {
protected override void OnDestroy() { #if UNITY_EDITOR GraphicRebuildTracker.UnTrackGraphic(this); #endif GraphicRegistry.UnregisterGraphicForCanvas(canvas, this); CanvasUpdateRegistry.UnRegisterCanvasElementForRebuild(this); if (m_CachedMesh) { Destroy(m_CachedMesh); } m_CachedMesh = null; base.OnDestroy(); }
/// <summary> /// Mark the Graphic and the canvas as having been changed. /// </summary> protected override void OnEnable() { base.OnEnable(); CacheCanvas(); GraphicRegistry.RegisterGraphicForCanvas(canvas, this); #if UNITY_EDITOR GraphicRebuildTracker.TrackGraphic(this); #endif if (s_WhiteTexture == null) { s_WhiteTexture = Texture2D.whiteTexture; } SetAllDirty(); }
/// <summary> /// Clear references. /// </summary> protected override void OnDisable() { #if UNITY_EDITOR GraphicRebuildTracker.UnTrackGraphic(this); #endif GraphicRegistry.UnregisterGraphicForCanvas(canvas, this); CanvasUpdateRegistry.UnRegisterCanvasElementForRebuild(this); if (canvasRenderer != null) { canvasRenderer.Clear(); } LayoutRebuilder.MarkLayoutForRebuild(rectTransform); base.OnDisable(); }
protected override void OnTransformParentChanged() { base.OnTransformParentChanged(); m_Canvas = null; if (!IsActive()) { return; } CacheCanvas(); GraphicRegistry.RegisterGraphicForCanvas(canvas, this); //全部重建(布局、材质、顶点) SetAllDirty(); }
public void SetRaycastDirty() { if (m_RaycastTargetCache != m_RaycastTarget) { if (m_RaycastTarget && isActiveAndEnabled) { GraphicRegistry.RegisterRaycastGraphicForCanvas(canvas, this); } else if (!m_RaycastTarget) { GraphicRegistry.UnregisterRaycastGraphicForCanvas(canvas, this); } } m_RaycastTargetCache = m_RaycastTarget; }
protected override void OnTransformParentChanged() { base.OnTransformParentChanged(); m_Canvas = null; if (!IsActive()) { return; } CacheCanvas(); if (raycastTarget) { GraphicRegistry.RegisterGraphicForCanvas(canvas, this); } SetAllDirty(); }
/// <summary> /// 16/6 2020 Graphic源码学习 /// 在更换父节点时调用方法 /// </summary> protected override void OnTransformParentChanged() { // Debug.Log(" OnTransformParentChanged"); base.OnTransformParentChanged(); m_Canvas = null; if (!IsActive()) { return; } //查找这个物体的canvas CacheCanvas(); //将canvas和图形组件进行绑定 GraphicRegistry.RegisterGraphicForCanvas(canvas, this); SetAllDirty(); }
protected override void OnCanvasHierarchyChanged() { Canvas canvas = this.m_Canvas; this.m_Canvas = null; if (this.IsActive()) { this.CacheCanvas(); if (canvas != this.m_Canvas) { GraphicRegistry.UnregisterGraphicForCanvas(canvas, this); if (this.IsActive()) { GraphicRegistry.RegisterGraphicForCanvas(this.canvas, this); } } } }
private static void Raycast(Canvas canvas, Camera eventCamera, Vector2 pointerPosition, List <Graphic> results) { IList <Graphic> graphicsForCanvas = GraphicRegistry.GetGraphicsForCanvas(canvas); for (int index = 0; index < graphicsForCanvas.Count; ++index) { Graphic graphic = graphicsForCanvas[index]; if (graphic.depth != -1 && graphic.raycastTarget && (RectTransformUtility.RectangleContainsScreenPoint(graphic.rectTransform, pointerPosition, eventCamera) && graphic.Raycast(pointerPosition, eventCamera))) { GraphicRaycaster.s_SortedGraphics.Add(graphic); } } GraphicRaycaster.s_SortedGraphics.Sort((Comparison <Graphic>)((g1, g2) => g2.depth.CompareTo(g1.depth))); for (int index = 0; index < GraphicRaycaster.s_SortedGraphics.Count; ++index) { results.Add(GraphicRaycaster.s_SortedGraphics[index]); } GraphicRaycaster.s_SortedGraphics.Clear(); }
private static void Raycast(Canvas canvas, Camera eventCamera, Vector2 pointerPosition, List <Graphic> results) { // Debug.Log("ttt" + pointerPoision + ":::" + camera); // Necessary for the event system var foundGraphics = GraphicRegistry.GetGraphicsForCanvas(canvas); for (int i = 0; i < foundGraphics.Count; ++i) { Graphic graphic = foundGraphics[i]; if (graphic.canvasRenderer.cull) { continue; } // -1 means it hasn't been processed by the canvas, which means it isn't actually drawn if (graphic.depth == -1 || !graphic.raycastTarget) { continue; } if (!RectTransformUtility.RectangleContainsScreenPoint(graphic.rectTransform, pointerPosition, eventCamera)) { continue; } if (graphic.Raycast(pointerPosition, eventCamera)) { s_SortedGraphics.Add(graphic); } } s_SortedGraphics.Sort((g1, g2) => g2.depth.CompareTo(g1.depth)); // StringBuilder cast = new StringBuilder(); for (int i = 0; i < s_SortedGraphics.Count; ++i) { results.Add(s_SortedGraphics[i]); } // Debug.Log (cast.ToString()); s_SortedGraphics.Clear(); }
protected override void 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) { GraphicRegistry.UnregisterGraphicForCanvas(currentCanvas, this); GraphicRegistry.RegisterGraphicForCanvas(canvas, this); } }