Lerp() private method

private Lerp ( float from, float to, float factor ) : float
from float
to float
factor float
return float
 void Update()
 {
     if (m_bPanel == true)
     {
         m_pLoginBox_Panel.alpha = NGUIMath.Lerp(m_pLoginBox_Panel.alpha, 1f, 3f * Time.deltaTime);
     }
     else
     {
         m_pLoginBox_Panel.alpha = NGUIMath.Lerp(m_pLoginBox_Panel.alpha, 0f, 3f * Time.deltaTime);
     }
 }
Exemplo n.º 2
0
    void Update()
    {
        if (Mathf.Abs(playerMonsterBar.barSize - playerBarData) <= minDistance)
        {
            playerMonsterBar.barSize = playerBarData;
        }
        if (Mathf.Abs(enemyMonsterBar.barSize - enemyBarData) <= minDistance)
        {
            enemyMonsterBar.barSize = enemyBarData;
        }

        //这里是闪烁monsterBar
        if (playerMonsterBar.barSize >= 1 - minDistance)
        {
            playerBarParticle.SetActive(true);
        }
        else
        {
            playerBarParticle.SetActive(false);
        }

        if (enemyMonsterBar.barSize >= 1 - minDistance)
        {
            enemyBarParticle.SetActive(true);
        }
        else
        {
            enemyBarParticle.SetActive(false);
        }

        if (playerMonsterBar.barSize == playerBarData && enemyMonsterBar.barSize == enemyBarData)
        {
            return;
        }

        float _v = NGUIMath.Lerp(playerMonsterBar.barSize, playerBarData, Time.deltaTime * 4);

        if (_v < 0.01f)
        {
            _v = 0.01f;
        }
        playerMonsterBar.barSize = _v;

        _v = NGUIMath.Lerp(enemyMonsterBar.barSize, enemyBarData, Time.deltaTime * 4);
        if (_v < 0.01f)
        {
            _v = 0.01f;
        }
        enemyMonsterBar.barSize = _v;
    }
Exemplo n.º 3
0
 static public int Lerp_s(IntPtr l)
 {
     try {
         System.Single a1;
         checkType(l, 1, out a1);
         System.Single a2;
         checkType(l, 2, out a2);
         System.Single a3;
         checkType(l, 3, out a3);
         var ret = NGUIMath.Lerp(a1, a2, a3);
         pushValue(l, ret);
         return(1);
     }
     catch (Exception e) {
         LuaDLL.luaL_error(l, e.ToString());
         return(0);
     }
 }
Exemplo n.º 4
0
 static public int Lerp_s(IntPtr l)
 {
     try {
         System.Single a1;
         checkType(l, 1, out a1);
         System.Single a2;
         checkType(l, 2, out a2);
         System.Single a3;
         checkType(l, 3, out a3);
         var ret = NGUIMath.Lerp(a1, a2, a3);
         pushValue(l, true);
         pushValue(l, ret);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Exemplo n.º 5
0
 static public int Lerp_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
         System.Single a1;
         checkType(l, 1, out a1);
         System.Single a2;
         checkType(l, 2, out a2);
         System.Single a3;
         checkType(l, 3, out a3);
         var ret = NGUIMath.Lerp(a1, a2, a3);
         pushValue(l, true);
         pushValue(l, ret);
         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
 }
Exemplo n.º 6
0
    /// <summary>
    /// Update the anchored edges and ensure the widget is registered with a panel.
    /// </summary>

    protected override void OnAnchor()
    {
        float     lt, bt, rt, tt;
        Transform trans  = cachedTransform;
        Transform parent = trans.parent;
        Vector3   pos    = trans.localPosition;
        Vector2   pvt    = pivotOffset;

        // Attempt to fast-path if all anchors match
        if (leftAnchor.target == bottomAnchor.target &&
            leftAnchor.target == rightAnchor.target &&
            leftAnchor.target == topAnchor.target)
        {
            Vector3[] sides = leftAnchor.GetSides(parent);

            if (sides != null)
            {
                lt         = NGUIMath.Lerp(sides[0].x, sides[2].x, leftAnchor.relative) + leftAnchor.absolute;
                rt         = NGUIMath.Lerp(sides[0].x, sides[2].x, rightAnchor.relative) + rightAnchor.absolute;
                bt         = NGUIMath.Lerp(sides[3].y, sides[1].y, bottomAnchor.relative) + bottomAnchor.absolute;
                tt         = NGUIMath.Lerp(sides[3].y, sides[1].y, topAnchor.relative) + topAnchor.absolute;
                mIsInFront = true;
            }
            else
            {
                // Anchored to a single transform
                Vector3 lp = GetLocalPos(leftAnchor, parent);
                lt         = lp.x + leftAnchor.absolute;
                bt         = lp.y + bottomAnchor.absolute;
                rt         = lp.x + rightAnchor.absolute;
                tt         = lp.y + topAnchor.absolute;
                mIsInFront = (!hideIfOffScreen || lp.z >= 0f);
            }
        }
        else
        {
            mIsInFront = true;

            // Left anchor point
            if (leftAnchor.target)
            {
                Vector3[] sides = leftAnchor.GetSides(parent);

                if (sides != null)
                {
                    lt = NGUIMath.Lerp(sides[0].x, sides[2].x, leftAnchor.relative) + leftAnchor.absolute;
                }
                else
                {
                    lt = GetLocalPos(leftAnchor, parent).x + leftAnchor.absolute;
                }
            }
            else
            {
                lt = pos.x - pvt.x * mWidth;
            }

            // Right anchor point
            if (rightAnchor.target)
            {
                Vector3[] sides = rightAnchor.GetSides(parent);

                if (sides != null)
                {
                    rt = NGUIMath.Lerp(sides[0].x, sides[2].x, rightAnchor.relative) + rightAnchor.absolute;
                }
                else
                {
                    rt = GetLocalPos(rightAnchor, parent).x + rightAnchor.absolute;
                }
            }
            else
            {
                rt = pos.x - pvt.x * mWidth + mWidth;
            }

            // Bottom anchor point
            if (bottomAnchor.target)
            {
                Vector3[] sides = bottomAnchor.GetSides(parent);

                if (sides != null)
                {
                    bt = NGUIMath.Lerp(sides[3].y, sides[1].y, bottomAnchor.relative) + bottomAnchor.absolute;
                }
                else
                {
                    bt = GetLocalPos(bottomAnchor, parent).y + bottomAnchor.absolute;
                }
            }
            else
            {
                bt = pos.y - pvt.y * mHeight;
            }

            // Top anchor point
            if (topAnchor.target)
            {
                Vector3[] sides = topAnchor.GetSides(parent);

                if (sides != null)
                {
                    tt = NGUIMath.Lerp(sides[3].y, sides[1].y, topAnchor.relative) + topAnchor.absolute;
                }
                else
                {
                    tt = GetLocalPos(topAnchor, parent).y + topAnchor.absolute;
                }
            }
            else
            {
                tt = pos.y - pvt.y * mHeight + mHeight;
            }
        }

        // Calculate the new position, width and height
        Vector3 newPos = new Vector3(Mathf.Lerp(lt, rt, pvt.x), Mathf.Lerp(bt, tt, pvt.y), pos.z);
        int     w      = Mathf.FloorToInt(rt - lt + 0.5f);
        int     h      = Mathf.FloorToInt(tt - bt + 0.5f);

        // Maintain the aspect ratio if requested and possible
        if (keepAspectRatio != AspectRatioSource.Free && aspectRatio != 0f)
        {
            if (keepAspectRatio == AspectRatioSource.BasedOnHeight)
            {
                w = Mathf.RoundToInt(h * aspectRatio);
            }
            else
            {
                h = Mathf.RoundToInt(w / aspectRatio);
            }
        }

        // Don't let the width and height get too small
        if (w < minWidth)
        {
            w = minWidth;
        }
        if (h < minHeight)
        {
            h = minHeight;
        }

        // Update the position if it has changed
        if (Vector3.SqrMagnitude(pos - newPos) > 0.001f)
        {
            cachedTransform.localPosition = newPos;
            if (mIsInFront)
            {
                mChanged = true;
            }
        }

        // Update the width and height if it has changed
        if (mWidth != w || mHeight != h)
        {
            mWidth  = w;
            mHeight = h;
            if (mIsInFront)
            {
                mChanged = true;
            }
            if (autoResizeBoxCollider)
            {
                ResizeCollider();
            }
        }
    }
Exemplo n.º 7
0
    protected override void OnAnchor()
    {
        Transform cachedTransform = base.cachedTransform;
        Transform parent          = cachedTransform.parent;
        Vector3   localPosition   = cachedTransform.localPosition;
        Vector2   pivotOffset     = this.pivotOffset;
        float     num;
        float     num2;
        float     num3;
        float     num4;

        if (leftAnchor.target == bottomAnchor.target && leftAnchor.target == rightAnchor.target && leftAnchor.target == topAnchor.target)
        {
            Vector3[] sides = leftAnchor.GetSides(parent);
            if (sides != null)
            {
                num        = NGUIMath.Lerp(sides[0].x, sides[2].x, leftAnchor.relative) + (float)leftAnchor.absolute;
                num2       = NGUIMath.Lerp(sides[0].x, sides[2].x, rightAnchor.relative) + (float)rightAnchor.absolute;
                num3       = NGUIMath.Lerp(sides[3].y, sides[1].y, bottomAnchor.relative) + (float)bottomAnchor.absolute;
                num4       = NGUIMath.Lerp(sides[3].y, sides[1].y, topAnchor.relative) + (float)topAnchor.absolute;
                mIsInFront = true;
            }
            else
            {
                Vector3 localPos = GetLocalPos(leftAnchor, parent);
                num        = localPos.x + (float)leftAnchor.absolute;
                num3       = localPos.y + (float)bottomAnchor.absolute;
                num2       = localPos.x + (float)rightAnchor.absolute;
                num4       = localPos.y + (float)topAnchor.absolute;
                mIsInFront = (!hideIfOffScreen || localPos.z >= 0f);
            }
        }
        else
        {
            mIsInFront = true;
            if ((bool)leftAnchor.target)
            {
                Vector3[] sides2 = leftAnchor.GetSides(parent);
                if (sides2 != null)
                {
                    num = NGUIMath.Lerp(sides2[0].x, sides2[2].x, leftAnchor.relative) + (float)leftAnchor.absolute;
                }
                else
                {
                    Vector3 localPos2 = GetLocalPos(leftAnchor, parent);
                    num = localPos2.x + (float)leftAnchor.absolute;
                }
            }
            else
            {
                num = localPosition.x - pivotOffset.x * (float)mWidth;
            }
            if ((bool)rightAnchor.target)
            {
                Vector3[] sides3 = rightAnchor.GetSides(parent);
                if (sides3 != null)
                {
                    num2 = NGUIMath.Lerp(sides3[0].x, sides3[2].x, rightAnchor.relative) + (float)rightAnchor.absolute;
                }
                else
                {
                    Vector3 localPos3 = GetLocalPos(rightAnchor, parent);
                    num2 = localPos3.x + (float)rightAnchor.absolute;
                }
            }
            else
            {
                num2 = localPosition.x - pivotOffset.x * (float)mWidth + (float)mWidth;
            }
            if ((bool)bottomAnchor.target)
            {
                Vector3[] sides4 = bottomAnchor.GetSides(parent);
                if (sides4 != null)
                {
                    num3 = NGUIMath.Lerp(sides4[3].y, sides4[1].y, bottomAnchor.relative) + (float)bottomAnchor.absolute;
                }
                else
                {
                    Vector3 localPos4 = GetLocalPos(bottomAnchor, parent);
                    num3 = localPos4.y + (float)bottomAnchor.absolute;
                }
            }
            else
            {
                num3 = localPosition.y - pivotOffset.y * (float)mHeight;
            }
            if ((bool)topAnchor.target)
            {
                Vector3[] sides5 = topAnchor.GetSides(parent);
                if (sides5 != null)
                {
                    num4 = NGUIMath.Lerp(sides5[3].y, sides5[1].y, topAnchor.relative) + (float)topAnchor.absolute;
                }
                else
                {
                    Vector3 localPos5 = GetLocalPos(topAnchor, parent);
                    num4 = localPos5.y + (float)topAnchor.absolute;
                }
            }
            else
            {
                num4 = localPosition.y - pivotOffset.y * (float)mHeight + (float)mHeight;
            }
        }
        Vector3 vector = new Vector3(Mathf.Lerp(num, num2, pivotOffset.x), Mathf.Lerp(num3, num4, pivotOffset.y), localPosition.z);
        int     num5   = Mathf.FloorToInt(num2 - num + 0.5f);
        int     num6   = Mathf.FloorToInt(num4 - num3 + 0.5f);

        if (keepAspectRatio != 0 && aspectRatio != 0f)
        {
            if (keepAspectRatio == AspectRatioSource.BasedOnHeight)
            {
                num5 = Mathf.RoundToInt((float)num6 * aspectRatio);
            }
            else
            {
                num6 = Mathf.RoundToInt((float)num5 / aspectRatio);
            }
        }
        if (num5 < minWidth)
        {
            num5 = minWidth;
        }
        if (num6 < minHeight)
        {
            num6 = minHeight;
        }
        if (Vector3.SqrMagnitude(localPosition - vector) > 0.001f)
        {
            base.cachedTransform.localPosition = vector;
            if (mIsInFront)
            {
                mChanged = true;
            }
        }
        if (mWidth != num5 || mHeight != num6)
        {
            mWidth  = num5;
            mHeight = num6;
            if (mIsInFront)
            {
                mChanged = true;
            }
            if (autoResizeBoxCollider)
            {
                ResizeCollider();
            }
        }
    }
Exemplo n.º 8
0
    protected override void OnAnchor()
    {
        if (this.mClipping == UIDrawCall.Clipping.None)
        {
            return;
        }
        Transform cachedTransform = base.cachedTransform;
        Transform parent          = cachedTransform.parent;
        Vector2   viewSize        = this.GetViewSize();
        Vector2   vector          = cachedTransform.localPosition;
        Single    num;
        Single    num2;
        Single    num3;
        Single    num4;

        if (this.leftAnchor.target == this.bottomAnchor.target && this.leftAnchor.target == this.rightAnchor.target && this.leftAnchor.target == this.topAnchor.target)
        {
            Vector3[] sides = this.leftAnchor.GetSides(parent);
            if (sides != null)
            {
                num  = NGUIMath.Lerp(sides[0].x, sides[2].x, this.leftAnchor.relative) + (Single)this.leftAnchor.absolute;
                num2 = NGUIMath.Lerp(sides[0].x, sides[2].x, this.rightAnchor.relative) + (Single)this.rightAnchor.absolute;
                num3 = NGUIMath.Lerp(sides[3].y, sides[1].y, this.bottomAnchor.relative) + (Single)this.bottomAnchor.absolute;
                num4 = NGUIMath.Lerp(sides[3].y, sides[1].y, this.topAnchor.relative) + (Single)this.topAnchor.absolute;
            }
            else
            {
                Vector2 vector2 = base.GetLocalPos(this.leftAnchor, parent);
                num  = vector2.x + (Single)this.leftAnchor.absolute;
                num3 = vector2.y + (Single)this.bottomAnchor.absolute;
                num2 = vector2.x + (Single)this.rightAnchor.absolute;
                num4 = vector2.y + (Single)this.topAnchor.absolute;
            }
        }
        else
        {
            if (this.leftAnchor.target)
            {
                Vector3[] sides2 = this.leftAnchor.GetSides(parent);
                if (sides2 != null)
                {
                    num = NGUIMath.Lerp(sides2[0].x, sides2[2].x, this.leftAnchor.relative) + (Single)this.leftAnchor.absolute;
                }
                else
                {
                    num = base.GetLocalPos(this.leftAnchor, parent).x + (Single)this.leftAnchor.absolute;
                }
            }
            else
            {
                num = this.mClipRange.x - 0.5f * viewSize.x;
            }
            if (this.rightAnchor.target)
            {
                Vector3[] sides3 = this.rightAnchor.GetSides(parent);
                if (sides3 != null)
                {
                    num2 = NGUIMath.Lerp(sides3[0].x, sides3[2].x, this.rightAnchor.relative) + (Single)this.rightAnchor.absolute;
                }
                else
                {
                    num2 = base.GetLocalPos(this.rightAnchor, parent).x + (Single)this.rightAnchor.absolute;
                }
            }
            else
            {
                num2 = this.mClipRange.x + 0.5f * viewSize.x;
            }
            if (this.bottomAnchor.target)
            {
                Vector3[] sides4 = this.bottomAnchor.GetSides(parent);
                if (sides4 != null)
                {
                    num3 = NGUIMath.Lerp(sides4[3].y, sides4[1].y, this.bottomAnchor.relative) + (Single)this.bottomAnchor.absolute;
                }
                else
                {
                    num3 = base.GetLocalPos(this.bottomAnchor, parent).y + (Single)this.bottomAnchor.absolute;
                }
            }
            else
            {
                num3 = this.mClipRange.y - 0.5f * viewSize.y;
            }
            if (this.topAnchor.target)
            {
                Vector3[] sides5 = this.topAnchor.GetSides(parent);
                if (sides5 != null)
                {
                    num4 = NGUIMath.Lerp(sides5[3].y, sides5[1].y, this.topAnchor.relative) + (Single)this.topAnchor.absolute;
                }
                else
                {
                    num4 = base.GetLocalPos(this.topAnchor, parent).y + (Single)this.topAnchor.absolute;
                }
            }
            else
            {
                num4 = this.mClipRange.y + 0.5f * viewSize.y;
            }
        }
        num  -= vector.x + this.mClipOffset.x;
        num2 -= vector.x + this.mClipOffset.x;
        num3 -= vector.y + this.mClipOffset.y;
        num4 -= vector.y + this.mClipOffset.y;
        Single x    = Mathf.Lerp(num, num2, 0.5f);
        Single y    = Mathf.Lerp(num3, num4, 0.5f);
        Single num5 = num2 - num;
        Single num6 = num4 - num3;
        Single num7 = Mathf.Max(2f, this.mClipSoftness.x);
        Single num8 = Mathf.Max(2f, this.mClipSoftness.y);

        if (num5 < num7)
        {
            num5 = num7;
        }
        if (num6 < num8)
        {
            num6 = num8;
        }
        this.baseClipRegion = new Vector4(x, y, num5, num6);
    }
Exemplo n.º 9
0
    /// <summary>
    /// Update the edges after the anchors have been updated.
    /// </summary>

    protected override void OnAnchor()
    {
        // No clipping = no edges to anchor
        if (mClipping == UIDrawCall.Clipping.None)
        {
            return;
        }

        Transform trans  = cachedTransform;
        Transform parent = trans.parent;

        Vector2 size   = GetViewSize();
        Vector2 offset = trans.localPosition;

        float lt, bt, rt, tt;

        // Attempt to fast-path if all anchors match
        if (leftAnchor.target == bottomAnchor.target &&
            leftAnchor.target == rightAnchor.target &&
            leftAnchor.target == topAnchor.target)
        {
            if (leftAnchor.rect != null)
            {
                Vector3[] sides = leftAnchor.rect.GetSides(parent);
                lt = NGUIMath.Lerp(sides[0].x, sides[2].x, leftAnchor.relative) + leftAnchor.absolute;
                rt = NGUIMath.Lerp(sides[0].x, sides[2].x, rightAnchor.relative) + rightAnchor.absolute;
                bt = NGUIMath.Lerp(sides[3].y, sides[1].y, bottomAnchor.relative) + bottomAnchor.absolute;
                tt = NGUIMath.Lerp(sides[3].y, sides[1].y, topAnchor.relative) + topAnchor.absolute;
            }
            else
            {
                // Anchored to a single transform
                Vector2 lp = GetLocalPos(leftAnchor, parent);
                lt = lp.x + leftAnchor.absolute;
                bt = lp.y + bottomAnchor.absolute;
                rt = lp.x + rightAnchor.absolute;
                tt = lp.y + topAnchor.absolute;
            }
        }
        else
        {
            // Left anchor point
            if (leftAnchor.target)
            {
                if (leftAnchor.rect != null)
                {
                    Vector3[] sides = leftAnchor.rect.GetSides(parent);
                    lt = NGUIMath.Lerp(sides[0].x, sides[2].x, leftAnchor.relative) + leftAnchor.absolute;
                }
                else
                {
                    lt = GetLocalPos(leftAnchor, parent).x + leftAnchor.absolute;
                }
            }
            else
            {
                lt = mClipRange.x - 0.5f * size.x;
            }

            // Right anchor point
            if (rightAnchor.target)
            {
                if (rightAnchor.rect != null)
                {
                    Vector3[] sides = rightAnchor.rect.GetSides(parent);
                    rt = NGUIMath.Lerp(sides[0].x, sides[2].x, rightAnchor.relative) + rightAnchor.absolute;
                }
                else
                {
                    rt = GetLocalPos(rightAnchor, parent).x + rightAnchor.absolute;
                }
            }
            else
            {
                rt = mClipRange.x + 0.5f * size.x;
            }

            // Bottom anchor point
            if (bottomAnchor.target)
            {
                if (bottomAnchor.rect != null)
                {
                    Vector3[] sides = bottomAnchor.rect.GetSides(parent);
                    bt = NGUIMath.Lerp(sides[3].y, sides[1].y, bottomAnchor.relative) + bottomAnchor.absolute;
                }
                else
                {
                    bt = GetLocalPos(bottomAnchor, parent).y + bottomAnchor.absolute;
                }
            }
            else
            {
                bt = mClipRange.y - 0.5f * size.y;
            }

            // Top anchor point
            if (topAnchor.target)
            {
                if (topAnchor.rect != null)
                {
                    Vector3[] sides = topAnchor.rect.GetSides(parent);
                    tt = NGUIMath.Lerp(sides[3].y, sides[1].y, topAnchor.relative) + topAnchor.absolute;
                }
                else
                {
                    tt = GetLocalPos(topAnchor, parent).y + topAnchor.absolute;
                }
            }
            else
            {
                tt = mClipRange.y + 0.5f * size.y;
            }
        }

        // Take the offset into consideration
        lt -= offset.x + mClipOffset.x;
        rt -= offset.x + mClipOffset.x;
        bt -= offset.y + mClipOffset.y;
        tt -= offset.y + mClipOffset.y;

        // Calculate the new position, width and height
        float newX = Mathf.Lerp(lt, rt, 0.5f);
        float newY = Mathf.Lerp(bt, tt, 0.5f);
        float w    = rt - lt;
        float h    = tt - bt;

        float minx = Mathf.Max(20f, mClipSoftness.x);
        float miny = Mathf.Max(20f, mClipSoftness.y);

        if (w < minx)
        {
            w = minx;
        }
        if (h < miny)
        {
            h = miny;
        }

        // Update the clipping range
        baseClipRegion = new Vector4(newX, newY, w, h);
    }
Exemplo n.º 10
0
    protected override void OnAnchor()
    {
        Transform cachedTransform = base.cachedTransform;
        Transform parent          = cachedTransform.parent;
        Vector3   localPosition   = cachedTransform.localPosition;
        Vector2   pivotOffset     = this.pivotOffset;
        float     num;
        float     num2;
        float     num3;
        float     num4;

        if (this.leftAnchor.target == this.bottomAnchor.target && this.leftAnchor.target == this.rightAnchor.target && this.leftAnchor.target == this.topAnchor.target)
        {
            Vector3[] sides = this.leftAnchor.GetSides(parent);
            if (sides != null)
            {
                num             = NGUIMath.Lerp(sides[0].x, sides[2].x, this.leftAnchor.relative) + (float)this.leftAnchor.absolute;
                num2            = NGUIMath.Lerp(sides[0].x, sides[2].x, this.rightAnchor.relative) + (float)this.rightAnchor.absolute;
                num3            = NGUIMath.Lerp(sides[3].y, sides[1].y, this.bottomAnchor.relative) + (float)this.bottomAnchor.absolute;
                num4            = NGUIMath.Lerp(sides[3].y, sides[1].y, this.topAnchor.relative) + (float)this.topAnchor.absolute;
                this.mIsInFront = true;
            }
            else
            {
                Vector3 localPos = base.GetLocalPos(this.leftAnchor, parent);
                num             = localPos.x + (float)this.leftAnchor.absolute;
                num3            = localPos.y + (float)this.bottomAnchor.absolute;
                num2            = localPos.x + (float)this.rightAnchor.absolute;
                num4            = localPos.y + (float)this.topAnchor.absolute;
                this.mIsInFront = (!this.hideIfOffScreen || localPos.z >= 0f);
            }
        }
        else
        {
            this.mIsInFront = true;
            if (this.leftAnchor.target)
            {
                Vector3[] sides2 = this.leftAnchor.GetSides(parent);
                if (sides2 != null)
                {
                    num = NGUIMath.Lerp(sides2[0].x, sides2[2].x, this.leftAnchor.relative) + (float)this.leftAnchor.absolute;
                }
                else
                {
                    num = base.GetLocalPos(this.leftAnchor, parent).x + (float)this.leftAnchor.absolute;
                }
            }
            else
            {
                num = localPosition.x - pivotOffset.x * (float)this.mWidth;
            }
            if (this.rightAnchor.target)
            {
                Vector3[] sides3 = this.rightAnchor.GetSides(parent);
                if (sides3 != null)
                {
                    num2 = NGUIMath.Lerp(sides3[0].x, sides3[2].x, this.rightAnchor.relative) + (float)this.rightAnchor.absolute;
                }
                else
                {
                    num2 = base.GetLocalPos(this.rightAnchor, parent).x + (float)this.rightAnchor.absolute;
                }
            }
            else
            {
                num2 = localPosition.x - pivotOffset.x * (float)this.mWidth + (float)this.mWidth;
            }
            if (this.bottomAnchor.target)
            {
                Vector3[] sides4 = this.bottomAnchor.GetSides(parent);
                if (sides4 != null)
                {
                    num3 = NGUIMath.Lerp(sides4[3].y, sides4[1].y, this.bottomAnchor.relative) + (float)this.bottomAnchor.absolute;
                }
                else
                {
                    num3 = base.GetLocalPos(this.bottomAnchor, parent).y + (float)this.bottomAnchor.absolute;
                }
            }
            else
            {
                num3 = localPosition.y - pivotOffset.y * (float)this.mHeight;
            }
            if (this.topAnchor.target)
            {
                Vector3[] sides5 = this.topAnchor.GetSides(parent);
                if (sides5 != null)
                {
                    num4 = NGUIMath.Lerp(sides5[3].y, sides5[1].y, this.topAnchor.relative) + (float)this.topAnchor.absolute;
                }
                else
                {
                    num4 = base.GetLocalPos(this.topAnchor, parent).y + (float)this.topAnchor.absolute;
                }
            }
            else
            {
                num4 = localPosition.y - pivotOffset.y * (float)this.mHeight + (float)this.mHeight;
            }
        }
        Vector3 vector = new Vector3(Mathf.Lerp(num, num2, pivotOffset.x), Mathf.Lerp(num3, num4, pivotOffset.y), localPosition.z);
        int     num5   = Mathf.FloorToInt(num2 - num + 0.5f);
        int     num6   = Mathf.FloorToInt(num4 - num3 + 0.5f);

        if (this.keepAspectRatio != UIWidget.AspectRatioSource.Free && this.aspectRatio != 0f)
        {
            if (this.keepAspectRatio == UIWidget.AspectRatioSource.BasedOnHeight)
            {
                num5 = Mathf.RoundToInt((float)num6 * this.aspectRatio);
            }
            else
            {
                num6 = Mathf.RoundToInt((float)num5 / this.aspectRatio);
            }
        }
        if (num5 < this.minWidth)
        {
            num5 = this.minWidth;
        }
        if (num6 < this.minHeight)
        {
            num6 = this.minHeight;
        }
        if (Vector3.SqrMagnitude(localPosition - vector) > 0.001f)
        {
            base.cachedTransform.localPosition = vector;
            if (this.mIsInFront)
            {
                this.mChanged = true;
            }
        }
        if (this.mWidth != num5 || this.mHeight != num6)
        {
            this.mWidth  = num5;
            this.mHeight = num6;
            if (this.mIsInFront)
            {
                this.mChanged = true;
            }
            if (this.autoResizeBoxCollider)
            {
                this.ResizeCollider();
            }
        }
    }
Exemplo n.º 11
0
 protected override void OnAnchor()
 {
     if (mClipping != 0)
     {
         Transform cachedTransform = base.cachedTransform;
         Transform parent          = cachedTransform.parent;
         Vector2   viewSize        = GetViewSize();
         Vector2   vector          = cachedTransform.localPosition;
         float     num;
         float     num2;
         float     num3;
         float     num4;
         if (leftAnchor.target == bottomAnchor.target && leftAnchor.target == rightAnchor.target && leftAnchor.target == topAnchor.target)
         {
             Vector3[] sides = leftAnchor.GetSides(parent);
             if (sides != null)
             {
                 num  = NGUIMath.Lerp(sides[0].x, sides[2].x, leftAnchor.relative) + (float)leftAnchor.absolute;
                 num2 = NGUIMath.Lerp(sides[0].x, sides[2].x, rightAnchor.relative) + (float)rightAnchor.absolute;
                 num3 = NGUIMath.Lerp(sides[3].y, sides[1].y, bottomAnchor.relative) + (float)bottomAnchor.absolute;
                 num4 = NGUIMath.Lerp(sides[3].y, sides[1].y, topAnchor.relative) + (float)topAnchor.absolute;
             }
             else
             {
                 Vector2 vector2 = GetLocalPos(leftAnchor, parent);
                 num  = vector2.x + (float)leftAnchor.absolute;
                 num3 = vector2.y + (float)bottomAnchor.absolute;
                 num2 = vector2.x + (float)rightAnchor.absolute;
                 num4 = vector2.y + (float)topAnchor.absolute;
             }
         }
         else
         {
             if ((bool)leftAnchor.target)
             {
                 Vector3[] sides2 = leftAnchor.GetSides(parent);
                 if (sides2 != null)
                 {
                     num = NGUIMath.Lerp(sides2[0].x, sides2[2].x, leftAnchor.relative) + (float)leftAnchor.absolute;
                 }
                 else
                 {
                     Vector3 localPos = GetLocalPos(leftAnchor, parent);
                     num = localPos.x + (float)leftAnchor.absolute;
                 }
             }
             else
             {
                 num = mClipRange.x - 0.5f * viewSize.x;
             }
             if ((bool)rightAnchor.target)
             {
                 Vector3[] sides3 = rightAnchor.GetSides(parent);
                 if (sides3 != null)
                 {
                     num2 = NGUIMath.Lerp(sides3[0].x, sides3[2].x, rightAnchor.relative) + (float)rightAnchor.absolute;
                 }
                 else
                 {
                     Vector3 localPos2 = GetLocalPos(rightAnchor, parent);
                     num2 = localPos2.x + (float)rightAnchor.absolute;
                 }
             }
             else
             {
                 num2 = mClipRange.x + 0.5f * viewSize.x;
             }
             if ((bool)bottomAnchor.target)
             {
                 Vector3[] sides4 = bottomAnchor.GetSides(parent);
                 if (sides4 != null)
                 {
                     num3 = NGUIMath.Lerp(sides4[3].y, sides4[1].y, bottomAnchor.relative) + (float)bottomAnchor.absolute;
                 }
                 else
                 {
                     Vector3 localPos3 = GetLocalPos(bottomAnchor, parent);
                     num3 = localPos3.y + (float)bottomAnchor.absolute;
                 }
             }
             else
             {
                 num3 = mClipRange.y - 0.5f * viewSize.y;
             }
             if ((bool)topAnchor.target)
             {
                 Vector3[] sides5 = topAnchor.GetSides(parent);
                 if (sides5 != null)
                 {
                     num4 = NGUIMath.Lerp(sides5[3].y, sides5[1].y, topAnchor.relative) + (float)topAnchor.absolute;
                 }
                 else
                 {
                     Vector3 localPos4 = GetLocalPos(topAnchor, parent);
                     num4 = localPos4.y + (float)topAnchor.absolute;
                 }
             }
             else
             {
                 num4 = mClipRange.y + 0.5f * viewSize.y;
             }
         }
         num  -= vector.x + mClipOffset.x;
         num2 -= vector.x + mClipOffset.x;
         num3 -= vector.y + mClipOffset.y;
         num4 -= vector.y + mClipOffset.y;
         float x    = Mathf.Lerp(num, num2, 0.5f);
         float y    = Mathf.Lerp(num3, num4, 0.5f);
         float num5 = num2 - num;
         float num6 = num4 - num3;
         float num7 = Mathf.Max(2f, mClipSoftness.x);
         float num8 = Mathf.Max(2f, mClipSoftness.y);
         if (num5 < num7)
         {
             num5 = num7;
         }
         if (num6 < num8)
         {
             num6 = num8;
         }
         baseClipRegion = new Vector4(x, y, num5, num6);
     }
 }
Exemplo n.º 12
0
 public unsafe static long $Invoke24(long instance, long *args)
 {
     return(GCHandledObjects.ObjectToGCHandle(NGUIMath.Lerp(*(float *)args, *(float *)(args + 1), *(float *)(args + 2))));
 }