unity image 画线
public class Drawing : MonoBehaviour, IPointerDownHandler, IDragHandler{public Image m_Image; //画线的Imageprotected Vector2 rectA; //起点protected Vector2 rectB; //终点protected float offsetX Screen.width / 2;protected float offsetY Screen.height / 2;protected RectTransform line;public void OnPointerDown(PointerEventData eventData){Debug.LogWarning($x:{eventData.position.x},y:{eventData.position.y});Debug.LogWarning($x:{Screen.width},y:{Screen.height});Vector2 startPoint new Vector2(eventData.position.x - offsetX,eventData.position.y - offsetY);rectA startPoint;if (line null){var image Instantiate(m_Image);image.transform.SetParent(m_Image.transform.parent);line image.GetComponentRectTransform();}}public void OnDrag(PointerEventData eventData){Vector2 endPoint new Vector2(eventData.position.x - offsetX,eventData.position.y - offsetY);rectB endPoint;DrawLine(line, rectA, rectB);}void DrawLine(RectTransform rect, Vector2 a, Vector2 b){float distance Vector2.Distance(a, b); // distancefloat angle Vector2.SignedAngle(a - b, Vector2.left); // anglerect.anchoredPosition (a b) / 2;rect.sizeDelta new Vector2(distance, 10);rect.transform.localRotation Quaternion.AngleAxis(-angle, Vector3.forward);}}