示例#1
0
 public void setBackground(myUGUIObject background)
 {
     mBackground = background;
     mBackground.setOnMouseDown(onMouseDown);
     mBackground.setOnScreenMouseUp(onScreenMouseUp);
     mBackground.setOnMouseMove(onMouseMove);
     mBackground.setOnMouseStay(onMouseStay);
     mScript.registeCollider(mBackground, true);
 }
示例#2
0
    // 自动排列一个节点下的所有子节点的位置,从左往右紧密排列
    public static void autoGridHorizontal(myUGUIObject root, float interval = 0.0f, bool resizeRootSize = true, float minWidth = 0.0f)
    {
        RectTransform transform  = root.getRectTransform();
        int           childCount = transform.childCount;
        Vector2       rootSize   = root.getWindowSize();

        // 如果要同时修改root的窗口大小为排列以后的内容大小,则需要提前获取内容排列后的宽高
        if (resizeRootSize)
        {
            float width = 0.0f;
            for (int i = 0; i < childCount; ++i)
            {
                RectTransform childRect = transform.GetChild(i).GetComponent <RectTransform>();
                if (!childRect.gameObject.activeSelf)
                {
                    continue;
                }
                width += childRect.rect.width;
                // 最后一个子节点后不再添加间隔
                if (i != childCount - 1)
                {
                    width += interval;
                }
            }
            rootSize.x = clampMin(width, minWidth);
            root.setWindowSize(rootSize);
        }
        float currentLeft = rootSize.x * transform.pivot.x;

        for (int i = 0; i < childCount; ++i)
        {
            RectTransform childRect = transform.GetChild(i).GetComponent <RectTransform>();
            if (!childRect.gameObject.activeSelf)
            {
                continue;
            }
            float curWidth = childRect.rect.width;
            childRect.localPosition = new Vector3(currentLeft + curWidth * 0.5f, childRect.localPosition.y);
            currentLeft            += curWidth;
            // 最后一个子节点后不再添加间隔
            if (i != childCount - 1)
            {
                currentLeft += interval;
            }
        }
    }
示例#3
0
    // 自动排列一个节点下的所有子节点的位置,从上往下紧密排列
    public static void autoGridVertical(myUGUIObject root, float interval = 0.0f, bool resizeRootSize = true, float minHeight = 0.0f)
    {
        RectTransform transform  = root.getRectTransform();
        int           childCount = transform.childCount;
        Vector2       rootSize   = root.getWindowSize();

        // 如果要同时修改root的窗口大小为排列以后的内容大小,则需要提前获取内容排列后的宽高
        if (resizeRootSize)
        {
            float height = 0.0f;
            for (int i = 0; i < childCount; ++i)
            {
                RectTransform childRect = transform.GetChild(i).GetComponent <RectTransform>();
                if (!childRect.gameObject.activeSelf)
                {
                    continue;
                }
                height += childRect.rect.height;
                // 最后一个子节点后不再添加间隔
                if (i != childCount - 1)
                {
                    height += interval;
                }
            }
            rootSize.y = clampMin(height, minHeight);
            root.setWindowSize(rootSize);
        }
        float currentTop = rootSize.y * (1.0f - transform.pivot.y);

        for (int i = 0; i < childCount; ++i)
        {
            RectTransform childRect = transform.GetChild(i).GetComponent <RectTransform>();
            if (!childRect.gameObject.activeSelf)
            {
                continue;
            }
            float curHeight = childRect.rect.height;
            childRect.localPosition = new Vector3(childRect.localPosition.x, currentTop - curHeight * 0.5f);
            currentTop -= curHeight;
            // 最后一个子节点后不再添加间隔
            if (i != childCount - 1)
            {
                currentTop -= interval;
            }
        }
    }
示例#4
0
 public override void resetProperty()
 {
     base.resetProperty();
     // mScript不重置
     //mScript = null;
     mBackground          = null;
     mForeground          = null;
     mThumb               = null;
     mSliderStartCallback = null;
     mSliderEndCallback   = null;
     mSliderCallback      = null;
     mDirection           = DRAG_DIRECTION.HORIZONTAL;
     mMode = SLIDER_MODE.FILL;
     mOriginForegroundSize     = Vector2.zero;
     mOriginForegroundPosition = Vector3.zero;
     mSliderValue = 0.0f;
     mDraging     = false;
 }
示例#5
0
 public void init(myUGUIObject background, myUGUIObject foreground, myUGUIObject thumb = null, SLIDER_MODE mode = SLIDER_MODE.FILL)
 {
     mName       = "UGUISlider";
     mMode       = mode;
     mBackground = background;
     mForeground = foreground;
     mThumb      = thumb;
     if (mThumb != null && mThumb.getParent() != mForeground)
     {
         logError("Foreground must be parent of Thumb");
         return;
     }
     if (mMode == SLIDER_MODE.SIZING)
     {
         mOriginForegroundSize     = mForeground.getWindowSize();
         mOriginForegroundPosition = mForeground.getPosition();
         if (mBackground == null)
         {
             logError("Background can not be null while slider mode is SIZING");
             return;
         }
         if (mForeground.getParent() != mBackground)
         {
             logError("Background must be parent of Foreground");
             return;
         }
     }
     if (mBackground != null)
     {
         mBackground.setOnMouseDown(onMouseDown);
         mBackground.setOnScreenMouseUp(onScreenMouseUp);
         mBackground.setOnMouseMove(onMouseMove);
         if (mBackground.getCollider() != null)
         {
             mScript.registeCollider(mBackground);
         }
     }
 }
示例#6
0
    public void recalculateDragView <T>(List <T> itemList, Vector2 itemSize, float space, myUGUIObject dragViewParent, Vector2 viewportSize, int countPerLine = 0, float lineSpace = 0.0f, bool horiFirst = false) where T : IDragViewItem
    {
        // 计算拖拽窗口大小
        int            count         = itemList.Count;
        int            widthCount    = 0;
        int            heightCount   = 0;
        DRAG_DIRECTION dragDirection = mDragViewComponent.getDragDirection();

        if (dragDirection == DRAG_DIRECTION.HORIZONTAL || dragDirection == DRAG_DIRECTION.FREE)
        {
            widthCount = countPerLine;
            if (widthCount > 0)
            {
                heightCount = ceil((float)count / widthCount);
            }
            else
            {
                heightCount = 1;
                widthCount  = count;
            }
        }
        else if (dragDirection == DRAG_DIRECTION.VERTICAL || dragDirection == DRAG_DIRECTION.FREE)
        {
            heightCount = countPerLine;
            if (heightCount > 0)
            {
                widthCount = ceil((float)count / heightCount);
            }
            else
            {
                widthCount  = 1;
                heightCount = count;
            }
        }
        Vector2 windowSize = getWindowSize();

        if (dragDirection == DRAG_DIRECTION.HORIZONTAL || dragDirection == DRAG_DIRECTION.FREE)
        {
            windowSize.x = itemSize.x * widthCount + space * (widthCount - 1);
            windowSize.y = itemSize.y * heightCount + lineSpace * (heightCount - 1);
        }
        else if (dragDirection == DRAG_DIRECTION.VERTICAL || dragDirection == DRAG_DIRECTION.FREE)
        {
            windowSize.x = itemSize.x * widthCount + lineSpace * (widthCount - 1);
            windowSize.y = itemSize.y * heightCount + space * (heightCount - 1);
        }
        clampMin(ref windowSize.x);
        clampMin(ref windowSize.y);
        setWindowSize(windowSize);
        // 设置所有子节点的位置
        for (int i = 0; i < count; ++i)
        {
            Vector3 itemPos = itemList[i].getPosition();
            if (dragDirection == DRAG_DIRECTION.HORIZONTAL || dragDirection == DRAG_DIRECTION.FREE)
            {
                // 排成多排
                if (countPerLine > 0)
                {
                    int horiIndex = horiFirst ? i % widthCount : i / heightCount;
                    int vertIndex = horiFirst ? i / widthCount : i % heightCount;
                    itemPos.x = (itemSize.x + space) * horiIndex + itemSize.x * 0.5f - windowSize.x * 0.5f;
                    itemPos.y = (itemSize.y + lineSpace) * (heightCount - vertIndex - 1) + itemSize.y * 0.5f - windowSize.y * 0.5f;
                }
                // 只排一排
                else
                {
                    itemPos.x = (itemSize.x + space) * i + itemSize.x * 0.5f - windowSize.x * 0.5f;
                }
            }
            if (dragDirection == DRAG_DIRECTION.VERTICAL || dragDirection == DRAG_DIRECTION.FREE)
            {
                // 排成多列
                if (countPerLine > 0)
                {
                    int horiIndex = horiFirst ? i % widthCount : i / heightCount;
                    int vertIndex = horiFirst ? i / widthCount : i % heightCount;
                    itemPos.x = (itemSize.x + lineSpace) * (horiIndex - widthCount - 1) + itemSize.x * 0.5f - windowSize.x * 0.5f;
                    itemPos.y = (itemSize.y + space) * vertIndex + itemSize.y * 0.5f - windowSize.y * 0.5f;
                }
                // 排成一列
                else
                {
                    itemPos.y = (itemSize.y + space) * (count - i - 1) + itemSize.y * 0.5f - windowSize.y * 0.5f;
                }
            }
            itemList[i].setPosition(itemPos);
        }
        // 重新计算拖拽窗口父节点的大小和位置,用于限定拖拽窗口的拖拽范围
        Vector3 parentPos  = dragViewParent.getPosition();
        Vector2 parentSize = Vector2.zero;

        autoAdjustParent(ref parentPos, ref parentSize, viewportSize);
        dragViewParent.setWindowSize(parentSize);
        FT.MOVE(dragViewParent, parentPos);
        autoResetPosition();
    }
示例#7
0
 public void setFillRect(myUGUIObject obj)
 {
     mSlider.fillRect = obj.getRectTransform();
 }