/// <summary> /// 获取出屏幕外的修正值 /// </summary> /// <returns></returns> private Vector2 GetoffScreenOut(RectTransform targetRect) { Vector2 offset = Vector2.zero; Vector3 pos = (WndManager.GetUINode() as UINode).UICamera.WorldToScreenPoint(targetRect.position); Vector2 v = new Vector2(targetRect.sizeDelta.x * targetRect.pivot.x, targetRect.sizeDelta.y * targetRect.pivot.y); float l = pos.x - v.x; float r = pos.x + v.x; float u = pos.y + v.y; float d = pos.y - v.y; if (l < 10) { offset.x = 10 - l; } if (r > Screen.width - 10) { offset.x = Screen.width - 10 - r; } if (d < 10) { offset.y = 10 - d; } if (u > Screen.height - 10) { offset.y = Screen.height - 10 - u; } return(offset); }
/// <summary> /// 显示tips /// </summary> /// <param name="msg">tip 内容</param> /// <param name="title">tip 标题</param> /// <param name="tipRect">弹出tips 的对象</param> /// <param name="align">对其方式</param> /// <param name="offset">修正偏移值</param> /// <returns></returns> public static bool ShowTips(string msg, string title, RectTransform tipRect, TipAlignment align, Vector2 offset) { ResourceManger.LoadWndItem("HintItem", (WndManager.GetUINode() as UINode).GetWndParent(WndType.DialogWnd), false, (obj) => { HintItem item = obj.GetComponent <HintItem>(); if (item != null) { item.SetData(new object[] { msg, title, tipRect, align, offset }); } }); return(true); }
private void SetPos(RectTransform targetRect, TipAlignment alig, Vector2 offset) { Vector3 targetScreenPos = (WndManager.GetUINode() as UINode).UICamera.WorldToScreenPoint(targetRect.position); Vector3 pos = (WndManager.GetUINode() as UINode).UICamera.WorldToScreenPoint(m_Rect.position); Vector2 center = targetScreenPos - pos; Vector2 v = GetPivotWH(m_Rect, targetRect); if (alig == TipAlignment.Left) { center.x -= v.x; } else if (alig == TipAlignment.Right) { center.x += v.x; } else if (alig == TipAlignment.Up) { center.y += v.y; } else if (alig == TipAlignment.Down) { center.y -= v.y; } else if (alig == TipAlignment.LeftUp) { center.x -= v.x; center.y += v.y; } else if (alig == TipAlignment.LeftDown) { center.x -= v.x; center.y -= v.y; } else if (alig == TipAlignment.RightUp) { center.x += v.x; center.y += v.y; } else if (alig == TipAlignment.RightDown) { center.x += v.x; center.y -= v.y; } m_Rect.localPosition = center + offset; center = m_Rect.localPosition; offset = GetoffScreenOut(m_Rect); m_Rect.localPosition = center + offset; }