UGUI坐标换算

//1屏幕坐标转UI坐标

Vector2 mouseUguiPos;

bool isRect = RectTransformUtility.ScreenPointToLocalPointInRectangle(DragTargetParentRect,

eventData.position, UICamera, out mouseUguiPos);

if (isRect)

{

offset = DragTarget.anchoredPosition - mouseUguiPos;

}

 

 

//2.UI坐标转屏幕坐标

///

/// 设置位置

///

public void SetAnchorPosition(RectTransform anchorRectTrans)

{

Vector2 showPosition = RectTransformUtility.WorldToScreenPoint(AppManager.Instance.canvas.worldCamera, anchorRectTrans.position);

showPosition = new Vector2(Mathf.Round(showPosition.x), Mathf.Round(showPosition.y));

SetAnchorPosition(showPosition);

}

你可能感兴趣的:(ugui,unity,unity)