GetPivotOffset() static public method

Helper function that converts the widget's pivot enum into a 0-1 range vector.
static public GetPivotOffset ( UIWidget, pv ) : Vector2
pv UIWidget,
return Vector2
Esempio n. 1
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;
                }
            }
        }
    }
Esempio n. 2
0
    /// <summary>
    /// Reset the position of all child objects based on the order of items in the list.
    /// </summary>

    protected void ResetPosition(BetterList <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
        for (int i = 0, imax = list.size; 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.size; i < imax; ++i)
        {
            Transform t = list[i];
            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)
            {
                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);
                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 (mMoveOffset != 0 && mMoveGap > 0 && mMoveDelay > 0)
        {
            float delay = 0;
            for (int i = 0; i < myTrans.childCount; ++i)
            {
                Transform t   = myTrans.GetChild(i);
                Vector3   pos = t.localPosition;
                pos.x          += mMoveOffset;
                t.localPosition = pos;
                TweenPosition tp = TweenPosition.Begin(t.gameObject, mMoveGap, new Vector3(pos.x - mMoveOffset, pos.y, pos.z));
                tp.delay = delay;
                delay   += mMoveDelay;
            }
        }
        if (mAlphaDuration > 0 && mAlphaDelay > 0)
        {
            float delay = 0;
            for (int i = 0; i < myTrans.childCount; ++i)
            {
                UIWidget w         = myTrans.GetChild(i).GetComponent <UIWidget>();
                float    tempAlpha = w.color.a;
                w.color = new Color(w.color.r, w.color.g, w.color.b, 0);
                TweenAlpha ta = TweenAlpha.Begin(w.gameObject, mAlphaDuration, tempAlpha);
                ta.delay = delay;
                delay   += mAlphaDelay;
            }
        }
    }
Esempio n. 3
0
    protected void RepositionVariableSize(List <Transform> children)
    {
        float num  = 0f;
        float num2 = 0f;
        int   num3 = (columns <= 0) ? 1 : (children.Count / columns + 1);
        int   num4 = (columns <= 0) ? children.Count : 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;

        for (int count = children.Count; i < count; i++)
        {
            Transform transform  = children[i];
            Bounds    bounds     = NGUIMath.CalculateRelativeWidgetBounds(transform, !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 >= columns && columns > 0)
            {
                num5 = 0;
                num6++;
            }
        }
        num5 = 0;
        num6 = 0;
        Vector2 pivotOffset = NGUIMath.GetPivotOffset(cellAlignment);
        int     j           = 0;

        for (int count2 = children.Count; j < count2; j++)
        {
            Transform transform2    = children[j];
            Bounds    bounds2       = array[num6, num5];
            Bounds    bounds3       = array2[num5];
            Bounds    bounds4       = array3[num6];
            Vector3   localPosition = transform2.localPosition;
            float     num7          = num;
            Vector3   extents       = bounds2.extents;
            float     num8          = num7 + extents.x;
            Vector3   center        = bounds2.center;
            localPosition.x = num8 - center.x;
            float   x     = localPosition.x;
            Vector3 max   = bounds2.max;
            float   x2    = max.x;
            Vector3 min   = bounds2.min;
            float   num9  = x2 - min.x;
            Vector3 max2  = bounds3.max;
            float   num10 = num9 - max2.x;
            Vector3 min2  = bounds3.min;
            localPosition.x = x - (Mathf.Lerp(0f, num10 + min2.x, pivotOffset.x) - padding.x);
            if (direction == Direction.Down)
            {
                float   num11    = 0f - num2;
                Vector3 extents2 = bounds2.extents;
                float   num12    = num11 - extents2.y;
                Vector3 center2  = bounds2.center;
                localPosition.y = num12 - center2.y;
                float   y     = localPosition.y;
                Vector3 max3  = bounds2.max;
                float   y2    = max3.y;
                Vector3 min3  = bounds2.min;
                float   num13 = y2 - min3.y;
                Vector3 max4  = bounds4.max;
                float   num14 = num13 - max4.y;
                Vector3 min4  = bounds4.min;
                localPosition.y = y + (Mathf.Lerp(num14 + min4.y, 0f, pivotOffset.y) - padding.y);
            }
            else
            {
                float   num15    = num2;
                Vector3 extents3 = bounds2.extents;
                float   num16    = num15 + extents3.y;
                Vector3 center3  = bounds2.center;
                localPosition.y = num16 - center3.y;
                float   y3    = localPosition.y;
                Vector3 max5  = bounds2.max;
                float   y4    = max5.y;
                Vector3 min5  = bounds2.min;
                float   num17 = y4 - min5.y;
                Vector3 max6  = bounds4.max;
                float   num18 = num17 - max6.y;
                Vector3 min6  = bounds4.min;
                localPosition.y = y3 - (Mathf.Lerp(0f, num18 + min6.y, pivotOffset.y) - padding.y);
            }
            float   num19 = num;
            Vector3 size  = bounds3.size;
            num = num19 + (size.x + padding.x * 2f);
            transform2.localPosition = localPosition;
            if (++num5 >= columns && columns > 0)
            {
                num5 = 0;
                num6++;
                num = 0f;
                float   num20 = num2;
                Vector3 size2 = bounds4.size;
                num2 = num20 + (size2.y + padding.y * 2f);
            }
        }
        if (pivot != 0)
        {
            pivotOffset = NGUIMath.GetPivotOffset(pivot);
            Bounds    bounds5    = NGUIMath.CalculateRelativeWidgetBounds(base.transform);
            Vector3   size3      = bounds5.size;
            float     num21      = Mathf.Lerp(0f, size3.x, pivotOffset.x);
            Vector3   size4      = bounds5.size;
            float     num22      = Mathf.Lerp(0f - size4.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.target.x -= num21;
                    component.target.y -= num22;
                }
                else
                {
                    Vector3 localPosition2 = child.localPosition;
                    localPosition2.x   -= num21;
                    localPosition2.y   -= num22;
                    child.localPosition = localPosition2;
                }
            }
        }
    }
Esempio n. 4
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);
                }
            }
        }
    }
Esempio n. 5
0
    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.transform;
        int       i         = 0;
        int       count     = list.Count;

        while (i < count)
        {
            Transform transform2 = list[i];
            Vector3   vector     = transform2.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.isPlaying && Vector3.SqrMagnitude(transform2.localPosition - vector) >= 0.0001f)
            {
                SpringPosition springPosition = SpringPosition.Begin(transform2.gameObject, vector, 15f);
                springPosition.updateScrollView = true;
                springPosition.ignoreTimeScale  = 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++;
            }
            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.childCount; j++)
            {
                Transform      child     = transform.GetChild(j);
                SpringPosition component = child.GetComponent <SpringPosition>();
                if (component != null)
                {
                    SpringPosition springPosition2 = component;
                    springPosition2.target.x = springPosition2.target.x - num5;
                    SpringPosition springPosition3 = component;
                    springPosition3.target.y = springPosition3.target.y - num6;
                }
                else
                {
                    Vector3 localPosition = child.localPosition;
                    localPosition.x    -= num5;
                    localPosition.y    -= num6;
                    child.localPosition = localPosition;
                }
            }
        }
    }
Esempio n. 6
0
    /// <summary>
    /// Adjust the panel's position and clipping rectangle.
    /// </summary>

    void AdjustClipping(UIPanel p, Vector3 startLocalPos, Vector4 startCR, Vector3 worldDelta, UIWidget.Pivot pivot)
    {
        Transform  t             = p.cachedTransform;
        Transform  parent        = t.parent;
        Matrix4x4  parentToLocal = (parent != null) ? t.parent.worldToLocalMatrix : Matrix4x4.identity;
        Matrix4x4  worldToLocal  = parentToLocal;
        Quaternion invRot        = Quaternion.Inverse(t.localRotation);

        worldToLocal = worldToLocal * Matrix4x4.TRS(Vector3.zero, invRot, Vector3.one);
        Vector3 localDelta = worldToLocal.MultiplyVector(worldDelta);

        float left   = 0f;
        float right  = 0f;
        float top    = 0f;
        float bottom = 0f;

        Vector2 dragPivot = NGUIMath.GetPivotOffset(pivot);

        if (dragPivot.x == 0f && dragPivot.y == 1f)
        {
            left = localDelta.x;
            top  = localDelta.y;
        }
        else if (dragPivot.x == 0f && dragPivot.y == 0.5f)
        {
            left = localDelta.x;
        }
        else if (dragPivot.x == 0f && dragPivot.y == 0f)
        {
            left   = localDelta.x;
            bottom = localDelta.y;
        }
        else if (dragPivot.x == 0.5f && dragPivot.y == 1f)
        {
            top = localDelta.y;
        }
        else if (dragPivot.x == 0.5f && dragPivot.y == 0f)
        {
            bottom = localDelta.y;
        }
        else if (dragPivot.x == 1f && dragPivot.y == 1f)
        {
            right = localDelta.x;
            top   = localDelta.y;
        }
        else if (dragPivot.x == 1f && dragPivot.y == 0.5f)
        {
            right = localDelta.x;
        }
        else if (dragPivot.x == 1f && dragPivot.y == 0f)
        {
            right  = localDelta.x;
            bottom = localDelta.y;
        }

        AdjustClipping(p, startCR,
                       Mathf.RoundToInt(left),
                       Mathf.RoundToInt(top),
                       Mathf.RoundToInt(right),
                       Mathf.RoundToInt(bottom));
    }
Esempio n. 7
0
    /// <summary>
    /// Reset the position of all child objects based on the order of items in the list.
    /// </summary>

    protected void ResetPosition(BetterList <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.size; 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.size; 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)
            {
                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);
                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;
                }
            }
        }
    }
Esempio n. 8
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;

        Vector2 po = NGUIMath.GetPivotOffset(cellAlignment);

        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 -= Mathf.Lerp(0f, b.max.x - b.min.x - br.max.x + br.min.x, po.x) - padding.x;

            if (direction == Direction.Down)
            {
                pos.y  = -yOffset - b.extents.y - b.center.y;
                pos.y += Mathf.Lerp(b.max.y - b.min.y - bc.max.y + bc.min.y, 0f, po.y) - padding.y;
            }
            else
            {
                pos.y  = yOffset + b.extents.y - b.center.y;
                pos.y -= Mathf.Lerp(0f, b.max.y - b.min.y - bc.max.y + bc.min.y, po.y) - padding.y;
            }

            xOffset += br.size.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)
        {
            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.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;
                }
            }
        }
    }
Esempio n. 9
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 total = 0;      //wilson
        int maxX  = 0;
        int maxY  = 0;

        if (sorting != Sorting.None || sorted)
        {
            list.Clear();
            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   = Vector3.zero;

                //wilson
                if (arrangement == Arrangement.Mix)
                {
                    pos.x = cellWidth * x + total / (maxPerLine * maxPerRank) * cellWidth * maxPerLine;
                    pos.y = -cellHeight * y;
                    pos.z = depth;
                }
                else if (arrangement == Arrangement.Vertical)
                {
                    pos.x = cellWidth * x;
                    pos.y = -cellHeight * y;
                    pos.z = depth;
                }
                else
                {
                    pos.x = cellWidth * y;
                    pos.y = -cellHeight * x - cellHeight * y;
                    pos.z = 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);

                //wilson
                if (arrangement == Arrangement.Mix)
                {
                    if (++x >= maxPerLine && maxPerLine > 0)
                    {
                        x = 0;
                        if (++y >= maxPerRank && maxPerRank > 0)
                        {
                            y = 0;
                        }
                    }
                }
                else
                {
                    if (++x >= maxPerLine && maxPerLine > 0)
                    {
                        x = 0;
                        ++y;
                    }
                }
                ++total;
            }
        }
        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   = Vector3.zero;

                //wilson
                if (arrangement == Arrangement.Mix)
                {
                    pos.x = cellWidth * x + total / (maxPerLine * maxPerRank) * cellWidth * maxPerLine;
                    pos.y = -cellHeight * y;
                    pos.z = depth;
                }

                else if (arrangement == Arrangement.Vertical)
                {
                    pos.x = cellWidth * x;
                    pos.y = -cellHeight * y;
                    pos.z = depth;
                }
                else
                {
                    pos.x = cellWidth * y;
                    pos.y = -cellHeight * x;
                    pos.z = depth;
                }
                t.localPosition = pos;

                //wilson
                if (arrangement == Arrangement.Mix)
                {
                    if (++x >= maxPerLine && maxPerLine > 0)
                    {
                        x = 0;
                        if (++y >= maxPerRank && maxPerRank > 0)
                        {
                            y = 0;
                        }
                    }
                }
                else
                {
                    if (++x >= maxPerLine && maxPerLine > 0)
                    {
                        x = 0;
                        ++y;
                    }
                }
                ++total;
            }
        }

        // 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();
        }
    }
Esempio n. 10
0
    /// <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();
        }
    }
Esempio n. 11
0
    /// <summary>
    /// Restrict the scroll view's contents to be within the scroll view's bounds.
    /// </summary>

    public bool RestrictWithinBounds(bool instant, bool horizontal, bool vertical)
    {
        if (mPanel == null)
        {
            return(false);
        }

        Bounds  b          = bounds;
        Vector3 constraint = mPanel.CalculateConstrainOffset(b.min, b.max);

        if (!horizontal)
        {
            constraint.x = 0f;
        }
        if (!vertical)
        {
            constraint.y = 0f;
        }
        #region add by oyp 2017.4.13
        if (NeedbackPosition)
        {
            Vector2 pv      = NGUIMath.GetPivotOffset(contentPivot);
            float   x       = pv.x;
            float   y       = 1 - pv.y;
            Vector4 clip    = mPanel.finalClipRegion;
            UIGrid  tUIGrid = gameObject.GetComponentInChildren <UIGrid>();
            float   hx      = clip.z * 0.5f;
            float   hy      = clip.w * 0.5f;

            float left = b.min.x + hx;
            if (tUIGrid != null && this.movement == Movement.Horizontal)
            {
                left = b.min.x + hx - (float)(tUIGrid.cellWidth * 0.5);
            }
            float right  = b.max.x - hx;
            float bottom = b.min.y + hy;
            float top    = b.max.y - hy;
            if (tUIGrid != null && this.movement == Movement.Vertical)
            {
                top = b.max.y - hy + (float)(tUIGrid.cellHeight * 0.5);
            }
            if (mPanel.clipping == UIDrawCall.Clipping.SoftClip)
            {
                left   -= mPanel.clipSoftness.x;
                right  += mPanel.clipSoftness.x;
                bottom -= mPanel.clipSoftness.y;
                top    += mPanel.clipSoftness.y;
            }

            // Calculate the offset based on the scroll value
            float ox = Mathf.Lerp(left, right, x);
            float oy = Mathf.Lerp(top, bottom, y);


            if (tUIGrid != null)
            {
                if (canMoveVertically && !shouldMoveVertically)
                {
                    constraint = new Vector3(pv.x, -oy - mTrans.localPosition.y, 0);
                }
                else if (canMoveHorizontally && !shouldMoveHorizontally)
                {
                    constraint = new Vector3(-ox - mTrans.localPosition.x, pv.y, 0);
                }
            }
        }
        #endregion
        if (constraint.sqrMagnitude > 0.1f)
        {
            if (!instant && dragEffect == DragEffect.MomentumAndSpring)
            {
                // Spring back into place
                Vector3 pos = mTrans.localPosition + constraint;
                pos.x = Mathf.Round(pos.x);
                pos.y = Mathf.Round(pos.y);
                SpringPanel.Begin(mPanel.gameObject, pos, 13f).strength = 8f;
            }
            else
            {
                // Jump back into place
                MoveRelative(constraint);

                // Clear the momentum in the constrained direction
                if (Mathf.Abs(constraint.x) > 0.01f)
                {
                    mMomentum.x = 0;
                }
                if (Mathf.Abs(constraint.y) > 0.01f)
                {
                    mMomentum.y = 0;
                }
                if (Mathf.Abs(constraint.z) > 0.01f)
                {
                    mMomentum.z = 0;
                }
                mScroll = 0f;
            }
            return(true);
        }
        return(false);
    }
Esempio n. 12
0
    /// <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;
                }
            }
        }
    }
Esempio n. 13
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;
                }
            }
        }
    }
Esempio n. 14
0
        public override void Reposition()
        {
            // Basically taken from UIGrid.Reposition.
            if (Application.isPlaying && !this.mInitDone && NGUITools.GetActive(this))
            {
                this.mReposition = true;
                return;
            }

            if (!this.mInitDone)
            {
                this.Init();
            }

            this.mReposition = false;
            Transform myTrans = this.transform;

            int x    = this.CellOffset % this.maxPerLine;
            int y    = this.CellOffset / this.maxPerLine;
            int maxX = 0;
            int maxY = 0;

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

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

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

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

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

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

                    if (this.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 >= this.maxPerLine && this.maxPerLine > 0)
                    {
                        x = 0;
                        ++y;
                    }
                }
            }
            else
            {
                for (int i = 0; i < myTrans.childCount; ++i)
                {
                    Transform t = myTrans.GetChild(i);

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

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

                    if (this.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 >= this.maxPerLine && this.maxPerLine > 0)
                    {
                        x = 0;
                        ++y;
                    }
                }
            }

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

                float fx, fy;

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

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

                    if (!NGUITools.GetActive(t.gameObject) && this.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 (this.keepWithinPanel && this.mPanel != null)
            {
                this.mPanel.ConstrainTargetToBounds(myTrans, true);
            }

            if (this.onReposition != null)
            {
                this.onReposition();
            }
        }
Esempio n. 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 != NGUIGrid.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 == NGUIGrid.Sorting.Alphabetic)
            {
                betterList.Sort(new BetterList <Transform> .CompareFunc(NGUIGrid.SortByName));
            }
            else if (this.sorting == NGUIGrid.Sorting.Horizontal)
            {
                betterList.Sort(new BetterList <Transform> .CompareFunc(NGUIGrid.SortHorizontal));
            }
            else if (this.sorting == NGUIGrid.Sorting.Vertical)
            {
                betterList.Sort(new BetterList <Transform> .CompareFunc(NGUIGrid.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 != NGUIGrid.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 != NGUIGrid.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 == NGUIGrid.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();
        }
    }
Esempio n. 16
0
 /// <summary>
 /// 显示最后一个
 /// </summary>
 /// <param name="moveSmooth"></param>
 public void ShowLastOne(bool moveSmooth)
 {
     if (moveSmooth)
     {
         mCalculatedBounds = false;
         Bounds  bound      = bounds;
         Vector2 region     = new Vector2(mPanel.finalClipRegion.z, mPanel.finalClipRegion.w);
         Vector2 realRegion = (bound.max - bound.min);
         if (movement == Movement.Horizontal)
         {
             mMoveSmoothToLast = realRegion.x >= region.x;
         }
         else if (movement == Movement.Vertical)
         {
             mMoveSmoothToLast = realRegion.y > region.y;
         }
         else if (movement == Movement.Unrestricted)
         {
             mMoveSmoothToLast = realRegion.magnitude > region.magnitude;
         }
         if (mMoveSmoothToLast)
         {
             mToLastOffset = mPanel.clipOffset - (Vector2)bound.min;
         }
     }
     else
     {
         ResetPosition();
         Vector2 pv = NGUIMath.GetPivotOffset(contentPivot);
         float   x  = (horizontalScrollBar != null) ? horizontalScrollBar.value : pv.x;
         float   y  = (verticalScrollBar != null) ? verticalScrollBar.value : 1f - pv.y;
         if (movement == Movement.Vertical)
         {
             y = shouldMove ? 1f : 0f;
             if (verticalScrollBar != null)
             {
                 verticalScrollBar.value = y;
                 OnScrollBar();
             }
             else
             {
                 SetDragAmount(x, y, false);
                 SetDragAmount(x, y, true);
             }
         }
         else if (movement == Movement.Horizontal)
         {
             x = shouldMove ? 1f : 0f;
             if (horizontalScrollBar != null)
             {
                 horizontalScrollBar.value = x;
                 OnScrollBar();
             }
             else
             {
                 SetDragAmount(x, y, false);
                 SetDragAmount(x, y, true);
             }
         }
         else if (movement == Movement.Unrestricted)
         {
             y = shouldMove ? 1f : 0f;
             x = shouldMove ? 1f : 0f;
             if (verticalScrollBar != null && horizontalScrollBar != null)
             {
                 verticalScrollBar.value   = y;
                 horizontalScrollBar.value = x;
                 OnScrollBar();
             }
             else
             {
                 SetDragAmount(x, y, false);
                 SetDragAmount(x, y, true);
             }
         }
     }
 }
Esempio n. 17
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);
            }

            //by fxc 2019/1/7 解决缓存机制带来的第一个uiview一直放在(0,0,0)点位置的问题
            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;
                }
            }
        }
    }
Esempio n. 18
0
    public override 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)
        {
            BetterList <Transform> spotsList = new BetterList <Transform>();

            BetterList <Transform> actualItems = new BetterList <Transform>();

            foreach (Transform childTransform in transform)
            {
                if (childTransform.gameObject.name.Contains("Spot"))
                {
                    //spotsList.Insert(int.Parse(childTransform.gameObject.name.Substring(4, 2) ) - 1, childTransform);
                    spotsList.Add(childTransform);
                }
                else
                {
                    if (childTransform && (!hideInactive || NGUITools.GetActive(childTransform.gameObject)))
                    {
                        actualItems.Add(childTransform);
                    }
                }
            }


            //Debug.Log(spotsList);

            //for (int i = 0; i < myTrans.childCount; ++i)
            //{

            //    Transform t = myTrans.GetChild(i);

            //}

            //SortHorizontal (Transform a, Transform b) { return a.localPosition.x.CompareTo(b.localPosition.x); }

            actualItems.Sort(SortVertical);
            spotsList.Sort(SortVertical);

            //actualItems.Sort(SortQueue);



            //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);

            //list.Sort({ return list. })

            for (int i = 0, imax = actualItems.size; i < imax; ++i)
            {
                //Transform t = actualItems[actualItems.size - 1 - i];

                Transform t = actualItems[i];

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

                float depth = t.localPosition.z;
                //Debug.Log("POSITION NOW ");
                //Vector3 pos = t.parent.InverseTransformPoint(list[i].position);
                Vector3 pos = spotsList[i].localPosition;
                //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;
                }
            }

            zonePanelManager.ReorderCustomerList(actualItems);
        }
        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();
        }
    }
Esempio n. 19
0
    protected void RepositionVariableSize(List <Transform> children)
    {
        float num  = 0f;
        float num2 = 0f;
        int   num3 = (this.columns > 0) ? (children.Count / this.columns + 1) : 1;
        int   num4 = (this.columns > 0) ? this.columns : children.Count;

        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)
                {
                    SpringPosition expr_415_cp_0_cp_0 = component;
                    expr_415_cp_0_cp_0.target.x = expr_415_cp_0_cp_0.target.x - num7;
                    SpringPosition expr_427_cp_0_cp_0 = component;
                    expr_427_cp_0_cp_0.target.y = expr_427_cp_0_cp_0.target.y - num8;
                }
                else
                {
                    Vector3 localPosition2 = child.localPosition;
                    localPosition2.x   -= num7;
                    localPosition2.y   -= num8;
                    child.localPosition = localPosition2;
                }
            }
        }
    }
Esempio n. 20
0
    protected override void ResetPosition(List <Transform> list)
    {
        if (!VariableChildSize)
        {
            base.ResetPosition(list);
            return;
        }
        mReposition = false;

        // Epic hack: Unparent all children so that we get to control the order in which they are re-added back in
        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;
        Vector3   pos     = Vector3.zero;

        // 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];
            t.parent = myTrans;

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

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

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

            UIWidget wid = t.GetComponentInChildren <UIMyGridItem>();
            if (wid != null)
            {
                if (arrangement == Arrangement.Horizontal)
                {
                    if (x > 0)
                    {
                        pos.x += wid.width;
                    }
                    if (y > 0)
                    {
                        pos.y -= wid.height;
                    }
                }
                else
                {
                    if (y > 0)
                    {
                        pos.x += wid.width;
                    }
                    if (x > 0)
                    {
                        pos.y -= wid.height;
                    }
                }
            }
        }

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

            float fx, fy;
            fx = Mathf.Lerp(0f, maxX, po.x);
            fy = Mathf.Lerp(maxY, 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 pos1 = t.localPosition;
                    pos1.x         -= fx;
                    pos1.y         -= fy;
                    t.localPosition = pos1;
                }
            }
        }
    }
Esempio n. 21
0
    protected void RepositionVariableSize(List <Transform> children)
    {
        //IL_0090: Unknown result type (might be due to invalid IL or missing references)
        //IL_0095: Unknown result type (might be due to invalid IL or missing references)
        //IL_0099: Unknown result type (might be due to invalid IL or missing references)
        //IL_009e: Unknown result type (might be due to invalid IL or missing references)
        //IL_00a4: Unknown result type (might be due to invalid IL or missing references)
        //IL_00a9: Unknown result type (might be due to invalid IL or missing references)
        //IL_00ab: Unknown result type (might be due to invalid IL or missing references)
        //IL_00b9: Unknown result type (might be due to invalid IL or missing references)
        //IL_00be: Unknown result type (might be due to invalid IL or missing references)
        //IL_00c0: Unknown result type (might be due to invalid IL or missing references)
        //IL_00d0: Unknown result type (might be due to invalid IL or missing references)
        //IL_00d2: Unknown result type (might be due to invalid IL or missing references)
        //IL_00e0: Unknown result type (might be due to invalid IL or missing references)
        //IL_00f0: Unknown result type (might be due to invalid IL or missing references)
        //IL_0139: Unknown result type (might be due to invalid IL or missing references)
        //IL_013e: Unknown result type (might be due to invalid IL or missing references)
        //IL_0160: Unknown result type (might be due to invalid IL or missing references)
        //IL_0165: Unknown result type (might be due to invalid IL or missing references)
        //IL_0170: Unknown result type (might be due to invalid IL or missing references)
        //IL_0175: Unknown result type (might be due to invalid IL or missing references)
        //IL_0180: Unknown result type (might be due to invalid IL or missing references)
        //IL_0185: Unknown result type (might be due to invalid IL or missing references)
        //IL_0189: Unknown result type (might be due to invalid IL or missing references)
        //IL_018e: Unknown result type (might be due to invalid IL or missing references)
        //IL_0195: Unknown result type (might be due to invalid IL or missing references)
        //IL_019a: Unknown result type (might be due to invalid IL or missing references)
        //IL_01a6: Unknown result type (might be due to invalid IL or missing references)
        //IL_01ab: Unknown result type (might be due to invalid IL or missing references)
        //IL_01c9: Unknown result type (might be due to invalid IL or missing references)
        //IL_01ce: Unknown result type (might be due to invalid IL or missing references)
        //IL_01d9: Unknown result type (might be due to invalid IL or missing references)
        //IL_01de: Unknown result type (might be due to invalid IL or missing references)
        //IL_01ea: Unknown result type (might be due to invalid IL or missing references)
        //IL_01ef: Unknown result type (might be due to invalid IL or missing references)
        //IL_01fb: Unknown result type (might be due to invalid IL or missing references)
        //IL_0200: Unknown result type (might be due to invalid IL or missing references)
        //IL_0239: Unknown result type (might be due to invalid IL or missing references)
        //IL_023e: Unknown result type (might be due to invalid IL or missing references)
        //IL_024a: Unknown result type (might be due to invalid IL or missing references)
        //IL_024f: Unknown result type (might be due to invalid IL or missing references)
        //IL_0268: Unknown result type (might be due to invalid IL or missing references)
        //IL_026d: Unknown result type (might be due to invalid IL or missing references)
        //IL_0278: Unknown result type (might be due to invalid IL or missing references)
        //IL_027d: Unknown result type (might be due to invalid IL or missing references)
        //IL_0289: Unknown result type (might be due to invalid IL or missing references)
        //IL_028e: Unknown result type (might be due to invalid IL or missing references)
        //IL_029a: Unknown result type (might be due to invalid IL or missing references)
        //IL_029f: Unknown result type (might be due to invalid IL or missing references)
        //IL_02d6: Unknown result type (might be due to invalid IL or missing references)
        //IL_02db: Unknown result type (might be due to invalid IL or missing references)
        //IL_02e7: Unknown result type (might be due to invalid IL or missing references)
        //IL_02ec: Unknown result type (might be due to invalid IL or missing references)
        //IL_030a: Unknown result type (might be due to invalid IL or missing references)
        //IL_030f: Unknown result type (might be due to invalid IL or missing references)
        //IL_031a: Unknown result type (might be due to invalid IL or missing references)
        //IL_031f: Unknown result type (might be due to invalid IL or missing references)
        //IL_032b: Unknown result type (might be due to invalid IL or missing references)
        //IL_0330: Unknown result type (might be due to invalid IL or missing references)
        //IL_033c: Unknown result type (might be due to invalid IL or missing references)
        //IL_0341: Unknown result type (might be due to invalid IL or missing references)
        //IL_036c: Unknown result type (might be due to invalid IL or missing references)
        //IL_0371: Unknown result type (might be due to invalid IL or missing references)
        //IL_0390: Unknown result type (might be due to invalid IL or missing references)
        //IL_03c7: Unknown result type (might be due to invalid IL or missing references)
        //IL_03cc: Unknown result type (might be due to invalid IL or missing references)
        //IL_0409: Unknown result type (might be due to invalid IL or missing references)
        //IL_040e: Unknown result type (might be due to invalid IL or missing references)
        //IL_0411: Unknown result type (might be due to invalid IL or missing references)
        //IL_0416: Expected O, but got Unknown
        //IL_0416: Unknown result type (might be due to invalid IL or missing references)
        //IL_041b: Unknown result type (might be due to invalid IL or missing references)
        //IL_0424: Unknown result type (might be due to invalid IL or missing references)
        //IL_0429: Unknown result type (might be due to invalid IL or missing references)
        //IL_0442: Unknown result type (might be due to invalid IL or missing references)
        //IL_0447: Unknown result type (might be due to invalid IL or missing references)
        //IL_0465: Unknown result type (might be due to invalid IL or missing references)
        //IL_046a: Expected O, but got Unknown
        //IL_0478: Unknown result type (might be due to invalid IL or missing references)
        //IL_047d: Expected O, but got Unknown
        //IL_04c6: Unknown result type (might be due to invalid IL or missing references)
        //IL_04cb: Unknown result type (might be due to invalid IL or missing references)
        //IL_04ef: Unknown result type (might be due to invalid IL or missing references)
        float num  = 0f;
        float num2 = 0f;
        int   num3 = (columns <= 0) ? 1 : (children.Count / columns + 1);
        int   num4 = (columns <= 0) ? children.Count : columns;

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

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

        for (int count2 = children.Count; j < count2; j++)
        {
            Transform val3          = children[j];
            Bounds    val4          = array[num6, num5];
            Bounds    val5          = array2[num5];
            Bounds    val6          = array3[num6];
            Vector3   localPosition = val3.get_localPosition();
            float     num7          = num;
            Vector3   extents       = val4.get_extents();
            float     num8          = num7 + extents.x;
            Vector3   center        = val4.get_center();
            localPosition.x = num8 - center.x;
            float   x     = localPosition.x;
            Vector3 max   = val4.get_max();
            float   x2    = max.x;
            Vector3 min   = val4.get_min();
            float   num9  = x2 - min.x;
            Vector3 max2  = val5.get_max();
            float   num10 = num9 - max2.x;
            Vector3 min2  = val5.get_min();
            localPosition.x = x - (Mathf.Lerp(0f, num10 + min2.x, pivotOffset.x) - padding.x);
            if (direction == Direction.Down)
            {
                float   num11    = 0f - num2;
                Vector3 extents2 = val4.get_extents();
                float   num12    = num11 - extents2.y;
                Vector3 center2  = val4.get_center();
                localPosition.y = num12 - center2.y;
                float   y     = localPosition.y;
                Vector3 max3  = val4.get_max();
                float   y2    = max3.y;
                Vector3 min3  = val4.get_min();
                float   num13 = y2 - min3.y;
                Vector3 max4  = val6.get_max();
                float   num14 = num13 - max4.y;
                Vector3 min4  = val6.get_min();
                localPosition.y = y + (Mathf.Lerp(num14 + min4.y, 0f, pivotOffset.y) - padding.y);
            }
            else
            {
                float   num15    = num2;
                Vector3 extents3 = val4.get_extents();
                float   num16    = num15 + extents3.y;
                Vector3 center3  = val4.get_center();
                localPosition.y = num16 - center3.y;
                float   y3    = localPosition.y;
                Vector3 max5  = val4.get_max();
                float   y4    = max5.y;
                Vector3 min5  = val4.get_min();
                float   num17 = y4 - min5.y;
                Vector3 max6  = val6.get_max();
                float   num18 = num17 - max6.y;
                Vector3 min6  = val6.get_min();
                localPosition.y = y3 - (Mathf.Lerp(0f, num18 + min6.y, pivotOffset.y) - padding.y);
            }
            float   num19 = num;
            Vector3 size  = val5.get_size();
            num = num19 + (size.x + padding.x * 2f);
            val3.set_localPosition(localPosition);
            if (++num5 >= columns && columns > 0)
            {
                num5 = 0;
                num6++;
                num = 0f;
                float   num20 = num2;
                Vector3 size2 = val6.get_size();
                num2 = num20 + (size2.y + padding.y * 2f);
            }
        }
        if (pivot != 0)
        {
            pivotOffset = NGUIMath.GetPivotOffset(pivot);
            Bounds    val7  = NGUIMath.CalculateRelativeWidgetBounds(this.get_transform());
            Vector3   size3 = val7.get_size();
            float     num21 = Mathf.Lerp(0f, size3.x, pivotOffset.x);
            Vector3   size4 = val7.get_size();
            float     num22 = Mathf.Lerp(0f - size4.y, 0f, pivotOffset.y);
            Transform val8  = this.get_transform();
            for (int k = 0; k < val8.get_childCount(); k++)
            {
                Transform      val9      = val8.GetChild(k);
                SpringPosition component = val9.GetComponent <SpringPosition>();
                if (component != null)
                {
                    component.target.x -= num21;
                    component.target.y -= num22;
                }
                else
                {
                    Vector3 localPosition2 = val9.get_localPosition();
                    localPosition2.x -= num21;
                    localPosition2.y -= num22;
                    val9.set_localPosition(localPosition2);
                }
            }
        }
    }
Esempio n. 22
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;
                }
            }
        }
    }