SpringDampen() static public method

Same as the Vector3 version, it's a framerate-independent Lerp.
static public SpringDampen ( Vector2 &velocity, float strength, float deltaTime ) : Vector2
velocity Vector2
strength float
deltaTime float
return Vector2
Ejemplo n.º 1
0
    void Update()
    {
        if (mSlide && mCurrentCell != null && mCurrentCell.Value != null)
        {
            Vector3 offset = mSlidePos - mCurrentCell.Value.transform.localPosition;

            if (!Mathf.Approximately(offset.magnitude, 0f))
            {
                if (mSlideSpeed.magnitude < offset.magnitude)
                {
                    SwitchDirection direction = OffsetDirection(offset);
                    if (direction == SwitchDirection.Positive)
                    {
                        mCurrentCell.Value.transform.localPosition += mSlideSpeed;
                    }
                    else if (direction == SwitchDirection.Negative)
                    {
                        mCurrentCell.Value.transform.localPosition -= mSlideSpeed;
                    }
                }
                else
                {
                    mCurrentCell.Value.transform.localPosition = mSlidePos;
                }

                if (mPreparedCell != null && mPreparedCell.Value != null)
                {
                    ZoomCell(mPreparedCell.Value, mCurrentCell.Value.transform.localPosition);
                    AlphaCell(mPreparedCell.Value, mCurrentCell.Value.transform.localPosition);
                }
            }
            else
            {
                ResetCell();
                if (mPreparedCell != null && mPreparedCell.Value != null)
                {
                    SwitchDirection direction = TargetDirection(mSlidePos);
                    if (direction != SwitchDirection.None)
                    {
                        HideCell(mCurrentCell.Value);

                        mCurrentCell  = mPreparedCell;
                        mCurrentIndex = mPreparedIndex;
                        SelectCell(mCurrentCell.Value, mCurrentIndex);

                        ResetPrepareCell(SwitchDirection.None);
                    }
                    else
                    {
                        HideCell(mPreparedCell.Value);
                        ResetPrepareCell(SwitchDirection.None);
                    }
                }

                mSlide    = false;
                mSlidePos = mSelectCenter;
            }
        }

        UpdateScroll();

        // attenuate the inertia
        NGUIMath.SpringDampen(ref mInertiaOffset, 9f, 0.025f);
    }
Ejemplo n.º 2
0
    public void Recenter()
    {
        if (this.mScrollView == null)
        {
            this.mScrollView = NGUITools.FindInParents <UIScrollView>(base.get_gameObject());
            if (this.mScrollView == null)
            {
                Debug.LogWarning(string.Concat(new object[]
                {
                    base.GetType(),
                    " requires ",
                    typeof(UIScrollView),
                    " on a parent object in order to work"
                }), this);
                base.set_enabled(false);
                return;
            }
            if (this.mScrollView)
            {
                this.mScrollView.centerOnChild = this;
                UIScrollView expr_94 = this.mScrollView;
                expr_94.onDragFinished = (UIScrollView.OnDragNotification)Delegate.Combine(expr_94.onDragFinished, new UIScrollView.OnDragNotification(this.OnDragFinished));
            }
            if (this.mScrollView.horizontalScrollBar != null)
            {
                UIProgressBar expr_D6 = this.mScrollView.horizontalScrollBar;
                expr_D6.onDragFinished = (UIProgressBar.OnDragFinished)Delegate.Combine(expr_D6.onDragFinished, new UIProgressBar.OnDragFinished(this.OnDragFinished));
            }
            if (this.mScrollView.verticalScrollBar != null)
            {
                UIProgressBar expr_118 = this.mScrollView.verticalScrollBar;
                expr_118.onDragFinished = (UIProgressBar.OnDragFinished)Delegate.Combine(expr_118.onDragFinished, new UIProgressBar.OnDragFinished(this.OnDragFinished));
            }
        }
        if (this.mScrollView.panel == null)
        {
            return;
        }
        Transform transform = base.get_transform();

        if (transform.get_childCount() == 0)
        {
            return;
        }
        Vector3[] worldCorners = this.mScrollView.panel.worldCorners;
        Vector3   vector       = (worldCorners[2] + worldCorners[0]) * 0.5f;
        Vector3   vector2      = this.mScrollView.currentMomentum * this.mScrollView.momentumAmount;
        Vector3   vector3      = NGUIMath.SpringDampen(ref vector2, 9f, 2f);
        Vector3   vector4      = vector - vector3 * 0.01f;
        float     num          = 3.40282347E+38f;
        Transform target       = null;
        int       num2         = 0;
        int       num3         = 0;
        int       i            = 0;
        int       childCount   = transform.get_childCount();
        int       num4         = 0;

        while (i < childCount)
        {
            Transform child = transform.GetChild(i);
            if (child.get_gameObject().get_activeInHierarchy())
            {
                float num5 = Vector3.SqrMagnitude(child.get_position() - vector4);
                if (num5 < num)
                {
                    num    = num5;
                    target = child;
                    num2   = i;
                    num3   = num4;
                }
                num4++;
            }
            i++;
        }
        if (this.nextPageThreshold > 0f && UICamera.currentTouch != null && this.mCenteredObject != null && this.mCenteredObject.get_transform() == transform.GetChild(num2))
        {
            Vector3 vector5 = UICamera.currentTouch.totalDelta;
            vector5 = base.get_transform().get_rotation() * vector5;
            UIScrollView.Movement movement = this.mScrollView.movement;
            float num6;
            if (movement != UIScrollView.Movement.Horizontal)
            {
                if (movement != UIScrollView.Movement.Vertical)
                {
                    num6 = vector5.get_magnitude();
                }
                else
                {
                    num6 = vector5.y;
                }
            }
            else
            {
                num6 = vector5.x;
            }
            if (Mathf.Abs(num6) > this.nextPageThreshold)
            {
                UIGrid component = base.GetComponent <UIGrid>();
                if (component != null && component.sorting != UIGrid.Sorting.None)
                {
                    List <Transform> childList = component.GetChildList();
                    if (num6 > this.nextPageThreshold)
                    {
                        if (num3 > 0)
                        {
                            target = childList.get_Item(num3 - 1);
                        }
                        else
                        {
                            target = ((!(base.GetComponent <UIWrapContent>() == null)) ? childList.get_Item(childList.get_Count() - 1) : childList.get_Item(0));
                        }
                    }
                    else if (num6 < -this.nextPageThreshold)
                    {
                        if (num3 < childList.get_Count() - 1)
                        {
                            target = childList.get_Item(num3 + 1);
                        }
                        else
                        {
                            target = ((!(base.GetComponent <UIWrapContent>() == null)) ? childList.get_Item(0) : childList.get_Item(childList.get_Count() - 1));
                        }
                    }
                }
                else
                {
                    Debug.LogWarning("Next Page Threshold requires a sorted UIGrid in order to work properly", this);
                }
            }
        }
        this.CenterOn(target, vector);
    }
Ejemplo n.º 3
0
    private void LateUpdate()
    {
        if (!Application.isPlaying)
        {
            return;
        }
        Single deltaTime = RealTime.deltaTime;

        if (this.showScrollBars != UIScrollView.ShowCondition.Always && (this.verticalScrollBar || this.horizontalScrollBar))
        {
            Boolean flag  = false;
            Boolean flag2 = false;
            if (this.showScrollBars != UIScrollView.ShowCondition.WhenDragging || this.mDragID != -10 || this.mMomentum.magnitude > 0.01f)
            {
                flag  = this.shouldMoveVertically;
                flag2 = this.shouldMoveHorizontally;
            }
            if (this.verticalScrollBar)
            {
                Single num = this.verticalScrollBar.alpha;
                num += ((!flag) ? (-deltaTime * 3f) : (deltaTime * 6f));
                num  = Mathf.Clamp01(num);
                if (this.verticalScrollBar.alpha != num)
                {
                    this.verticalScrollBar.alpha = num;
                }
            }
            if (this.horizontalScrollBar)
            {
                Single num2 = this.horizontalScrollBar.alpha;
                num2 += ((!flag2) ? (-deltaTime * 3f) : (deltaTime * 6f));
                num2  = Mathf.Clamp01(num2);
                if (this.horizontalScrollBar.alpha != num2)
                {
                    this.horizontalScrollBar.alpha = num2;
                }
            }
        }
        if (!this.mShouldMove)
        {
            return;
        }
        if (!this.mPressed)
        {
            if (this.mMomentum.magnitude > 0.0001f || Mathf.Abs(this.mScroll) > 0.0001f)
            {
                if (this.movement == UIScrollView.Movement.Horizontal)
                {
                    this.mMomentum -= this.mTrans.TransformDirection(new Vector3(this.mScroll * 0.05f, 0f, 0f));
                }
                else if (this.movement == UIScrollView.Movement.Vertical)
                {
                    this.mMomentum -= this.mTrans.TransformDirection(new Vector3(0f, this.mScroll * 0.05f, 0f));
                }
                else if (this.movement == UIScrollView.Movement.Unrestricted)
                {
                    this.mMomentum -= this.mTrans.TransformDirection(new Vector3(this.mScroll * 0.05f, this.mScroll * 0.05f, 0f));
                }
                else
                {
                    this.mMomentum -= this.mTrans.TransformDirection(new Vector3(this.mScroll * this.customMovement.x * 0.05f, this.mScroll * this.customMovement.y * 0.05f, 0f));
                }
                this.mScroll = NGUIMath.SpringLerp(this.mScroll, 0f, 20f, deltaTime);
                Vector3 absolute = NGUIMath.SpringDampen(ref this.mMomentum, this.dampenStrength, deltaTime);
                this.MoveAbsolute(absolute);
                if (this.restrictWithinPanel && this.mPanel.clipping != UIDrawCall.Clipping.None)
                {
                    if (NGUITools.GetActive(this.centerOnChild))
                    {
                        if (this.centerOnChild.nextPageThreshold != 0f)
                        {
                            this.mMomentum = Vector3.zero;
                            this.mScroll   = 0f;
                        }
                        else
                        {
                            this.centerOnChild.Recenter();
                        }
                    }
                    else
                    {
                        this.RestrictWithinBounds(false, this.canMoveHorizontally, this.canMoveVertically);
                    }
                }
                if (this.onMomentumMove != null)
                {
                    this.onMomentumMove();
                }
            }
            else
            {
                this.mScroll   = 0f;
                this.mMomentum = Vector3.zero;
                SpringPanel component = base.GetComponent <SpringPanel>();
                if (component != (UnityEngine.Object)null && component.enabled)
                {
                    return;
                }
                this.mShouldMove = false;
                if (this.onStoppedMoving != null)
                {
                    this.onStoppedMoving();
                }
            }
        }
        else
        {
            this.mScroll = 0f;
            NGUIMath.SpringDampen(ref this.mMomentum, 9f, deltaTime);
        }
    }
Ejemplo n.º 4
0
    /// <summary>
    /// Apply the dragging momentum.
    /// </summary>

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

        if (target == null)
        {
            return;
        }

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

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

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

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

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

        // Dampen the momentum
        NGUIMath.SpringDampen(ref mMomentum, 9f, delta);
    }
Ejemplo n.º 5
0
    /// <summary>
    /// Apply the dragging momentum.
    /// </summary>

    void LateUpdate()
    {
#if UNITY_EDITOR
        if (!Application.isPlaying)
        {
            return;
        }
#endif
        if (target == null)
        {
            return;
        }
        float delta = RealTime.deltaTime;

        mMomentum -= mScroll;
        mScroll    = NGUIMath.SpringLerp(mScroll, Vector3.zero, 20f, delta);

        // No momentum? Exit.
        if (mMomentum.magnitude < 0.0001f)
        {
            return;
        }

        if (!mPressed)
        {
            // Apply the momentum
            if (panelRegion == null)
            {
                FindPanel();
            }

            Move(NGUIMath.SpringDampen(ref mMomentum, 9f, delta));

            if (restrictWithinPanel && panelRegion != null)
            {
                UpdateBounds();

                if (panelRegion.ConstrainTargetToBounds(target, ref mBounds, dragEffect == DragEffect.None))
                {
                    CancelMovement();
                }
                else
                {
                    CancelSpring();
                }
            }

            // Dampen the momentum
            NGUIMath.SpringDampen(ref mMomentum, 9f, delta);

            // Cancel all movement (and snap to pixels) at the end
            if (mMomentum.magnitude < 0.0001f)
            {
                CancelMovement();
            }
        }
        else
        {
            NGUIMath.SpringDampen(ref mMomentum, 9f, delta);
        }
    }
Ejemplo n.º 6
0
    public void DoCellScale()
    {
        if (!CenterScale)
        {
            return;
        }
        if (mScrollView.panel == null)
        {
            return;
        }

        Transform trans = transform;

        if (trans.childCount == 0)
        {
            return;
        }

        // Calculate the panel's center in world coordinates
        Vector3[] corners     = mScrollView.panel.localCorners;
        Vector3   panelCenter = (corners[2] + corners[0]) * 0.5f;

        // Offset this value by the momentum
        Vector3 momentum     = mScrollView.currentMomentum * mScrollView.momentumAmount;
        Vector3 moveDelta    = NGUIMath.SpringDampen(ref momentum, 9f, 2f);
        Vector3 pickingPoint = panelCenter - moveDelta * 0.01f; // Magic number based on what "feels right"

        UIGrid grid     = GetComponent <UIGrid>();
        float  scaleDis = grid.cellWidth / 2f;

        if (mScrollView.movement == UIScrollView.Movement.Vertical)
        {
            scaleDis = grid.cellHeight / 2f;
        }

        // Determine the closest child
        for (int i = 0, imax = trans.childCount; i < imax; ++i)
        {
            Transform t = trans.GetChild(i);
            if (!t.gameObject.activeInHierarchy)
            {
                continue;
            }
            float sqrDist = Vector3.Magnitude(t.localPosition - pickingPoint);

            if (sqrDist < scaleDis)
            {
                t.localScale = Vector3.one * (1f + (ScaleRate - 1f) * (scaleDis - sqrDist) / scaleDis);
                if (CenterScaleChangeZ)
                {
                    var disPoint = t.localPosition - pickingPoint;
                    disPoint.z = 0;
                    var sqrDistXY = Vector3.Magnitude(disPoint);
                    t.localPosition = new Vector3(t.localPosition.x, t.localPosition.y, CenterScaleZPos * (scaleDis - sqrDistXY) / scaleDis);
                }
            }
            else
            {
                t.localScale = Vector3.one;
                if (CenterScaleChangeZ)
                {
                    t.localPosition = new Vector3(t.localPosition.x, t.localPosition.y, 0.0f);
                }
            }
        }
    }
Ejemplo n.º 7
0
    public void Recenter()
    {
        if (mScrollView == null)
        {
            mScrollView = NGUITools.FindInParents <UIScrollView>(gameObject);

            if (mScrollView == null)
            {
                Debug.LogWarning(GetType() + " requires " + typeof(UIScrollView) + " on a parent object in order to work", this);
                enabled = false;
                return;
            }
            else
            {
                if (mScrollView)
                {
                    mScrollView.centerOnChild   = this;
                    mScrollView.onDragFinished += OnDragFinished;
                }

                if (mScrollView.horizontalScrollBar != null)
                {
                    mScrollView.horizontalScrollBar.onDragFinished += OnDragFinished;
                }

                if (mScrollView.verticalScrollBar != null)
                {
                    mScrollView.verticalScrollBar.onDragFinished += OnDragFinished;
                }
            }
        }
        if (mScrollView.panel == null)
        {
            return;
        }

        Transform trans = transform;

        if (trans.childCount == 0)
        {
            return;
        }

        // Calculate the panel's center in world coordinates
        Vector3[] corners     = mScrollView.panel.worldCorners;
        Vector3   panelCenter = (corners[2] + corners[0]) * 0.5f;

        // Offset this value by the momentum
        Vector3 momentum     = mScrollView.currentMomentum * mScrollView.momentumAmount;
        Vector3 moveDelta    = NGUIMath.SpringDampen(ref momentum, 9f, 2f);
        Vector3 pickingPoint = panelCenter - moveDelta * 0.01f;         // Magic number based on what "feels right"

        float     min          = float.MaxValue;
        Transform closest      = null;
        int       index        = 0;
        int       ignoredIndex = 0;

        UIGrid           grid = GetComponent <UIGrid>();
        List <Transform> list = null;

        // Determine the closest child
        if (grid != null)
        {
            list = grid.GetChildList();

            for (int i = 0, imax = list.Count, ii = 0; i < imax; ++i)
            {
                Transform t = list[i];
                if (!t.gameObject.activeInHierarchy)
                {
                    continue;
                }
                float sqrDist = Vector3.SqrMagnitude(t.position - pickingPoint);

                if (sqrDist < min)
                {
                    min          = sqrDist;
                    closest      = t;
                    index        = i;
                    ignoredIndex = ii;
                }
                ++ii;
            }
        }
        else
        {
            for (int i = 0, imax = trans.childCount, ii = 0; i < imax; ++i)
            {
                Transform t = trans.GetChild(i);
                if (!t.gameObject.activeInHierarchy)
                {
                    continue;
                }
                float sqrDist = Vector3.SqrMagnitude(t.position - pickingPoint);

                if (sqrDist < min)
                {
                    min          = sqrDist;
                    closest      = t;
                    index        = i;
                    ignoredIndex = ii;
                }
                ++ii;
            }
        }

        // If we have a touch in progress and the next page threshold set
        if (nextPageThreshold > 0f && UICamera.currentTouch != null)
        {
            // If we're still on the same object
            if (mCenteredObject != null && mCenteredObject.transform == (list != null ? list[index] : trans.GetChild(index)))
            {
                Vector3 totalDelta = UICamera.currentTouch.totalDelta;
                totalDelta = transform.rotation * totalDelta;

                float delta = 0f;

                switch (mScrollView.movement)
                {
                case UIScrollView.Movement.Horizontal:
                {
                    delta = totalDelta.x;
                    break;
                }

                case UIScrollView.Movement.Vertical:
                {
                    delta = totalDelta.y;
                    break;
                }

                default:
                {
                    delta = totalDelta.magnitude;
                    break;
                }
                }

                if (Mathf.Abs(delta) > nextPageThreshold)
                {
                    if (delta > nextPageThreshold)
                    {
                        // Next page
                        if (list != null)
                        {
                            if (ignoredIndex > 0)
                            {
                                closest = list[ignoredIndex - 1];
                            }
                            else
                            {
                                closest = (GetComponent <UIWrapContent>() == null) ? list[0] : list[list.Count - 1];
                            }
                        }
                        else if (ignoredIndex > 0)
                        {
                            closest = trans.GetChild(ignoredIndex - 1);
                        }
                        else
                        {
                            closest = (GetComponent <UIWrapContent>() == null) ? trans.GetChild(0) : trans.GetChild(trans.childCount - 1);
                        }
                    }
                    else if (delta < -nextPageThreshold)
                    {
                        // Previous page
                        if (list != null)
                        {
                            if (ignoredIndex < list.Count - 1)
                            {
                                closest = list[ignoredIndex + 1];
                            }
                            else
                            {
                                closest = (GetComponent <UIWrapContent>() == null) ? list[list.Count - 1] : list[0];
                            }
                        }
                        else if (ignoredIndex < trans.childCount - 1)
                        {
                            closest = trans.GetChild(ignoredIndex + 1);
                        }
                        else
                        {
                            closest = (GetComponent <UIWrapContent>() == null) ? trans.GetChild(trans.childCount - 1) : trans.GetChild(0);
                        }
                    }
                }
            }
        }
        CenterOn(closest, panelCenter);
    }
Ejemplo n.º 8
0
        /// <summary>
        /// Apply the dragging momentum.
        /// </summary>

        void LateUpdate()
        {
            if (!Application.isPlaying)
            {
                return;
            }
            float delta = Time.fixedDeltaTime;

            if (!shouldMove)
            {
                return;
            }

            // Apply momentum
            if (!pressed)
            {
                if (momentum.magnitude > 0.01f || scroll != 0f)
                {
                    if (MovementType == Movement.Horizontal)
                    {
                        momentum -= trans.TransformDirection(new Vector3(scroll * 0.05f, 0f, 0f));
                    }
                    else if (MovementType == Movement.Vertical)
                    {
                        momentum -= trans.TransformDirection(new Vector3(0f, scroll * 0.05f, 0f));
                    }
                    else if (MovementType == Movement.Unrestricted)
                    {
                        momentum -= trans.TransformDirection(new Vector3(scroll * 0.05f, scroll * 0.05f, 0f));
                    }
                    else
                    {
                        momentum -= trans.TransformDirection(new Vector3(
                                                                 scroll * CustomMovement.x * 0.05f,
                                                                 scroll * CustomMovement.y * 0.05f, 0f));
                    }
                    scroll = NGUIMath.SpringLerp(scroll, 0f, 20f, delta);

                    // Move the scroll view
                    Vector3 offset = NGUIMath.SpringDampen(ref momentum, 9f, delta);
                    Moveable.MoveAbsolute(offset);



                    if (OnMomentumMove != null)
                    {
                        OnMomentumMove();
                    }
                }
                else
                {
                    scroll   = 0f;
                    momentum = Vector3.zero;

                    if (carouselCenterOnChild != null)
                    {
                        if (carouselCenterOnChild.enabled)
                        {
                            return;
                        }

                        carouselCenterOnChild.Recenter();
                    }

                    shouldMove = false;
                    if (OnStoppedMoving != null)
                    {
                        OnStoppedMoving();
                    }
                }
            }
            else
            {
                // Dampen the momentum
                scroll = 0f;
                NGUIMath.SpringDampen(ref momentum, 9f, delta);
            }
        }
Ejemplo n.º 9
0
    void Update()
    {
        if (_disableDrag)
        {
            return;
        }

        if (_bPressed)
        {
            Vector3 mousePose = Input.mousePosition;//cam.ScreenToWorldPoint(Input.mousePosition);//hitt.transform.position; //
            float   offsetX   = mousePose.x - _pressedMousePos.x;
            float   offsetY   = mousePose.y - _pressedMousePos.y;
            if (Mathf.Abs(offsetX) >= 10f || Mathf.Abs(offsetY) >= 10f)
            {
                if (_bDragDirReverse)
                {
                    _curCameraPos.x = _pressedCameraPos.x + offsetX * _dragSpeedVec.x / 2000f;
                    _curCameraPos.y = _pressedCameraPos.y + offsetY * _dragSpeedVec.y / 2000f;
                    _curCameraPos.z = _pressedCameraPos.z + offsetY * _dragSpeedVec.z / 2000f;
                }
                else
                {
                    _curCameraPos.x = _pressedCameraPos.x - offsetX * _dragSpeedVec.x / 2000f;
                    _curCameraPos.y = _pressedCameraPos.y - offsetX * _dragSpeedVec.y / 2000f;
                    _curCameraPos.z = _pressedCameraPos.z - offsetY * _dragSpeedVec.z / 2000f;
                }

                _curCameraPos      = ClampPoint(_curCameraPos, _minPoint, _maxPoint);
                transform.position = _curCameraPos;
//                _movePath.UpdateRotation();
                if (_onDragEvent != null)
                {
                    _onDragEvent(_curCameraPos);
                }


                if (_lastFrameMousePos != Vector3.zero)
                {
                    _deltaDrag.x = _lastFrameMousePos.x - mousePose.x;
                    _deltaDrag.y = _lastFrameMousePos.y - mousePose.y;
                    Vector2 offset = Vector2.Scale(_deltaDrag, -_scale);
                    // Adjust the momentum
                    if (_bDragDirReverse)
                    {
                        _mMomentum = Vector2.Lerp(_mMomentum, _mMomentum + offset * (0.01f * momentumAmount), 0.67f);
                    }
                    else
                    {
                        _mMomentum = Vector2.Lerp(_mMomentum, _mMomentum - offset * (0.01f * momentumAmount), 0.67f);
                    }

                    // Utils.LogSys.Log("mMomentum" + _mMomentum.ToString() + ", " + offset.ToString());
                }
                _lastFrameMousePos = mousePose;
                _bDrag             = true;
            }
            NGUIMath.SpringDampen(ref _mMomentum, 9f, RealTime.deltaTime);
        }
        else
        {
            if (_dragType == EDragType.MOMENTUM)
            {
                //惯性运动
                if (_mMomentum.magnitude > 0.01f)
                {
                    // Apply the momentum
                    Vector3 offsetPos = (Vector3)NGUIMath.SpringDampen(ref _mMomentum, 10f, RealTime.deltaTime);
                    _curCameraPos.x   += offsetPos.x * _dragSpeedVec.x / 2000f;
                    _curCameraPos.z   += offsetPos.y * _dragSpeedVec.z / 2000f;
                    _curCameraPos.y   += offsetPos.y * _dragSpeedVec.y / 2000f;
                    _curCameraPos      = ClampPoint(_curCameraPos, _minPoint, _maxPoint);
                    transform.position = _curCameraPos;
                    // _movePath.UpdateRotation();
                    if (_onDragEvent != null)
                    {
                        _onDragEvent(_curCameraPos);
                    }
                }
                else
                {
                    NGUIMath.SpringDampen(ref _mMomentum, 9f, RealTime.deltaTime);
                }
            }
        }

        if (Input.GetMouseButtonDown(0))                       //点下去
        {
            if (UtilTools.ClickInValidArea())                  //点的是有效区
            {
                if (!HasUICoverSelf() || !UtilTools.ClickUI()) //忽略UI || 没点到UI
                {
                    if (_dragType != EDragType.NONE)
                    {
                        //还在滑动
                        if (_mMomentum.magnitude > 1f)
                        {
                            _bDrag = true;
                        }
                        else
                        {
                            _bDrag = false;
                        }
                    }
                    else
                    {
                        _bDrag = false;
                    }

                    _curCameraPos      = transform.position;
                    _bPressed          = true;
                    _pressedMousePos   = Input.mousePosition;
                    _pressedCameraPos  = _curCameraPos;
                    _mMomentum         = Vector2.zero;
                    _deltaDrag         = Vector2.zero;
                    _lastFrameMousePos = Vector3.zero;
                }
            }
        }
        else if (Input.GetMouseButtonUp(0))//弹起
        {
            _bPressed = false;
        }
    }
Ejemplo n.º 10
0
    void Pan()
    {
        if (InputManager.fingerInputDic.Count == 1)
        {
            InputManager.FingerInput fingerInput = InputManager.Instance.GetCurrentInput();

            if (fingerInput.currentTouchPhase == TouchPhase.Began)
            {
                this.momentumVector       = Vector2.zero;
                this.springDampStrengthen = this.springDampStrengthenMax;
                this.dragStartPosition    = fingerInput.currentPoint;
                if (this.springPosition != null)
                {
                    this.springPosition.enabled = false;
                }
            }
            else if (fingerInput.currentTouchPhase == TouchPhase.Moved)
            {
                float x = (fingerInput.prevPoint.x - fingerInput.currentPoint.x);
                float y = (fingerInput.currentPoint.y - fingerInput.prevPoint.y);

                Vector2 deltaDrag = new Vector2(x, y);
                this.momentumVector = momentumVector + deltaDrag * ((0.02f / CameraManager.tkCamera.ZoomFactor) * momentumAmount);
                this.panAcumVector += this.momentumVector;
            }
            else if (fingerInput.currentTouchPhase == TouchPhase.Canceled ||
                     fingerInput.currentTouchPhase == TouchPhase.Ended)
            {
                Vector3       direction = (Vector3)fingerInput.currentPoint - this.dragStartPosition;
                Direction8Way way       = Helper.GetDirectionType(direction);
                float         panTH     = this.panThresHolds;
                if (way == Direction8Way.n || way == Direction8Way.s)
                {
                    panTH = panTH * (Screen.height / Screen.width);
                }
                float distance = Vector3.Distance(fingerInput.currentPoint, this.dragStartPosition);
                if (distance > panTH)
                {
                    this.springDampStrengthen = this.springDampStrengthenMin;
                }
                else
                {
                    this.springDampStrengthen = this.springDampStrengthenMax;
                }
                this.ConstrainBounds(false);
            }
        }
        else
        {
            this.panAcumVector   = Vector3.zero;
            this.IsCameraPanning = false;
        }

        float deltaTime = Time.deltaTime;

        if (momentumVector.magnitude > 0.0f)
        {
            Vector2 dampingVector = NGUIMath.SpringDampen(ref momentumVector, this.springDampStrengthen, deltaTime);
            if (float.IsNaN(dampingVector.x) == false && float.IsNaN(dampingVector.y) == false)
            {
                this.IsCameraPanning = true;
                CameraManager.tkCamera.transform.Translate(dampingVector, Space.Self);
            }
            if (ConstrainBounds(false) == false)
            {
                springPosition.enabled = false;
            }
        }
    }
Ejemplo n.º 11
0
    private void LateUpdate()
    {
        if (repositionClipping)
        {
            repositionClipping = false;
            mCalculatedBounds  = false;
            SetDragAmount(relativePositionOnReset.x, relativePositionOnReset.y, true);
        }

        if (Application.isPlaying)
        {
            var deltaTime = UpdateRealTimeDelta();
            if (showScrollBars != ShowCondition.Always)
            {
                var shouldMoveVertically   = false;
                var shouldMoveHorizontally = false;
                if (showScrollBars != ShowCondition.WhenDragging || mDragID != -10 || mMomentum.magnitude > 0.01f)
                {
                    shouldMoveVertically   = this.shouldMoveVertically;
                    shouldMoveHorizontally = this.shouldMoveHorizontally;
                }

                if (verticalScrollBar != null)
                {
                    var num2 = verticalScrollBar.alpha + (!shouldMoveVertically ? -deltaTime * 3f : deltaTime * 6f);
                    num2 = Mathf.Clamp01(num2);
                    if (verticalScrollBar.alpha != num2)
                    {
                        verticalScrollBar.alpha = num2;
                    }
                }

                if (horizontalScrollBar != null)
                {
                    var num3 = horizontalScrollBar.alpha + (!shouldMoveHorizontally ? -deltaTime * 3f : deltaTime * 6f);
                    num3 = Mathf.Clamp01(num3);
                    if (horizontalScrollBar.alpha != num3)
                    {
                        horizontalScrollBar.alpha = num3;
                    }
                }
            }

            if (mShouldMove && !mPressed)
            {
                mMomentum -= scale * (mScroll * 0.05f);
                if (mMomentum.magnitude > 0.0001f)
                {
                    mScroll = NGUIMath.SpringLerp(mScroll, 0f, 20f, deltaTime);
                    var absolute = NGUIMath.SpringDampen(ref mMomentum, 9f, deltaTime);
                    MoveAbsolute(absolute);
                    if (restrictWithinPanel && mPanel.clipping != UIDrawCall.Clipping.None)
                    {
                        RestrictWithinBounds(false);
                    }

                    if (mMomentum.magnitude < 0.0001f)
                    {
                        onDragFinished?.Invoke();
                    }

                    return;
                }

                mScroll   = 0f;
                mMomentum = Vector3.zero;
            }
            else
            {
                mScroll = 0f;
            }

            NGUIMath.SpringDampen(ref mMomentum, 9f, deltaTime);
        }
    }
Ejemplo n.º 12
0
    void Update()
    {
        if (_disableDrag)
        {
            return;
        }

        if (_movePath == null)
        {
            return;
        }

        if (_bPressed)
        {
            Vector3 mousePose = Input.mousePosition;//cam.ScreenToWorldPoint(Input.mousePosition);//hitt.transform.position; //
            float   offsetX   = mousePose.x - _pressedMousePos.x;
            if (Mathf.Abs(offsetX) >= 10f)
            {
                if (_bDragDirReverse)
                {
                    _curCameraPos = _pressedCameraPos + offsetX / 2000f;
                }
                else
                {
                    _curCameraPos = _pressedCameraPos - offsetX / 2000f;
                }


                _curCameraPos      = Mathf.Clamp(_curCameraPos, 0f, 1f);
                transform.position = _movePath.GetPointAtTime(_curCameraPos);
                _movePath.UpdateRotation();
                if (_onDragEvent != null)
                {
                    _onDragEvent(_curCameraPos);
                }


                if (_lastFrameMousePos != Vector3.zero)
                {
                    _deltaDrag.x = _lastFrameMousePos.x - mousePose.x;
                    _deltaDrag.y = _lastFrameMousePos.y - mousePose.y;
                    Vector2 offset = Vector2.Scale(_deltaDrag, -_scale);
                    // Adjust the momentum
                    if (_bDragDirReverse)
                    {
                        _mMomentum = Vector2.Lerp(_mMomentum, _mMomentum + offset * (0.01f * momentumAmount), 0.67f);
                    }
                    else
                    {
                        _mMomentum = Vector2.Lerp(_mMomentum, _mMomentum - offset * (0.01f * momentumAmount), 0.67f);
                    }

                    // Utils.LogSys.Log("mMomentum" + _mMomentum.ToString() + ", " + offset.ToString());
                }
                _lastFrameMousePos = mousePose;
                _bDrag             = true;
            }
            NGUIMath.SpringDampen(ref _mMomentum, 9f, RealTime.deltaTime);
        }
        else
        {
            if (_dragType == EDragType.MOMENTUM)
            {
                //惯性运动
                if (_mMomentum.magnitude > 0.01f)
                {
                    // Apply the momentum
                    Vector3 offsetPos = (Vector3)NGUIMath.SpringDampen(ref _mMomentum, 10f, RealTime.deltaTime);
                    _curCameraPos     += offsetPos.x / 2000f;
                    _curCameraPos      = Mathf.Clamp(_curCameraPos, 0f, 1f);
                    transform.position = _movePath.GetPointAtTime(_curCameraPos);
                    _movePath.UpdateRotation();
                    if (_onDragEvent != null)
                    {
                        _onDragEvent(_curCameraPos);
                    }
                }
                else
                {
                    NGUIMath.SpringDampen(ref _mMomentum, 9f, RealTime.deltaTime);
                }
            }
            else if (_dragType == EDragType.PAGEVIEW)
            {
                //滑到指定点
                if (_pageViewTargetPoint != -1f)
                {
                    bool bStop = false;
                    if (_mMomentum.magnitude > 0.01f)//正在滑动
                    {
                        float distance = _pageViewTargetPoint - _curCameraPos;
                        if (Mathf.Abs(distance) > 0.01f)
                        {
                            float dir = _bDragDirReverse?-1f:1f;
                            if (Mathf.Abs(distance) < _pageViewBeginSlowDistance)
                            {
                                Vector3 offsetPos = (Vector3)NGUIMath.SpringDampen(ref _mMomentum, 10f, RealTime.deltaTime);
                                _curCameraPos -= dir * offsetPos.x / 2000f;
                            }
                            else
                            {
                                _curCameraPos -= dir * _mMomentum.x / 2000f;
                            }
                            _curCameraPos = Mathf.Clamp(_curCameraPos, 0f, 1f);
                            float newDistance = _pageViewTargetPoint - _curCameraPos;
                            if (newDistance * distance > 0f)//还没到目标
                            {
                                transform.position = _movePath.GetPointAtTime(_curCameraPos);
                                _movePath.UpdateRotation();
                            }
                            else//超过目标点了
                            {
                                bStop = true;
                            }
                        }
                        else//已接近目标
                        {
                            bStop = true;
                        }
                    }
                    else//停止滑动
                    {
                        bStop = true;
                    }

                    if (bStop)
                    {
                        _curCameraPos      = _pageViewTargetPoint;
                        transform.position = _movePath.GetPointAtTime(_curCameraPos);
                        _movePath.UpdateRotation();
                        if (_onDragEvent != null)
                        {
                            _onDragEvent(_curCameraPos);
                        }
                        _mMomentum           = Vector2.zero;
                        _pageViewTargetPoint = -1f;
                    }
                }
            }
        }

        if (Input.GetMouseButtonDown(0))                              //点下去
        {
            if (!UtilTools.ClickUI() && UtilTools.ClickInValidArea()) //没点到UI && 点的是有效区
            {
                if (_dragType != EDragType.NONE)
                {
                    //还在滑动
                    if (_mMomentum.magnitude > 1f)
                    {
                        _bDrag = true;
                    }
                    else
                    {
                        _bDrag = false;
                    }
                }
                else
                {
                    _bDrag = false;
                }

                _bPressed          = true;
                _pressedMousePos   = Input.mousePosition;
                _pressedCameraPos  = _curCameraPos;
                _mMomentum         = Vector2.zero;
                _deltaDrag         = Vector2.zero;
                _lastFrameMousePos = Vector3.zero;
            }
        }
        else if (Input.GetMouseButtonUp(0))//弹起
        {
            _bPressed = false;
            if (_dragType == EDragType.PAGEVIEW)
            {
                if (_pageViewPoints.Count == 0)
                {
                    _pageViewTargetPoint = -1;
                }
                else
                {
                    int     dir       = 1;
                    Vector3 offsetPos = (Vector3)NGUIMath.SpringDampen(ref _mMomentum, 10f, RealTime.deltaTime);
                    if (Mathf.Abs(offsetPos.x) > 1f)  //拖动时,翻到拖动方向的那一页

                    {
                        int offPage = -1;//-1表示前一页,1表示后一页
                        if (_mMomentum.x > 0f)
                        {
                            offPage = 1;
                        }
                        _pageViewTargetPoint = GetTargetPage(_curCameraPos, offPage, ref dir);
                    }
                    else//原地弹起时,靠近哪页就滚动到哪一页
                    {
                        _pageViewTargetPoint = GetTargetPage(_curCameraPos, 0, ref dir);
                    }
                    if (_pageViewTargetPoint == -1f || Mathf.Abs(_curCameraPos - _pageViewTargetPoint) <= 0.01f)
                    {
                        _mMomentum = Vector2.zero;
                    }
                    else
                    {
                        _mMomentum = new Vector2(dir * _pageMomentum, 0f);
                    }
                }
            }
            //Utils.LogSys.Log("camera path value " + _curCameraPos);
        }
    }
Ejemplo n.º 13
0
    public void Recenter()
    {
        if (this.mScrollView == null)
        {
            this.mScrollView = NGUITools.FindInParents <UIScrollView>(base.gameObject);
            if (this.mScrollView == null)
            {
                Debug.LogWarning(string.Concat(new object[]
                {
                    base.GetType(),
                    " requires ",
                    typeof(UIScrollView),
                    " on a parent object in order to work"
                }), this);
                base.enabled = false;
                return;
            }
            if (this.mScrollView)
            {
                this.mScrollView.centerOnChild = this;
                UIScrollView uiscrollView = this.mScrollView;
                uiscrollView.onDragFinished = (UIScrollView.OnDragNotification)Delegate.Combine(uiscrollView.onDragFinished, new UIScrollView.OnDragNotification(this.OnDragFinished));
            }
            if (this.mScrollView.horizontalScrollBar != null)
            {
                UIProgressBar horizontalScrollBar = this.mScrollView.horizontalScrollBar;
                horizontalScrollBar.onDragFinished = (UIProgressBar.OnDragFinished)Delegate.Combine(horizontalScrollBar.onDragFinished, new UIProgressBar.OnDragFinished(this.OnDragFinished));
            }
            if (this.mScrollView.verticalScrollBar != null)
            {
                UIProgressBar verticalScrollBar = this.mScrollView.verticalScrollBar;
                verticalScrollBar.onDragFinished = (UIProgressBar.OnDragFinished)Delegate.Combine(verticalScrollBar.onDragFinished, new UIProgressBar.OnDragFinished(this.OnDragFinished));
            }
        }
        if (this.mScrollView.panel == null)
        {
            return;
        }
        Transform transform = base.transform;

        if (transform.childCount == 0)
        {
            return;
        }
        Vector3[] worldCorners = this.mScrollView.panel.worldCorners;
        Vector3   vector       = (worldCorners[2] + worldCorners[0]) * 0.5f;
        Vector3   vector2      = this.mScrollView.currentMomentum * this.mScrollView.momentumAmount;
        Vector3   a            = NGUIMath.SpringDampen(ref vector2, 9f, 2f);
        Vector3   b            = vector - a * 0.01f;
        float     num          = float.MaxValue;
        Transform target       = null;
        int       num2         = 0;
        int       i            = 0;
        int       childCount   = transform.childCount;

        while (i < childCount)
        {
            Transform child = transform.GetChild(i);
            if (child.gameObject.activeInHierarchy)
            {
                float num3 = Vector3.SqrMagnitude(child.position - b);
                if (num3 < num)
                {
                    num    = num3;
                    target = child;
                    num2   = i;
                }
            }
            i++;
        }
        if (this.nextPageThreshold > 0f && UICamera.currentTouch != null && this.mCenteredObject != null && this.mCenteredObject.transform == transform.GetChild(num2))
        {
            Vector2 totalDelta             = UICamera.currentTouch.totalDelta;
            UIScrollView.Movement movement = this.mScrollView.movement;
            float num4;
            if (movement != UIScrollView.Movement.Horizontal)
            {
                if (movement != UIScrollView.Movement.Vertical)
                {
                    num4 = totalDelta.magnitude;
                }
                else
                {
                    num4 = totalDelta.y;
                }
            }
            else
            {
                num4 = totalDelta.x;
            }
            if (Mathf.Abs(num4) > this.nextPageThreshold)
            {
                UIGrid component = base.GetComponent <UIGrid>();
                if (component != null && component.sorting != UIGrid.Sorting.None)
                {
                    List <Transform> childList = component.GetChildList();
                    if (num4 > this.nextPageThreshold)
                    {
                        if (num2 > 0)
                        {
                            target = childList[num2 - 1];
                        }
                        else
                        {
                            target = childList[0];
                        }
                    }
                    else if (num4 < -this.nextPageThreshold)
                    {
                        if (num2 < childList.Count - 1)
                        {
                            target = childList[num2 + 1];
                        }
                        else
                        {
                            target = childList[childList.Count - 1];
                        }
                    }
                }
                else
                {
                    Debug.LogWarning("Next Page Threshold requires a sorted UIGrid in order to work properly", this);
                }
            }
        }
        this.CenterOn(target, vector);
    }
Ejemplo n.º 14
0
    public void Recenter()
    {
        if (mScrollView == null)
        {
            mScrollView = NGUITools.FindInParents <UIScrollView>(base.gameObject);
            if (mScrollView == null)
            {
                Debug.LogWarning(GetType() + " requires " + typeof(UIScrollView) + " on a parent object in order to work", this);
                base.enabled = false;
                return;
            }
            if ((bool)mScrollView)
            {
                mScrollView.centerOnChild = this;
                UIScrollView uIScrollView = mScrollView;
                uIScrollView.onDragFinished = (UIScrollView.OnDragNotification)Delegate.Combine(uIScrollView.onDragFinished, new UIScrollView.OnDragNotification(OnDragFinished));
            }
            if (mScrollView.horizontalScrollBar != null)
            {
                UIProgressBar horizontalScrollBar = mScrollView.horizontalScrollBar;
                horizontalScrollBar.onDragFinished = (UIProgressBar.OnDragFinished)Delegate.Combine(horizontalScrollBar.onDragFinished, new UIProgressBar.OnDragFinished(OnDragFinished));
            }
            if (mScrollView.verticalScrollBar != null)
            {
                UIProgressBar verticalScrollBar = mScrollView.verticalScrollBar;
                verticalScrollBar.onDragFinished = (UIProgressBar.OnDragFinished)Delegate.Combine(verticalScrollBar.onDragFinished, new UIProgressBar.OnDragFinished(OnDragFinished));
            }
        }
        if (mScrollView.panel == null)
        {
            return;
        }
        Transform transform = base.transform;

        if (transform.childCount == 0)
        {
            return;
        }
        Vector3[] worldCorners = mScrollView.panel.worldCorners;
        Vector3   vector       = (worldCorners[2] + worldCorners[0]) * 0.5f;
        Vector3   velocity     = mScrollView.currentMomentum * mScrollView.momentumAmount;
        Vector3   a            = NGUIMath.SpringDampen(ref velocity, 9f, 2f);
        Vector3   b            = vector - a * 0.01f;
        float     num          = float.MaxValue;
        Transform target       = null;
        int       index        = 0;
        int       num2         = 0;
        int       i            = 0;
        int       childCount   = transform.childCount;
        int       num3         = 0;

        for (; i < childCount; i++)
        {
            Transform child = transform.GetChild(i);
            if (child.gameObject.activeInHierarchy)
            {
                float num4 = Vector3.SqrMagnitude(child.position - b);
                if (num4 < num)
                {
                    num    = num4;
                    target = child;
                    index  = i;
                    num2   = num3;
                }
                num3++;
            }
        }
        if (nextPageThreshold > 0f && UICamera.currentTouch != null && mCenteredObject != null && mCenteredObject.transform == transform.GetChild(index))
        {
            Vector3 point = UICamera.currentTouch.totalDelta;
            point = base.transform.rotation * point;
            float num5;
            switch (mScrollView.movement)
            {
            case UIScrollView.Movement.Horizontal:
                num5 = point.x;
                break;

            case UIScrollView.Movement.Vertical:
                num5 = point.y;
                break;

            default:
                num5 = point.magnitude;
                break;
            }
            if (Mathf.Abs(num5) > nextPageThreshold)
            {
                UIGrid component = GetComponent <UIGrid>();
                if (component != null && component.sorting != 0)
                {
                    List <Transform> childList = component.GetChildList();
                    if (num5 > nextPageThreshold)
                    {
                        target = ((num2 <= 0) ? ((!(GetComponent <UIWrapContent>() == null)) ? childList[childList.Count - 1] : childList[0]) : childList[num2 - 1]);
                    }
                    else if (num5 < 0f - nextPageThreshold)
                    {
                        target = ((num2 >= childList.Count - 1) ? ((!(GetComponent <UIWrapContent>() == null)) ? childList[0] : childList[childList.Count - 1]) : childList[num2 + 1]);
                    }
                }
                else
                {
                    Debug.LogWarning("Next Page Threshold requires a sorted UIGrid in order to work properly", this);
                }
            }
        }
        CenterOn(target, vector);
    }
Ejemplo n.º 15
0
    // Token: 0x060000C0 RID: 192 RVA: 0x00019454 File Offset: 0x00017654
    private void LateUpdate()
    {
        if (this.repositionClipping)
        {
            this.repositionClipping = false;
            this.mCalculatedBounds  = false;
            this.SetDragAmount(this.relativePositionOnReset.x, this.relativePositionOnReset.y, true);
        }
        if (!Application.isPlaying)
        {
            return;
        }
        float num = base.UpdateRealTimeDelta();

        if (this.showScrollBars != UIDraggablePanel.ShowCondition.Always)
        {
            bool flag  = false;
            bool flag2 = false;
            if (this.showScrollBars != UIDraggablePanel.ShowCondition.WhenDragging || this.mDragID != -10 || this.mMomentum.magnitude > 0.01f)
            {
                flag  = this.shouldMoveVertically;
                flag2 = this.shouldMoveHorizontally;
            }
            if (this.verticalScrollBar)
            {
                float num2 = this.verticalScrollBar.alpha;
                num2 += ((!flag) ? (-num * 3f) : (num * 6f));
                num2  = Mathf.Clamp01(num2);
                if (this.verticalScrollBar.alpha != num2)
                {
                    this.verticalScrollBar.alpha = num2;
                }
            }
            if (this.horizontalScrollBar)
            {
                float num3 = this.horizontalScrollBar.alpha;
                num3 += ((!flag2) ? (-num * 3f) : (num * 6f));
                num3  = Mathf.Clamp01(num3);
                if (this.horizontalScrollBar.alpha != num3)
                {
                    this.horizontalScrollBar.alpha = num3;
                }
            }
        }
        if (this.mShouldMove && !this.mPressed)
        {
            this.mMomentum -= this.scale * (this.mScroll * 0.05f);
            if (this.mMomentum.magnitude > 0.0001f)
            {
                this.mScroll = NGUIMath.SpringLerp(this.mScroll, 0f, 20f, num);
                Vector3 absolute = NGUIMath.SpringDampen(ref this.mMomentum, 9f, num);
                this.MoveAbsolute(absolute);
                if (this.restrictWithinPanel && this.mPanel.clipping != UIDrawCall.Clipping.None)
                {
                    this.RestrictWithinBounds(false);
                }
                if (this.mMomentum.magnitude < 0.0001f && this.onDragFinished != null)
                {
                    this.onDragFinished();
                }
                return;
            }
            this.mScroll   = 0f;
            this.mMomentum = Vector3.zero;
        }
        else
        {
            this.mScroll = 0f;
        }
        NGUIMath.SpringDampen(ref this.mMomentum, 9f, num);
    }
Ejemplo n.º 16
0
 private void LateUpdate()
 {
     if (!this.mPanel.enabled)
     {
         this.mMomentum = Vector3.zero;
     }
     else
     {
         if (this.mPanel.changedLastFrame)
         {
             this.OnPanelChanged();
         }
         if (this.repositionClipping)
         {
             this.repositionClipping = false;
             this.mCalculatedBounds  = false;
             this.SetDragAmount(this.relativePositionOnReset.x, this.relativePositionOnReset.y, true);
         }
         if (Application.isPlaying)
         {
             float deltaTime = base.UpdateRealTimeDelta();
             if (this.showScrollBars != ShowCondition.Always)
             {
                 bool shouldMoveVertically   = false;
                 bool shouldMoveHorizontally = false;
                 if ((this.showScrollBars != ShowCondition.WhenDragging) || (this.mTouches > 0))
                 {
                     shouldMoveVertically   = this.shouldMoveVertically;
                     shouldMoveHorizontally = this.shouldMoveHorizontally;
                 }
                 if (this.verticalScrollBar != null)
                 {
                     float num2 = this.verticalScrollBar.alpha + (!shouldMoveVertically ? (-deltaTime * 3f) : (deltaTime * 6f));
                     num2 = Mathf.Clamp01(num2);
                     if (this.verticalScrollBar.alpha != num2)
                     {
                         this.verticalScrollBar.alpha = num2;
                     }
                 }
                 if (this.horizontalScrollBar != null)
                 {
                     float num3 = this.horizontalScrollBar.alpha + (!shouldMoveHorizontally ? (-deltaTime * 3f) : (deltaTime * 6f));
                     num3 = Mathf.Clamp01(num3);
                     if (this.horizontalScrollBar.alpha != num3)
                     {
                         this.horizontalScrollBar.alpha = num3;
                     }
                 }
             }
             if (this.mShouldMove && !this.mPressed)
             {
                 this.mMomentum += (Vector3)(this.scale * (-this.mScroll * 0.05f));
                 if (this.mMomentum.magnitude > 0.0001f)
                 {
                     this.mScroll = NGUIMath.SpringLerp(this.mScroll, 0f, 20f, deltaTime);
                     Vector3 absolute = NGUIMath.SpringDampen(ref this.mMomentum, 9f, deltaTime);
                     this.MoveAbsolute(absolute);
                     if ((this.restrictWithinPanel || this.restrictWithinPanelWithScroll) && (this.mPanel.clipping != UIDrawCall.Clipping.None))
                     {
                         this.RestrictWithinBounds(false);
                     }
                     return;
                 }
                 this.mScroll = 0f;
             }
             else
             {
                 this.mScroll = 0f;
             }
             NGUIMath.SpringDampen(ref this.mMomentum, 9f, deltaTime);
         }
     }
 }
Ejemplo n.º 17
0
    /// <summary>
    /// Apply the dragging momentum.
    /// </summary>

    void LateUpdate()
    {
        if (!Application.isPlaying)
        {
            return;
        }
        float delta = RealTime.deltaTime;

        // Fade the scroll bars if needed
        if (showScrollBars != ShowCondition.Always && (verticalScrollBar || horizontalScrollBar))
        {
            bool vertical   = false;
            bool horizontal = false;

            if (showScrollBars != ShowCondition.WhenDragging || mDragID != -10 || mMomentum.magnitude > 0.01f)
            {
                vertical   = shouldMoveVertically;
                horizontal = shouldMoveHorizontally;
            }

            if (verticalScrollBar)
            {
                float alpha = verticalScrollBar.alpha;
                alpha += vertical ? delta * 6f : -delta * 3f;
                alpha  = Mathf.Clamp01(alpha);
                if (verticalScrollBar.alpha != alpha)
                {
                    verticalScrollBar.alpha = alpha;
                }
            }

            if (horizontalScrollBar)
            {
                float alpha = horizontalScrollBar.alpha;
                alpha += horizontal ? delta * 6f : -delta * 3f;
                alpha  = Mathf.Clamp01(alpha);
                if (horizontalScrollBar.alpha != alpha)
                {
                    horizontalScrollBar.alpha = alpha;
                }
            }
        }

        // Apply momentum
        if (mShouldMove && !mPressed)
        {
            if (movement == Movement.Horizontal)
            {
                mMomentum -= mTrans.TransformDirection(new Vector3(mScroll * 0.05f, 0f, 0f));
            }
            else if (movement == Movement.Vertical)
            {
                mMomentum -= mTrans.TransformDirection(new Vector3(0f, mScroll * 0.05f, 0f));
            }
            else if (movement == Movement.Unrestricted)
            {
                mMomentum -= mTrans.TransformDirection(new Vector3(mScroll * 0.05f, mScroll * 0.05f, 0f));
            }
            else
            {
                mMomentum -= mTrans.TransformDirection(new Vector3(
                                                           mScroll * customMovement.x * 0.05f,
                                                           mScroll * customMovement.y * 0.05f, 0f));
            }

            if (mMomentum.magnitude > 0.0001f)
            {
                mScroll = NGUIMath.SpringLerp(mScroll, 0f, 20f, delta);

                // Move the scroll view
                Vector3 offset = NGUIMath.SpringDampen(ref mMomentum, 9f, delta);
                MoveAbsolute(offset);

                // Restrict the contents to be within the scroll view's bounds
                if (restrictWithinPanel && mPanel.clipping != UIDrawCall.Clipping.None)
                {
                    RestrictWithinBounds(false, canMoveHorizontally, canMoveVertically);
                }

                if (mMomentum.magnitude < 0.0001f && onDragFinished != null)
                {
                    onDragFinished();
                }

                return;
            }
            else
            {
                mScroll   = 0f;
                mMomentum = Vector3.zero;
            }
        }
        else
        {
            mScroll = 0f;
        }

        // Dampen the momentum
        NGUIMath.SpringDampen(ref mMomentum, 9f, delta);
    }
Ejemplo n.º 18
0
    public void Recenter()
    {
        //IL_0013: Unknown result type (might be due to invalid IL or missing references)
        //IL_0018: Expected O, but got Unknown
        //IL_0151: Unknown result type (might be due to invalid IL or missing references)
        //IL_0156: Expected O, but got Unknown
        //IL_017b: Unknown result type (might be due to invalid IL or missing references)
        //IL_0187: 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_0196: Unknown result type (might be due to invalid IL or missing references)
        //IL_019b: Unknown result type (might be due to invalid IL or missing references)
        //IL_01a2: Unknown result type (might be due to invalid IL or missing references)
        //IL_01b2: Unknown result type (might be due to invalid IL or missing references)
        //IL_01b7: 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_01cc: Unknown result type (might be due to invalid IL or missing references)
        //IL_01d3: Unknown result type (might be due to invalid IL or missing references)
        //IL_01d8: Unknown result type (might be due to invalid IL or missing references)
        //IL_01dd: Unknown result type (might be due to invalid IL or missing references)
        //IL_0231: Unknown result type (might be due to invalid IL or missing references)
        //IL_0247: Unknown result type (might be due to invalid IL or missing references)
        //IL_024c: Unknown result type (might be due to invalid IL or missing references)
        //IL_024e: Unknown result type (might be due to invalid IL or missing references)
        //IL_02a3: Unknown result type (might be due to invalid IL or missing references)
        //IL_02a8: Expected O, but got Unknown
        //IL_02ac: Unknown result type (might be due to invalid IL or missing references)
        //IL_02c2: Unknown result type (might be due to invalid IL or missing references)
        //IL_02c7: Unknown result type (might be due to invalid IL or missing references)
        //IL_02c9: Unknown result type (might be due to invalid IL or missing references)
        //IL_0334: Unknown result type (might be due to invalid IL or missing references)
        //IL_0351: Unknown result type (might be due to invalid IL or missing references)
        //IL_0365: Unknown result type (might be due to invalid IL or missing references)
        //IL_036a: Unknown result type (might be due to invalid IL or missing references)
        //IL_036f: Unknown result type (might be due to invalid IL or missing references)
        //IL_0372: Unknown result type (might be due to invalid IL or missing references)
        //IL_0377: Unknown result type (might be due to invalid IL or missing references)
        //IL_037c: Unknown result type (might be due to invalid IL or missing references)
        //IL_037e: Unknown result type (might be due to invalid IL or missing references)
        //IL_0383: Unknown result type (might be due to invalid IL or missing references)
        //IL_0459: Unknown result type (might be due to invalid IL or missing references)
        //IL_045e: Expected O, but got Unknown
        //IL_0478: Unknown result type (might be due to invalid IL or missing references)
        //IL_048b: Unknown result type (might be due to invalid IL or missing references)
        //IL_0490: Expected O, but got Unknown
        //IL_0517: Unknown result type (might be due to invalid IL or missing references)
        //IL_051c: Expected O, but got Unknown
        //IL_053d: Unknown result type (might be due to invalid IL or missing references)
        //IL_0549: Unknown result type (might be due to invalid IL or missing references)
        //IL_054e: Expected O, but got Unknown
        //IL_0553: Unknown result type (might be due to invalid IL or missing references)
        if (mScrollView == null)
        {
            mScrollView = NGUITools.FindInParents <UIScrollView>(this.get_gameObject());
            if (mScrollView == null)
            {
                Debug.LogWarning((object)(GetType() + " requires " + typeof(UIScrollView) + " on a parent object in order to work"), this);
                this.set_enabled(false);
                return;
            }
            if (Object.op_Implicit(mScrollView))
            {
                mScrollView.centerOnChild = this;
                UIScrollView uIScrollView = mScrollView;
                uIScrollView.onDragFinished = (UIScrollView.OnDragNotification)Delegate.Combine(uIScrollView.onDragFinished, new UIScrollView.OnDragNotification(OnDragFinished));
            }
            if (mScrollView.horizontalScrollBar != null)
            {
                UIProgressBar horizontalScrollBar = mScrollView.horizontalScrollBar;
                horizontalScrollBar.onDragFinished = (UIProgressBar.OnDragFinished)Delegate.Combine(horizontalScrollBar.onDragFinished, new UIProgressBar.OnDragFinished(OnDragFinished));
            }
            if (mScrollView.verticalScrollBar != null)
            {
                UIProgressBar verticalScrollBar = mScrollView.verticalScrollBar;
                verticalScrollBar.onDragFinished = (UIProgressBar.OnDragFinished)Delegate.Combine(verticalScrollBar.onDragFinished, new UIProgressBar.OnDragFinished(OnDragFinished));
            }
        }
        if (!(mScrollView.panel == null))
        {
            Transform val = this.get_transform();
            if (val.get_childCount() != 0)
            {
                Vector3[]        worldCorners = mScrollView.panel.worldCorners;
                Vector3          val2         = (worldCorners[2] + worldCorners[0]) * 0.5f;
                Vector3          velocity     = mScrollView.currentMomentum * mScrollView.momentumAmount;
                Vector3          val3         = NGUIMath.SpringDampen(ref velocity, 9f, 2f);
                Vector3          val4         = val2 - val3 * 0.01f;
                float            num          = 3.40282347E+38f;
                Transform        target       = null;
                int              num2         = 0;
                int              num3         = 0;
                UIGrid           component    = this.GetComponent <UIGrid>();
                List <Transform> list         = null;
                if (component != null)
                {
                    list = component.GetChildList();
                    int i     = 0;
                    int count = list.Count;
                    int num4  = 0;
                    for (; i < count; i++)
                    {
                        Transform val5 = list[i];
                        if (val5.get_gameObject().get_activeInHierarchy())
                        {
                            float num5 = Vector3.SqrMagnitude(val5.get_position() - val4);
                            if (num5 < num)
                            {
                                num    = num5;
                                target = val5;
                                num2   = i;
                                num3   = num4;
                            }
                            num4++;
                        }
                    }
                }
                else
                {
                    int j          = 0;
                    int childCount = val.get_childCount();
                    int num6       = 0;
                    for (; j < childCount; j++)
                    {
                        Transform val6 = val.GetChild(j);
                        if (val6.get_gameObject().get_activeInHierarchy())
                        {
                            float num7 = Vector3.SqrMagnitude(val6.get_position() - val4);
                            if (num7 < num)
                            {
                                num    = num7;
                                target = val6;
                                num2   = j;
                                num3   = num6;
                            }
                            num6++;
                        }
                    }
                }
                if (nextPageThreshold > 0f && UICamera.currentTouch != null && mCenteredObject != null && mCenteredObject.get_transform() == ((list == null) ? ((object)val.GetChild(num2)) : ((object)list[num2])))
                {
                    Vector3 val7 = Vector2.op_Implicit(UICamera.currentTouch.totalDelta);
                    val7 = this.get_transform().get_rotation() * val7;
                    float num8 = 0f;
                    switch (mScrollView.movement)
                    {
                    case UIScrollView.Movement.Horizontal:
                        num8 = val7.x;
                        break;

                    case UIScrollView.Movement.Vertical:
                        num8 = val7.y;
                        break;

                    default:
                        num8 = val7.get_magnitude();
                        break;
                    }
                    if (Mathf.Abs(num8) > nextPageThreshold)
                    {
                        if (num8 > nextPageThreshold)
                        {
                            target = ((list != null) ? ((object)((num3 <= 0) ? ((!(this.GetComponent <UIWrapContent>() == null)) ? list[list.Count - 1] : list[0]) : list[num3 - 1])) : ((object)((num3 <= 0) ? ((!(this.GetComponent <UIWrapContent>() == null)) ? val.GetChild(val.get_childCount() - 1) : val.GetChild(0)) : val.GetChild(num3 - 1))));
                        }
                        else if (num8 < 0f - nextPageThreshold)
                        {
                            target = ((list != null) ? ((object)((num3 >= list.Count - 1) ? ((!(this.GetComponent <UIWrapContent>() == null)) ? list[0] : list[list.Count - 1]) : list[num3 + 1])) : ((object)((num3 >= val.get_childCount() - 1) ? ((!(this.GetComponent <UIWrapContent>() == null)) ? val.GetChild(0) : val.GetChild(val.get_childCount() - 1)) : val.GetChild(num3 + 1))));
                        }
                    }
                }
                CenterOn(target, val2);
            }
        }
    }
Ejemplo n.º 19
0
    private void LateUpdate()
    {
        if (!this.mPanel.enabled)
        {
            this.mMomentum = Vector3.zero;
            return;
        }
        if (this.mPanel.changedLastFrame)
        {
            this.OnPanelChanged();
        }
        if (this.repositionClipping)
        {
            this.repositionClipping = false;
            this.mCalculatedBounds  = false;
            this.SetDragAmount(this.relativePositionOnReset.x, this.relativePositionOnReset.y, true);
        }
        if (!Application.isPlaying)
        {
            return;
        }
        float single = base.UpdateRealTimeDelta();

        if (this.showScrollBars != UIDraggablePanel.ShowCondition.Always)
        {
            bool flag  = false;
            bool flag1 = false;
            if (this.showScrollBars != UIDraggablePanel.ShowCondition.WhenDragging || this.mTouches > 0)
            {
                flag  = this.shouldMoveVertically;
                flag1 = this.shouldMoveHorizontally;
            }
            if (this.verticalScrollBar)
            {
                float single1 = this.verticalScrollBar.alpha;
                single1 = single1 + (!flag ? -single * 3f : single * 6f);
                single1 = Mathf.Clamp01(single1);
                if (this.verticalScrollBar.alpha != single1)
                {
                    this.verticalScrollBar.alpha = single1;
                }
            }
            if (this.horizontalScrollBar)
            {
                float single2 = this.horizontalScrollBar.alpha;
                single2 = single2 + (!flag1 ? -single * 3f : single * 6f);
                single2 = Mathf.Clamp01(single2);
                if (this.horizontalScrollBar.alpha != single2)
                {
                    this.horizontalScrollBar.alpha = single2;
                }
            }
        }
        if (!this.mShouldMove || this.mPressed)
        {
            this.mScroll = 0f;
        }
        else
        {
            UIDraggablePanel uIDraggablePanel = this;
            uIDraggablePanel.mMomentum = uIDraggablePanel.mMomentum + (this.scale * (-this.mScroll * 0.05f));
            if (this.mMomentum.magnitude > 0.0001f)
            {
                this.mScroll = NGUIMath.SpringLerp(this.mScroll, 0f, 20f, single);
                Vector3 vector3 = NGUIMath.SpringDampen(ref this.mMomentum, 9f, single);
                this.MoveAbsolute(vector3);
                if ((this.restrictWithinPanel || this.restrictWithinPanelWithScroll) && this.mPanel.clipping != UIDrawCall.Clipping.None)
                {
                    this.RestrictWithinBounds(false);
                }
                return;
            }
            this.mScroll = 0f;
        }
        NGUIMath.SpringDampen(ref this.mMomentum, 9f, single);
    }
Ejemplo n.º 20
0
    private void LateUpdate()
    {
        if (!Application.isPlaying)
        {
            return;
        }
        float deltaTime = RealTime.deltaTime;

        if (this.showScrollBars != UIScrollView.ShowCondition.Always && (this.verticalScrollBar || this.horizontalScrollBar))
        {
            bool flag  = false;
            bool flag2 = false;
            if (this.showScrollBars != UIScrollView.ShowCondition.WhenDragging || this.mDragID != -10 || this.mMomentum.magnitude > 0.01f)
            {
                flag  = this.shouldMoveVertically;
                flag2 = this.shouldMoveHorizontally;
            }
            if (this.verticalScrollBar)
            {
                float num = this.verticalScrollBar.alpha;
                num += ((!flag) ? (-deltaTime * 3f) : (deltaTime * 6f));
                num  = Mathf.Clamp01(num);
                if (this.verticalScrollBar.alpha != num)
                {
                    this.verticalScrollBar.alpha = num;
                }
            }
            if (this.horizontalScrollBar)
            {
                float num2 = this.horizontalScrollBar.alpha;
                num2 += ((!flag2) ? (-deltaTime * 3f) : (deltaTime * 6f));
                num2  = Mathf.Clamp01(num2);
                if (this.horizontalScrollBar.alpha != num2)
                {
                    this.horizontalScrollBar.alpha = num2;
                }
            }
        }
        if (this.mShouldMove && !this.mPressed)
        {
            if (this.movement == UIScrollView.Movement.Horizontal)
            {
                this.mMomentum -= this.mTrans.TransformDirection(new Vector3(this.mScroll * 0.05f, 0f, 0f));
            }
            else if (this.movement == UIScrollView.Movement.Vertical)
            {
                this.mMomentum -= this.mTrans.TransformDirection(new Vector3(0f, this.mScroll * 0.05f, 0f));
            }
            else if (this.movement == UIScrollView.Movement.Unrestricted)
            {
                this.mMomentum -= this.mTrans.TransformDirection(new Vector3(this.mScroll * 0.05f, this.mScroll * 0.05f, 0f));
            }
            else
            {
                this.mMomentum -= this.mTrans.TransformDirection(new Vector3(this.mScroll * this.customMovement.x * 0.05f, this.mScroll * this.customMovement.y * 0.05f, 0f));
            }
            if (this.mMomentum.magnitude > 0.0001f)
            {
                this.mScroll = NGUIMath.SpringLerp(this.mScroll, 0f, 20f, deltaTime);
                Vector3 absolute = NGUIMath.SpringDampen(ref this.mMomentum, 9f, deltaTime);
                this.MoveAbsolute(absolute);
                if (this.restrictWithinPanel && this.mPanel.clipping != UIDrawCall.Clipping.None)
                {
                    this.RestrictWithinBounds(false, this.canMoveHorizontally, this.canMoveVertically);
                }
                if (this.mMomentum.magnitude < 0.0001f && this.onDragFinished != null)
                {
                    this.onDragFinished();
                }
                return;
            }
            this.mScroll   = 0f;
            this.mMomentum = Vector3.zero;
        }
        else
        {
            this.mScroll = 0f;
        }
        if (this.mAutoMove)
        {
            if (this.mMoveAmount * this.mMoveSpeed <= this.mDestAmount * this.mMoveSpeed)
            {
                if (this.movement == UIScrollView.Movement.Custom)
                {
                    if (this.customMovement.x > 0f)
                    {
                        this.mMoveAmount += deltaTime * this.mMoveSpeed;
                        this.SetDragAmount(this.mMoveAmount, 0f, false);
                    }
                    else if (this.customMovement.y > 0f)
                    {
                        this.mMoveAmount += deltaTime * this.mMoveSpeed;
                        this.SetDragAmount(0f, this.mMoveAmount, false);
                    }
                }
            }
            else
            {
                this.mAutoMove = false;
            }
        }
        NGUIMath.SpringDampen(ref this.mMomentum, 9f, deltaTime);
    }
Ejemplo n.º 21
0
    private void LateUpdate()
    {
        if (!Application.isPlaying)
        {
            return;
        }
        float deltaTime = RealTime.deltaTime;

        if (showScrollBars != 0 && ((bool)verticalScrollBar || (bool)horizontalScrollBar))
        {
            bool flag  = false;
            bool flag2 = false;
            if (showScrollBars != ShowCondition.WhenDragging || mDragID != -10 || mMomentum.magnitude > 0.01f)
            {
                flag  = shouldMoveVertically;
                flag2 = shouldMoveHorizontally;
            }
            if ((bool)verticalScrollBar)
            {
                float alpha = verticalScrollBar.alpha;
                alpha += ((!flag) ? ((0f - deltaTime) * 3f) : (deltaTime * 6f));
                alpha  = Mathf.Clamp01(alpha);
                if (verticalScrollBar.alpha != alpha)
                {
                    verticalScrollBar.alpha = alpha;
                }
            }
            if ((bool)horizontalScrollBar)
            {
                float alpha2 = horizontalScrollBar.alpha;
                alpha2 += ((!flag2) ? ((0f - deltaTime) * 3f) : (deltaTime * 6f));
                alpha2  = Mathf.Clamp01(alpha2);
                if (horizontalScrollBar.alpha != alpha2)
                {
                    horizontalScrollBar.alpha = alpha2;
                }
            }
        }
        if (!mShouldMove)
        {
            return;
        }
        if (!mPressed)
        {
            if (mMomentum.magnitude > 0.0001f || mScroll != 0f)
            {
                if (movement == Movement.Horizontal)
                {
                    mMomentum -= mTrans.TransformDirection(new Vector3(mScroll * 0.05f, 0f, 0f));
                }
                else if (movement == Movement.Vertical)
                {
                    mMomentum -= mTrans.TransformDirection(new Vector3(0f, mScroll * 0.05f, 0f));
                }
                else if (movement == Movement.Unrestricted)
                {
                    mMomentum -= mTrans.TransformDirection(new Vector3(mScroll * 0.05f, mScroll * 0.05f, 0f));
                }
                else
                {
                    mMomentum -= mTrans.TransformDirection(new Vector3(mScroll * customMovement.x * 0.05f, mScroll * customMovement.y * 0.05f, 0f));
                }
                mScroll = NGUIMath.SpringLerp(mScroll, 0f, 20f, deltaTime);
                Vector3 absolute = NGUIMath.SpringDampen(ref mMomentum, dampenStrength, deltaTime);
                MoveAbsolute(absolute);
                if (restrictWithinPanel && mPanel.clipping != 0)
                {
                    if (NGUITools.GetActive(centerOnChild))
                    {
                        if (centerOnChild.nextPageThreshold != 0f)
                        {
                            mMomentum = Vector3.zero;
                            mScroll   = 0f;
                        }
                        else
                        {
                            centerOnChild.Recenter();
                        }
                    }
                    else
                    {
                        RestrictWithinBounds(instant: false, canMoveHorizontally, canMoveVertically);
                    }
                }
                if (onMomentumMove != null)
                {
                    onMomentumMove();
                }
                return;
            }
            mScroll   = 0f;
            mMomentum = Vector3.zero;
            SpringPanel component = GetComponent <SpringPanel>();
            if (!(component != null) || !component.enabled)
            {
                mShouldMove = false;
                if (onStoppedMoving != null)
                {
                    onStoppedMoving();
                }
            }
        }
        else
        {
            mScroll = 0f;
            NGUIMath.SpringDampen(ref mMomentum, 9f, deltaTime);
        }
    }
Ejemplo n.º 22
0
    public void Recenter()
    {
        if (this.mScrollView == null)
        {
            this.mScrollView = NGUITools.FindInParents <UIScrollView>(base.gameObject);
            if (this.mScrollView == null)
            {
                Debug.LogWarning(string.Concat(new object[]
                {
                    base.GetType(),
                    " requires ",
                    typeof(UIScrollView),
                    " on a parent object in order to work"
                }), this);
                base.enabled = false;
                return;
            }
            if (this.mScrollView)
            {
                this.mScrollView.centerOnChild = this;
            }
            if (this.mScrollView.horizontalScrollBar != null)
            {
                UIProgressBar expr_AF = this.mScrollView.horizontalScrollBar;
                expr_AF.onDragFinished = (UIProgressBar.OnDragFinished)Delegate.Combine(expr_AF.onDragFinished, new UIProgressBar.OnDragFinished(this.OnDragFinished));
            }
            if (this.mScrollView.verticalScrollBar != null)
            {
                UIProgressBar expr_F1 = this.mScrollView.verticalScrollBar;
                expr_F1.onDragFinished = (UIProgressBar.OnDragFinished)Delegate.Combine(expr_F1.onDragFinished, new UIProgressBar.OnDragFinished(this.OnDragFinished));
            }
        }
        if (this.mScrollView.panel == null)
        {
            return;
        }
        Transform transform = base.transform;

        if (transform.childCount == 0)
        {
            return;
        }
        Vector3[]        worldCorners = this.mScrollView.panel.worldCorners;
        Vector3          vector       = (worldCorners[2] + worldCorners[0]) * 0.5f;
        Vector3          vector2      = this.mScrollView.currentMomentum * this.mScrollView.momentumAmount;
        Vector3          a            = NGUIMath.SpringDampen(ref vector2, 9f, 2f);
        Vector3          b            = vector - a * 0.01f;
        float            num          = 3.40282347E+38f;
        Transform        target       = null;
        int              index        = 0;
        int              num2         = 0;
        UIGrid           component    = base.GetComponent <UIGrid>();
        List <Transform> list         = null;

        if (component != null)
        {
            list = component.GetChildList();
            int i     = 0;
            int count = list.Count;
            int num3  = 0;
            while (i < count)
            {
                Transform transform2 = list[i];
                if (transform2.gameObject.activeInHierarchy)
                {
                    float num4 = Vector3.SqrMagnitude(transform2.position - b);
                    if (num4 < num)
                    {
                        num    = num4;
                        target = transform2;
                        index  = i;
                        num2   = num3;
                    }
                    num3++;
                }
                i++;
            }
        }
        else
        {
            int j          = 0;
            int childCount = transform.childCount;
            int num5       = 0;
            while (j < childCount)
            {
                Transform child = transform.GetChild(j);
                if (child.gameObject.activeInHierarchy)
                {
                    float num6 = Vector3.SqrMagnitude(child.position - b);
                    if (num6 < num)
                    {
                        num    = num6;
                        target = child;
                        index  = j;
                        num2   = num5;
                    }
                    num5++;
                }
                j++;
            }
        }
        if (this.nextPageThreshold > 0f && UICamera.currentTouch != null && this.mCenteredObject != null && this.mCenteredObject.transform == ((list == null) ? transform.GetChild(index) : list[index]))
        {
            Vector3 point = UICamera.currentTouch.totalDelta;
            point = base.transform.rotation * point;
            UIScrollView.Movement movement = this.mScrollView.movement;
            float num7;
            if (movement != UIScrollView.Movement.Horizontal)
            {
                if (movement != UIScrollView.Movement.Vertical)
                {
                    num7 = point.magnitude;
                }
                else
                {
                    num7 = -point.y;
                }
            }
            else
            {
                num7 = point.x;
            }
            if (Mathf.Abs(num7) > this.nextPageThreshold)
            {
                if (num7 > this.nextPageThreshold)
                {
                    if (list != null)
                    {
                        if (num2 > 0)
                        {
                            target = list[num2 - 1];
                        }
                        else
                        {
                            target = ((!(base.GetComponent <UIWrapContent>() == null)) ? list[list.Count - 1] : list[0]);
                        }
                    }
                    else if (num2 > 0)
                    {
                        target = transform.GetChild(num2 - 1);
                    }
                    else
                    {
                        target = ((!(base.GetComponent <UIWrapContent>() == null)) ? transform.GetChild(transform.childCount - 1) : transform.GetChild(0));
                    }
                }
                else if (num7 < -this.nextPageThreshold)
                {
                    if (list != null)
                    {
                        if (num2 < list.Count - 1)
                        {
                            target = list[num2 + 1];
                        }
                        else
                        {
                            target = ((!(base.GetComponent <UIWrapContent>() == null)) ? list[0] : list[list.Count - 1]);
                        }
                    }
                    else if (num2 < transform.childCount - 1)
                    {
                        target = transform.GetChild(num2 + 1);
                    }
                    else
                    {
                        target = ((!(base.GetComponent <UIWrapContent>() == null)) ? transform.GetChild(0) : transform.GetChild(transform.childCount - 1));
                    }
                }
            }
        }
        this.CenterOn(target, vector);
    }
Ejemplo n.º 23
0
    /// <summary>
    /// Apply the dragging momentum.
    /// </summary>

    void LateUpdate()
    {
        // If the panel's geometry changed, recalculate the bounds
        if (mPanel.changedLastFrame)
        {
            UpdateScrollbars(true);
        }

        // Inspector functionality
        if (repositionClipping)
        {
            repositionClipping = false;
            mCalculatedBounds  = false;
            SetDragAmount(relativePositionOnReset.x, relativePositionOnReset.y, true);
        }

        if (!Application.isPlaying)
        {
            return;
        }
        float delta = UpdateRealTimeDelta();

        // Fade the scroll bars if needed
        if (showScrollBars != ShowCondition.Always)
        {
            bool vertical   = false;
            bool horizontal = false;

            if (showScrollBars != ShowCondition.WhenDragging || mDragID != -10 || mMomentum.magnitude > 0.01f)
            {
                vertical   = shouldMoveVertically;
                horizontal = shouldMoveHorizontally;
            }

            if (verticalScrollBar)
            {
                float alpha = verticalScrollBar.alpha;
                alpha += vertical ? delta * 6f : -delta * 3f;
                alpha  = Mathf.Clamp01(alpha);
                if (verticalScrollBar.alpha != alpha)
                {
                    verticalScrollBar.alpha = alpha;
                }
            }

            if (horizontalScrollBar)
            {
                float alpha = horizontalScrollBar.alpha;
                alpha += horizontal ? delta * 6f : -delta * 3f;
                alpha  = Mathf.Clamp01(alpha);
                if (horizontalScrollBar.alpha != alpha)
                {
                    horizontalScrollBar.alpha = alpha;
                }
            }
        }

        // Apply momentum
        if (mShouldMove && !mPressed)
        {
            mMomentum -= scale * (mScroll * 0.05f);

            if (mMomentum.magnitude > 0.0001f)
            {
                mScroll = NGUIMath.SpringLerp(mScroll, 0f, 20f, delta);

                // Move the panel
                Vector3 offset = NGUIMath.SpringDampen(ref mMomentum, 9f, delta);
                MoveAbsolute(offset);

                // Restrict the contents to be within the panel's bounds
                if (restrictWithinPanel && mPanel.clipping != UIDrawCall.Clipping.None)
                {
                    RestrictWithinBounds(false);
                }
                return;
            }
            else
            {
                mScroll   = 0f;
                mMomentum = Vector3.zero;
            }
        }
        else
        {
            mScroll = 0f;
        }

        // Dampen the momentum
        NGUIMath.SpringDampen(ref mMomentum, 9f, delta);
    }
Ejemplo n.º 24
0
    private void LateUpdate()
    {
        if (repositionClipping)
        {
            repositionClipping = false;
            mCalculatedBounds  = false;
            SetDragAmount(relativePositionOnReset.x, relativePositionOnReset.y, updateScrollbars: true);
        }
        if (!Application.isPlaying)
        {
            return;
        }
        float num = UpdateRealTimeDelta();

        if (showScrollBars != 0)
        {
            bool flag  = false;
            bool flag2 = false;
            if (showScrollBars != ShowCondition.WhenDragging || mDragID != -10 || mMomentum.magnitude > 0.01f)
            {
                flag  = shouldMoveVertically;
                flag2 = shouldMoveHorizontally;
            }
            if ((bool)verticalScrollBar)
            {
                float alpha = verticalScrollBar.alpha;
                alpha += ((!flag) ? ((0f - num) * 3f) : (num * 6f));
                alpha  = Mathf.Clamp01(alpha);
                if (verticalScrollBar.alpha != alpha)
                {
                    verticalScrollBar.alpha = alpha;
                }
            }
            if ((bool)horizontalScrollBar)
            {
                float alpha2 = horizontalScrollBar.alpha;
                alpha2 += ((!flag2) ? ((0f - num) * 3f) : (num * 6f));
                alpha2  = Mathf.Clamp01(alpha2);
                if (horizontalScrollBar.alpha != alpha2)
                {
                    horizontalScrollBar.alpha = alpha2;
                }
            }
        }
        if (mShouldMove && !mPressed)
        {
            mMomentum -= scale * (mScroll * 0.05f);
            if (mMomentum.magnitude > 0.0001f)
            {
                mScroll = NGUIMath.SpringLerp(mScroll, 0f, 20f, num);
                Vector3 absolute = NGUIMath.SpringDampen(ref mMomentum, 9f, num);
                MoveAbsolute(absolute);
                if (restrictWithinPanel && mPanel.clipping != 0)
                {
                    RestrictWithinBounds(instant: false);
                }
                if (mMomentum.magnitude < 0.0001f && onDragFinished != null)
                {
                    onDragFinished();
                }
                return;
            }
            mScroll   = 0f;
            mMomentum = Vector3.zero;
        }
        else
        {
            mScroll = 0f;
        }
        NGUIMath.SpringDampen(ref mMomentum, 9f, num);
    }
    /// <summary>
    /// Apply the dragging momentum.
    /// </summary>

    void LateUpdate()
    {
        if (!Application.isPlaying)
        {
            return;
        }
        float delta = RealTime.deltaTime;

        // Fade the scroll bars if needed
        if (showScrollBars != ShowCondition.Always && (verticalScrollBar || horizontalScrollBar))
        {
            bool vertical   = false;
            bool horizontal = false;

            if (showScrollBars != ShowCondition.WhenDragging || mDragID != -10 || mMomentum.magnitude > 0.01f)
            {
                vertical   = shouldMoveVertically;
                horizontal = shouldMoveHorizontally;
            }

            if (verticalScrollBar)
            {
                float alpha = verticalScrollBar.alpha;
                alpha += vertical ? delta * 6f : -delta * 3f;
                alpha  = Mathf.Clamp01(alpha);
                if (verticalScrollBar.alpha != alpha)
                {
                    verticalScrollBar.alpha = alpha;
                }
            }

            if (horizontalScrollBar)
            {
                float alpha = horizontalScrollBar.alpha;
                alpha += horizontal ? delta * 6f : -delta * 3f;
                alpha  = Mathf.Clamp01(alpha);
                if (horizontalScrollBar.alpha != alpha)
                {
                    horizontalScrollBar.alpha = alpha;
                }
            }
        }

        if (!mShouldMove)
        {
            return;
        }

        // Apply momentum
        if (!mPressed)
        {
            if (mMomentum.magnitude > 0.0001f || mScroll != 0f)
            {
                if (movement == Movement.Horizontal)
                {
                    mMomentum -= mTrans.TransformDirection(new Vector3(mScroll * 0.05f, 0f, 0f));
                }
                else if (movement == Movement.Vertical)
                {
                    mMomentum -= mTrans.TransformDirection(new Vector3(0f, mScroll * 0.05f, 0f));
                }
                else if (movement == Movement.Unrestricted)
                {
                    mMomentum -= mTrans.TransformDirection(new Vector3(mScroll * 0.05f, mScroll * 0.05f, 0f));
                }
                else
                {
                    mMomentum -= mTrans.TransformDirection(new Vector3(
                                                               mScroll * customMovement.x * 0.05f,
                                                               mScroll * customMovement.y * 0.05f, 0f));
                }
                mScroll = NGUIMath.SpringLerp(mScroll, 0f, 20f, delta);

                // Move the scroll view
                Vector3 offset = NGUIMath.SpringDampen(ref mMomentum, dampenStrength, delta);
                MoveAbsolute(offset);

                // Restrict the contents to be within the scroll view's bounds
                if (restrictWithinPanel && mPanel.clipping != UIDrawCall.Clipping.None)
                {
                    if (NGUITools.GetActive(centerOnChild))
                    {
                        if (centerOnChild.nextPageThreshold != 0f)
                        {
                            mMomentum = Vector3.zero;
                            mScroll   = 0f;
                        }
                        else
                        {
                            centerOnChild.Recenter();
                        }
                    }
                    else
                    {
                        RestrictWithinBounds(false, canMoveHorizontally, canMoveVertically);
                    }
                }

                if (onMomentumMove != null)
                {
                    onMomentumMove();
                }
            }
            else
            {
                mScroll   = 0f;
                mMomentum = Vector3.zero;

                SpringPanel sp = GetComponent <SpringPanel>();
                if (sp != null && sp.enabled)
                {
                    return;
                }

                mShouldMove = false;
                if (onStoppedMoving != null)
                {
                    onStoppedMoving();
                }
            }
        }
        else
        {
            // Dampen the momentum
            mScroll = 0f;
            NGUIMath.SpringDampen(ref mMomentum, 9f, delta);
        }
    }
Ejemplo n.º 26
0
    /// <summary>
    /// Apply the dragging momentum.
    /// </summary>

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

        if (target == null)
        {
            return;
        }

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

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

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

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

                        if (backTop && (mBounds.size.y < mPanel.clipRange.w) && (mBounds.max.y < mPanel.clipRange.y + mPanel.clipRange.w * 0.5f))
                        {
                            if (!mPanel.ConstrainTargetToBounds1Top(target, ref mBounds, false))
                            {
                                SpringPosition sp = target.GetComponent <SpringPosition>();
                                if (sp != null)
                                {
                                    sp.enabled = false;
                                }
                            }
                        }
                        else
                        {
                            if (!mPanel.ConstrainTargetToBounds(target, ref mBounds, dragEffect == DragEffect.None))
                            {
                                SpringPosition sp = target.GetComponent <SpringPosition>();
                                if (sp != null)
                                {
                                    sp.enabled = false;
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                mScroll = 0f;
            }
        }
    }