示例#1
0
    void Update()
    {
        alphaMod = Mathf.MoveTowards(alphaMod, (isEnabled && !aimingAt) ? 1f : 0f, Time.unscaledDeltaTime * 5f);
        foreach (UIWidget widget in widgets)
        {
            widget.alpha = widget.defaultAlpha * alphaMod * osMod;
        }

        if (target != null)
        {
            BaseStats bs = target.GetComponent <BaseStats>();
            targetDead = (bs != null && bs.curHealth <= 0);
        }

        if (target == null || targetDead)
        {
            isEnabled = false;
        }

        if (!isEnabled && alphaMod <= 0f)
        {
            return;
        }

        curWidth = normalWidth;
        if (DarkRef.isModernWidescreen)
        {
            curWidth = modernWideWidth;
        }
        else if (DarkRef.isOldWidescreen)
        {
            curWidth = oldWideWidth;
        }

        curScale = (scalingEnabled) ? DarkRef.ScaleWithDistance(distance, nearDistance, farDistance, nearScale, farScale) : 1f;

        if (mainCamera == null)
        {
            return;
        }

        if (target != null)
        {
            m_LastPos = target.position;
            pos       = GetBasicViewportPosition(target.position);
        }
        else
        {
            pos = GetBasicViewportPosition(m_LastPos);
        }

        Vector3 currentTarget = (target == null) ? m_LastPos : target.position;

        if (pos.z < 0f)
        {
            pos = GetAdvancedViewportPosition(currentTarget, 1.0f, pos);
        }
        else if (pos.x < 0f)
        {
            if (pos.x <= -1.0f)
            {
                pos = GetAdvancedViewportPosition(currentTarget, 1.0f, pos);
            }
            else
            {
                pos = GetAdvancedViewportPosition(currentTarget, 1.0f - (1.0f - Mathf.Abs(pos.x)), pos);
            }
        }
        else if (pos.x > 1.0f)
        {
            if (pos.x >= 2.0f)
            {
                pos = GetAdvancedViewportPosition(currentTarget, 1.0f, pos);
            }
            else
            {
                pos = GetAdvancedViewportPosition(currentTarget, 1.0f - (1.0f - (pos.x - 1.0f)), pos);
            }
        }
        else if (pos.y < 0f)
        {
            if (pos.y <= -1.0f)
            {
                pos = GetAdvancedViewportPosition(currentTarget, 1.0f, pos);
            }
            else
            {
                pos = GetAdvancedViewportPosition(currentTarget, 1.0f - (1.0f - Mathf.Abs(pos.x)), pos);
            }
        }
        else if (pos.y > 2.0f)
        {
            if (pos.y >= 2.0f)
            {
                pos = GetAdvancedViewportPosition(currentTarget, 1.0f, pos);
            }
            else
            {
                pos = GetAdvancedViewportPosition(currentTarget, 1.0f - (1.0f - (pos.y - 1.0f)), pos);
            }
        }

        int markerX = Mathf.RoundToInt(-curWidth + (pos.x * curWidth * 2f));
        int markerY = Mathf.RoundToInt(-normalHeight + (pos.y * normalHeight * 2f));

        rotation = 0f;
        if (pos.x > 0f && pos.x < 1f && pos.y > 0f && pos.y < 1f)
        {
            markerPos  = new Vector2(markerX, markerY);
            curOffset  = Vector2.zero;
            curTexture = GUITextures[0];
        }
        else if (pos.x <= 0f)
        {
            if (pos.y <= 0f)
            {
                markerPos  = new Vector2(-curWidth, -normalHeight);
                curOffset  = new Vector2(edgeOffset.x, edgeOffset.y);
                curTexture = GUITextures[3];
                rotation   = 135f;
            }
            else if (pos.y >= 1f)
            {
                markerPos  = new Vector2(-curWidth, normalHeight);
                curOffset  = new Vector2(edgeOffset.x, -edgeOffset.y);
                curTexture = GUITextures[3];
                rotation   = 45f;
            }
            else
            {
                markerPos  = new Vector2(-curWidth, Mathf.Clamp(markerY, -normalHeight, normalHeight));
                curOffset  = new Vector2(edgeOffset.x, 0f);
                curTexture = GUITextures[1];
            }
        }
        else if (pos.x >= 1f)
        {
            if (pos.y <= 0f)
            {
                markerPos  = new Vector2(curWidth, -normalHeight);
                curOffset  = new Vector2(-edgeOffset.x, edgeOffset.y);
                curTexture = GUITextures[3];
                rotation   = -135f;
            }
            else if (pos.y >= 1f)
            {
                markerPos  = new Vector2(curWidth, normalHeight);
                curOffset  = new Vector2(-edgeOffset.x, -edgeOffset.y);
                curTexture = GUITextures[3];
                rotation   = -45f;
            }
            else
            {
                markerPos  = new Vector2(curWidth, Mathf.Clamp(markerY, -normalHeight, normalHeight));
                curOffset  = new Vector2(-edgeOffset.x, 0f);
                curTexture = GUITextures[2];
            }
        }
        else if (pos.y <= 0f)
        {
            markerPos  = new Vector2(markerX, -normalHeight);
            curOffset  = new Vector2(0f, edgeOffset.y);
            curTexture = GUITextures[4];
        }
        else if (pos.y >= 1f)
        {
            markerPos  = new Vector2(markerX, normalHeight);
            curOffset  = new Vector2(0f, -edgeOffset.y);
            curTexture = GUITextures[3];
        }

        osMod = (pos.x <= 0f || pos.x >= 1f || pos.y <= 0f || pos.y >= 1f) ? 0.35f : 1f;

        if (markerTexture.mainTexture != curTexture)
        {
            markerTexture.mainTexture = curTexture;
        }

        if (pos.x <= textBorder.x)
        {
            pivotPoint = UIWidget.Pivot.Left;
            xText      = -12f;
        }
        else if (pos.x >= textBorder.y)
        {
            pivotPoint = UIWidget.Pivot.Right;
            xText      = 12f;
        }
        else
        {
            pivotPoint = UIWidget.Pivot.Center;
            xText      = 0f;
        }

        if (distanceLabel.pivot != pivotPoint)
        {
            distanceLabel.pivot    = pivotPoint;
            descriptionLabel.pivot = pivotPoint;
        }

        if (pos.y <= textBorder.z)
        {
            yText  = 32f;
            yText2 = 20f;
        }
        else
        {
            yText  = -20f;
            yText2 = -33f;
        }

        offsetReal = Vector2.Lerp(offsetReal, curOffset, Time.unscaledDeltaTime * 5f);

        distanceLabel.cachedTrans.localPosition    = Vector3.Lerp(distanceLabel.cachedTrans.localPosition, new Vector3(xText, yText, 0f), Time.unscaledDeltaTime * 10f);
        descriptionLabel.cachedTrans.localPosition = Vector3.Lerp(descriptionLabel.cachedTrans.localPosition, new Vector3(xText, yText2, 0f), Time.unscaledDeltaTime * 10f);

        tr.localPosition = markerPos + offsetReal;

        markerTexture.cachedTrans.localRotation = Quaternion.Slerp(markerTexture.cachedTrans.localRotation, Quaternion.Euler(0f, 0f, rotation), Time.unscaledDeltaTime * 8f);
        aimingAt = (ac != null && ac.isAiming && Mathf.Abs(pos.x - 0.5f) < 0.2f && Mathf.Abs(pos.y - 0.5f) < 0.2f);
    }