UGUI笔记——3D坐标转换成UGUI坐标
UGUI笔记——3D坐标转换成UGUI坐标
Canvas的模式为ScreenSpace-Camera
private void SetUIPosition(Vector3 worldPosition)
{Vector3 screenPosition = RectTransformUtility.WorldToScreenPoint(mainCamera, worldPosition);Vector2 localPoint;if(RectTransformUtility.ScreenPointToLocalPointInRectangle(rectTransform.transform.parent.GetComponent<RectTransform>(),screenPosition,uiCamera,out localPoint)) {rectTransform.anchoredPosition = localPoint;}
}
Canvas的模式为ScreenSpace-Overlay
private void SetUIPosition(Vector3 worldPosition) {Vector3 screenPosition = RectTransformUtility.WorldToScreenPoint(GlobalDefine.mainCamera, worldPosition);Vector2 localPosition;if (RectTransformUtility.ScreenPointToLocalPointInRectangle(mRectTransform.transform.parent.GetComponent<RectTransform>(), screenPosition, null, out localPosition)){mRectTransform.anchoredPosition = localPosition;}}
