您的位置:首页 > 其它

获得物体在屏幕上的localPosition的方法举例

2017-05-02 02:28 225 查看
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;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息