UnityEngine.UI.MaskUtilities.IsDescendantOrSelf C# (CSharp) Method

IsDescendantOrSelf() public static method

Helper function to determine if the child is a descendant of father or is father.

public static IsDescendantOrSelf ( Transform father, Transform child ) : bool
father UnityEngine.Transform The transform to compare against.
child UnityEngine.Transform The starting transform to search up the hierarchy.
return bool
        public static bool IsDescendantOrSelf(Transform father, Transform child)
        {
            if ((father != null) && (child != null))
            {
                if (father == child)
                {
                    return true;
                }
                while (child.parent != null)
                {
                    if (child.parent == father)
                    {
                        return true;
                    }
                    child = child.parent;
                }
            }
            return false;
        }

Usage Example

コード例 #1
0
        public static void GetRectMasksForClip(RectMask2D clipper, List <RectMask2D> masks)
        {
            masks.Clear();
            List <Canvas> list = ListPool <Canvas> .Get();

            List <RectMask2D> list2 = ListPool <RectMask2D> .Get();

            clipper.transform.GetComponentsInParent <RectMask2D>(false, list2);
            if (list2.Count > 0)
            {
                clipper.transform.GetComponentsInParent <Canvas>(false, list);
                for (int i = list2.Count - 1; i >= 0; i--)
                {
                    if (list2[i].IsActive())
                    {
                        bool flag = true;
                        for (int j = list.Count - 1; j >= 0; j--)
                        {
                            if (!MaskUtilities.IsDescendantOrSelf(list[j].transform, list2[i].transform) && list[j].overrideSorting)
                            {
                                flag = false;
                                break;
                            }
                        }
                        if (flag)
                        {
                            masks.Add(list2[i]);
                        }
                    }
                }
            }
            ListPool <RectMask2D> .Release(list2);

            ListPool <Canvas> .Release(list);
        }
All Usage Examples Of UnityEngine.UI.MaskUtilities::IsDescendantOrSelf