思路:
主要用到了 RectTransformUtility里面的ScreenPointToLocalPointInRectangle函数
public static bool ScreenPointToLocalPointInRectangle
(RectTransform rect, ----- 希望得到坐标结果的父对象
Vector2 screenPoint, ----- 鼠标位置
Camera cam, ----- UI摄像机
out Vector2 localPoint); ----- 相对于父对象的坐标
Vector2 localPos;
RectTransformUtility.ScreenPointToLocalPointInRectangle((RectTransform)GameObject.FindGameObjectWithTag("Bottom").transform,//希望得到坐标结果的父对象
(eventData as PointerEventData).position, // 鼠标位置
(eventData as PointerEventData).pressEventCamera, //UI摄像机
out localPos);
nowDragImg.transform.localPosition = localPos;//相对于父对象的坐标