CalculateConstrainOffset() public method

Calculate the offset needed to be constrained within the panel's bounds.
public CalculateConstrainOffset ( Vector2 min, Vector2 max ) : Vector3
min Vector2
max Vector2
return Vector3
Ejemplo n.º 1
0
    /// <summary>
    /// Restrict the panel's contents to be within the panel's bounds.
    /// </summary>

    public bool RestrictWithinBounds(bool instant)
    {
        Vector3 constraint = mPanel.CalculateConstrainOffset(bounds.min, bounds.max);

        if (constraint.magnitude > 0.001f)
        {
            if (!instant && dragEffect == DragEffect.MomentumAndSpring)
            {
                // Spring back into place
                SpringPanel.Begin(mPanel.gameObject, mTrans.localPosition + constraint, 13f);
            }
            else
            {
                // Jump back into place
                MoveRelative(constraint);
                mMomentum = Vector3.zero;
                mScroll   = 0f;
            }
            return(true);
        }
        return(false);
    }
Ejemplo n.º 2
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)
    {
        Bounds  b          = bounds;
        Vector3 constraint = mPanel.CalculateConstrainOffset(b.min, b.max);

        if (!horizontal)
        {
            constraint.x = 0f;
        }
        if (!vertical)
        {
            constraint.y = 0f;
        }

        if (constraint.sqrMagnitude > 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);
                mSpring = true;
                SpringPanel sp = SpringPanel.Begin(mPanel.gameObject, pos, 13f);
                sp.onFinished = OnSpringPanelFinished;
            }
            else
            {
                // Jump back into place
                MoveRelative(constraint);
                mMomentum = Vector3.zero;
                mScroll   = 0f;
            }
            return(true);
        }
        return(false);
    }
Ejemplo n.º 3
0
    void OnPress(bool pressed)
    {
        //Debug.Log("DragPanel Pressed: " + pressed);
        if (pressed)
        {
            last_position = UICamera.lastHit.point;
            // Create the plane to drag along
            plane = new Plane(mTrans.rotation * Vector3.back, last_position);
            //is_pressed = true;
            is_tranform = false;
        }
        else
        {
            is_tranform = true;
            Vector3 distance = Vector3.zero;
            if (!scrollByPage)    //
            {
                distance = panel.CalculateConstrainOffset(bounds.min, bounds.max);
                if (distance.magnitude > 0.001f)
                {
                    target_position = mTrans.localPosition + distance;
                }
            }
            else    //处理整页滑动
            {
                int currentPage = 1;

                interval = (bounds.max - bounds.min) / pages;
                if (dragType == DragType.Vertical)
                {
                    currentPage = (int)Mathf.Ceil((mTrans.localPosition.y - localPosition.y) / interval.y);
                    currentPage = Mathf.Clamp(currentPage, 1, pages);
                    distance.x  = localPosition.x;
                    distance.y  = localPosition.y + (currentPage - 1) * interval.y;
                }
                else if (dragType == DragType.Horizontal)
                {
                    currentPage = (int)Mathf.Ceil((mTrans.localPosition.x - localPosition.x) / interval.x); //上取整数
                    currentPage = Mathf.Clamp(currentPage, 1, pages);                                       //判断页数
                    distance.y  = localPosition.y;
                    distance.x  = localPosition.x + (currentPage - 1) * interval.x;
                    //distance = panel.CalculateConstrainOffset(new Vector3( bounds.min.x + interval.x * (currentPage - 1), bounds.min.y, bounds.min.z), new Vector3(bounds.min.x + interval.x * currentPage, bounds.max.y, bounds.min.z));
                }
                target_position = distance;
            }
        }
    }
Ejemplo n.º 4
0
 static int CalculateConstrainOffset(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 3);
         UIPanel             obj  = (UIPanel)ToLua.CheckObject <UIPanel>(L, 1);
         UnityEngine.Vector2 arg0 = ToLua.ToVector2(L, 2);
         UnityEngine.Vector2 arg1 = ToLua.ToVector2(L, 3);
         UnityEngine.Vector3 o    = obj.CalculateConstrainOffset(arg0, arg1);
         ToLua.Push(L, o);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Ejemplo n.º 5
0
 static public int CalculateConstrainOffset(IntPtr l)
 {
     try {
         UIPanel             self = (UIPanel)checkSelf(l);
         UnityEngine.Vector2 a1;
         checkType(l, 2, out a1);
         UnityEngine.Vector2 a2;
         checkType(l, 3, out a2);
         var ret = self.CalculateConstrainOffset(a1, a2);
         pushValue(l, true);
         pushValue(l, ret);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Ejemplo n.º 6
0
    public void RestrictWithinBounds(bool instant)
    {
        UIPanel uIPanel = this.mPanel;
        AABBox  aABBox  = this.bounds;
        Vector3 vector3 = uIPanel.CalculateConstrainOffset(aABBox.min, this.bounds.max);

        if (vector3.magnitude <= 0.001f)
        {
            this.DisableSpring();
        }
        else if (instant || this.dragEffect != UIDraggablePanel.DragEffect.MomentumAndSpring)
        {
            this.MoveRelative(vector3);
            this.mMomentum = Vector3.zero;
            this.mScroll   = 0f;
        }
        else
        {
            SpringPanel.Begin(this.mPanel.gameObject, this.mTrans.localPosition + vector3, 13f);
        }
    }
    /// <summary>
    /// Show the popup list dialog.
    /// </summary>

    public void Show()
    {
        if (enabled && NGUITools.GetActive(gameObject) && mChild == null && atlas != null && isValid && items.Count > 0)
        {
            mLabelList.Clear();
            StopCoroutine("CloseIfUnselected");

            // Ensure the popup's source has the selection
            UICamera.selectedObject = (UICamera.hoveredObject ?? gameObject);
            mSelection = UICamera.selectedObject;
            source     = UICamera.selectedObject;

            if (source == null)
            {
                Debug.LogError("Popup list needs a source object...");
                return;
            }

            mOpenFrame = Time.frameCount;

            // Automatically locate the panel responsible for this object
            if (mPanel == null)
            {
                mPanel = UIPanel.Find(transform);
                if (mPanel == null)
                {
                    return;
                }
            }

            // Calculate the dimensions of the object triggering the popup list so we can position it below it
            Vector3 min;
            Vector3 max;

            // Create the root object for the list
            mChild       = new GameObject("Drop-down List");
            mChild.layer = gameObject.layer;
            current      = this;

            Transform t = mChild.transform;
            t.parent = mPanel.cachedTransform;
            Vector3 pos;

            // Manually triggered popup list on some other game object
            if (openOn == OpenOn.Manual && mSelection != gameObject)
            {
                pos             = UICamera.lastEventPosition;
                min             = mPanel.cachedTransform.InverseTransformPoint(mPanel.anchorCamera.ScreenToWorldPoint(pos));
                max             = min;
                t.localPosition = min;
                pos             = t.position;
            }
            else
            {
                Bounds bounds = NGUIMath.CalculateRelativeWidgetBounds(mPanel.cachedTransform, transform, false, false);
                min             = bounds.min;
                max             = bounds.max;
                t.localPosition = min;
                pos             = t.position;
            }

            StartCoroutine("CloseIfUnselected");

            t.localRotation = Quaternion.identity;
            t.localScale    = Vector3.one;

            // Add a sprite for the background
            mBackground       = NGUITools.AddSprite(mChild, atlas, backgroundSprite);
            mBackground.pivot = UIWidget.Pivot.TopLeft;
            mBackground.depth = NGUITools.CalculateNextDepth(mPanel.gameObject);
            mBackground.color = backgroundColor;

            // We need to know the size of the background sprite for padding purposes
            Vector4 bgPadding = mBackground.border;
            mBgBorder = bgPadding.y;
            mBackground.cachedTransform.localPosition = new Vector3(0f, bgPadding.y, 0f);

            // Add a sprite used for the selection
            mHighlight       = NGUITools.AddSprite(mChild, atlas, highlightSprite);
            mHighlight.pivot = UIWidget.Pivot.TopLeft;
            mHighlight.color = highlightColor;

            UISpriteData hlsp = mHighlight.GetAtlasSprite();
            if (hlsp == null)
            {
                return;
            }

            float          hlspHeight = hlsp.borderTop;
            float          fontHeight = activeFontSize;
            float          dynScale = activeFontScale;
            float          labelHeight = fontHeight * dynScale;
            float          x = 0f, y = -padding.y;
            List <UILabel> labels = new List <UILabel>();

            // Clear the selection if it's no longer present
            if (!items.Contains(mSelectedItem))
            {
                mSelectedItem = null;
            }

            // Run through all items and create labels for each one
            for (int i = 0, imax = items.Count; i < imax; ++i)
            {
                string s = items[i];

                UILabel lbl = NGUITools.AddWidget <UILabel>(mChild);
                lbl.name         = i.ToString();
                lbl.pivot        = UIWidget.Pivot.TopLeft;
                lbl.bitmapFont   = bitmapFont;
                lbl.trueTypeFont = trueTypeFont;
                lbl.fontSize     = fontSize;
                lbl.fontStyle    = fontStyle;
                lbl.text         = isLocalized ? Localization.Get(s) : s;
                lbl.color        = textColor;
                lbl.cachedTransform.localPosition = new Vector3(bgPadding.x + padding.x - lbl.pivotOffset.x, y, -1f);
                lbl.overflowMethod = UILabel.Overflow.ResizeFreely;
                lbl.alignment      = alignment;
                labels.Add(lbl);

                y -= labelHeight;
                y -= padding.y;
                x  = Mathf.Max(x, lbl.printedSize.x);

                // Add an event listener
                UIEventListener listener = UIEventListener.Get(lbl.gameObject);
                listener.onHover   = OnItemHover;
                listener.onPress   = OnItemPress;
                listener.parameter = s;

                // Move the selection here if this is the right label
                if (mSelectedItem == s || (i == 0 && string.IsNullOrEmpty(mSelectedItem)))
                {
                    Highlight(lbl, true);
                }

                // Add this label to the list
                mLabelList.Add(lbl);
            }

            // The triggering widget's width should be the minimum allowed width
            x = Mathf.Max(x, (max.x - min.x) - (bgPadding.x + padding.x) * 2f);

            float   cx       = x;
            Vector3 bcCenter = new Vector3(cx * 0.5f, -labelHeight * 0.5f, 0f);
            Vector3 bcSize   = new Vector3(cx, (labelHeight + padding.y), 1f);

            // Run through all labels and add colliders
            for (int i = 0, imax = labels.Count; i < imax; ++i)
            {
                UILabel lbl = labels[i];
                NGUITools.AddWidgetCollider(lbl.gameObject);
                lbl.autoResizeBoxCollider = false;
                BoxCollider bc = lbl.GetComponent <BoxCollider>();

                if (bc != null)
                {
                    bcCenter.z = bc.center.z;
                    bc.center  = bcCenter;
                    bc.size    = bcSize;
                }
                else
                {
                    BoxCollider2D b2d = lbl.GetComponent <BoxCollider2D>();
#if UNITY_4_3 || UNITY_4_5 || UNITY_4_6
                    b2d.center = bcCenter;
#else
                    b2d.offset = bcCenter;
#endif
                    b2d.size = bcSize;
                }
            }

            int lblWidth = Mathf.RoundToInt(x);
            x += (bgPadding.x + padding.x) * 2f;
            y -= bgPadding.y;

            // Scale the background sprite to envelop the entire set of items
            mBackground.width  = Mathf.RoundToInt(x);
            mBackground.height = Mathf.RoundToInt(-y + bgPadding.y);

            // Set the label width to make alignment work
            for (int i = 0, imax = labels.Count; i < imax; ++i)
            {
                UILabel lbl = labels[i];
                lbl.overflowMethod = UILabel.Overflow.ShrinkContent;
                lbl.width          = lblWidth;
            }

            // Scale the highlight sprite to envelop a single item
            float scaleFactor = 2f * atlas.pixelSize;
            float w           = x - (bgPadding.x + padding.x) * 2f + hlsp.borderLeft * scaleFactor;
            float h           = labelHeight + hlspHeight * scaleFactor;
            mHighlight.width  = Mathf.RoundToInt(w);
            mHighlight.height = Mathf.RoundToInt(h);

            bool placeAbove = (position == Position.Above);

            if (position == Position.Auto)
            {
                UICamera cam = UICamera.FindCameraForLayer(mSelection.layer);

                if (cam != null)
                {
                    Vector3 viewPos = cam.cachedCamera.WorldToViewportPoint(pos);
                    placeAbove = (viewPos.y < 0.5f);
                }
            }

            // If the list should be animated, let's animate it by expanding it
            if (isAnimated)
            {
                AnimateColor(mBackground);

                if (Time.timeScale == 0f || Time.timeScale >= 0.1f)
                {
                    float bottom = y + labelHeight;
                    Animate(mHighlight, placeAbove, bottom);
                    for (int i = 0, imax = labels.Count; i < imax; ++i)
                    {
                        Animate(labels[i], placeAbove, bottom);
                    }
                    AnimateScale(mBackground, placeAbove, bottom);
                }
            }

            // If we need to place the popup list above the item, we need to reposition everything by the size of the list
            if (placeAbove)
            {
                min.y           = max.y - bgPadding.y;
                max.y           = min.y + mBackground.height;
                max.x           = min.x + mBackground.width;
                t.localPosition = new Vector3(min.x, max.y - bgPadding.y, min.z);
            }
            else
            {
                max.y = min.y + bgPadding.y;
                min.y = max.y - mBackground.height;
                max.x = min.x + mBackground.width;
            }

            Transform pt = mPanel.cachedTransform.parent;

            if (pt != null)
            {
                min = mPanel.cachedTransform.TransformPoint(min);
                max = mPanel.cachedTransform.TransformPoint(max);
                min = pt.InverseTransformPoint(min);
                max = pt.InverseTransformPoint(max);
            }

            // Ensure that everything fits into the panel's visible range
            Vector3 offset = mPanel.hasClipping ? Vector3.zero : mPanel.CalculateConstrainOffset(min, max);
            pos             = t.localPosition + offset;
            pos.x           = Mathf.Round(pos.x);
            pos.y           = Mathf.Round(pos.y);
            t.localPosition = pos;
        }
        else
        {
            OnSelect(false);
        }
    }
Ejemplo n.º 8
0
    // Token: 0x060002AE RID: 686 RVA: 0x0001AAA4 File Offset: 0x00018CA4
    public virtual void Show()
    {
        if (!base.enabled || !NGUITools.GetActive(base.gameObject) || !(UIPopupList.mChild == null) || !this.isValid || this.items.Count <= 0)
        {
            this.OnSelect(false);
            return;
        }
        this.mLabelList.Clear();
        base.StopCoroutine("CloseIfUnselected");
        UICamera.selectedObject = (UICamera.hoveredObject ?? base.gameObject);
        this.mSelection         = UICamera.selectedObject;
        this.source             = this.mSelection;
        if (this.source == null)
        {
            Debug.LogError("Popup list needs a source object...");
            return;
        }
        this.mOpenFrame = Time.frameCount;
        if (this.mPanel == null)
        {
            this.mPanel = UIPanel.Find(base.transform);
            if (this.mPanel == null)
            {
                return;
            }
        }
        UIPopupList.mChild       = new GameObject("Drop-down List");
        UIPopupList.mChild.layer = base.gameObject.layer;
        if (this.separatePanel)
        {
            if (base.GetComponent <Collider>() != null)
            {
                UIPopupList.mChild.AddComponent <Rigidbody>().isKinematic = true;
            }
            else if (base.GetComponent <Collider2D>() != null)
            {
                UIPopupList.mChild.AddComponent <Rigidbody2D>().isKinematic = true;
            }
            UIPanel uipanel = UIPopupList.mChild.AddComponent <UIPanel>();
            uipanel.depth        = 1000000;
            uipanel.sortingOrder = this.mPanel.sortingOrder;
        }
        UIPopupList.current = this;
        Transform cachedTransform = this.mPanel.cachedTransform;
        Transform transform       = UIPopupList.mChild.transform;

        transform.parent = cachedTransform;
        Transform parent = cachedTransform;

        if (this.separatePanel)
        {
            UIRoot uiroot = this.mPanel.GetComponentInParent <UIRoot>();
            if (uiroot == null && UIRoot.list.Count != 0)
            {
                uiroot = UIRoot.list[0];
            }
            if (uiroot != null)
            {
                parent = uiroot.transform;
            }
        }
        Vector3 vector;
        Vector3 vector2;

        if (this.openOn == UIPopupList.OpenOn.Manual && this.mSelection != base.gameObject)
        {
            this.startingPosition = UICamera.lastEventPosition;
            vector  = cachedTransform.InverseTransformPoint(this.mPanel.anchorCamera.ScreenToWorldPoint(this.startingPosition));
            vector2 = vector;
            transform.localPosition = vector;
            this.startingPosition   = transform.position;
        }
        else
        {
            Bounds bounds = NGUIMath.CalculateRelativeWidgetBounds(cachedTransform, base.transform, false, false);
            vector  = bounds.min;
            vector2 = bounds.max;
            transform.localPosition = vector;
            this.startingPosition   = transform.position;
        }
        base.StartCoroutine("CloseIfUnselected");
        float fitScale = this.fitScale;

        transform.localRotation = Quaternion.identity;
        transform.localScale    = new Vector3(fitScale, fitScale, fitScale);
        int num = this.separatePanel ? 0 : NGUITools.CalculateNextDepth(this.mPanel.gameObject);

        if (this.background2DSprite != null)
        {
            UI2DSprite ui2DSprite = UIPopupList.mChild.AddWidget(num);
            ui2DSprite.sprite2D = this.background2DSprite;
            this.mBackground    = ui2DSprite;
        }
        else
        {
            if (!(this.atlas != null))
            {
                return;
            }
            this.mBackground = UIPopupList.mChild.AddSprite(this.atlas as INGUIAtlas, this.backgroundSprite, num);
        }
        bool flag = this.position == UIPopupList.Position.Above;

        if (this.position == UIPopupList.Position.Auto)
        {
            UICamera uicamera = UICamera.FindCameraForLayer(this.mSelection.layer);
            if (uicamera != null)
            {
                flag = (uicamera.cachedCamera.WorldToViewportPoint(this.startingPosition).y < 0.5f);
            }
        }
        this.mBackground.pivot = UIWidget.Pivot.TopLeft;
        this.mBackground.color = this.backgroundColor;
        Vector4 border = this.mBackground.border;

        this.mBgBorder = border.y;
        this.mBackground.cachedTransform.localPosition = new Vector3(0f, flag ? (border.y * 2f - (float)this.overlap) : ((float)this.overlap), 0f);
        if (this.highlight2DSprite != null)
        {
            UI2DSprite ui2DSprite2 = UIPopupList.mChild.AddWidget(num + 1);
            ui2DSprite2.sprite2D = this.highlight2DSprite;
            this.mHighlight      = ui2DSprite2;
        }
        else
        {
            if (!(this.atlas != null))
            {
                return;
            }
            this.mHighlight = UIPopupList.mChild.AddSprite(this.atlas as INGUIAtlas, this.highlightSprite, num + 1);
        }
        float num2 = 0f;
        float num3 = 0f;

        if (this.mHighlight.hasBorder)
        {
            num2 = this.mHighlight.border.w;
            num3 = this.mHighlight.border.x;
        }
        this.mHighlight.pivot = UIWidget.Pivot.TopLeft;
        this.mHighlight.color = this.highlightColor;
        float          num4 = (float)this.activeFontSize * this.activeFontScale;
        float          num5 = num4 + this.padding.y;
        float          num6 = 0f;
        float          num7 = flag ? (border.y - this.padding.y - (float)this.overlap) : (-this.padding.y - border.y + (float)this.overlap);
        float          num8 = border.y * 2f + this.padding.y;
        List <UILabel> list = new List <UILabel>();

        if (!this.items.Contains(this.mSelectedItem))
        {
            this.mSelectedItem = null;
        }
        int i     = 0;
        int count = this.items.Count;

        while (i < count)
        {
            string  text    = this.items[i];
            UILabel uilabel = UIPopupList.mChild.AddWidget(this.mBackground.depth + 2);
            uilabel.name         = i.ToString();
            uilabel.pivot        = UIWidget.Pivot.TopLeft;
            uilabel.bitmapFont   = (this.bitmapFont as INGUIFont);
            uilabel.trueTypeFont = this.trueTypeFont;
            uilabel.fontSize     = this.fontSize;
            uilabel.fontStyle    = this.fontStyle;
            uilabel.text         = (this.isLocalized ? Localization.Get(text, true) : text);
            uilabel.modifier     = this.textModifier;
            uilabel.color        = this.textColor;
            uilabel.cachedTransform.localPosition = new Vector3(border.x + this.padding.x - uilabel.pivotOffset.x, num7, -1f);
            uilabel.overflowMethod = UILabel.Overflow.ResizeFreely;
            uilabel.alignment      = this.alignment;
            uilabel.symbolStyle    = NGUIText.SymbolStyle.Colored;
            list.Add(uilabel);
            num8 += num5;
            num7 -= num5;
            num6  = Mathf.Max(num6, uilabel.printedSize.x);
            UIEventListener uieventListener = UIEventListener.Get(uilabel.gameObject);
            uieventListener.onHover   = new UIEventListener.BoolDelegate(this.OnItemHover);
            uieventListener.onPress   = new UIEventListener.BoolDelegate(this.OnItemPress);
            uieventListener.onClick   = new UIEventListener.VoidDelegate(this.OnItemClick);
            uieventListener.parameter = text;
            if (this.mSelectedItem == text || (i == 0 && string.IsNullOrEmpty(this.mSelectedItem)))
            {
                this.Highlight(uilabel, true);
            }
            this.mLabelList.Add(uilabel);
            i++;
        }
        num6 = Mathf.Max(num6, vector2.x - vector.x - (border.x + this.padding.x) * 2f);
        float   num9    = num6;
        Vector3 vector3 = new Vector3(num9 * 0.5f, -num4 * 0.5f, 0f);
        Vector3 vector4 = new Vector3(num9, num4 + this.padding.y, 1f);
        int     j       = 0;
        int     count2  = list.Count;

        while (j < count2)
        {
            UILabel uilabel2 = list[j];
            NGUITools.AddWidgetCollider(uilabel2.gameObject);
            uilabel2.autoResizeBoxCollider = false;
            BoxCollider component = uilabel2.GetComponent <BoxCollider>();
            if (component != null)
            {
                vector3.z        = component.center.z;
                component.center = vector3;
                component.size   = vector4;
            }
            else
            {
                BoxCollider2D component2 = uilabel2.GetComponent <BoxCollider2D>();
                component2.offset = vector3;
                component2.size   = vector4;
            }
            j++;
        }
        int width = Mathf.RoundToInt(num6);

        num6 += (border.x + this.padding.x) * 2f;
        num7 -= border.y;
        this.mBackground.width  = Mathf.RoundToInt(num6);
        this.mBackground.height = Mathf.RoundToInt(num8);
        int k      = 0;
        int count3 = list.Count;

        while (k < count3)
        {
            UILabel uilabel3 = list[k];
            uilabel3.overflowMethod = UILabel.Overflow.ShrinkContent;
            uilabel3.width          = width;
            k++;
        }
        float      num10      = 2f;
        INGUIAtlas inguiatlas = this.atlas as INGUIAtlas;

        if (inguiatlas != null)
        {
            num10 *= inguiatlas.pixelSize;
        }
        float f  = num6 - (border.x + this.padding.x) * 2f + num3 * num10;
        float f2 = num4 + num2 * num10;

        this.mHighlight.width  = Mathf.RoundToInt(f);
        this.mHighlight.height = Mathf.RoundToInt(f2);
        if (this.isAnimated)
        {
            this.AnimateColor(this.mBackground);
            if (Time.timeScale == 0f || Time.timeScale >= 0.1f)
            {
                float bottom = num7 + num4;
                this.Animate(this.mHighlight, flag, bottom);
                int l      = 0;
                int count4 = list.Count;
                while (l < count4)
                {
                    this.Animate(list[l], flag, bottom);
                    l++;
                }
                this.AnimateScale(this.mBackground, flag, bottom);
            }
        }
        if (flag)
        {
            float num11 = border.y * fitScale;
            vector.y  = vector2.y - border.y * fitScale;
            vector2.y = vector.y + ((float)this.mBackground.height - border.y * 2f) * fitScale;
            vector2.x = vector.x + (float)this.mBackground.width * fitScale;
            transform.localPosition = new Vector3(vector.x, vector2.y - num11, vector.z);
        }
        else
        {
            vector2.y = vector.y + border.y * fitScale;
            vector.y  = vector2.y - (float)this.mBackground.height * fitScale;
            vector2.x = vector.x + (float)this.mBackground.width * fitScale;
        }
        UIPanel uipanel2 = this.mPanel;

        for (;;)
        {
            UIRect parent2 = uipanel2.parent;
            if (parent2 == null)
            {
                break;
            }
            UIPanel componentInParent = parent2.GetComponentInParent <UIPanel>();
            if (componentInParent == null)
            {
                break;
            }
            uipanel2 = componentInParent;
        }
        if (cachedTransform != null)
        {
            vector  = cachedTransform.TransformPoint(vector);
            vector2 = cachedTransform.TransformPoint(vector2);
            vector  = uipanel2.cachedTransform.InverseTransformPoint(vector);
            vector2 = uipanel2.cachedTransform.InverseTransformPoint(vector2);
            float pixelSizeAdjustment = UIRoot.GetPixelSizeAdjustment(base.gameObject);
            vector  /= pixelSizeAdjustment;
            vector2 /= pixelSizeAdjustment;
        }
        Vector3 b       = uipanel2.CalculateConstrainOffset(vector, vector2);
        Vector3 vector5 = transform.localPosition + b;

        vector5.x = Mathf.Round(vector5.x);
        vector5.y = Mathf.Round(vector5.y);
        transform.localPosition = vector5;
        transform.parent        = parent;
    }
Ejemplo n.º 9
0
    /// <summary>
    /// Restrict the panel's contents to be within the panel's bounds.
    /// </summary>

    public bool RestrictWithinBounds(bool instant)
    {
        Vector3 constraint = mPanel.CalculateConstrainOffset(bounds.min, bounds.max);

        if (restrictPanelMode != RestrictMode.None)
        {
            Vector3 minBounds = bounds.min;
            Vector3 maxBounds = bounds.max;

            float   offsetX = mPanel.clipRange.z * 0.5f;
            float   offsetY = mPanel.clipRange.w * 0.5f;
            Vector2 minArea = new Vector2(mPanel.clipRange.x - offsetX, mPanel.clipRange.y - offsetY);
            Vector2 maxArea = new Vector2(mPanel.clipRange.x + offsetX, mPanel.clipRange.y + offsetY);

            if (mPanel.clipping == UIDrawCall.Clipping.SoftClip)
            {
                minArea.x += mPanel.clipSoftness.x;
                minArea.y += mPanel.clipSoftness.y;
                maxArea.x -= mPanel.clipSoftness.x;
                maxArea.y -= mPanel.clipSoftness.y;
            }

            if (restrictPanelMode == RestrictMode.NegativeEdge)
            {
                if (minBounds.x > minArea.x)
                {
                    constraint.x = minArea.x - minBounds.x;
                }
                if (minBounds.y > minArea.y)
                {
                    constraint.y = minArea.y - minBounds.y;
                }
            }
            else if (restrictPanelMode == RestrictMode.PositiveEdge)
            {
                if (maxBounds.x < maxArea.x)
                {
                    constraint.x = maxArea.x - maxBounds.x;
                }
                if (maxBounds.y < maxArea.y)
                {
                    constraint.y = maxArea.y - maxBounds.y;
                }
            }
        }

        // fufeng modify: restrict only in scale
        if (Mathf.Approximately(scale.x, 0f))
        {
            constraint.x = 0f;
        }
        if (Mathf.Approximately(scale.y, 0f))
        {
            constraint.y = 0f;
        }
        if (Mathf.Approximately(scale.z, 0f))
        {
            constraint.z = 0f;
        }

        if (constraint.magnitude > 0.001f)
        {
            if (!instant && dragEffect == DragEffect.MomentumAndSpring)
            {
                // Spring back into place
                SpringPanel.Begin(mPanel.gameObject, mTrans.localPosition + constraint, 13f);
            }
            else
            {
                // Jump back into place
                MoveRelative(constraint, false);
                mMomentum = Vector3.zero;
                mScroll   = 0f;
            }
            return(true);
        }
        return(false);
    }
Ejemplo n.º 10
0
    //===============================================================================================


    public bool RestrictWithinBounds(Bounds bounds, bool instant, bool horizontal, bool vertical, bool constrainToTop, bool constrainToLeft)
    {
        // [modified] by wsh 2017/02/23
        // almost the same with original function except for adding params:bounds、constrainToTop、constrainToLeft
        if (mPanel == null)
        {
            return(false);
        }

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

        if (!horizontal)
        {
            constraint.x = 0f;
        }
        if (!vertical)
        {
            constraint.y = 0f;
        }

        //===============================================================================================
        // [added] by wsh
        // constrainToTop if vertical or constrainToLeft if horizontal
        if (restrictWithinPanel && vertical && constrainToTop && bounds.size.y < mPanel.finalClipRegion.w)
        {
            float offset = 0f;
            if (constraint.y >= 0.01f)
            {
                offset = mPanel.finalClipRegion.w - bounds.size.y;
            }
            else if (Mathf.Abs(constraint.y) < 0.01f)
            {
                offset = (mPanel.finalClipRegion.y + mPanel.finalClipRegion.w * 0.5f) - bounds.max.y;
            }

            if (offset != 0f && mPanel.softBorderPadding && mPanel.clipping == UIDrawCall.Clipping.SoftClip)
            {
                offset -= mPanel.clipSoftness.y;
            }
            constraint.y += offset;
        }

        if (restrictWithinPanel && horizontal && constrainToLeft && bounds.size.x < mPanel.finalClipRegion.z)
        {
            float offset = 0f;
            if (constraint.x <= -0.01f)
            {
                offset = mPanel.finalClipRegion.z - bounds.size.x;
            }
            else if (Mathf.Abs(constraint.x) < 0.01f)
            {
                offset = bounds.min.x - (mPanel.finalClipRegion.x - mPanel.finalClipRegion.z * 0.5f);
            }
            if (offset != 0f && mPanel.softBorderPadding && mPanel.clipping == UIDrawCall.Clipping.SoftClip)
            {
                offset -= mPanel.clipSoftness.x;
            }
            constraint.x -= offset;
        }
        //===============================================================================================

        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, 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);
    }
Ejemplo n.º 11
0
 public void Show()
 {
     if (base.enabled && NGUITools.GetActive(base.gameObject) && mChild == null && atlas != null && isValid && items.Count > 0)
     {
         mLabelList.Clear();
         if (mPanel == null)
         {
             mPanel = UIPanel.Find(base.transform);
             if (mPanel == null)
             {
                 return;
             }
         }
         handleEvents = true;
         Transform transform = base.transform;
         mChild       = new GameObject("Drop-down List");
         mChild.layer = base.gameObject.layer;
         Transform transform2 = mChild.transform;
         transform2.parent = transform.parent;
         base.StopCoroutine("CloseIfUnselected");
         if (UICamera.selectedObject == null)
         {
             mSelection = base.gameObject;
             UICamera.selectedObject = mSelection;
         }
         else
         {
             mSelection = UICamera.selectedObject;
         }
         Vector3 v;
         Vector3 vector2;
         Vector3 vector;
         if (openOn == OpenOn.Manual && mSelection != base.gameObject)
         {
             vector = transform2.parent.InverseTransformPoint(mPanel.anchorCamera.ScreenToWorldPoint(UICamera.lastTouchPosition));
             v      = vector;
             transform2.localPosition = vector;
             vector2 = transform2.position;
         }
         else
         {
             Bounds bounds = NGUIMath.CalculateRelativeWidgetBounds(transform.parent, transform, considerInactive: false, considerParents: false);
             vector = bounds.min;
             v      = bounds.max;
             transform2.localPosition = vector;
             vector2 = transform.position;
         }
         StartCoroutine("CloseIfUnselected");
         transform2.localRotation = Quaternion.identity;
         transform2.localScale    = Vector3.one;
         mBackground       = NGUITools.AddSprite(mChild, atlas, backgroundSprite);
         mBackground.pivot = UIWidget.Pivot.TopLeft;
         mBackground.depth = NGUITools.CalculateNextDepth(mPanel.gameObject);
         mBackground.color = backgroundColor;
         Vector4 border = mBackground.border;
         mBgBorder = border.y;
         mBackground.cachedTransform.localPosition = new Vector3(0f, border.y, 0f);
         mHighlight       = NGUITools.AddSprite(mChild, atlas, highlightSprite);
         mHighlight.pivot = UIWidget.Pivot.TopLeft;
         mHighlight.color = highlightColor;
         UISpriteData atlasSprite = mHighlight.GetAtlasSprite();
         if (atlasSprite == null)
         {
             return;
         }
         float          num             = atlasSprite.borderTop;
         float          num2            = activeFontSize;
         float          activeFontScale = this.activeFontScale;
         float          num3            = num2 * activeFontScale;
         float          num4            = 0f;
         float          num5            = 0f - padding.y;
         List <UILabel> list            = new List <UILabel>();
         if (!items.Contains(mSelectedItem))
         {
             mSelectedItem = null;
         }
         int i = 0;
         for (int count = items.Count; i < count; i++)
         {
             string  text    = items[i];
             UILabel uILabel = NGUITools.AddWidget <UILabel>(mChild);
             uILabel.name         = i.ToString();
             uILabel.pivot        = UIWidget.Pivot.TopLeft;
             uILabel.bitmapFont   = bitmapFont;
             uILabel.trueTypeFont = trueTypeFont;
             uILabel.fontSize     = fontSize;
             uILabel.fontStyle    = fontStyle;
             uILabel.text         = ((!isLocalized) ? text : Localization.Get(text));
             uILabel.color        = textColor;
             Transform cachedTransform = uILabel.cachedTransform;
             float     num6            = border.x + padding.x;
             Vector2   pivotOffset     = uILabel.pivotOffset;
             cachedTransform.localPosition = new Vector3(num6 - pivotOffset.x, num5, -1f);
             uILabel.overflowMethod        = UILabel.Overflow.ResizeFreely;
             uILabel.alignment             = alignment;
             list.Add(uILabel);
             num5 -= num3;
             num5 -= padding.y;
             float   a           = num4;
             Vector2 printedSize = uILabel.printedSize;
             num4 = Mathf.Max(a, printedSize.x);
             UIEventListener uIEventListener = UIEventListener.Get(uILabel.gameObject);
             uIEventListener.onHover   = OnItemHover;
             uIEventListener.onPress   = OnItemPress;
             uIEventListener.onClick   = OnItemClick;
             uIEventListener.parameter = text;
             if (mSelectedItem == text || (i == 0 && string.IsNullOrEmpty(mSelectedItem)))
             {
                 Highlight(uILabel, instant: true);
             }
             mLabelList.Add(uILabel);
         }
         num4 = Mathf.Max(num4, (v.x - vector.x) * activeFontScale - (border.x + padding.x) * 2f);
         float   num7    = num4;
         Vector3 vector3 = new Vector3(num7 * 0.5f, (0f - num3) * 0.5f, 0f);
         Vector3 vector4 = new Vector3(num7, num3 + padding.y, 1f);
         int     j       = 0;
         for (int count2 = list.Count; j < count2; j++)
         {
             UILabel uILabel2 = list[j];
             NGUITools.AddWidgetCollider(uILabel2.gameObject);
             uILabel2.autoResizeBoxCollider = false;
             BoxCollider component = uILabel2.GetComponent <BoxCollider>();
             if ((UnityEngine.Object)component != null)
             {
                 Vector3 center = component.center;
                 vector3.z        = center.z;
                 component.center = vector3;
                 component.size   = vector4;
             }
             else
             {
                 BoxCollider2D component2 = uILabel2.GetComponent <BoxCollider2D>();
                 component2.offset = vector3;
                 component2.size   = vector4;
             }
         }
         int width = Mathf.RoundToInt(num4);
         num4 += (border.x + padding.x) * 2f;
         num5 -= border.y;
         mBackground.width  = Mathf.RoundToInt(num4);
         mBackground.height = Mathf.RoundToInt(0f - num5 + border.y);
         int k = 0;
         for (int count3 = list.Count; k < count3; k++)
         {
             UILabel uILabel3 = list[k];
             uILabel3.overflowMethod = UILabel.Overflow.ShrinkContent;
             uILabel3.width          = width;
         }
         float num8 = 2f * atlas.pixelSize;
         float f    = num4 - (border.x + padding.x) * 2f + (float)atlasSprite.borderLeft * num8;
         float f2   = num3 + num * num8;
         mHighlight.width  = Mathf.RoundToInt(f);
         mHighlight.height = Mathf.RoundToInt(f2);
         bool flag = position == Position.Above;
         if (position == Position.Auto)
         {
             UICamera uICamera = UICamera.FindCameraForLayer(mSelection.layer);
             if (uICamera != null)
             {
                 Vector3 vector5 = uICamera.cachedCamera.WorldToViewportPoint(vector2);
                 flag = (vector5.y < 0.5f);
             }
         }
         if (isAnimated)
         {
             float bottom = num5 + num3;
             Animate(mHighlight, flag, bottom);
             int l = 0;
             for (int count4 = list.Count; l < count4; l++)
             {
                 Animate(list[l], flag, bottom);
             }
             AnimateColor(mBackground);
             AnimateScale(mBackground, flag, bottom);
         }
         if (flag)
         {
             transform2.localPosition = new Vector3(vector.x, v.y - num5 - border.y, vector.z);
         }
         vector = transform2.localPosition;
         v.x    = vector.x + (float)mBackground.width;
         v.y    = vector.y - (float)mBackground.height;
         v.z    = vector.z;
         Vector3 vector6 = mPanel.CalculateConstrainOffset(vector, v);
         transform2.localPosition += vector6;
     }
     else
     {
         OnSelect(isSelected: false);
     }
 }
Ejemplo n.º 12
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);

        // 检测边界
        bool isTop = false, isBottom = false, isLeft = false, isRight = false;

        mPanel.CheckBorder(ref isTop, ref isBottom, ref isLeft, ref isRight);

        // Debug.LogError("Reset 1" + constraint);
        if (!horizontal)
        {
            constraint.x = 0f;
        }
        if (!vertical)
        {
            constraint.y = 0f;
        }

        mConstraint = constraint;
        if (isRight)
        {
            mConstraint.x = 1;
        }
        if (isLeft)
        {
            mConstraint.x = -1;
        }
        if (isTop)
        {
            mConstraint.y = 1;
        }
        if (isBottom)
        {
            mConstraint.y = -1;
        }
        if (!horizontal)
        {
            mConstraint.x = 0f;
        }
        if (!vertical)
        {
            mConstraint.y = 0f;
        }

        //Debug.LogError("Reset 2" + mConstraint);
        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);

                if (backWhenFits && !disableDragIfFits)
                {
                    pos += GetMoveOffsets() - constraint;
                }

                sp          = SpringPanel.Begin(mPanel.gameObject, pos, 13f, sp);
                sp.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);
    }
Ejemplo n.º 13
0
    private void OnClipMove(UIPanel panel)
    {
        if (mScrollView == null || mDataCount == 0)
        {
            return;
        }
        var scrollViewBounds = NGUIMath.CalculateRelativeWidgetBounds(mScrollView.transform);
        var tPanelOffset     = panel.CalculateConstrainOffset(scrollViewBounds.min, scrollViewBounds.max);

        var moveTop  = mMovement == UIScrollView.Movement.Vertical && tPanelOffset.y < -1;
        var moveDown = mMovement == UIScrollView.Movement.Vertical && tPanelOffset.y > 1;

        var moveLeft  = mMovement == UIScrollView.Movement.Horizontal && tPanelOffset.x > 1;
        var moveRight = mMovement == UIScrollView.Movement.Horizontal && tPanelOffset.x < -1;

        //var moveDir = moveTop ? -1 : moveDown ? 1 : 0;
        //Debug.LogError(tPanelOffset.x + "," + tPanelOffset.y);
        //Debug.LogError(tPanelOffset.x);
        //Debug.LogError(moveDir);
        if (showItemGoLinkList.Count == 0)
        {
            return;
        }

        var firstGo     = showItemGoLinkList.First.Value;//第一个
        T   firstCtrler = null;

        ItemGoDic.TryGetValue(firstGo, out firstCtrler);
        var firstCtrlRealBound = NGUIMath.CalculateRelativeWidgetBounds(firstGo.transform);

        firstCtrlRealBound.center += firstGo.transform.localPosition;

        var lastGo     = showItemGoLinkList.Last.Value;//最后一个
        T   lastCtrler = null;

        ItemGoDic.TryGetValue(lastGo, out lastCtrler);
        var lastCtrlRealBound = NGUIMath.CalculateRelativeWidgetBounds(lastGo.transform);

        lastCtrlRealBound.center += lastGo.transform.localPosition;

        if (moveTop || moveLeft)
        {
            //往上拉
            //Debug.LogError("往上拉<-1");
            if (showItemGoLinkList.Count > 0)
            {
                if (lastCtrler != null)
                {
                    var firstIndex = lastCtrler.dataIndex;
                    //Debug.Log(string.Format("{0},{1},{2},{3},{4}", FirstGo.transform.localPosition.y, FirstCtrler.mBounds.size.y, Interval, tempBoundy, FirstIndex));

                    if (firstIndex < mDataCount - 1)
                    {
                        T   ctrler = null;
                        var index  = ++firstIndex;
                        ctrler = GetItemInResPoolOrAdd(index);
                        //Debug.Log(index);

                        if (ctrler != null)
                        {
                            var go = ctrler.GetGo();
                            if (mUpdateItem != null)
                            {
                                mUpdateItem(ctrler, index);
                            }
                            ctrler.bounds = NGUIMath.CalculateRelativeWidgetBounds(go.transform);
                            if (mMovement == UIScrollView.Movement.Vertical)
                            {
                                var tempBoundy = lastCtrlRealBound.min.y - ctrler.bounds.max.y - Interval;//ctrler.bounds.max.y 这里相当于size/2
                                go.transform.localPosition = new Vector3(mPanelBounds.center.x, tempBoundy, 0);
                                Add2ShowListFrom(ItemsState.Tail, go);
                            }
                            else if (mMovement == UIScrollView.Movement.Horizontal)
                            {
                                var tempBoundx = lastCtrlRealBound.max.x + (-ctrler.bounds.min.x) + Interval;//ctrler.bounds.max.y 这里相当于size/2
                                go.transform.localPosition = new Vector3(tempBoundx, mPanelBounds.center.y, 0);
                                Add2ShowListFrom(ItemsState.Tail, go);
                            }
                        }
                    }
                    //删除
                    bool isLastData = lastCtrler.dataIndex == mDataCount - 1;
                    bRestrictWithinPanel = isLastData;
                    //Debug.LogError(isLastData);
                    if (mScrollView.isDragging)
                    {
                        //Debug.Log("移删");
                        if (!isLastData)
                        {
                            CheckBeyondRemoveToResPool();
                        }
                    }
                    else if (isLastData)
                    {
                        RestrictWithinBounds();
                    }
                }
            }
        }
        else if (moveDown || moveRight)
        {
            //往下拉
            //Debug.LogError("往下拉>1");
            if (showItemGoLinkList.Count > 0)
            {
                if (firstCtrler != null)
                {
                    var firstIndex = firstCtrler.dataIndex;

                    if (firstIndex > 0)
                    {
                        T   ctrler = null;
                        var index  = --firstIndex;
                        ctrler = GetItemInResPoolOrAdd(index);
                        if (ctrler != null)
                        {
                            var go = ctrler.GetGo();
                            if (mUpdateItem != null)
                            {
                                mUpdateItem(ctrler, index);
                            }
                            ctrler.bounds = NGUIMath.CalculateRelativeWidgetBounds(go.transform);
                            if (mMovement == UIScrollView.Movement.Vertical)
                            {
                                var tempBoundy = firstCtrlRealBound.max.y + (-ctrler.bounds.min.y) + Interval;//-ctrler.bounds.min.y 这里相当于size/2
                                go.transform.localPosition = new Vector3(mPanelBounds.center.x, tempBoundy, 0);
                                Add2ShowListFrom(ItemsState.Head, go);
                                //Debug.Log(ctrler.dataIndex);
                            }
                            else if (mMovement == UIScrollView.Movement.Horizontal)
                            {
                                var tempBoundx = firstCtrlRealBound.min.x - ctrler.bounds.max.x - Interval;//ctrler.bounds.max.x 这里相当于size/2
                                go.transform.localPosition = new Vector3(tempBoundx, mPanelBounds.center.y, 0);
                                Add2ShowListFrom(ItemsState.Head, go);
                            }
                        }
                    }
                    //删除
                    bool isFirstData = firstCtrler.dataIndex == 0;
                    bRestrictWithinPanel = isFirstData;
                    if (mScrollView.isDragging)
                    {
                        //Debug.Log("移删");
                        if (!isFirstData)
                        {
                            CheckBeyondRemoveToResPool();
                        }
                    }
                    else if (isFirstData)
                    {
                        RestrictWithinBounds();
                    }
                }
            }
        }
        else
        {
            bool isLastData  = lastCtrler != null && lastCtrler.dataIndex == mDataCount - 1;
            bool isFirstData = firstCtrler != null && firstCtrler.dataIndex == 0;
            bRestrictWithinPanel = isFirstData || isLastData;

            if (!mScrollView.isDragging)
            {
                //Debug.LogError("234234");
                CheckBeyondRemoveToResPool();
            }
        }
    }
Ejemplo n.º 14
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);
    }
Ejemplo n.º 15
0
 public void Show()
 {
     //IL_000c: Unknown result type (might be due to invalid IL or missing references)
     //IL_0011: Expected O, but got Unknown
     //IL_007b: Unknown result type (might be due to invalid IL or missing references)
     //IL_00d5: Unknown result type (might be due to invalid IL or missing references)
     //IL_00da: Expected O, but got Unknown
     //IL_00fb: Unknown result type (might be due to invalid IL or missing references)
     //IL_0100: Expected O, but got Unknown
     //IL_010b: Unknown result type (might be due to invalid IL or missing references)
     //IL_0125: Unknown result type (might be due to invalid IL or missing references)
     //IL_012a: Expected O, but got Unknown
     //IL_014f: Unknown result type (might be due to invalid IL or missing references)
     //IL_015e: Unknown result type (might be due to invalid IL or missing references)
     //IL_0163: Unknown result type (might be due to invalid IL or missing references)
     //IL_0168: Unknown result type (might be due to invalid IL or missing references)
     //IL_017f: 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_018a: Unknown result type (might be due to invalid IL or missing references)
     //IL_018b: Unknown result type (might be due to invalid IL or missing references)
     //IL_018c: 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_01ac: Unknown result type (might be due to invalid IL or missing references)
     //IL_01b3: Expected O, but got Unknown
     //IL_01b3: Unknown result type (might be due to invalid IL or missing references)
     //IL_01b8: Unknown result type (might be due to invalid IL or missing references)
     //IL_01bc: Unknown result type (might be due to invalid IL or missing references)
     //IL_01c1: Unknown result type (might be due to invalid IL or missing references)
     //IL_01c4: 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_01cb: Unknown result type (might be due to invalid IL or missing references)
     //IL_01d2: Unknown result type (might be due to invalid IL or missing references)
     //IL_01d7: 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_01e5: Unknown result type (might be due to invalid IL or missing references)
     //IL_01f0: Unknown result type (might be due to invalid IL or missing references)
     //IL_022e: Unknown result type (might be due to invalid IL or missing references)
     //IL_0233: Expected O, but got Unknown
     //IL_0244: Unknown result type (might be due to invalid IL or missing references)
     //IL_0254: Unknown result type (might be due to invalid IL or missing references)
     //IL_0259: Unknown result type (might be due to invalid IL or missing references)
     //IL_0284: Unknown result type (might be due to invalid IL or missing references)
     //IL_02bd: Unknown result type (might be due to invalid IL or missing references)
     //IL_03a7: Unknown result type (might be due to invalid IL or missing references)
     //IL_03d4: Unknown result type (might be due to invalid IL or missing references)
     //IL_03fa: Unknown result type (might be due to invalid IL or missing references)
     //IL_03ff: Unknown result type (might be due to invalid IL or missing references)
     //IL_0410: Unknown result type (might be due to invalid IL or missing references)
     //IL_0453: Unknown result type (might be due to invalid IL or missing references)
     //IL_0458: Unknown result type (might be due to invalid IL or missing references)
     //IL_046a: Unknown result type (might be due to invalid IL or missing references)
     //IL_046f: Expected O, but got Unknown
     //IL_0580: Unknown result type (might be due to invalid IL or missing references)
     //IL_0585: Expected O, but got Unknown
     //IL_05ac: Unknown result type (might be due to invalid IL or missing references)
     //IL_05b1: Unknown result type (might be due to invalid IL or missing references)
     //IL_05c1: Unknown result type (might be due to invalid IL or missing references)
     //IL_05ca: Unknown result type (might be due to invalid IL or missing references)
     //IL_05e1: Unknown result type (might be due to invalid IL or missing references)
     //IL_05e3: Unknown result type (might be due to invalid IL or missing references)
     //IL_05ef: Unknown result type (might be due to invalid IL or missing references)
     //IL_05f1: Unknown result type (might be due to invalid IL or missing references)
     //IL_074d: Unknown result type (might be due to invalid IL or missing references)
     //IL_074e: Unknown result type (might be due to invalid IL or missing references)
     //IL_0753: Unknown result type (might be due to invalid IL or missing references)
     //IL_0865: Unknown result type (might be due to invalid IL or missing references)
     //IL_08cb: Unknown result type (might be due to invalid IL or missing references)
     //IL_08d0: Expected O, but got Unknown
     //IL_08ea: Unknown result type (might be due to invalid IL or missing references)
     //IL_08eb: Unknown result type (might be due to invalid IL or missing references)
     //IL_08f0: Unknown result type (might be due to invalid IL or missing references)
     //IL_08fc: Unknown result type (might be due to invalid IL or missing references)
     //IL_08fd: Unknown result type (might be due to invalid IL or missing references)
     //IL_0902: Unknown result type (might be due to invalid IL or missing references)
     //IL_0905: Unknown result type (might be due to invalid IL or missing references)
     //IL_0906: Unknown result type (might be due to invalid IL or missing references)
     //IL_090b: Unknown result type (might be due to invalid IL or missing references)
     //IL_090e: Unknown result type (might be due to invalid IL or missing references)
     //IL_090f: Unknown result type (might be due to invalid IL or missing references)
     //IL_0914: Unknown result type (might be due to invalid IL or missing references)
     //IL_091b: Unknown result type (might be due to invalid IL or missing references)
     //IL_091c: Unknown result type (might be due to invalid IL or missing references)
     //IL_0921: Unknown result type (might be due to invalid IL or missing references)
     //IL_0922: Unknown result type (might be due to invalid IL or missing references)
     //IL_0927: Unknown result type (might be due to invalid IL or missing references)
     //IL_092c: Unknown result type (might be due to invalid IL or missing references)
     //IL_092f: Unknown result type (might be due to invalid IL or missing references)
     //IL_0934: Unknown result type (might be due to invalid IL or missing references)
     //IL_0936: Unknown result type (might be due to invalid IL or missing references)
     //IL_093b: Unknown result type (might be due to invalid IL or missing references)
     //IL_0963: Unknown result type (might be due to invalid IL or missing references)
     if (this.get_enabled() && NGUITools.GetActive(this.get_gameObject()) && mChild == null && atlas != null && isValid && items.Count > 0)
     {
         mLabelList.Clear();
         this.StopCoroutine("CloseIfUnselected");
         UICamera.selectedObject = (UICamera.hoveredObject ?? this.get_gameObject());
         mSelection = UICamera.selectedObject;
         source     = UICamera.selectedObject;
         if (source == null)
         {
             Debug.LogError((object)"Popup list needs a source object...");
         }
         else
         {
             mOpenFrame = Time.get_frameCount();
             if (mPanel == null)
             {
                 mPanel = UIPanel.Find(this.get_transform());
                 if (mPanel == null)
                 {
                     return;
                 }
             }
             mChild = new GameObject("Drop-down List");
             mChild.set_layer(this.get_gameObject().get_layer());
             current = this;
             Transform val = mChild.get_transform();
             val.set_parent(mPanel.cachedTransform);
             Vector3 val2;
             Vector3 val3;
             Vector3 val4;
             if (openOn == OpenOn.Manual && mSelection != this.get_gameObject())
             {
                 val2 = Vector2.op_Implicit(UICamera.lastEventPosition);
                 val3 = mPanel.cachedTransform.InverseTransformPoint(mPanel.anchorCamera.ScreenToWorldPoint(val2));
                 val4 = val3;
                 val.set_localPosition(val3);
                 val2 = val.get_position();
             }
             else
             {
                 Bounds val5 = NGUIMath.CalculateRelativeWidgetBounds(mPanel.cachedTransform, this.get_transform(), false, false);
                 val3 = val5.get_min();
                 val4 = val5.get_max();
                 val.set_localPosition(val3);
                 val2 = val.get_position();
             }
             this.StartCoroutine("CloseIfUnselected");
             val.set_localRotation(Quaternion.get_identity());
             val.set_localScale(Vector3.get_one());
             mBackground       = NGUITools.AddSprite(mChild, atlas, backgroundSprite);
             mBackground.pivot = UIWidget.Pivot.TopLeft;
             mBackground.depth = NGUITools.CalculateNextDepth(mPanel.get_gameObject());
             mBackground.color = backgroundColor;
             Vector4 border = mBackground.border;
             mBgBorder = border.y;
             mBackground.cachedTransform.set_localPosition(new Vector3(0f, border.y, 0f));
             mHighlight       = NGUITools.AddSprite(mChild, atlas, highlightSprite);
             mHighlight.pivot = UIWidget.Pivot.TopLeft;
             mHighlight.color = highlightColor;
             UISpriteData atlasSprite = mHighlight.GetAtlasSprite();
             if (atlasSprite != null)
             {
                 float          num             = (float)atlasSprite.borderTop;
                 float          num2            = (float)activeFontSize;
                 float          activeFontScale = this.activeFontScale;
                 float          num3            = num2 * activeFontScale;
                 float          num4            = 0f;
                 float          num5            = 0f - padding.y;
                 List <UILabel> list            = new List <UILabel>();
                 if (!items.Contains(mSelectedItem))
                 {
                     mSelectedItem = null;
                 }
                 int i = 0;
                 for (int count = items.Count; i < count; i++)
                 {
                     string  text    = items[i];
                     UILabel uILabel = NGUITools.AddWidget <UILabel>(mChild);
                     uILabel.set_name(i.ToString());
                     uILabel.pivot        = UIWidget.Pivot.TopLeft;
                     uILabel.bitmapFont   = bitmapFont;
                     uILabel.trueTypeFont = trueTypeFont;
                     uILabel.fontSize     = fontSize;
                     uILabel.fontStyle    = fontStyle;
                     uILabel.text         = ((!isLocalized) ? text : Localization.Get(text));
                     uILabel.color        = textColor;
                     object  cachedTransform = (object)uILabel.cachedTransform;
                     float   num6            = border.x + padding.x;
                     Vector2 pivotOffset     = uILabel.pivotOffset;
                     cachedTransform.set_localPosition(new Vector3(num6 - pivotOffset.x, num5, -1f));
                     uILabel.overflowMethod = UILabel.Overflow.ResizeFreely;
                     uILabel.alignment      = alignment;
                     list.Add(uILabel);
                     num5 -= num3;
                     num5 -= padding.y;
                     float   num7        = num4;
                     Vector2 printedSize = uILabel.printedSize;
                     num4 = Mathf.Max(num7, printedSize.x);
                     UIEventListener uIEventListener = UIEventListener.Get(uILabel.get_gameObject());
                     uIEventListener.onHover   = OnItemHover;
                     uIEventListener.onPress   = OnItemPress;
                     uIEventListener.parameter = text;
                     if (mSelectedItem == text || (i == 0 && string.IsNullOrEmpty(mSelectedItem)))
                     {
                         Highlight(uILabel, true);
                     }
                     mLabelList.Add(uILabel);
                 }
                 num4 = Mathf.Max(num4, val4.x - val3.x - (border.x + padding.x) * 2f);
                 float   num8 = num4;
                 Vector3 val6 = default(Vector3);
                 val6._002Ector(num8 * 0.5f, (0f - num3) * 0.5f, 0f);
                 Vector3 val7 = default(Vector3);
                 val7._002Ector(num8, num3 + padding.y, 1f);
                 int j = 0;
                 for (int count2 = list.Count; j < count2; j++)
                 {
                     UILabel uILabel2 = list[j];
                     NGUITools.AddWidgetCollider(uILabel2.get_gameObject());
                     uILabel2.autoResizeBoxCollider = false;
                     BoxCollider component = uILabel2.GetComponent <BoxCollider>();
                     if (component != null)
                     {
                         Vector3 center = component.get_center();
                         val6.z = center.z;
                         component.set_center(val6);
                         component.set_size(val7);
                     }
                     else
                     {
                         BoxCollider2D component2 = uILabel2.GetComponent <BoxCollider2D>();
                         component2.set_offset(Vector2.op_Implicit(val6));
                         component2.set_size(Vector2.op_Implicit(val7));
                     }
                 }
                 int width = Mathf.RoundToInt(num4);
                 num4 += (border.x + padding.x) * 2f;
                 num5 -= border.y;
                 mBackground.width  = Mathf.RoundToInt(num4);
                 mBackground.height = Mathf.RoundToInt(0f - num5 + border.y);
                 int k = 0;
                 for (int count3 = list.Count; k < count3; k++)
                 {
                     UILabel uILabel3 = list[k];
                     uILabel3.overflowMethod = UILabel.Overflow.ShrinkContent;
                     uILabel3.width          = width;
                 }
                 float num9  = 2f * atlas.pixelSize;
                 float num10 = num4 - (border.x + padding.x) * 2f + (float)atlasSprite.borderLeft * num9;
                 float num11 = num3 + num * num9;
                 mHighlight.width  = Mathf.RoundToInt(num10);
                 mHighlight.height = Mathf.RoundToInt(num11);
                 bool flag = position == Position.Above;
                 if (position == Position.Auto)
                 {
                     UICamera uICamera = UICamera.FindCameraForLayer(mSelection.get_layer());
                     if (uICamera != null)
                     {
                         Vector3 val8 = uICamera.cachedCamera.WorldToViewportPoint(val2);
                         flag = (val8.y < 0.5f);
                     }
                 }
                 if (isAnimated)
                 {
                     AnimateColor(mBackground);
                     if (Time.get_timeScale() == 0f || Time.get_timeScale() >= 0.1f)
                     {
                         float bottom = num5 + num3;
                         Animate(mHighlight, flag, bottom);
                         int l = 0;
                         for (int count4 = list.Count; l < count4; l++)
                         {
                             Animate(list[l], flag, bottom);
                         }
                         AnimateScale(mBackground, flag, bottom);
                     }
                 }
                 if (flag)
                 {
                     val3.y = val4.y - border.y;
                     val4.y = val3.y + (float)mBackground.height;
                     val4.x = val3.x + (float)mBackground.width;
                     val.set_localPosition(new Vector3(val3.x, val4.y - border.y, val3.z));
                 }
                 else
                 {
                     val4.y = val3.y + border.y;
                     val3.y = val4.y - (float)mBackground.height;
                     val4.x = val3.x + (float)mBackground.width;
                 }
                 Transform val9 = mPanel.cachedTransform.get_parent();
                 if (val9 != null)
                 {
                     val3 = mPanel.cachedTransform.TransformPoint(val3);
                     val4 = mPanel.cachedTransform.TransformPoint(val4);
                     val3 = val9.InverseTransformPoint(val3);
                     val4 = val9.InverseTransformPoint(val4);
                 }
                 Vector3 val10 = mPanel.CalculateConstrainOffset(Vector2.op_Implicit(val3), Vector2.op_Implicit(val4));
                 val2   = val.get_localPosition() + val10;
                 val2.x = Mathf.Round(val2.x);
                 val2.y = Mathf.Round(val2.y);
                 val.set_localPosition(val2);
             }
         }
     }
     else
     {
         OnSelect(false);
     }
 }