Inheritance: IgnoreTimeScale
Beispiel #1
0
 private void NotifyListeners()
 {
     SpringPosition.current = this;
     if (this.onFinished != null)
     {
         this.onFinished();
     }
     if (this.eventReceiver != null && !string.IsNullOrEmpty(this.callWhenFinished))
     {
         this.eventReceiver.SendMessage(this.callWhenFinished, this, SendMessageOptions.DontRequireReceiver);
     }
     SpringPosition.current = null;
 }
Beispiel #2
0
	void InitObject()
	{
		if(icon == null)
			icon = transform.FindChild("Icon").GetComponent<UISprite>();
		if(backSprite == null)
			backSprite = transform.FindChild("Background").GetComponent<UISprite>();
		if(boxCollider == null)
			boxCollider = transform.GetComponent<BoxCollider>();

		if(springPosition == null)
			springPosition = transform.GetComponent<SpringPosition>();
		if (springPosition != null)
			springPosition.target = transform.localPosition;

		originPos = transform.localPosition;
	}
Beispiel #3
0
    /// <summary>
    /// Reset the position of all child objects based on the order of items in the list.
    /// </summary>

    protected virtual void ResetPosition(List <Transform> list)
    {
        mReposition = false;

        // Epic hack: Unparent all children so that we get to control the order in which they are re-added back in
        // EDIT: Turns out this does nothing.
        //for (int i = 0, imax = list.Count; i < imax; ++i)
        //	list[i].parent = null;

        int x    = 0;
        int y    = 0;
        int maxX = 0;
        int maxY = 0;

        //Transform myTrans = transform;

        // Re-add the children in the same order we have them in and position them accordingly
        for (int i = 0, imax = list.Count; i < imax; ++i)
        {
            Transform t = list[i];
            // See above
            //t.parent = myTrans;

            Vector3 pos   = t.localPosition;
            float   depth = pos.z;

            if (arrangement == Arrangement.CellSnap)
            {
                if (cellWidth > 0)
                {
                    pos.x = Mathf.Round(pos.x / cellWidth) * cellWidth;
                }
                if (cellHeight > 0)
                {
                    pos.y = Mathf.Round(pos.y / cellHeight) * cellHeight;
                }
            }
            else
            {
                pos = (arrangement == Arrangement.Horizontal) ?
                      new Vector3(cellWidth * x, -cellHeight * y, depth) :
                      new Vector3(cellWidth * y, -cellHeight * x, depth);
            }

            var smoothAnim = animateSmoothly && Application.isPlaying;

            // Special case: if the element is currently invisible and is fading in, we want to position it in the right place right away
            if (smoothAnim && animateFadeIn)
            {
                var tw = t.GetComponent <TweenAlpha>();
                if (tw != null && tw.enabled && tw.value == 0f && tw.to == 1f)
                {
                    smoothAnim = false;
                }
            }

            if (smoothAnim && (pivot != UIWidget.Pivot.TopLeft || Vector3.SqrMagnitude(t.localPosition - pos) >= 0.0001f))
            {
                var sp = SpringPosition.Begin(t.gameObject, pos, 15f);
                sp.updateScrollView = true;
                sp.ignoreTimeScale  = true;
            }
            else
            {
                t.localPosition = pos;
            }

            maxX = Mathf.Max(maxX, x);
            maxY = Mathf.Max(maxY, y);

            if (++x >= maxPerLine && maxPerLine > 0)
            {
                x = 0;
                ++y;
            }
        }

        // Apply the origin offset
        if (pivot != UIWidget.Pivot.TopLeft)
        {
            var po = NGUIMath.GetPivotOffset(pivot);

            float fx, fy;

            if (arrangement == Arrangement.Horizontal)
            {
                fx = Mathf.Lerp(0f, maxX * cellWidth, po.x);
                fy = Mathf.Lerp(-maxY * cellHeight, 0f, po.y);
            }
            else
            {
                fx = Mathf.Lerp(0f, maxY * cellWidth, po.x);
                fy = Mathf.Lerp(-maxX * cellHeight, 0f, po.y);
            }

            foreach (var t in list)
            {
                var sp = t.GetComponent <SpringPosition>();

                if (sp != null)
                {
                    sp.enabled   = false;
                    sp.target.x -= fx;
                    sp.target.y -= fy;
                    sp.enabled   = true;
                }
                else
                {
                    Vector3 pos = t.localPosition;
                    pos.x          -= fx;
                    pos.y          -= fy;
                    t.localPosition = pos;
                }
            }
        }
    }
Beispiel #4
0
    /// <summary>
    /// Positions the grid items, taking their own size into consideration.
    /// </summary>

    protected void RepositionVariableSize(List <Transform> children)
    {
        float xOffset = 0;
        float yOffset = 0;

        int cols = columns > 0 ? children.Count / columns + 1 : 1;
        int rows = columns > 0 ? columns : children.Count;

        Bounds[,] bounds = new Bounds[cols, rows];
        Bounds[] boundsRows = new Bounds[rows];
        Bounds[] boundsCols = new Bounds[cols];

        int x = 0;
        int y = 0;

        for (int i = 0, imax = children.Count; i < imax; ++i)
        {
            Transform t = children[i];
            Bounds    b = NGUIMath.CalculateRelativeWidgetBounds(t, !hideInactive);

            Vector3 scale = t.localScale;
            b.min        = Vector3.Scale(b.min, scale);
            b.max        = Vector3.Scale(b.max, scale);
            bounds[y, x] = b;

            boundsRows[x].Encapsulate(b);
            boundsCols[y].Encapsulate(b);

            if (++x >= columns && columns > 0)
            {
                x = 0;
                ++y;
            }
        }

        x = 0;
        y = 0;

        for (int i = 0, imax = children.Count; i < imax; ++i)
        {
            Transform t  = children[i];
            Bounds    b  = bounds[y, x];
            Bounds    br = boundsRows[x];
            Bounds    bc = boundsCols[y];

            Vector3 pos = t.localPosition;
            pos.x  = xOffset + b.extents.x - b.center.x;
            pos.x += b.min.x - br.min.x + padding.x;

            if (direction == Direction.Down)
            {
                pos.y  = -yOffset - b.extents.y - b.center.y;
                pos.y += (b.max.y - b.min.y - bc.max.y + bc.min.y) * 0.5f - padding.y;
            }
            else
            {
                pos.y  = yOffset + (b.extents.y - b.center.y);
                pos.y -= (b.max.y - b.min.y - bc.max.y + bc.min.y) * 0.5f - padding.y;
            }

            xOffset += br.max.x - br.min.x + padding.x * 2f;

            t.localPosition = pos;

            if (++x >= columns && columns > 0)
            {
                x = 0;
                ++y;

                xOffset  = 0f;
                yOffset += bc.size.y + padding.y * 2f;
            }
        }

        // Apply the origin offset
        if (pivot != UIWidget.Pivot.TopLeft)
        {
            Vector2 po = NGUIMath.GetPivotOffset(pivot);

            float fx, fy;

            Bounds b = NGUIMath.CalculateRelativeWidgetBounds(transform);

            fx = Mathf.Lerp(0f, b.size.x, po.x);
            fy = Mathf.Lerp(-b.size.y, 0f, po.y);

            Transform myTrans = transform;

            for (int i = 0; i < myTrans.childCount; ++i)
            {
                Transform      t  = myTrans.GetChild(i);
                SpringPosition sp = t.GetComponent <SpringPosition>();

                if (sp != null)
                {
                    sp.target.x -= fx;
                    sp.target.y -= fy;
                }
                else
                {
                    Vector3 pos = t.localPosition;
                    pos.x          -= fx;
                    pos.y          -= fy;
                    t.localPosition = pos;
                }
            }
        }
    }
Beispiel #5
0
    // Token: 0x0600021F RID: 543 RVA: 0x00017F74 File Offset: 0x00016174
    protected virtual void ResetPosition(List <Transform> list)
    {
        this.mReposition = false;
        int num   = 0;
        int num2  = 0;
        int num3  = 0;
        int num4  = 0;
        int i     = 0;
        int count = list.Count;

        while (i < count)
        {
            Transform transform = list[i];
            Vector3   vector    = transform.localPosition;
            float     z         = vector.z;
            if (this.arrangement == UIGrid.Arrangement.CellSnap)
            {
                if (this.cellWidth > 0f)
                {
                    vector.x = Mathf.Round(vector.x / this.cellWidth) * this.cellWidth;
                }
                if (this.cellHeight > 0f)
                {
                    vector.y = Mathf.Round(vector.y / this.cellHeight) * this.cellHeight;
                }
            }
            else
            {
                vector = ((this.arrangement == UIGrid.Arrangement.Horizontal) ? new Vector3(this.cellWidth * (float)num, -this.cellHeight * (float)num2, z) : new Vector3(this.cellWidth * (float)num2, -this.cellHeight * (float)num, z));
            }
            if (this.animateSmoothly && Application.isPlaying && (this.pivot != UIWidget.Pivot.TopLeft || Vector3.SqrMagnitude(transform.localPosition - vector) >= 0.0001f))
            {
                SpringPosition springPosition = SpringPosition.Begin(transform.gameObject, vector, 15f);
                springPosition.updateScrollView = true;
                springPosition.ignoreTimeScale  = true;
            }
            else
            {
                transform.localPosition = vector;
            }
            num3 = Mathf.Max(num3, num);
            num4 = Mathf.Max(num4, num2);
            if (++num >= this.maxPerLine && this.maxPerLine > 0)
            {
                num = 0;
                num2++;
            }
            i++;
        }
        if (this.pivot != UIWidget.Pivot.TopLeft)
        {
            Vector2 pivotOffset = NGUIMath.GetPivotOffset(this.pivot);
            float   num5;
            float   num6;
            if (this.arrangement == UIGrid.Arrangement.Horizontal)
            {
                num5 = Mathf.Lerp(0f, (float)num3 * this.cellWidth, pivotOffset.x);
                num6 = Mathf.Lerp((float)(-(float)num4) * this.cellHeight, 0f, pivotOffset.y);
            }
            else
            {
                num5 = Mathf.Lerp(0f, (float)num4 * this.cellWidth, pivotOffset.x);
                num6 = Mathf.Lerp((float)(-(float)num3) * this.cellHeight, 0f, pivotOffset.y);
            }
            foreach (Transform transform2 in list)
            {
                SpringPosition component = transform2.GetComponent <SpringPosition>();
                if (component != null)
                {
                    component.enabled = false;
                    SpringPosition springPosition2 = component;
                    springPosition2.target.x = springPosition2.target.x - num5;
                    SpringPosition springPosition3 = component;
                    springPosition3.target.y = springPosition3.target.y - num6;
                    component.enabled        = true;
                }
                else
                {
                    Vector3 localPosition = transform2.localPosition;
                    localPosition.x         -= num5;
                    localPosition.y         -= num6;
                    transform2.localPosition = localPosition;
                }
            }
        }
    }
Beispiel #6
0
    public void Reposition()
    {
        if (Application.isPlaying && !mStarted)
        {
            mReposition = true;
            return;
        }
        else if (_cachedTr == null)
        {
            _cachedTr = transform;
        }

        mReposition = false;

        int x = 0;
        int y = 0;

        if (sorted)
        {
            List <Transform> list = new List <Transform>();

            for (int i = 0; i < _cachedTr.childCount; ++i)
            {
                Transform t = _cachedTr.GetChild(i);
                if (t && (!hideInactive || NGUITools.GetActive(t.gameObject)))
                {
                    list.Add(t);
                }
            }
            if (isChat)
            {
                list.Sort(ReverseSortByName);
            }
            else
            {
                list.Sort(SortByName);
            }

            for (int i = 0, imax = list.Count; i < imax; ++i)
            {
                Transform t = list[i];

                if (!NGUITools.GetActive(t.gameObject) && hideInactive)
                {
                    continue;
                }

                float   depth = t.localPosition.z;
                Vector3 pos   = (arrangement == Arrangement.Horizontal) ?
                                new Vector3(cellWidth * x, -cellHeight * y, depth) :
                                new Vector3(cellWidth * y, -cellHeight * x, depth);

                if (animateSmoothly && Application.isPlaying)
                {
                    SpringPosition.Begin(t.gameObject, pos, 15f);
                }
                else
                {
                    t.localPosition = pos;
                }

                if (++x >= maxPerLine && maxPerLine > 0)
                {
                    x = 0;
                    ++y;
                }
            }
        }
        else
        {
            for (int i = 0; i < _cachedTr.childCount; i++)
            {
                Transform t = _cachedTr.GetChild(i);

                if (!NGUITools.GetActive(t.gameObject) && hideInactive)
                {
                    continue;
                }
                float   depth = t.localPosition.z;
                Vector3 pos   = (arrangement == Arrangement.Horizontal) ?
                                new Vector3(cellWidth * x, -cellHeight * y, depth) :
                                new Vector3(cellWidth * y, -cellHeight * x, depth);

                if (animateSmoothly && Application.isPlaying)
                {
                    SpringPosition.Begin(t.gameObject, pos, 15f);
                }
                else
                {
                    t.localPosition = pos;
                }

                if (++x >= maxPerLine && maxPerLine > 0)
                {
                    x = 0;
                    y++;
                }
            }
        }

        UIScrollView drag = NGUITools.FindInParents <UIScrollView>(gameObject);

        if (drag != null)
        {
            drag.UpdateScrollbars(true);
        }
    }
Beispiel #7
0
    public virtual void Reposition()
    {
        if (UnityEngine.Application.isPlaying && !mInitDone && NGUITools.GetActive(this))
        {
            mReposition = true;
            return;
        }

        if (!mInitDone)
        {
            Init();
        }

        mReposition = false;
        UnityEngine.Transform myTrans = transform;
        bool noonesort = true;
        int  x         = 0;
        int  y         = 0;

        if (DFReposition)
        {
            DFReposition = false;
            noonesort    = false;
            List <UnityEngine.Transform> list = new List <UnityEngine.Transform>();

            for (int i = 0; i < myTrans.childCount; ++i)
            {
                UnityEngine.Transform t = myTrans.GetChild(i);
                if (t && (!hideInactive || NGUITools.GetActive(t.gameObject)))
                {
                    list.Add(t);
                }
            }
            DFMSort(list);

            for (int i = 0, imax = list.Count; i < imax; ++i)
            {
                UnityEngine.Transform t = list[i];
                t.name = "Item" + i;

                if (!NGUITools.GetActive(t.gameObject) && hideInactive)
                {
                    continue;
                }

                float depth             = t.localPosition.z;
                UnityEngine.Vector3 pos = (arrangement == Arrangement.Horizontal) ?
                                          new UnityEngine.Vector3(cellWidth * x, -cellHeight * y, depth) :
                                          new UnityEngine.Vector3(cellWidth * y, -cellHeight * x, depth);

                if (animateSmoothly && UnityEngine.Application.isPlaying)
                {
                    SpringPosition.Begin(t.gameObject, pos, 15f).updateScrollView = true;
                }
                else
                {
                    t.localPosition = pos;
                }

                if (++x >= maxPerLine && maxPerLine > 0)
                {
                    x = 0;
                    ++y;
                }
            }
        }
        if (sorted && noonesort)
        {
            List <UnityEngine.Transform> list = new List <UnityEngine.Transform>();

            for (int i = 0; i < myTrans.childCount; ++i)
            {
                UnityEngine.Transform t = myTrans.GetChild(i);
                if (t && (!hideInactive || NGUITools.GetActive(t.gameObject)))
                {
                    list.Add(t);
                }
            }
            Sort(list);

            for (int i = 0, imax = list.Count; i < imax; ++i)
            {
                UnityEngine.Transform t = list[i];

                if (!NGUITools.GetActive(t.gameObject) && hideInactive)
                {
                    continue;
                }

                float depth             = t.localPosition.z;
                UnityEngine.Vector3 pos = (arrangement == Arrangement.Horizontal) ?
                                          new UnityEngine.Vector3(cellWidth * x, -cellHeight * y, depth) :
                                          new UnityEngine.Vector3(cellWidth * y, -cellHeight * x, depth);

                if (animateSmoothly && UnityEngine.Application.isPlaying)
                {
                    SpringPosition.Begin(t.gameObject, pos, 15f).updateScrollView = true;
                }
                else
                {
                    t.localPosition = pos;
                }

                if (++x >= maxPerLine && maxPerLine > 0)
                {
                    x = 0;
                    ++y;
                }
            }
        }

        if (keepWithinPanel && mPanel != null)
        {
            mPanel.ConstrainTargetToBounds(myTrans, true);
        }

        if (onReposition != null)
        {
            onReposition();
        }
    }
Beispiel #8
0
    public virtual void Reposition()
    {
        if (Application.isPlaying && !mInitDone && NGUITools.GetActive(this))
        {
            mReposition = true;
            return;
        }

        if (!mInitDone)
        {
            Init();
        }

        mReposition = false;
        Transform myTrans = transform;

        int x    = 0;
        int y    = 0;
        int maxX = 0;
        int maxY = 0;

        if (sorting != Sorting.None || sorted)
        {
            BetterList <Transform> list = new BetterList <Transform>();

            for (int i = 0; i < myTrans.childCount; ++i)
            {
                Transform t = myTrans.GetChild(i);
                if (t && (!hideInactive || NGUITools.GetActive(t.gameObject)))
                {
                    list.Add(t);
                }
            }

            if (sorting == Sorting.Alphabetic)
            {
                list.Sort(SortByName);
            }
            else if (sorting == Sorting.Horizontal)
            {
                list.Sort(SortHorizontal);
            }
            else if (sorting == Sorting.Vertical)
            {
                list.Sort(SortVertical);
            }
            else
            {
                Sort(list);
            }

            for (int i = 0, imax = list.size; i < imax; ++i)
            {
                Transform t = list[i];

                if (!NGUITools.GetActive(t.gameObject) && hideInactive)
                {
                    continue;
                }

                float   depth = t.localPosition.z;
                Vector3 pos   = (arrangement == Arrangement.Horizontal) ?
                                new Vector3(cellWidth * x, -cellHeight * y, depth) :
                                new Vector3(cellWidth * y, -cellHeight * x, depth);

                if (animateSmoothly && Application.isPlaying)
                {
                    SpringPosition.Begin(t.gameObject, pos, 15f).updateScrollView = true;
                }
                else
                {
                    t.localPosition = pos;
                }

                maxX = Mathf.Max(maxX, x);
                maxY = Mathf.Max(maxY, y);

                if (++x >= maxPerLine && maxPerLine > 0)
                {
                    x = 0;
                    ++y;
                }
            }
        }
        else
        {
            for (int i = 0; i < myTrans.childCount; ++i)
            {
                Transform t = myTrans.GetChild(i);

                if (!NGUITools.GetActive(t.gameObject) && hideInactive)
                {
                    continue;
                }

                float   depth = t.localPosition.z;
                Vector3 pos   = (arrangement == Arrangement.Horizontal) ?
                                new Vector3(cellWidth * x, -cellHeight * y, depth) :
                                new Vector3(cellWidth * y, -cellHeight * x, depth);

                if (animateSmoothly && Application.isPlaying)
                {
                    SpringPosition.Begin(t.gameObject, pos, 15f).updateScrollView = true;
                }
                else
                {
                    t.localPosition = pos;
                }

                maxX = Mathf.Max(maxX, x);
                maxY = Mathf.Max(maxY, y);

                if (++x >= maxPerLine && maxPerLine > 0)
                {
                    x = 0;
                    ++y;
                }
            }
        }

        // Apply the origin offset
        if (pivot != UIWidget.Pivot.TopLeft)
        {
            Vector2 po = NGUIMath.GetPivotOffset(pivot);

            float fx, fy;

            if (arrangement == Arrangement.Horizontal)
            {
                fx = Mathf.Lerp(0f, maxX * cellWidth, po.x);
                fy = Mathf.Lerp(-maxY * cellHeight, 0f, po.y);
            }
            else
            {
                fx = Mathf.Lerp(0f, maxY * cellWidth, po.x);
                fy = Mathf.Lerp(-maxX * cellHeight, 0f, po.y);
            }

            for (int i = 0; i < myTrans.childCount; ++i)
            {
                Transform t = myTrans.GetChild(i);

                if (!NGUITools.GetActive(t.gameObject) && hideInactive)
                {
                    continue;
                }

                SpringPosition sp = t.GetComponent <SpringPosition>();

                if (sp != null)
                {
                    sp.target.x -= fx;
                    sp.target.y -= fy;
                }
                else
                {
                    Vector3 pos = t.localPosition;
                    pos.x          -= fx;
                    pos.y          -= fy;
                    t.localPosition = pos;
                }
            }
        }

        if (keepWithinPanel && mPanel != null)
        {
            mPanel.ConstrainTargetToBounds(myTrans, true);
        }

        if (onReposition != null)
        {
            onReposition();
        }

        ChildrenMoveIn();
    }
Beispiel #9
0
    /*
     * public object UserData//用户数据,一般用于辨别拖拽物的身份
     * {
     *  get { return m_UserData; }
     *  set {
     *      if(m_UserData!=null)
     *      {
     *          IDisposable disposableObj = m_UserData as IDisposable;
     *          if (disposableObj != null) disposableObj.Dispose();
     *      }
     *      m_UserData = value;
     *  }
     * }
     */

    //void OnDestroy()
    //{
    //UserData = null;
    //}
    /// <summary>
    /// 开始拖拽
    /// </summary>
    protected override void OnDragDropStart()
    {
        //记录起始位置
        if (UIFlyRoot.Single != null)
        {
            m_StartPos = gameObject.transform.position;
        }

        //通知容器 开始拖
        NotifyDragDropStart(OwnerSurface, this);

        //通知拖拽开始
        base.OnDragDropStart();


        //提升widget深度
        NGuiHelper.DepthUpward(gameObject, 50);

        //记录鼠标位置和拖拽物之间的偏移量
        m_DragDropItemPlane = new Plane(new Vector3(0, 0, 1), mTrans.position.z);

        if (EnableDragDropOffset)
        {
            Ray   ray = UICamera.currentRay;
            float enter;
            if (m_DragDropItemPlane.Raycast(ray, out enter))
            {
                m_DragDropOffset = ray.GetPoint(enter) - mTrans.position;
            }
        }
        else
        {
            m_DragDropOffset = Vector3.zero;
        }


        ////////////////////////////////////////////////////////////////////////////////////
        if (!draggedItems.Contains(this))
        {
            draggedItems.Add(this);
        }

        // Automatically disable the scroll view
        if (mDragScrollView != null)
        {
            mDragScrollView.enabled = false;
        }

        // Disable the collider so that it doesn't intercept events
        if (mButton != null)
        {
            mButton.isEnabled = false;
        }
        else if (mCollider != null)
        {
            mCollider.enabled = false;
        }
        else if (mCollider2D != null)
        {
            mCollider2D.enabled = false;
        }

        mParent = mTrans.parent;
        mRoot   = NGUITools.FindInParents <UIRoot>(mParent);
        mGrid   = NGUITools.FindInParents <UIGrid>(mParent);
        mTable  = NGUITools.FindInParents <UITable>(mParent);

        // Re-parent the item
        if (UIDragDropRoot.root != null)
        {
            mTrans.parent = UIDragDropRoot.root;
        }

        Vector3 pos = mTrans.localPosition;

        pos.z = 0f;
        mTrans.localPosition = pos;

        TweenPosition tp = GetComponent <TweenPosition>();

        if (tp != null)
        {
            tp.enabled = false;
        }

        SpringPosition sp = GetComponent <SpringPosition>();

        if (sp != null)
        {
            sp.enabled = false;
        }

        // Notify the widgets that the parent has changed
        NGUITools.MarkParentAsChanged(gameObject);

        if (mTable != null)
        {
            mTable.repositionNow = true;
        }
        if (mGrid != null)
        {
            mGrid.repositionNow = true;
        }
    }
Beispiel #10
0
    private IEnumerator MoveOn(GameObject goItem)
    {
        // 等待消失动画完成
        yield return(new WaitForSeconds(_aniTime));

        goItem.SendMessage("OnWrapDisappearEnd", SendMessageOptions.DontRequireReceiver);

        Vector3 disappearPos = goItem.transform.localPosition;
        // 移到最后或者最前
        Vector3 rightPos = GetRightestPos() + new Vector3(itemSize, 0f, 0f);

        // 可以移动到最右
        // 不需要取绝对值,横向滚动条物件的x值肯定大于等于0
        // 纵向的才要
        if (Mathf.RoundToInt(rightPos.x / itemSize) < totalSize)
        {
            goItem.transform.localPosition = rightPos;
            onUpdateItem(goItem.transform, Mathf.Abs(Mathf.RoundToInt(goItem.transform.localPosition.x / itemSize)));
        }
        else
        {
            Vector3 leftPos = GetLeftestPos() - new Vector3(itemSize, 0f, 0f);

            // 可以移动最左
            // 这里不能取绝对值。。 否则结果肯定大于等于0了
            if (Mathf.RoundToInt(leftPos.x / itemSize) >= 0)
            {
                goItem.transform.localPosition = leftPos;
                onUpdateItem(goItem.transform, Mathf.Abs(Mathf.RoundToInt(goItem.transform.localPosition.x / itemSize)));
            }
            else
            {
                // 两边都不满足,则移动到最右,并且隐藏
                goItem.transform.localPosition = rightPos;
                NGUITools.SetActive(goItem, false);
            }
        }

        // 如果总大小小于预留控件大小,则需要隐藏刚消失的控件
//         if (totalSize < mChildren.size)
//         {
//             NGUITools.SetActive(goItem, false);
//         }
//         else
//         {
//             onUpdateItem(goItem.transform, Mathf.Abs(Mathf.RoundToInt(goItem.transform.localPosition.x / itemSize)));
//         }

        bool hasSpring = false;

        // 超过消失点的控件,spring到合适位置
        // to do 如果是不可见的控件,不能用spring,直接设置到目标位置
        for (int i = 0; i < mChildren.size; ++i)
        {
            Transform t = mChildren[i];

            if (t.localPosition.x > disappearPos.x)
            {
                if (NGUITools.GetActive(t.gameObject))
                {
                    hasSpring = true;
                    if (Mathf.RoundToInt(t.localPosition.x - disappearPos.x) == itemSize)
                    {
                        t.gameObject.SendMessage("OnWrapSpringBegin", SendMessageOptions.DontRequireReceiver);
                        SpringPosition.Begin(t.gameObject, t.localPosition - new Vector3(itemSize, 0f, 0f), _aniSpringStrenth).onFinished = _onAniFinish;
                    }
                    else
                    {
                        SpringPosition.Begin(t.gameObject, t.localPosition - new Vector3(itemSize, 0f, 0f), _aniSpringStrenth);
                    }
                }
                else
                {
                    t.localPosition = t.localPosition - new Vector3(itemSize, 0f, 0f);
                }
            }
        }

        if (!hasSpring)
        {
            if (_onAniFinish != null)
            {
                _onAniFinish();
                _onAniFinish = null;
            }
        }
    }
Beispiel #11
0
    protected void ResetPositionMiddle()
    {
        if (pivot != UIWidget.Pivot.Center)
        {
            return;
        }
        List <Transform> list = new List <Transform>();

        for (int i = 0; i < transform.childCount; ++i)
        {
            Transform t = transform.GetChild(i);
            list.Add(t);
        }
        int       x       = 0;
        int       y       = 0;
        int       maxX    = 0;
        int       maxY    = 0;
        Transform myTrans = transform;

        // Re-add the children in the same order we have them in and position them accordingly
        for (int i = 0, imax = list.Count; i < imax; ++i)
        {
            Transform t = list[i];
            // See above
            //t.parent = myTrans;

            Vector3 pos   = t.localPosition;
            float   depth = pos.z;

            pos = (arrangement == Arrangement.Horizontal) ? new Vector3(cellWidth * x, -cellHeight * y, depth) :new Vector3(cellWidth * y, -cellHeight * x, depth);

            //if (animateSmoothly && Application.isPlaying && Vector3.SqrMagnitude(t.localPosition - pos) >= 0.0001f)
            //{
            //    SpringPosition sp = SpringPosition.Begin(t.gameObject, pos, 15f);
            //    sp.updateScrollView = true;
            //    sp.ignoreTimeScale = true;
            //}
            //else
            t.localPosition = pos;

            maxX = Mathf.Max(maxX, x);
            maxY = Mathf.Max(maxY, y);

            if (++x >= maxPerLine && maxPerLine > 0)
            {
                x = 0;
                ++y;
            }
        }

        // Apply the origin offset
        if (pivot != UIWidget.Pivot.TopLeft)
        {
            Vector2 po = NGUIMath.GetPivotOffset(pivot);

            float fx, fy;

            if (arrangement == Arrangement.Horizontal)
            {
                fx = Mathf.Lerp(0f, maxX * cellWidth, po.x);
                fy = Mathf.Lerp(-maxY * cellHeight, 0f, po.y);
            }
            else
            {
                fx = Mathf.Lerp(0f, maxY * cellWidth, po.x);
                fy = Mathf.Lerp(-maxX * cellHeight, 0f, po.y);
            }

            for (int i = 0; i < myTrans.childCount; ++i)
            {
                Transform      t  = myTrans.GetChild(i);
                SpringPosition sp = t.GetComponent <SpringPosition>();

                if (sp != null)
                {
                    sp.target.x -= fx;
                    sp.target.y -= fy;
                }
                else
                {
                    Vector3 pos = t.localPosition;
                    pos.x          -= fx;
                    pos.y          -= fy;
                    t.localPosition = pos;
                }
            }
        }
    }
Beispiel #12
0
    protected void RepositionVariableSize(List <Transform> children)
    {
        float num  = 0f;
        float num2 = 0f;
        int   num3 = (this.columns <= 0) ? 1 : (children.get_Count() / this.columns + 1);
        int   num4 = (this.columns <= 0) ? children.get_Count() : this.columns;

        Bounds[,] array = new Bounds[num3, num4];
        Bounds[] array2 = new Bounds[num4];
        Bounds[] array3 = new Bounds[num3];
        int      num5   = 0;
        int      num6   = 0;
        int      i      = 0;
        int      count  = children.get_Count();

        while (i < count)
        {
            Transform transform  = children.get_Item(i);
            Bounds    bounds     = NGUIMath.CalculateRelativeWidgetBounds(transform, !this.hideInactive);
            Vector3   localScale = transform.get_localScale();
            bounds.set_min(Vector3.Scale(bounds.get_min(), localScale));
            bounds.set_max(Vector3.Scale(bounds.get_max(), localScale));
            array[num6, num5] = bounds;
            array2[num5].Encapsulate(bounds);
            array3[num6].Encapsulate(bounds);
            if (++num5 >= this.columns && this.columns > 0)
            {
                num5 = 0;
                num6++;
            }
            i++;
        }
        num5 = 0;
        num6 = 0;
        Vector2 pivotOffset = NGUIMath.GetPivotOffset(this.cellAlignment);
        int     j           = 0;
        int     count2      = children.get_Count();

        while (j < count2)
        {
            Transform transform2    = children.get_Item(j);
            Bounds    bounds2       = array[num6, num5];
            Bounds    bounds3       = array2[num5];
            Bounds    bounds4       = array3[num6];
            Vector3   localPosition = transform2.get_localPosition();
            localPosition.x  = num + bounds2.get_extents().x - bounds2.get_center().x;
            localPosition.x -= Mathf.Lerp(0f, bounds2.get_max().x - bounds2.get_min().x - bounds3.get_max().x + bounds3.get_min().x, pivotOffset.x) - this.padding.x;
            if (this.direction == UITable.Direction.Down)
            {
                localPosition.y  = -num2 - bounds2.get_extents().y - bounds2.get_center().y;
                localPosition.y += Mathf.Lerp(bounds2.get_max().y - bounds2.get_min().y - bounds4.get_max().y + bounds4.get_min().y, 0f, pivotOffset.y) - this.padding.y;
            }
            else
            {
                localPosition.y  = num2 + bounds2.get_extents().y - bounds2.get_center().y;
                localPosition.y -= Mathf.Lerp(0f, bounds2.get_max().y - bounds2.get_min().y - bounds4.get_max().y + bounds4.get_min().y, pivotOffset.y) - this.padding.y;
            }
            num += bounds3.get_size().x + this.padding.x * 2f;
            transform2.set_localPosition(localPosition);
            if (++num5 >= this.columns && this.columns > 0)
            {
                num5 = 0;
                num6++;
                num   = 0f;
                num2 += bounds4.get_size().y + this.padding.y * 2f;
            }
            j++;
        }
        if (this.pivot != UIWidget.Pivot.TopLeft)
        {
            pivotOffset = NGUIMath.GetPivotOffset(this.pivot);
            Bounds    bounds5    = NGUIMath.CalculateRelativeWidgetBounds(base.get_transform());
            float     num7       = Mathf.Lerp(0f, bounds5.get_size().x, pivotOffset.x);
            float     num8       = Mathf.Lerp(-bounds5.get_size().y, 0f, pivotOffset.y);
            Transform transform3 = base.get_transform();
            for (int k = 0; k < transform3.get_childCount(); k++)
            {
                Transform      child     = transform3.GetChild(k);
                SpringPosition component = child.GetComponent <SpringPosition>();
                if (component != null)
                {
                    SpringPosition expr_49C_cp_0 = component;
                    expr_49C_cp_0.target.x = expr_49C_cp_0.target.x - num7;
                    SpringPosition expr_4B1_cp_0 = component;
                    expr_4B1_cp_0.target.y = expr_4B1_cp_0.target.y - num8;
                }
                else
                {
                    Vector3 localPosition2 = child.get_localPosition();
                    localPosition2.x -= num7;
                    localPosition2.y -= num8;
                    child.set_localPosition(localPosition2);
                }
            }
        }
    }
Beispiel #13
0
    /// <summary>
    /// Apply the dragging momentum.
    /// </summary>

    void LateUpdate()
    {
        float delta = UpdateRealTimeDelta();

        if (target == null)
        {
            return;
        }

        if (mPressed)
        {
            // Disable the spring movement
            SpringPosition sp = target.GetComponent <SpringPosition>();
            if (sp != null)
            {
                sp.enabled = false;
            }
            mScroll = 0f;
        }
        else
        {
            mMomentum += scale * (-mScroll * 0.05f);
            mScroll    = NGUIMath.SpringLerp(mScroll, 0f, 20f, delta);

            if (mMomentum.magnitude > 0.0001f)
            {
                // Apply the momentum
                if (mPanel == null)
                {
                    FindPanel();
                }

                if (mPanel != null)
                {
                    Vector3 oLocalPos = target.localPosition;
                    target.position += NGUIMath.SpringDampen(ref mMomentum, 9f, delta);
                    Vector3 nLocalPos = target.localPosition;
                    if (scale.x == 0)
                    {
                        target.localPosition = new Vector3(oLocalPos.x, nLocalPos.y, nLocalPos.z);
                    }
                    else if (scale.y == 0)
                    {
                        target.localPosition = new Vector3(nLocalPos.x, oLocalPos.y, nLocalPos.z);
                    }

                    if (restrictWithinPanel && mPanel.clipping != UIDrawCall.Clipping.None)
                    {
                        mBounds = IgnoreTexture ? NGUIMath.GetBoundsIngnoreTexture(mPanel.cachedTransform, target) : NGUIMath.CalculateRelativeWidgetBounds(mPanel.cachedTransform, target);

                        if (backTop && (mBounds.size.y < mPanel.clipRange.w) && (mBounds.max.y < mPanel.clipRange.y + mPanel.clipRange.w * 0.5f))
                        {
                            if (!mPanel.ConstrainTargetToBounds1Top(target, ref mBounds, false))
                            {
                                SpringPosition sp = target.GetComponent <SpringPosition>();
                                if (sp != null)
                                {
                                    sp.enabled = false;
                                }
                            }
                        }
                        else
                        {
                            if (!mPanel.ConstrainTargetToBounds(target, ref mBounds, dragEffect == DragEffect.None))
                            {
                                SpringPosition sp = target.GetComponent <SpringPosition>();
                                if (sp != null)
                                {
                                    sp.enabled = false;
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                mScroll = 0f;
            }
        }
    }
Beispiel #14
0
    override protected void ResetPosition(List <Transform> list)
    {
        //base.ResetPosition(list);
        //return;

        mReposition = false;

        int       x       = 0;
        int       y       = 0;
        int       maxX    = 0;
        int       maxY    = 0;
        Transform myTrans = transform;

        // Re-add the children in the same order we have them in and position them accordingly
        Vector3 prevPos = Vector3.zero;

        for (int i = 0, imax = list.Count; i < imax; ++i)
        {
            UIWidget rect     = list[i].GetComponent <UIWidget>();
            UIWidget prevRect = i > 0 ? list[i - 1].GetComponent <UIWidget>() : null;

            cellWidth  = rect.width * .5f + (prevRect != null ? prevRect.width * .5f : 0);
            cellHeight = rect.height * .5f + (prevRect != null ? prevRect.height * .5f : 0);

            Transform t     = list[i];
            float     depth = t.localPosition.z;
            Vector3   pos   = (arrangement == Arrangement.Horizontal) ?
                              new Vector3(cellWidth + prevPos.x, y, depth) :
                              new Vector3(x, -cellHeight + prevPos.y, depth);

            if (animateSmoothly && Application.isPlaying)
            {
                SpringPosition.Begin(t.gameObject, pos, 15f).updateScrollView = true;
            }
            else
            {
                t.localPosition = pos;
            }

            prevPos = pos;

            maxX = Mathf.Max(maxX, x);
            maxY = Mathf.Max(maxY, y);

            if (++x >= maxPerLine && maxPerLine > 0)
            {
                x = 0;
                ++y;
            }
        }

        // Apply the origin offset
        if (pivot != UIWidget.Pivot.TopLeft)
        {
            Vector2 po = NGUIMath.GetPivotOffset(pivot);

            float fx, fy;

            if (arrangement == Arrangement.Horizontal)
            {
                fx = Mathf.Lerp(0f, maxX * cellWidth, po.x);
                fy = Mathf.Lerp(-maxY * cellHeight, 0f, po.y);
            }
            else
            {
                fx = Mathf.Lerp(0f, maxY * cellWidth, po.x);
                fy = Mathf.Lerp(-maxX * cellHeight, 0f, po.y);
            }

            for (int i = 0; i < myTrans.childCount; ++i)
            {
                Transform      t  = myTrans.GetChild(i);
                SpringPosition sp = t.GetComponent <SpringPosition>();

                if (sp != null)
                {
                    sp.target.x -= fx;
                    sp.target.y -= fy;
                }
                else
                {
                    Vector3 pos = t.localPosition;
                    pos.x          -= fx;
                    pos.y          -= fy;
                    t.localPosition = pos;
                }
            }
        }
    }
Beispiel #15
0
    public virtual void Reposition()
    {
        if (Application.isPlaying && !this.mInitDone && NGUITools.GetActive(this))
        {
            this.mReposition = true;
            return;
        }
        if (!this.mInitDone)
        {
            this.Init();
        }
        this.mReposition = false;
        Transform transform = base.transform;
        int       num       = 0;
        int       num2      = 0;
        int       num3      = 0;
        int       num4      = 0;

        if (this.sorting != UIGrid.Sorting.None || this.sorted)
        {
            BetterList <Transform> betterList = new BetterList <Transform>();
            for (int i = 0; i < transform.childCount; i++)
            {
                Transform child = transform.GetChild(i);
                if (child && (!this.hideInactive || NGUITools.GetActive(child.gameObject)))
                {
                    betterList.Add(child);
                }
            }
            if (this.sorting == UIGrid.Sorting.Alphabetic)
            {
                betterList.Sort(new BetterList <Transform> .CompareFunc(UIGrid.SortByName));
            }
            else if (this.sorting == UIGrid.Sorting.Horizontal)
            {
                betterList.Sort(new BetterList <Transform> .CompareFunc(UIGrid.SortHorizontal));
            }
            else if (this.sorting == UIGrid.Sorting.Vertical)
            {
                betterList.Sort(new BetterList <Transform> .CompareFunc(UIGrid.SortVertical));
            }
            else
            {
                this.Sort(betterList);
            }
            int j    = 0;
            int size = betterList.size;
            while (j < size)
            {
                Transform transform2 = betterList[j];
                if (NGUITools.GetActive(transform2.gameObject) || !this.hideInactive)
                {
                    float   z      = transform2.localPosition.z;
                    Vector3 vector = (this.arrangement != UIGrid.Arrangement.Horizontal) ? new Vector3(this.cellWidth * (float)num2, -this.cellHeight * (float)num, z) : new Vector3(this.cellWidth * (float)num, -this.cellHeight * (float)num2, z);
                    if (this.animateSmoothly && Application.isPlaying)
                    {
                        SpringPosition.Begin(transform2.gameObject, vector, 15f).updateScrollView = true;
                    }
                    else
                    {
                        transform2.localPosition = vector;
                    }
                    num3 = Mathf.Max(num3, num);
                    num4 = Mathf.Max(num4, num2);
                    if (++num >= this.maxPerLine && this.maxPerLine > 0)
                    {
                        num = 0;
                        num2++;
                    }
                }
                j++;
            }
        }
        else
        {
            for (int k = 0; k < transform.childCount; k++)
            {
                Transform child2 = transform.GetChild(k);
                if (NGUITools.GetActive(child2.gameObject) || !this.hideInactive)
                {
                    float   z2      = child2.localPosition.z;
                    Vector3 vector2 = (this.arrangement != UIGrid.Arrangement.Horizontal) ? new Vector3(this.cellWidth * (float)num2, -this.cellHeight * (float)num, z2) : new Vector3(this.cellWidth * (float)num, -this.cellHeight * (float)num2, z2);
                    if (this.animateSmoothly && Application.isPlaying)
                    {
                        SpringPosition.Begin(child2.gameObject, vector2, 15f).updateScrollView = true;
                    }
                    else
                    {
                        child2.localPosition = vector2;
                    }
                    num3 = Mathf.Max(num3, num);
                    num4 = Mathf.Max(num4, num2);
                    if (++num >= this.maxPerLine && this.maxPerLine > 0)
                    {
                        num = 0;
                        num2++;
                    }
                }
            }
        }
        if (this.pivot != UIWidget.Pivot.TopLeft)
        {
            Vector2 pivotOffset = NGUIMath.GetPivotOffset(this.pivot);
            float   num5;
            float   num6;
            if (this.arrangement == UIGrid.Arrangement.Horizontal)
            {
                num5 = Mathf.Lerp(0f, (float)num3 * this.cellWidth, pivotOffset.x);
                num6 = Mathf.Lerp((float)(-(float)num4) * this.cellHeight, 0f, pivotOffset.y);
            }
            else
            {
                num5 = Mathf.Lerp(0f, (float)num4 * this.cellWidth, pivotOffset.x);
                num6 = Mathf.Lerp((float)(-(float)num3) * this.cellHeight, 0f, pivotOffset.y);
            }
            for (int l = 0; l < transform.childCount; l++)
            {
                Transform child3 = transform.GetChild(l);
                if (NGUITools.GetActive(child3.gameObject) || !this.hideInactive)
                {
                    SpringPosition component = child3.GetComponent <SpringPosition>();
                    if (component != null)
                    {
                        SpringPosition expr_44A_cp_0 = component;
                        expr_44A_cp_0.target.x = expr_44A_cp_0.target.x - num5;
                        SpringPosition expr_45F_cp_0 = component;
                        expr_45F_cp_0.target.y = expr_45F_cp_0.target.y - num6;
                    }
                    else
                    {
                        Vector3 localPosition = child3.localPosition;
                        localPosition.x     -= num5;
                        localPosition.y     -= num6;
                        child3.localPosition = localPosition;
                    }
                }
            }
        }
        if (this.keepWithinPanel && this.mPanel != null)
        {
            this.mPanel.ConstrainTargetToBounds(transform, true);
        }
        if (this.onReposition != null)
        {
            this.onReposition();
        }
    }
Beispiel #16
0
    protected void RepositionVariableSize(List <Transform> children)
    {
        float num  = 0f;
        float num2 = 0f;
        int   num3 = (this.columns <= 0) ? 1 : (children.Count / this.columns + 1);
        int   num4 = (this.columns <= 0) ? children.Count : this.columns;

        Bounds[,] array = new Bounds[num3, num4];
        Bounds[] array2 = new Bounds[num4];
        Bounds[] array3 = new Bounds[num3];
        int      num5   = 0;
        int      num6   = 0;
        int      i      = 0;
        int      count  = children.Count;

        while (i < count)
        {
            Transform transform  = children[i];
            Bounds    bounds     = NGUIMath.CalculateRelativeWidgetBounds(transform, !this.hideInactive);
            Vector3   localScale = transform.localScale;
            bounds.min        = Vector3.Scale(bounds.min, localScale);
            bounds.max        = Vector3.Scale(bounds.max, localScale);
            array[num6, num5] = bounds;
            array2[num5].Encapsulate(bounds);
            array3[num6].Encapsulate(bounds);
            if (++num5 >= this.columns && this.columns > 0)
            {
                num5 = 0;
                num6++;
            }
            i++;
        }
        num5 = 0;
        num6 = 0;
        Vector2 pivotOffset = NGUIMath.GetPivotOffset(this.cellAlignment);
        int     j           = 0;
        int     count2      = children.Count;

        while (j < count2)
        {
            Transform transform2    = children[j];
            Bounds    bounds2       = array[num6, num5];
            Bounds    bounds3       = array2[num5];
            Bounds    bounds4       = array3[num6];
            Vector3   localPosition = transform2.localPosition;
            localPosition.x  = num + bounds2.extents.x - bounds2.center.x;
            localPosition.x -= Mathf.Lerp(0f, bounds2.max.x - bounds2.min.x - bounds3.max.x + bounds3.min.x, pivotOffset.x) - this.padding.x;
            if (this.direction == UITable.Direction.Down)
            {
                localPosition.y  = -num2 - bounds2.extents.y - bounds2.center.y;
                localPosition.y += Mathf.Lerp(bounds2.max.y - bounds2.min.y - bounds4.max.y + bounds4.min.y, 0f, pivotOffset.y) - this.padding.y;
            }
            else
            {
                localPosition.y  = num2 + bounds2.extents.y - bounds2.center.y;
                localPosition.y -= Mathf.Lerp(0f, bounds2.max.y - bounds2.min.y - bounds4.max.y + bounds4.min.y, pivotOffset.y) - this.padding.y;
            }
            num += bounds3.size.x + this.padding.x * 2f;
            transform2.localPosition = localPosition;
            if (++num5 >= this.columns && this.columns > 0)
            {
                num5 = 0;
                num6++;
                num   = 0f;
                num2 += bounds4.size.y + this.padding.y * 2f;
            }
            j++;
        }
        if (this.pivot != UIWidget.Pivot.TopLeft)
        {
            pivotOffset = NGUIMath.GetPivotOffset(this.pivot);
            Bounds    bounds5    = NGUIMath.CalculateRelativeWidgetBounds(base.transform);
            float     num7       = Mathf.Lerp(0f, bounds5.size.x, pivotOffset.x);
            float     num8       = Mathf.Lerp(-bounds5.size.y, 0f, pivotOffset.y);
            Transform transform3 = base.transform;
            for (int k = 0; k < transform3.childCount; k++)
            {
                Transform      child     = transform3.GetChild(k);
                SpringPosition component = child.GetComponent <SpringPosition>();
                if (component != null)
                {
                    component.enabled = false;
                    SpringPosition expr_4A9_cp_0 = component;
                    expr_4A9_cp_0.target.x = expr_4A9_cp_0.target.x - num7;
                    SpringPosition expr_4BE_cp_0 = component;
                    expr_4BE_cp_0.target.y = expr_4BE_cp_0.target.y - num8;
                    component.enabled      = true;
                }
                else
                {
                    Vector3 localPosition2 = child.localPosition;
                    localPosition2.x   -= num7;
                    localPosition2.y   -= num8;
                    child.localPosition = localPosition2;
                }
            }
        }
    }
Beispiel #17
0
    public void Reposition()
    {
        if (Application.isPlaying && !mStarted)
        {
            mReposition = true;
            return;
        }

        if (!mInitDone)
        {
            Init();
        }

        mReposition = false;
        Transform myTrans = transform;

        int x      = 0;
        int y      = 0;
        int height = 0;

        for (int i = 0; i < myTrans.childCount; ++i)
        {
            Transform t = myTrans.GetChild(i);

            // UISprite cell = t.FindChild("back").gameObject.GetComponent<UISprite>();
            UISprite cell = t.GetComponent <UISprite>();
            if (!NGUITools.GetActive(t.gameObject) && hideInactive)
            {
                continue;
            }

            float depth = t.localPosition.z;

            Vector3 pos = new Vector3(0, -height, depth);

            height += cell.height;

            if (animateSmoothly && Application.isPlaying)
            {
                SpringPosition.Begin(t.gameObject, pos, 15f);
            }
            else
            {
                t.localPosition = pos;
            }

            if (++x >= maxPerLine && maxPerLine > 0)
            {
                x = 0;
                ++y;
            }
        }

        if (mDrag != null)
        {
            mDrag.UpdateScrollbars(true);
            mDrag.RestrictWithinBounds(true);
        }
        else if (mPanel != null)
        {
            mPanel.ConstrainTargetToBounds(myTrans, true);
        }

        if (onReposition != null)
        {
            onReposition();
        }
    }
Beispiel #18
0
    /// <summary>
    /// Perform any logic related to starting the drag & drop operation.
    /// </summary>

    protected virtual void OnDragDropStart()
    {
        if (!draggedItems.Contains(this))
        {
            draggedItems.Add(this);
        }

        // Automatically disable the scroll view
        if (mDragScrollView != null)
        {
            mDragScrollView.enabled = false;
        }

        // Disable the collider so that it doesn't intercept events
        if (mButton != null)
        {
            mButton.isEnabled = false;
        }
        else if (mCollider != null)
        {
            mCollider.enabled = false;
        }
        else if (mCollider2D != null)
        {
            mCollider2D.enabled = false;
        }

        mParent = mTrans.parent;
        mRoot   = NGUITools.FindInParents <UIRoot>(mParent);
        mGrid   = NGUITools.FindInParents <UIGrid>(mParent);
        mTable  = NGUITools.FindInParents <UITable>(mParent);

        // Re-parent the item
        if (UIDragDropRoot.root != null)
        {
            mTrans.parent = UIDragDropRoot.root;
        }

        Vector3 pos = mTrans.localPosition;

        pos.z = 0f;
        mTrans.localPosition = pos;

        TweenPosition tp = GetComponent <TweenPosition>();

        if (tp != null)
        {
            tp.enabled = false;
        }

        SpringPosition sp = GetComponent <SpringPosition>();

        if (sp != null)
        {
            sp.enabled = false;
        }

        // Notify the widgets that the parent has changed
        NGUITools.MarkParentAsChanged(gameObject);

        if (mTable != null)
        {
            mTable.repositionNow = true;
        }
        if (mGrid != null)
        {
            mGrid.repositionNow = true;
        }
    }
    protected virtual void ResetPosition(List <Transform> list)
    {
        this.mReposition = false;
        int       num       = 0;
        int       num2      = 0;
        int       num3      = 0;
        int       num4      = 0;
        Transform transform = base.get_transform();
        int       i         = 0;
        int       count     = list.get_Count();

        while (i < count)
        {
            Transform transform2 = list.get_Item(i);
            Vector3   vector     = transform2.get_localPosition();
            float     z          = vector.z;
            if (this.arrangement == UIGrid.Arrangement.CellSnap)
            {
                if (this.cellWidth > 0f)
                {
                    vector.x = Mathf.Round(vector.x / this.cellWidth) * this.cellWidth;
                }
                if (this.cellHeight > 0f)
                {
                    vector.y = Mathf.Round(vector.y / this.cellHeight) * this.cellHeight;
                }
            }
            else
            {
                vector = ((this.arrangement != UIGrid.Arrangement.Horizontal) ? new Vector3(this.cellWidth * (float)num2, -this.cellHeight * (float)num, z) : new Vector3(this.cellWidth * (float)num, -this.cellHeight * (float)num2, z));
            }
            if (this.animateSmoothly && Application.get_isPlaying())
            {
                SpringPosition springPosition = SpringPosition.Begin(transform2.get_gameObject(), vector, 15f);
                springPosition.updateScrollView = true;
                springPosition.ignoreTimeScale  = true;
            }
            else
            {
                transform2.set_localPosition(vector);
            }
            num3 = Mathf.Max(num3, num);
            num4 = Mathf.Max(num4, num2);
            if (++num >= this.maxPerLine && this.maxPerLine > 0)
            {
                num = 0;
                num2++;
            }
            i++;
        }
        if (this.pivot != UIWidget.Pivot.TopLeft)
        {
            Vector2 pivotOffset = NGUIMath.GetPivotOffset(this.pivot);
            float   num5;
            float   num6;
            if (this.arrangement == UIGrid.Arrangement.Horizontal)
            {
                num5 = Mathf.Lerp(0f, (float)num3 * this.cellWidth, pivotOffset.x);
                num6 = Mathf.Lerp((float)(-(float)num4) * this.cellHeight, 0f, pivotOffset.y);
            }
            else
            {
                num5 = Mathf.Lerp(0f, (float)num4 * this.cellWidth, pivotOffset.x);
                num6 = Mathf.Lerp((float)(-(float)num3) * this.cellHeight, 0f, pivotOffset.y);
            }
            for (int j = 0; j < transform.get_childCount(); j++)
            {
                Transform      child     = transform.GetChild(j);
                SpringPosition component = child.GetComponent <SpringPosition>();
                if (component != null)
                {
                    SpringPosition expr_24F_cp_0 = component;
                    expr_24F_cp_0.target.x = expr_24F_cp_0.target.x - num5;
                    SpringPosition expr_264_cp_0 = component;
                    expr_264_cp_0.target.y = expr_264_cp_0.target.y - num6;
                }
                else
                {
                    Vector3 localPosition = child.get_localPosition();
                    localPosition.x -= num5;
                    localPosition.y -= num6;
                    child.set_localPosition(localPosition);
                }
            }
        }
    }
Beispiel #20
0
    /// <summary>
    /// Reset the position of all child objects based on the order of items in the list.
    /// </summary>

    protected void ResetPosition(List <Transform> list)
    {
        mReposition = false;

        // Epic hack: Unparent all children so that we get to control the order in which they are re-added back in
        // EDIT: Turns out this does nothing.
        //for (int i = 0, imax = list.Count; i < imax; ++i)
        //	list[i].parent = null;

        int       x       = 0;
        int       y       = 0;
        int       maxX    = 0;
        int       maxY    = 0;
        Transform myTrans = transform;

        // Re-add the children in the same order we have them in and position them accordingly
        for (int i = 0, imax = list.Count; i < imax; ++i)
        {
            Transform t = list[i];
            // See above
            //t.parent = myTrans;

            float   depth = t.localPosition.z;
            Vector3 pos   = (arrangement == Arrangement.Horizontal) ?
                            new Vector3(cellWidth * x, -cellHeight * y, depth) :
                            new Vector3(cellWidth * y, -cellHeight * x, depth);

            if (animateSmoothly && Application.isPlaying && Vector3.SqrMagnitude(t.localPosition - pos) >= 0.0001f)
            {
                SpringPosition sp = SpringPosition.Begin(t.gameObject, pos, 15f);
                sp.updateScrollView = true;
                sp.ignoreTimeScale  = true;
            }
            else
            {
                t.localPosition = pos;
            }

            maxX = Mathf.Max(maxX, x);
            maxY = Mathf.Max(maxY, y);

            if (++x >= maxPerLine && maxPerLine > 0)
            {
                x = 0;
                ++y;
            }
        }

        // Apply the origin offset
        if (pivot != UIWidget.Pivot.TopLeft)
        {
            Vector2 po = NGUIMath.GetPivotOffset(pivot);

            float fx, fy;

            if (arrangement == Arrangement.Horizontal)
            {
                fx = Mathf.Lerp(0f, maxX * cellWidth, po.x);
                fy = Mathf.Lerp(-maxY * cellHeight, 0f, po.y);
            }
            else
            {
                fx = Mathf.Lerp(0f, maxY * cellWidth, po.x);
                fy = Mathf.Lerp(-maxX * cellHeight, 0f, po.y);
            }

            for (int i = 0; i < myTrans.childCount; ++i)
            {
                Transform      t  = myTrans.GetChild(i);
                SpringPosition sp = t.GetComponent <SpringPosition>();

                if (sp != null)
                {
                    sp.target.x -= fx;
                    sp.target.y -= fy;
                }
                else
                {
                    Vector3 pos = t.localPosition;
                    pos.x          -= fx;
                    pos.y          -= fy;
                    t.localPosition = pos;
                }
            }
        }
    }
    /// <summary>
    /// Recalculate the position of all elements within the grid, sorting them alphabetically if necessary.
    /// </summary>

    protected void ResetPosition(List <GameObject> list)
    {
        int       x       = 0;
        int       y       = 0;
        int       maxX    = 0;
        int       maxY    = 0;
        Transform myTrans = transform;

        for (int i = 0, imax = list.Count; i < imax; ++i)
        {
            Transform t = list[i].transform;

            float   depth = t.localPosition.z;
            Vector3 pos   = (arrangement == Arrangement.Horizontal) ?
                            new Vector3(cellWidth * x, -cellHeight * y, depth) :
                            new Vector3(cellWidth * y, -cellHeight * x, depth);

            t.localPosition = pos;

            maxX = Mathf.Max(maxX, x);
            maxY = Mathf.Max(maxY, y);

            if (++x >= maxPerLine && maxPerLine > 0)
            {
                x = 0;
                ++y;
            }
        }

        // Apply the origin offset
        if (pivot != UIWidget.Pivot.TopLeft)
        {
            Vector2 po = NGUIMath.GetPivotOffset(pivot);

            float fx, fy;

            if (arrangement == Arrangement.Horizontal)
            {
                fx = Mathf.Lerp(0f, maxX * cellWidth, po.x);
                fy = Mathf.Lerp(-maxY * cellHeight, 0f, po.y);
            }
            else
            {
                fx = Mathf.Lerp(0f, maxY * cellWidth, po.x);
                fy = Mathf.Lerp(-maxX * cellHeight, 0f, po.y);
            }

            for (int i = 0; i < list.Count; ++i)
            {
                Transform      t  = list[i].transform;
                SpringPosition sp = t.GetComponent <SpringPosition>();

                if (sp != null)
                {
                    sp.target.x -= fx;
                    sp.target.y -= fy;
                }
                else
                {
                    Vector3 pos = t.localPosition;
                    pos.x          -= fx;
                    pos.y          -= fy;
                    t.localPosition = pos;
                }
            }
        }
    }
    /// <summary>
    /// Recalculate the position of all elements within the grid, sorting them alphabetically if necessary.
    /// </summary>

    public void Reposition(bool isByNum = false)                       //  使用数字顺序时需要传参数true,其余情况下仍然走false的字典序  /
    {
        if (!mStarted)
        {
            repositionNow = true;
            return;
        }

        Transform myTrans = transform;

        int x    = 0;
        int y    = 0;
        int maxX = 0;
        int maxY = 0;

        if (sorted)
        {
            List <Transform> list = new List <Transform>();

            for (int i = 0; i < myTrans.childCount; ++i)
            {
                Transform t = myTrans.GetChild(i);
                if (t && (!hideInactive || NGUITools.GetActive(t.gameObject)))
                {
                    list.Add(t);
                }
            }
            if (isByNum)
            {
                list.Sort(SortByNum);
            }
            else
            {
                list.Sort(SortByName);
            }

            for (int i = 0, imax = list.Count; i < imax; ++i)
            {
                Transform t = list[i];

                if (!NGUITools.GetActive(t.gameObject) && hideInactive)
                {
                    continue;
                }

                float depth = t.localPosition.z;
                t.localPosition = (arrangement == Arrangement.Horizontal) ?
                                  new Vector3(cellWidth * x, -cellHeight * y, depth) :
                                  new Vector3(cellWidth * y, -cellHeight * x, depth);

                maxX = Mathf.Max(maxX, x);
                maxY = Mathf.Max(maxY, y);

                if (++x >= maxPerLine && maxPerLine > 0)
                {
                    x = 0;
                    ++y;
                }
            }
        }
        else
        {
            for (int i = 0; i < myTrans.childCount; ++i)
            {
                Transform t = myTrans.GetChild(i);

                if (!NGUITools.GetActive(t.gameObject) && hideInactive)
                {
                    continue;
                }

                float depth = t.localPosition.z;
                t.localPosition = (arrangement == Arrangement.Horizontal) ?
                                  new Vector3(cellWidth * x, -cellHeight * y, depth) :
                                  new Vector3(cellWidth * y, -cellHeight * x, depth);

                maxX = Mathf.Max(maxX, x);
                maxY = Mathf.Max(maxY, y);

                if (++x >= maxPerLine && maxPerLine > 0)
                {
                    x = 0;
                    ++y;
                }
            }
        }

        // Apply the origin offset
        if (pivot != UIWidget.Pivot.TopLeft)
        {
            Vector2 po = NGUIMath.GetPivotOffset(pivot);

            float fx, fy;

            if (arrangement == Arrangement.Horizontal)
            {
                fx = Mathf.Lerp(0f, maxX * cellWidth, po.x);
                fy = Mathf.Lerp(-maxY * cellHeight, 0f, po.y);
            }
            else
            {
                fx = Mathf.Lerp(0f, maxY * cellWidth, po.x);
                fy = Mathf.Lerp(-maxX * cellHeight, 0f, po.y);
            }

            for (int i = 0; i < myTrans.childCount; ++i)
            {
                Transform      t  = myTrans.GetChild(i);
                SpringPosition sp = t.GetComponent <SpringPosition>();

                if (sp != null)
                {
                    sp.target.x -= fx;
                    sp.target.y -= fy;
                }
                else
                {
                    Vector3 pos = t.localPosition;
                    pos.x          -= fx;
                    pos.y          -= fy;
                    t.localPosition = pos;
                }
            }
        }

        UIDraggablePanel drag = NGUITools.FindInParents <UIDraggablePanel>(gameObject);

        if (drag != null)
        {
            drag.UpdateScrollbars(true);
        }

        if (onReposition != null)
        {
            onReposition();
        }
    }
Beispiel #23
0
    /// <summary>
    /// Apply the dragging momentum.
    /// </summary>

    void LateUpdate()
    {
        float delta = UpdateRealTimeDelta();

        if (target == null)
        {
            return;
        }

        if (mPressed)
        {
            // Disable the spring movement
            SpringPosition sp = target.GetComponent <SpringPosition>();
            if (sp != null)
            {
                sp.enabled = false;
            }
            mScroll = 0f;
        }
        else
        {
            mMomentum += scale * (-mScroll * 0.05f);
            mScroll    = NGUIMath.SpringLerp(mScroll, 0f, 20f, delta);

            if (mMomentum.magnitude > 0.0001f)
            {
                // Apply the momentum
                if (mPanel == null)
                {
                    FindPanel();
                }

                if (mPanel != null)
                {
                    target.position += NGUIMath.SpringDampen(ref mMomentum, 9f, delta);

                    if (restrictWithinPanel && mPanel.clipping != UIDrawCall.Clipping.None)
                    {
                        mBounds = NGUIMath.CalculateRelativeWidgetBounds(mPanel.cachedTransform, target);

                        if (!mPanel.ConstrainTargetToBounds(target, ref mBounds, dragEffect == DragEffect.None))
                        {
                            SpringPosition sp = target.GetComponent <SpringPosition>();
                            if (sp != null)
                            {
                                sp.enabled = false;
                            }
                        }
                    }
                    return;
                }
            }
            else
            {
                mScroll = 0f;
            }
        }

        // Dampen the momentum
        NGUIMath.SpringDampen(ref mMomentum, 9f, delta);
    }
Beispiel #24
0
	/// <summary>
	/// Notify all finished event listeners.
	/// </summary>

	void NotifyListeners ()
	{
		current = this;

		if (onFinished != null) onFinished();

		if (eventReceiver != null && !string.IsNullOrEmpty(callWhenFinished))
			eventReceiver.SendMessage(callWhenFinished, this, SendMessageOptions.DontRequireReceiver);

		current = null;
	}
    public void ChangeDataSources(int count)
    {
        int LastDataCount = mDataCount;

        mDataCount = count;
        if (count >= mVisualCellCount)
        {
            if (count >= LastDataCount)
            {
                if (LastDataCount <= MaxVisualCellCount)
                {
                    SetDataSources(mDataCount);
                }
                else
                {
                    for (int i = moveBottomCount; i < moveBottomCount + mVisualCellCount; i++)
                    {
                        CallLua(i);
                    }
                }
            }
            else
            {
                if (LastDataCount != moveBottomCount + mVisualCellCount)
                {
                    for (int i = moveBottomCount; i < moveBottomCount + mVisualCellCount; i++)
                    {
                        CallLua(i);
                    }
                }
                else
                {
                    //get the bottom of data
                    if (LastDataCount >= mVisualCellCount)
                    {
                        int minuCount = LastDataCount - count;

                        int     lastIndex  = LineFlowLayout.childrens.Count - 1;
                        int     cacheCount = moveBottomCount;
                        Vector3 cellHeight = new Vector3(0, mCellHeight, 0);

                        for (int i = 0; i < minuCount; i++)
                        {
                            Vector3 pos = LineFlowLayout.childrens[0].tran.localPosition;
                            LineFlowLayout.childrens.RemoveAt(lastIndex);
                            int removeIndex = (cacheCount - 1) % mVisualCellCount;
                            mCellList[removeIndex].transform.localPosition = pos + cellHeight;
                            LineFlowLayout.childrens.Insert(0, new UILineFlowLayoutChild(mCellList[removeIndex].transform, false));
                            moveBottomCount--;
                            cacheCount--;
                        }

                        for (int i = moveBottomCount; i < moveBottomCount + mVisualCellCount; i++)
                        {
                            CallLua(i);
                        }

                        Vector3 dragPos = DragTarget.transform.localPosition;
                        DragTarget.transform.localPosition = new Vector3(dragPos.x, dragPos.y - mCellHeight * minuCount, dragPos.z);
                        SpringPosition sprPos = GetMySpringPosition();
                        if (sprPos != null)
                        {
                            sprPos.target = DragTarget.transform.localPosition;
                        }
                    }
                    else
                    {
                        SetDataSources(mDataCount);
                    }
                }
            }
        }
        else
        {
            SetDataSources(count);
        }
    }