void CacheCanvas() { var list = NewListPool <Canvas> .Get(); this.GetComponentsInParent(false, list); for (int i = 0; i < list.Count; i++) { if (list[i] != null && list[i].isActiveAndEnabled) { mCanvas = list[i]; break; } } NewListPool <Canvas> .Release(list); }
public static void GetRectMasksForClip(NewRectMask2D clipper, List <NewRectMask2D> masks) { masks.Clear(); var rectMaskComponents = NewListPool <NewRectMask2D> .Get(); var canvasComponents = NewListPool <Canvas> .Get(); clipper.GetComponentsInParent(false, rectMaskComponents); if (rectMaskComponents.Count > 0) { clipper.GetComponentsInParent(false, canvasComponents); } for (int i = rectMaskComponents.Count - 1; i >= 0; i--) { if (!rectMaskComponents[i].isActiveAndEnabled) { continue; } bool canAdd = true; for (int j = canvasComponents.Count - 1; j >= 0; j--) { if (canvasComponents[j].overrideSorting && IsDesendantOrSelf(canvasComponents[i].transform, rectMaskComponents[i].transform)) { canAdd = false; } } if (canAdd) { masks.Add(rectMaskComponents[i]); } } NewListPool <NewRectMask2D> .Release(rectMaskComponents); NewListPool <Canvas> .Release(canvasComponents); }
public static NewRectMask2D GetRectMaskForClippable(IClippable clippable) { var rectMaskComponents = NewListPool <NewRectMask2D> .Get(); var canvasComponents = NewListPool <Canvas> .Get(); NewRectMask2D targetMask = null; clippable.rectTransform.GetComponentsInParent(false, rectMaskComponents); for (int i = 0; i < rectMaskComponents.Count; i++) { targetMask = rectMaskComponents[i]; if (targetMask.gameObject == clippable.gameObject) { continue; } if (!targetMask.isActiveAndEnabled) { continue; } clippable.rectTransform.GetComponentsInParent(false, canvasComponents); for (int j = 0; j < canvasComponents.Count; j++) { if (canvasComponents[j].overrideSorting && !IsDesendantOrSelf(canvasComponents[j].transform, targetMask.transform)) { targetMask = null; break; } } return(targetMask); } NewListPool <NewRectMask2D> .Release(rectMaskComponents); NewListPool <Canvas> .Release(canvasComponents); return(targetMask); }
public static Transform FindRootSortOverrideCanvas(Transform start) { var canvasList = NewListPool <Canvas> .Get(); start.GetComponentsInParent(false, canvasList); Canvas target = null; for (int i = 0; i < canvasList.Count; i++) { target = canvasList[i]; if (canvasList[i].overrideSorting) { break; } } return(target != null ? target.transform : null); }
public static void Notify2DMaskStateChanged(Component mask) { var components = NewListPool <Component> .Get(); mask.GetComponentsInChildren(components); for (var i = 0; i < components.Count; i++) { if (components[i] == null || components[i].gameObject == mask.gameObject) { continue; } var toNotify = components[i] as IClippable; if (toNotify != null) { toNotify.RecalculateClipping(); } } NewListPool <Component> .Release(components); }
public static int GetStencilDepth(Transform transform, Transform stopAfter) { var depth = 0; if (transform == stopAfter) { return(depth); } Transform t = transform.parent; var maskComponents = NewListPool <NewMask> .Get(); while (t != null) { t.GetComponents(maskComponents); for (int i = 0; i < maskComponents.Count; i++) { var mask = maskComponents[i]; if (mask != null && mask.MaskEnabled() && mask.graphic.IsActive()) { depth++; break; } } if (t == stopAfter) { break; } t = t.parent; } NewListPool <NewMask> .Release(maskComponents); return(depth); }
public static void NotifyStencilStateChanged(Component mask) { var components = NewListPool <Component> .Get(); mask.GetComponentsInChildren(components); for (int i = 0; i < components.Count; i++) { if (components[i] == null || components[i].gameObject == mask.gameObject) { continue; } var maskable = components[i] as IMaskable; if (maskable != null) { maskable.RecalculateMasking(); } } NewListPool <Component> .Release(components); }