Пример #1
0
    // 返回值是最后一个窗口的深度值,ignoreInactive表示是否忽略未启用的节点
    protected int setUIChildDepth(txUIObject ui, int uiDepth, bool includeSelf = true, bool ignoreInactive = false)
    {
        // NGUI不需要重新设置所有节点的深度
        if (mIsNGUI)
        {
            return(0);
        }
        // 先设置当前窗口的深度
        if (includeSelf)
        {
            ui.setDepth(uiDepth);
        }
        // 再设置子窗口的深度
        int endDepth = ui.getDepth();

        if (ignoreInactive && !ui.isActive())
        {
            return(endDepth);
        }
        Transform transform  = ui.getTransform();
        int       childCount = transform.childCount;

        for (int i = 0; i < childCount; ++i)
        {
            txUIObject uiObj = getUIObject(transform.GetChild(i).gameObject);
            if (uiObj != null)
            {
                endDepth = setUIChildDepth(uiObj, endDepth + 1);
            }
        }
        return(endDepth);
    }
Пример #2
0
    //------------------------------------------------------------------------------------------------------------------------------------------
    public Vector3[] getLocalMinMaxPixelPos()
    {
        // 获得第一个带widget的父节点的rect
        UIRect  rect             = WidgetUtility.findParentRect(mObject);
        Vector2 parentWidgetSize = WidgetUtility.getRectSize(rect);
        // 计算父节点的世界缩放
        Vector3    worldScale  = getMatrixScale(mTransform.parent.localToWorldMatrix);
        txUIObject root        = mLayout.isNGUI() ? mLayoutManager.getNGUIRoot() : mLayoutManager.getUGUIRoot();
        Vector3    uiRootScale = root.getTransform().localScale;
        Vector2    parentScale = new Vector2(worldScale.x / uiRootScale.x, worldScale.y / uiRootScale.y);
        // 计算移动的位置范围
        Vector2 minPos = new Vector2(parentWidgetSize.x / 2.0f * mMinRelativePos.x / parentScale.x, parentWidgetSize.y / 2.0f * mMinRelativePos.y / parentScale.y);
        Vector2 maxPos = new Vector2(parentWidgetSize.x / 2.0f * mMaxRelativePos.x / parentScale.x, parentWidgetSize.y / 2.0f * mMaxRelativePos.y / parentScale.y);

        if (mClampType == CLAMP_TYPE.CT_EDGE)
        {
            Vector2 thisSize = getWindowSize(true);
            minPos += thisSize / 2.0f;
            maxPos -= thisSize / 2.0f;
            if (!mClampInner)
            {
                swap(ref minPos, ref maxPos);
            }
        }
        else if (mClampType == CLAMP_TYPE.CT_CENTER)
        {
        }
        return(new Vector3[2] {
            minPos, maxPos
        });
    }
Пример #3
0
    public Vector2 getWorldScale()
    {
        Vector3    scale       = getMatrixScale(mTransform.localToWorldMatrix);
        txUIObject root        = mLayout.isNGUI() ? mLayoutManager.getNGUIRoot() : mLayoutManager.getUGUIRoot();
        Vector3    uiRootScale = root.getTransform().localScale;

        return(new Vector2(scale.x / uiRootScale.x, scale.y / uiRootScale.y));
    }
Пример #4
0
 //set
 //-------------------------------------------------------------------------------------------------------------------------------------
 public void setParent(txUIObject parent)
 {
     if (mParent == parent)
     {
         return;
     }
     // 从原来的父节点上移除
     mParent?.removeChild(this);
     // 设置新的父节点
     mParent = parent;
     if (parent != null)
     {
         parent.addChild(this);
         if (mTransform.parent != parent.getTransform())
         {
             mTransform.SetParent(parent.getTransform());
         }
     }
 }
Пример #5
0
    public GameObject instantiateObject(txUIObject parent, string prefabPath, string name, string tag = null)
    {
        GameObject go = mObjectPool.createObject(prefabPath, tag);

        if (go != null)
        {
            go.name = name;
            go.SetActive(false);
            go.transform.SetParent(parent.getTransform());
        }
        return(go);
    }
    //------------------------------------------------------------------------------------------------------------------------------------------
    protected Vector3[] getLocalMinMaxPixelPos()
    {
        if (mMinMaxPosDirty)
        {
            bool    isNGUI           = mWindow.getLayout().isNGUI();
            Vector2 parentWidgetSize = Vector2.zero;
            if (isNGUI)
            {
#if USE_NGUI
                // 获得第一个带widget的父节点的rect
                if (mParentRect == null)
                {
                    mParentRect = WidgetUtility.findNGUIParentRect(mWindow.getObject());
                }
                parentWidgetSize = WidgetUtility.getNGUIRectSize(mParentRect);
#endif
            }
            else
            {
                parentWidgetSize = mWindow.getParent().getWindowSize();
            }
            // 计算父节点的世界缩放
            Vector2    worldScale  = getMatrixScale(mWindow.getTransform().parent.localToWorldMatrix);
            txUIObject root        = mLayoutManager.getUIRoot(isNGUI);
            Vector2    uiRootScale = root.getTransform().localScale;
            Vector2    parentScale = worldScale / uiRootScale;
            // 计算移动的位置范围
            Vector2 minPos = parentWidgetSize * 0.5f * mMinRelativePos / parentScale;
            Vector2 maxPos = parentWidgetSize * 0.5f * mMaxRelativePos / parentScale;
            if (mClampType == CLAMP_TYPE.CT_EDGE)
            {
                Vector2 thisSize = mWindow.getWindowSize(true);
                minPos += thisSize * 0.5f;
                maxPos -= thisSize * 0.5f;
                if (!mClampInner)
                {
                    swap(ref minPos, ref maxPos);
                }
            }
            else if (mClampType == CLAMP_TYPE.CT_CENTER)
            {
            }
            mMinMaxPos[0]   = minPos;
            mMinMaxPos[1]   = maxPos;
            mMinMaxPosDirty = false;
        }
        return(mMinMaxPos);
    }
Пример #7
0
 public override void update(float elapsedTime)
 {
     base.update(elapsedTime);
     if (mMouseDown && mDragingCallback != null)
     {
         mDragingCallback();
     }
     if (mMoveSpeed > 0.0f)
     {
         // 只有鼠标未按下时才衰减速度
         if (!mMouseDown)
         {
             mMoveSpeed = lerp(mMoveSpeed, 0.0f, elapsedTime * 5.0f, 0.01f);
         }
         Vector3 curPosition = getPosition();
         curPosition += mMoveNormal * mMoveSpeed * mMoveSpeedScale * elapsedTime;
         // 获得第一个带widget的父节点的rect
         UIRect  rect             = WidgetUtility.findParentRect(mObject);
         Vector2 parentWidgetSize = WidgetUtility.getRectSize(rect);
         // 计算父节点的世界缩放
         Vector3    worldScale  = getMatrixScale(mTransform.parent.localToWorldMatrix);
         txUIObject root        = mLayout.isNGUI() ? mLayoutManager.getNGUIRoot() : mLayoutManager.getUGUIRoot();
         Vector3    uiRootScale = root.getTransform().localScale;
         Vector2    parentScale = new Vector2(worldScale.x / uiRootScale.x, worldScale.y / uiRootScale.y);
         // 计算移动的位置范围
         Vector2 minPos   = new Vector2(parentWidgetSize.x / 2.0f * mMinPos.x, parentWidgetSize.y / 2.0f * mMinPos.y);
         Vector2 maxPos   = new Vector2(parentWidgetSize.x / 2.0f * mMaxPos.x, parentWidgetSize.y / 2.0f * mMaxPos.y);
         Vector2 thisSize = getWindowSize(true);
         float   minX     = (minPos.x - thisSize.x / 2.0f) / parentScale.x;
         float   maxX     = (maxPos.x + thisSize.x / 2.0f) / parentScale.x;
         float   minY     = (minPos.y - thisSize.y / 2.0f) / parentScale.y;
         float   maxY     = (maxPos.y + thisSize.y / 2.0f) / parentScale.y;
         if (mDragDirection == DRAG_DIRECTION.DD_HORIZONTAL || mDragDirection == DRAG_DIRECTION.DD_FREE)
         {
             // 有可以滑动范围时需要限定在一定范围
             if (minX <= maxX)
             {
                 clamp(ref curPosition.x, minX, maxX);
             }
             // 不能滑动时,固定位置
             else
             {
                 curPosition.x = getPosition().x;
             }
         }
         if (mDragDirection == DRAG_DIRECTION.DD_VERTICAL || mDragDirection == DRAG_DIRECTION.DD_FREE)
         {
             // 有可以滑动范围时需要限定在一定范围
             if (minY <= maxY)
             {
                 clamp(ref curPosition.y, minY, maxY);
             }
             // 不能滑动时,固定位置
             else
             {
                 curPosition.y = getPosition().y;
             }
         }
         setLocalPosition(curPosition);
     }
 }