public JPoint PopupPoint(JRect rect, JPoint moveDir) { UnityEngine.Debug.Log("x"); if (IsIn(rect) || rect.IsIn(this)) { JPoint tmCenter = rect.center; JPoint p = rect.center - center; float d = p.Mod; JPoint dir = moveDir.Contrary; dir = dir.Normal; float absX = Math.Abs(dir.x); float absY = Math.Abs(dir.y); float heightSum = (rect.height + this.height) / 2f; float widthSum = (rect.width + this.width) / 2f; UnityEngine.Debug.Log(widthSum); //向上下弹-- if (absY >= absX) { float y = rect.center.y + (dir.y >= 0 ? heightSum : -heightSum); tmCenter.y = y; } else //向左右弹-- { float x = rect.center.x + (dir.x >= 0 ? widthSum : -widthSum); tmCenter.x = x; } return tmCenter; } return rect.center; }
public bool IsIn(JRect rect) { if (IsIn(rect.point1) || IsIn(rect.point2)) { return true; } return false; }
public static void DrawJRect(JRect rect) { Vector2 p1, p2, p3, p4; p1 = JTools.JPoint2Vector2(rect.point1); p4 = JTools.JPoint2Vector2(rect.point2); p2 = new Vector2(p4.x, p1.y); p3 = new Vector2(p1.x, p4.y); Gizmos.DrawLine(p1, p2); Gizmos.DrawLine(p2, p4); Gizmos.DrawLine(p3, p4); Gizmos.DrawLine(p1, p3); }
public static void PrintJRect(JRect rect) { Debug.Log(string.Format("JRect:({0},{1}),{2},{3}", rect.center.x, rect.center.y, rect.width, rect.height)); }