//简单方式
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;

public class Drag : MonoBehaviour, /IPointerDownHandler,/ IDragHandler, IPointerClickHandler
{
private RectTransform self;

private void Awake()
{
    self = GetComponent<RectTransform>();
}

public void OnDrag(PointerEventData eventData)
{
    //锚点的位置加上鼠标移动
    self.anchoredPosition += eventData.delta;
}

public void OnPointerClick(PointerEventData eventData)//点击是执行
{
    //双击是隐藏界面
    if (eventData.clickCount == 2)
    {
        gameObject.SetActive(false);
    }
}

}

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
public class DIalogDrag : MonoBehaviour, IPointerDownHandler,IDragHandler,IPointerClickHandler
{
private RectTransform parentRTF;
private void Start()
{
//设置UI长宽
RectTransform rtf = GetComponent();
rtf.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 700);
rtf.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 400);

    parentRTF = this.transform.parent as RectTransform;
}
private Vector3 siftVector;
//按下时执行
public void OnPointerDown(PointerEventData eventData)
{
    //记录按下点到中心点偏移量

    Vector3 wordPoint;
    //屏幕坐标-->世界坐标
    //(父物体的变换组件,屏幕坐标,摄像机,out 世界坐标)
    RectTransformUtility.ScreenPointToWorldPointInRectangle(parentRTF, eventData.position, eventData.pressEventCamera, out wordPoint);
    siftVector = this.transform.position - wordPoint;
}
//拖拽时执行
public void OnDrag(PointerEventData eventData)
{
    Vector3 wordPoint;
    //屏幕坐标-->世界坐标
    //(父物体的变换组件,屏幕坐标,摄像机,out 世界坐标)
    RectTransformUtility.ScreenPointToWorldPointInRectangle(parentRTF, eventData.position, eventData.pressEventCamera, out wordPoint);
    this.transform.position = wordPoint + siftVector ;
    
}

public void OnPointerClick(PointerEventData eventData)
{
    if (eventData.clickCount == 2)
        Destroy (this .gameObject );
}

}