Exemplo n.º 1
0
    public static bool IsPointInsideEllipse(Vector2 p1, TRect rect1)
    {
        float   a = 0;
        float   b = 0;
        float   c = 0;
        Vector2 c1;
        Vector2 c2;

        if (rect1.width > rect1.height)
        {
            a  = rect1.width * 0.5f;
            b  = rect1.height * 0.5f;
            c  = Mathf.Sqrt(a * a - b * b);
            c1 = new Vector2(rect1.x - c, rect1.y);
            c2 = new Vector2(rect1.x + c, rect1.y);
        }
        else
        {
            b  = rect1.width * 0.5f;
            a  = rect1.height * 0.5f;
            c  = Mathf.Sqrt(a * a - b * b);
            c1 = new Vector2(rect1.x, rect1.y - c);
            c2 = new Vector2(rect1.x, rect1.y + c);
        }
        float dist = Vector2.Distance(p1, c1) + Vector2.Distance(p1, c2);

        return(dist < 2 * a);
    }
Exemplo n.º 2
0
    public static TRect FormatToReal(TRect ellipse)
    {
        TRect _new = new TRect();

        _new.center = FormatToReal(ellipse.center);
        _new.size   = FormatToReal(ellipse.size);
        return(_new);
    }
Exemplo n.º 3
0
    public static Vector2 GetHangLerp(Vector2 curHangUIPoint)
    {
        TRect   cachedRect = hangRect;
        Vector2 point      = hangRect.MakePosInside(curHangUIPoint);
        float   lerpX      = (point.x - cachedRect.left) / cachedRect.width;
        float   lerpY      = (point.y - cachedRect.bottom) / cachedRect.height;

        return(new Vector2(lerpX, lerpY));
    }
Exemplo n.º 4
0
    public static TRect GetObjectScreenRect(Vector3 centerPos, float width, float height)
    {
        Vector3 cp               = mainCamera.WorldToScreenPoint(centerPos);
        Vector3 up               = mainCamera.WorldToScreenPoint(centerPos + Vector3.up);
        int     project          = cp.z > 0 ? 1 : -1; // 是否指在屏幕后?
        float   point3dTo2dRatio = up.y - cp.y;
        float   boxWidth         = point3dTo2dRatio * width;
        float   boxHeight        = point3dTo2dRatio * height;
        TRect   rect             = new TRect(cp, new Vector2(boxWidth, boxHeight) * project);

        return(rect);
    }
Exemplo n.º 5
0
    /// <summary>
    /// 点到矩形四条边最近距离以及最近的点
    /// </summary>
    /// <param name="point"></param>
    /// <param name="rect"></param>
    /// <param name="subPoint"></param>
    /// <param name="dist"></param>
    public static void GetPointToRectSidesNearestPointAndDist(Vector2 point, TRect rect, out Vector2 subPoint, out float dist)
    {
        Vector2 outSubPoint = Vector2.zero;
        float   outDist     = float.MaxValue;

        Vector2[] rectSubPoint = { new Vector2(rect.x - rect.width * 0.5f, rect.y + rect.height * 0.5f)                                         // 左上
                                   ,                                       new Vector2(rect.x + rect.width * 0.5f, rect.y + rect.height * 0.5f) // 右上
                                   ,                                       new Vector2(rect.x + rect.width * 0.5f, rect.y - rect.height * 0.5f) // 右下
                                   ,                                       new Vector2(rect.x - rect.width * 0.5f, rect.y - rect.height * 0.5f) // 左下
                                   ,                                       new Vector2(rect.x - rect.width * 0.5f, rect.y + rect.height * 0.5f) // 左上
        };

        GetPointToPointLinesNearestPointAndDist(point, rectSubPoint, out outSubPoint, out outDist);
        subPoint = outSubPoint;
        dist     = outDist;
    }
Exemplo n.º 6
0
 public static bool IsTwoEllipseCollisionSimple(TRect rect1, TRect rect2)
 {
     return(IsTwoEllipseCollisionSimple(rect1.center, rect1.size, rect2.center, rect2.size));
 }
Exemplo n.º 7
0
        void UpdateDraw()
        {
            foreach (var p in playerMgr.models)
            {
                if (!p.isCached)
                {
                    continue;
                }
                if (!p.root)
                {
                    continue;
                }
                if (!p.isAlive)
                {
                    continue;
                }
                if (!p.root.gameObject.activeInHierarchy)
                {
                    continue;
                }
                if (!Settings.isEspFriendly && p.isFriend)
                {
                    continue;
                }

                var color = p.isFriend ? Color.green : Color.red;

                // NAME
                var        _name      = p.root.name;
                Color      lastColor  = GUI.color;
                TextAnchor lastAnchor = GUI.skin.label.alignment;
                GUI.contentColor         = Color.black;
                GUI.skin.label.alignment = TextAnchor.MiddleCenter;
                var _rect = p.GetRect();
                _rect.y = Screen.height - _rect.y;
                var __rect = new Rect(_rect.center, _rect.size);
                __rect.y     -= __rect.height;
                __rect.x      = __rect.x - 100;
                __rect.height = 20;
                __rect.width  = 200;
                GUI.Label(__rect, _name);
                __rect.x        -= 1;
                __rect.y        -= 1;
                GUI.contentColor = color;
                GUI.Label(__rect, _name);
                GUI.contentColor         = lastColor;
                GUI.skin.label.alignment = lastAnchor;

                if (Settings.isEspBox)
                {
                    var rect = p.GetRect();
                    // Log.Print(p.name + " : " + rect);
                    if (rect.height != 0)
                    {
                        D_R(p.GetRect(), color);
                    }
                }

                if (Settings.isEspBoneLine)
                {
                    foreach (var line in p.GetLines())
                    {
                        D_L(line, color);
                    }
                }

                if (Settings.isEspAirLine)
                {
                    var rect = p.GetRect();
                    if (rect.height != 0)
                    {
                        var boxTopCenter    = new Vector2(rect.x, rect.top);
                        var screenTopCenter = new Vector2(Screen.width * 0.5f, Screen.height);
                        D_L(new TLine(boxTopCenter, screenTopCenter), color);
                    }
                }

                if (Settings.isEspHp)
                {
                    var rect = p.GetRect();
                    if (rect.height != 0)
                    {
                        var x  = rect.right + 4;
                        var y  = rect.bottom + 1;
                        var h  = (rect.height - 2) * p.hp / p.hpMax;
                        var p1 = new Vector2(x, y);
                        var p2 = new Vector2(x, y + h);
                        D_L(new TLine(p1, p2), color);
                        p1.x += 1; p2.x += 1;
                        D_L(new TLine(p1, p2), color);
                        p1.x += 1; p2.x += 1;
                        D_L(new TLine(p1, p2), color);
                        var bgRect = new TRect(x + 1, rect.center.y, 5, rect.height);
                        D_R(bgRect, Color.black * 0.7f);
                    }
                }
            }
        }
Exemplo n.º 8
0
 private void D_R(TRect r, Color color)
 {
     GizmosPro.DrawRect(r, color);
 }