Пример #1
0
    public void init(LAYOUT_TYPE type, string name, int renderOrder, bool isNGUI, bool isScene)
    {
        mName    = name;
        mType    = type;
        mIsNGUI  = isNGUI;
        mIsScene = isScene;
        mScript  = mLayoutManager.createScript(mName, this);
        if (mScript == null)
        {
            logError("can not create layout script! type : " + mType);
        }
        // 初始化布局脚本
        if (!mIsScene)
        {
            if (mIsNGUI)
            {
                mScript.newObject(out mLayoutPanel, mLayoutManager.getNGUIRoot(), mName);
            }
            else
            {
                mScript.newObject(out mLayoutCanvas, mLayoutManager.getUGUIRoot(), mName);
            }
        }
        else
        {
            if (mIsNGUI)
            {
                mScript.newObject(out mLayoutPanel, null, mName);
            }
            else
            {
                mScript.newObject(out mLayoutCanvas, null, mName);
            }
        }
        mScript.newObject(out mRoot, getLayoutPanel(), "Root");
        setRenderOrder(renderOrder);
        mScript.setRoot(mRoot);
        mScript.assignWindow();
        // 布局实例化完成,初始化之前,需要调用自适应组件的更新
        ScaleAnchor   scaleAnchor  = getLayoutPanel().getObject().GetComponent <ScaleAnchor>();
        PaddingAnchor customAnchor = getLayoutPanel().getObject().GetComponent <PaddingAnchor>();

        if (scaleAnchor != null)
        {
            ScaleAnchor.forceUpdateChildren(getLayoutPanel().getObject());
        }
        if (customAnchor != null)
        {
            PaddingAnchor.forceUpdateChildren(getLayoutPanel().getObject());
        }
        mScript.init();
        mScriptInited = true;
        // 加载完布局后强制隐藏
        setVisibleForce(false);
    }
Пример #2
0
    public void forceUpdateChildren()
    {
        // 先更新自己
        updateRect(true);
        // 然后更新所有子节点
        int childCount = transform.childCount;

        for (int i = 0; i < childCount; ++i)
        {
            ScaleAnchor anchor = transform.GetChild(i).GetComponent <ScaleAnchor>();
            if (anchor != null)
            {
                anchor.forceUpdateChildren();
            }
        }
    }