Beispiel #1
0
    //-------------------------------------------------------------------------------------------------------------------
    public static void addPaddingAnchor(GameObject obj)
    {
        // 先设置自己的Anchor
        if (obj.GetComponent <PaddingAnchor>() == null)
        {
            // 只要有Rect就可以添加该组件,panel也可以添加
            UIRect rect = WidgetUtility.getGameObjectRect(obj);
            if (rect != null)
            {
                PaddingAnchor anchor = obj.AddComponent <PaddingAnchor>();
                anchor.setAnchorMode(ANCHOR_MODE.AM_NEAR_PARENT_SIDE);
            }
        }
        // 再设置子节点的Anchor
        int childCount = obj.transform.childCount;

        for (int i = 0; i < childCount; ++i)
        {
            addPaddingAnchor(obj.transform.GetChild(i).gameObject);
        }
    }