SpringLerp() static public méthode

Quaternion.Slerp(from, to, Time.deltaTime * strength) is not framerate-independent. This function is.
static public SpringLerp ( Quaternion from, Quaternion to, float strength, float deltaTime ) : Quaternion
from Quaternion
to Quaternion
strength float
deltaTime float
Résultat Quaternion
    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)
        {
            return;
        }
        if (!this.mPressed)
        {
            if (this.mMomentum.magnitude > 0.0001f || this.mScroll != 0f)
            {
                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 != null && component.enabled)
                {
                    return;
                }
                this.mShouldMove = false;
                if (this.onStoppedMoving != null)
                {
                    this.onStoppedMoving();
                }
            }
        }
        else
        {
            this.mScroll = 0f;
            NGUIMath.SpringDampen(ref this.mMomentum, 9f, deltaTime);
        }
    }
Exemple #2
0
 public static Vector3 SpringLerp(Vector3 from, Vector3 to, float strength, float deltaTime)
 {
     return(Vector3.Lerp(from, to, NGUIMath.SpringLerp(strength, deltaTime)));
 }
Exemple #3
0
 static public int SpringLerp_s(IntPtr l)
 {
     try {
                     #if DEBUG
         var    method     = System.Reflection.MethodBase.GetCurrentMethod();
         string methodName = GetMethodName(method);
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.BeginSample(methodName);
                     #else
         Profiler.BeginSample(methodName);
                     #endif
                     #endif
         int argc = LuaDLL.lua_gettop(l);
         if (argc == 2)
         {
             System.Single a1;
             checkType(l, 1, out a1);
             System.Single a2;
             checkType(l, 2, out a2);
             var ret = NGUIMath.SpringLerp(a1, a2);
             pushValue(l, true);
             pushValue(l, ret);
             return(2);
         }
         else if (matchType(l, argc, 1, typeof(float), typeof(float), typeof(float), typeof(float)))
         {
             System.Single a1;
             checkType(l, 1, out a1);
             System.Single a2;
             checkType(l, 2, out a2);
             System.Single a3;
             checkType(l, 3, out a3);
             System.Single a4;
             checkType(l, 4, out a4);
             var ret = NGUIMath.SpringLerp(a1, a2, a3, a4);
             pushValue(l, true);
             pushValue(l, ret);
             return(2);
         }
         else if (matchType(l, argc, 1, typeof(UnityEngine.Vector2), typeof(UnityEngine.Vector2), typeof(float), typeof(float)))
         {
             UnityEngine.Vector2 a1;
             checkType(l, 1, out a1);
             UnityEngine.Vector2 a2;
             checkType(l, 2, out a2);
             System.Single a3;
             checkType(l, 3, out a3);
             System.Single a4;
             checkType(l, 4, out a4);
             var ret = NGUIMath.SpringLerp(a1, a2, a3, a4);
             pushValue(l, true);
             pushValue(l, ret);
             return(2);
         }
         else if (matchType(l, argc, 1, typeof(UnityEngine.Vector3), typeof(UnityEngine.Vector3), typeof(float), typeof(float)))
         {
             UnityEngine.Vector3 a1;
             checkType(l, 1, out a1);
             UnityEngine.Vector3 a2;
             checkType(l, 2, out a2);
             System.Single a3;
             checkType(l, 3, out a3);
             System.Single a4;
             checkType(l, 4, out a4);
             var ret = NGUIMath.SpringLerp(a1, a2, a3, a4);
             pushValue(l, true);
             pushValue(l, ret);
             return(2);
         }
         else if (matchType(l, argc, 1, typeof(UnityEngine.Quaternion), typeof(UnityEngine.Quaternion), typeof(float), typeof(float)))
         {
             UnityEngine.Quaternion a1;
             checkType(l, 1, out a1);
             UnityEngine.Quaternion a2;
             checkType(l, 2, out a2);
             System.Single a3;
             checkType(l, 3, out a3);
             System.Single a4;
             checkType(l, 4, out a4);
             var ret = NGUIMath.SpringLerp(a1, a2, a3, a4);
             pushValue(l, true);
             pushValue(l, ret);
             return(2);
         }
         pushValue(l, false);
         LuaDLL.lua_pushstring(l, "No matched override function SpringLerp to call");
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
             #if DEBUG
     finally {
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.EndSample();
                     #else
         Profiler.EndSample();
                     #endif
     }
             #endif
 }
    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 ? (deltaTime * 6f) : ((0f - deltaTime) * 3f));
                alpha  = Mathf.Clamp01(alpha);
                if (verticalScrollBar.alpha != alpha)
                {
                    verticalScrollBar.alpha = alpha;
                }
            }
            if ((bool)horizontalScrollBar)
            {
                float alpha = horizontalScrollBar.alpha;
                alpha += (flag2 ? (deltaTime * 6f) : ((0f - deltaTime) * 3f));
                alpha  = Mathf.Clamp01(alpha);
                if (horizontalScrollBar.alpha != alpha)
                {
                    horizontalScrollBar.alpha = alpha;
                }
            }
        }
        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, deltaTime);
                Vector3 absolute = NGUIMath.SpringDampen(ref mMomentum, 9f, deltaTime);
                MoveAbsolute(absolute);
                if (restrictWithinPanel && mPanel.clipping != 0)
                {
                    RestrictWithinBounds(instant: false, canMoveHorizontally, canMoveVertically);
                }
                if (mMomentum.magnitude < 0.0001f && onDragFinished != null)
                {
                    onDragFinished();
                }
                return;
            }
            mScroll   = 0f;
            mMomentum = Vector3.zero;
        }
        else
        {
            mScroll = 0f;
        }
        NGUIMath.SpringDampen(ref mMomentum, 9f, deltaTime);
    }
    /// <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 || mTouches > 0)
            {
                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;
            }
        }
        else
        {
            mScroll = 0f;
        }

        // Dampen the momentum
        NGUIMath.SpringDampen(ref mMomentum, 9f, delta);
    }
Exemple #6
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);
    }
    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);
    }
Exemple #8
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);
        }
    }
Exemple #9
0
    /// <summary>
    /// Advance toward the target position.
    /// </summary>

    void Update()
    {
        float delta = ignoreTimeScale ? UpdateRealTimeDelta() : Time.deltaTime;

        if (worldSpace)
        {
            if (mThreshold == 0f)
            {
                mThreshold = (target - mTrans.position).magnitude * 0.001f;
            }
            mTrans.position = NGUIMath.SpringLerp(mTrans.position, target, strength, delta);

            if (mThreshold >= (target - mTrans.position).magnitude)
            {
                mTrans.position = target;

                if (onFinished != null)
                {
                    onFinished(this);
                }

                var boxCollider = gameObject.GetComponent <BoxCollider>();
                if (boxCollider != null)
                {
                    boxCollider.enabled = true;
                }

                if (eventReceiver != null && !string.IsNullOrEmpty(callWhenFinished))
                {
                    eventReceiver.SendMessage(callWhenFinished, this, SendMessageOptions.DontRequireReceiver);
                }
                enabled = false;
            }
        }
        else
        {
            if (mThreshold == 0f)
            {
                mThreshold = (target - mTrans.localPosition).magnitude * 0.001f;
            }
            mTrans.localPosition = NGUIMath.SpringLerp(mTrans.localPosition, target, strength, delta);

            if (mThreshold >= (target - mTrans.localPosition).magnitude)
            {
                mTrans.localPosition = target;

                if (onFinished != null)
                {
                    onFinished(this);
                }

                var boxCollider = gameObject.GetComponent <BoxCollider>();
                if (boxCollider != null)
                {
                    boxCollider.enabled = true;
                }

                if (eventReceiver != null && !string.IsNullOrEmpty(callWhenFinished))
                {
                    eventReceiver.SendMessage(callWhenFinished, this, SendMessageOptions.DontRequireReceiver);
                }
                enabled = false;
            }
        }
    }
Exemple #10
0
 static public int SpringLerp_s(IntPtr l)
 {
     try {
         int argc = LuaDLL.lua_gettop(l);
         if (argc == 2)
         {
             System.Single a1;
             checkType(l, 1, out a1);
             System.Single a2;
             checkType(l, 2, out a2);
             var ret = NGUIMath.SpringLerp(a1, a2);
             pushValue(l, ret);
             return(1);
         }
         else if (matchType(l, argc, 1, typeof(UnityEngine.Vector3), typeof(UnityEngine.Vector3), typeof(float), typeof(float)))
         {
             UnityEngine.Vector3 a1;
             checkType(l, 1, out a1);
             UnityEngine.Vector3 a2;
             checkType(l, 2, out a2);
             System.Single a3;
             checkType(l, 3, out a3);
             System.Single a4;
             checkType(l, 4, out a4);
             var ret = NGUIMath.SpringLerp(a1, a2, a3, a4);
             pushValue(l, ret);
             return(1);
         }
         else if (matchType(l, argc, 1, typeof(UnityEngine.Quaternion), typeof(UnityEngine.Quaternion), typeof(float), typeof(float)))
         {
             UnityEngine.Quaternion a1;
             checkType(l, 1, out a1);
             UnityEngine.Quaternion a2;
             checkType(l, 2, out a2);
             System.Single a3;
             checkType(l, 3, out a3);
             System.Single a4;
             checkType(l, 4, out a4);
             var ret = NGUIMath.SpringLerp(a1, a2, a3, a4);
             pushValue(l, ret);
             return(1);
         }
         else if (matchType(l, argc, 1, typeof(float), typeof(float), typeof(float), typeof(float)))
         {
             System.Single a1;
             checkType(l, 1, out a1);
             System.Single a2;
             checkType(l, 2, out a2);
             System.Single a3;
             checkType(l, 3, out a3);
             System.Single a4;
             checkType(l, 4, out a4);
             var ret = NGUIMath.SpringLerp(a1, a2, a3, a4);
             pushValue(l, ret);
             return(1);
         }
         else if (matchType(l, argc, 1, typeof(UnityEngine.Vector2), typeof(UnityEngine.Vector2), typeof(float), typeof(float)))
         {
             UnityEngine.Vector2 a1;
             checkType(l, 1, out a1);
             UnityEngine.Vector2 a2;
             checkType(l, 2, out a2);
             System.Single a3;
             checkType(l, 3, out a3);
             System.Single a4;
             checkType(l, 4, out a4);
             var ret = NGUIMath.SpringLerp(a1, a2, a3, a4);
             pushValue(l, ret);
             return(1);
         }
         LuaDLL.luaL_error(l, "No matched override function to call");
         return(0);
     }
     catch (Exception e) {
         LuaDLL.luaL_error(l, e.ToString());
         return(0);
     }
 }
Exemple #11
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);
         }
     }
 }
Exemple #12
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);
            }
        }
Exemple #13
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);
        }
    }
Exemple #14
0
 public static Quaternion SpringLerp(Quaternion from, Quaternion to, float strength, float deltaTime)
 {
     return(Quaternion.Slerp(from, to, NGUIMath.SpringLerp(strength, deltaTime)));
 }
Exemple #15
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);
    }
Exemple #16
0
 private void LateUpdate()
 {
     if (Application.isPlaying)
     {
         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)
         {
             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, 9f, 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();
                     }
                 }
                 else
                 {
                     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);
             }
         }
     }
 }
Exemple #17
0
 public unsafe static long $Invoke42(long instance, long *args)
 {
     return(GCHandledObjects.ObjectToGCHandle(NGUIMath.SpringLerp(*(*(IntPtr *)args), *(*(IntPtr *)(args + 1)), *(float *)(args + 2), *(float *)(args + 3))));
 }
Exemple #18
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);
    }
Exemple #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);
    }
Exemple #20
0
    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 = Vectors.zero;
        }
        else
        {
            this.mScroll = 0f;
        }
        NGUIMath.SpringDampen(ref this.mMomentum, 9f, num);
    }
Exemple #21
0
 public static Vector2 SpringLerp(Vector2 from, Vector2 to, Single strength, Single deltaTime)
 {
     return(Vector2.Lerp(from, to, NGUIMath.SpringLerp(strength, deltaTime)));
 }
Exemple #22
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;
                }
            }
        }

        if (!mShouldMove)
        {
            return;
        }

        // Apply momentum
        if (!mPressed)
        {
            if (mMomentum.magnitude > 0.0001f || Mathf.Abs(mScroll) > 0.0001f)
            {
                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);
        }
    }
Exemple #23
0
    /// <summary>
    /// Apply the dragging momentum.
    /// </summary>

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

        if (target == null)
        {
            return;
        }

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

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

                if (mPanel != null)
                {
                    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;
            }
        }
    }