//添加 带锚点 public virtual void AddComponent(ERect rect, E_Anchor anchor) { // TODO bug 没有fixed float pos_x = rect.Ex; float pos_y = rect.Ey; E_Anchor e = (anchor & E_Anchor.Left); if ((anchor & E_Anchor.Left) == E_Anchor.Left) { pos_x = rect.Ew / 2; } else if ((anchor & E_Anchor.Right) == E_Anchor.Right) { pos_x = _size.x - pos_x - rect.Ew / 2; } /*else if ((anchor & E_Anchor.center) == E_Anchor.center) * { * pos_x = _size.x / 2 + pos_x; * }*/ /* if ((anchor & E_Anchor.center) == E_Anchor.center) * { * pos_y = _size.y / 2 + pos_y; * } * else */ if ((anchor & E_Anchor.UP) == E_Anchor.UP) { pos_y = pos_y + rect.Eh / 2; } else if ((anchor & E_Anchor.DOWN) == E_Anchor.DOWN) { pos_y = _size.y + pos_y - rect.Eh / 2; } if ((anchor & E_Anchor.DOWN_CENTER) == E_Anchor.DOWN_CENTER) { pos_x = (_size.x / 2) - (rect.Ew / 2); pos_y = _size.y + pos_y - rect.Eh / 2; } rect.ResetPosition(pos_x, pos_y); _internal_add_chile(rect); }
public static Rect ApplyAnchor(Rect rect, E_Anchor anchor) { if (anchor == E_Anchor.TopCenter || anchor == E_Anchor.MiddleCenter || anchor == E_Anchor.BottomCenter) { rect.x -= rect.width / 2; } else if (anchor == E_Anchor.TopRight || anchor == E_Anchor.MiddleRight || anchor == E_Anchor.BottomRight) { rect.x -= rect.width; } if (anchor == E_Anchor.MiddleLeft || anchor == E_Anchor.MiddleCenter || anchor == E_Anchor.MiddleRight) { rect.y -= rect.height / 2; } else if (anchor == E_Anchor.BottomLeft || anchor == E_Anchor.BottomCenter || anchor == E_Anchor.BottomRight) { rect.y -= rect.height; } return rect; }
public Rect GetScreenRect(Vector3 point, float width, float height, E_Anchor anchor) { Vector3 screenPoint = RectTool.ReverseScreenY(rawCamera.WorldToScreenPoint(point)); Rect rectScreen = new Rect(screenPoint.x, screenPoint.y, width, height); anchor.Apply(rectScreen); return rectScreen; }
public override void AddComponent(ERect rect, E_Anchor anchor) { Debug.LogError("垂直布局,不支持这种添加方式"); }
//添加 public virtual void AddComponent(ERect rect) { E_Anchor a = E_Anchor.Left | E_Anchor.UP; AddComponent(rect, a); }