public static Vector3 ScreenLocalPosition(Transform target, Vector3 pos)
{
//变换屏幕坐标到世界坐标
if (Get.UiCamera.orthographic)
{
pos.x = Mathf.Round(pos.x);
pos.y = Mathf.Round(pos.y);
pos.z = Mathf.Round(pos.z);
}
pos = Get.UiCamera.ScreenToWorldPoint(pos);
if (!Get.UiCamera.orthographic || target.parent == default(Transform)) return pos;
//变换父级(ngui)坐标到世界坐标
pos = target.parent.InverseTransformPoint(pos);
pos.x = Mathf.RoundToInt(pos.x);
pos.y = Mathf.RoundToInt(pos.y);
pos.z = Mathf.RoundToInt(pos.z);
return pos;
获得物体在屏幕上的localPosition的方法举例
最新推荐文章于 2024-06-07 20:53:45 发布