整体思路是这样的,首先,整个功能是使用unity的IBeginDragHandler,IDragHandler接口来实现,通过对点的拖动,根据鼠标位置重新计算图片大小及坐标。
右侧点的拖动:
private void Right()
{
if (startWidth + Input.mousePosition.x - startMouseX <= minWidth)
return;
gameObject.GetComponent<RectTransform>().sizeDelta = new Vector2(startWidth + Input.mousePosition.x - startMouseX, gameObject.GetComponent<RectTransform>().sizeDelta.y);
gameObject.transform.localPosition = new Vector3(startRectX + (gameObject.GetComponent<RectTransform>().sizeDelta.x - startWidth) / 2, gameObject.transform.localPosition.y);
}
资源已上传CSDN下载,链接: