訪問(wèn)網(wǎng)站出現(xiàn)目錄seo是什么專業(yè)的課程
RectTransformUtility-ScreenPointToWorldPointInRectangle - Unity 腳本 API
將一個(gè)屏幕空間點(diǎn)轉(zhuǎn)換為世界空間中位于給定RectTransform 平面上的一個(gè)位置。?
實(shí)現(xiàn)?
?獲取平面位置。
parentRT = transform.parent as RectTransform;
繼承IPointerDownHandler?和IDragHandler 接口。
鼠標(biāo)點(diǎn)擊時(shí)記錄鼠標(biāo)與UI 位置的偏差。
RectTransformUtility.ScreenPointToWorldPointInRectangle(parentRT, eventData.position, eventData.pressEventCamera, out Vector3 worldPoint);
offset = transform.position - worldPoint;
拖拽時(shí)記錄鼠標(biāo)位置并設(shè)定UI 位置。
RectTransformUtility.ScreenPointToWorldPointInRectangle(parentRT, eventData.position, eventData.pressEventCamera, out Vector3 worldPoint);
transform.position = worldPoint + offset;