Ejemplo n.º 1
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;
            }
        }
    }