private void NotifyMaskStateChanged() { if (graphic != null) { graphic.canvasRenderer.isMask = IsActive(); graphic.SetMaterialDirty(); } var components = ComponentListPool.Get(); GetComponentsInChildren(components); for (var i = 0; i < components.Count; i++) { if (components[i] == null || components[i].gameObject == gameObject) { continue; } var toNotify = components[i] as IMaskable; if (toNotify != null) { toNotify.ParentMaskStateChanged(); } } ComponentListPool.Release(components); }
private void PerformLayoutCalculation(RectTransform rect, UnityAction <Component> action) { if (rect == null) { return; } var components = ComponentListPool.Get(); rect.GetComponents(typeof(ILayoutElement), components); StripDisabledBehavioursFromList(components); // If there are no controllers on this rect we can skip this entire sub-tree // We don't need to consider controllers on children deeper in the sub-tree either, // since they will be their own roots. if (components.Count > 0) { // Layout calculations needs to executed bottom up with children being done before their parents, // because the parent calculated sizes rely on the sizes of the children. for (int i = 0; i < rect.childCount; i++) { PerformLayoutCalculation(rect.GetChild(i) as RectTransform, action); } for (int i = 0; i < components.Count; i++) { action(components[i]); } } ComponentListPool.Release(components); }
public virtual bool Raycast(Vector2 sp, Camera eventCamera) { var t = transform; var components = ComponentListPool.Get(); while (t != null) { t.GetComponents(components); for (var i = 0; i < components.Count; i++) { var filter = components[i] as ICanvasRaycastFilter; if (filter == null) { continue; } if (!filter.IsRaycastLocationValid(sp, eventCamera)) { ComponentListPool.Release(components); return(false); } } t = t.parent; } ComponentListPool.Release(components); return(true); }
private void UpdateInternalState() { if (!m_ShouldRecalculate) { return; } m_StencilValue = GetStencilForGraphic(); var t = transform.parent; m_IncludeForMasking = false; var components = ComponentListPool.Get(); while (m_Maskable && t != null) { t.GetComponents(typeof(IMask), components); if (components.Count > 0) { m_IncludeForMasking = true; break; } t = t.parent; } m_ShouldRecalculate = false; ComponentListPool.Release(components); }
private int GetStencilForGraphic() { var maskDepth = 0; var t = transform.parent; var components = ComponentListPool.Get(); while (t != null) { t.GetComponents(typeof(IMask), components); for (var i = 0; i < components.Count; i++) { var mask = components[i] as IMask; if (mask == null || !mask.MaskEnabled()) { continue; } maskDepth++; maskDepth = Mathf.Clamp(maskDepth, 0, 8); break; } t = t.parent; } ComponentListPool.Release(components); return(maskDepth); }
public static float GetLayoutProperty(RectTransform rect, System.Func <ILayoutElement, float> property, float defaultValue, out ILayoutElement source) { source = null; if (rect == null) { return(0); } float min = defaultValue; int maxPriority = System.Int32.MinValue; var components = ComponentListPool.Get(); rect.GetComponents(typeof(ILayoutElement), components); for (int i = 0; i < components.Count; i++) { var layoutComp = components[i] as ILayoutElement; if (layoutComp is Behaviour && (!(layoutComp as Behaviour).enabled || !(layoutComp as Behaviour).isActiveAndEnabled)) { continue; } int priority = layoutComp.layoutPriority; // If this layout components has lower priority than a previously used, ignore it. if (priority < maxPriority) { continue; } float prop = property(layoutComp); // If this layout property is set to a negative value, it means it should be ignored. if (prop < 0) { continue; } // If this layout component has higher priority than all previous ones, // overwrite with this one's value. if (priority > maxPriority) { min = prop; maxPriority = priority; source = layoutComp; } // If the layout component has the same priority as a previously used, // use the largest of the values with the same priority. else if (prop > min) { min = prop; source = layoutComp; } } ComponentListPool.Release(components); return(min); }
private void SendGraphicEnabledDisabled() { var components = ComponentListPool.Get(); GetComponents(typeof(IGraphicEnabledDisabled), components); for (int i = 0; i < components.Count; i++) { ((IGraphicEnabledDisabled)components[i]).OnSiblingGraphicEnabledDisabled(); } ComponentListPool.Release(components); }
public virtual bool Raycast(Vector2 sp, Camera eventCamera) { var t = transform; var components = ComponentListPool.Get(); bool ignoreParentGroups = false; while (t != null) { t.GetComponents(components); for (var i = 0; i < components.Count; i++) { var filter = components[i] as ICanvasRaycastFilter; if (filter == null) { continue; } var raycastValid = true; var group = components[i] as CanvasGroup; if (group != null) { if (ignoreParentGroups == false && group.ignoreParentGroups) { ignoreParentGroups = true; raycastValid = filter.IsRaycastLocationValid(sp, eventCamera); } else if (!ignoreParentGroups) { raycastValid = filter.IsRaycastLocationValid(sp, eventCamera); } } else { raycastValid = filter.IsRaycastLocationValid(sp, eventCamera); } if (!raycastValid) { ComponentListPool.Release(components); return(false); } } t = t.parent; } ComponentListPool.Release(components); return(true); }
private static bool ValidLayoutGroup(RectTransform parent) { if (parent == null) { return(false); } var comps = ComponentListPool.Get(); parent.GetComponents(typeof(ILayoutGroup), comps); StripDisabledBehavioursFromList(comps); var validCount = comps.Count > 0; ComponentListPool.Release(comps); return(validCount); }
private static bool ValidController(RectTransform layoutRoot) { if (layoutRoot == null) { return(false); } var comps = ComponentListPool.Get(); layoutRoot.GetComponents(typeof(ILayoutController), comps); StripDisabledBehavioursFromList(comps); var valid = comps.Count > 0; ComponentListPool.Release(comps); return(valid); }
private void PerformLayoutControl(RectTransform rect, UnityAction <Component> action) { if (rect == null) { return; } var components = ComponentListPool.Get(); rect.GetComponents(typeof(ILayoutController), components); StripDisabledBehavioursFromList(components); // If there are no controllers on this rect we can skip this entire sub-tree // We don't need to consider controllers on children deeper in the sub-tree either, // since they will be their own roots. if (components.Count > 0) { // Layout control needs to executed top down with parents being done before their children, // because the children rely on the sizes of the parents. // First call layout controllers that may change their own RectTransform for (int i = 0; i < components.Count; i++) { if (components[i] is ILayoutSelfController) { action(components[i]); } } // Then call the remaining, such as layout groups that change their children, taking their own RectTransform size into account. for (int i = 0; i < components.Count; i++) { if (!(components[i] is ILayoutSelfController)) { action(components[i]); } } for (int i = 0; i < rect.childCount; i++) { PerformLayoutControl(rect.GetChild(i) as RectTransform, action); } } ComponentListPool.Release(components); }
/// <summary> /// Update the renderer's vertices. /// </summary> protected virtual void UpdateGeometry() { var vbo = s_VboPool.Get(); if (rectTransform != null && rectTransform.rect.width >= 0 && rectTransform.rect.height >= 0) { OnFillVBO(vbo); } var components = ComponentListPool.Get(); GetComponents(typeof(IVertexModifier), components); for (var i = 0; i < components.Count; i++) { (components[i] as IVertexModifier).ModifyVertices(vbo); } ComponentListPool.Release(components); canvasRenderer.SetVertices(vbo); s_VboPool.Release(vbo); }