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 OnTransformParentChanged() { base.OnTransformParentChanged(); m_Canvas = null; if (!IsActive()) { return; } 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 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(); }
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]; // -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 OnBeforeTransformParentChanged() { GraphicRegistry.UnregisterGraphicForCanvas(canvas, this); LayoutRebuilder.MarkLayoutForRebuild(rectTransform); }