UGUI笔记——3D坐标转换成UGUI坐标

UGUI笔记------3D坐标转换成UGUI坐标

Canvas的模式为ScreenSpace-Camera

javascript 复制代码
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

javascript 复制代码
    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;
            }
        }
相关推荐
lingggggaaaa21 分钟前
免杀对抗——C2远控篇&PowerShell&有无文件落地&C#参数调用&绕AMSI&ETW&去混淆特征
c语言·开发语言·笔记·学习·安全·microsoft·c#
lxmyzzs35 分钟前
作为一名工程师,何不试试瑞芯微?
笔记·rk3588
wgego2 小时前
polarctf-web做题笔记
笔记·web安全
Highcharts.js2 小时前
使用 Highcharts 3D图表入门
3d·highcharts·使用文档·3d图表·交互图表·三维图表·3d 可视化
O***p6042 小时前
C++在游戏中的Ogre3D
游戏·3d·ogre
sdjnled2292 小时前
山东裸眼3D立体LED显示屏专业服务商
人工智能·3d
徒慕风流2 小时前
GeoSight:基于 Open3D 与 PySide6 的参数化 3D 模型处理与实时点云监控工具
计算机视觉·3d·信号处理
wdfk_prog3 小时前
[Linux]学习笔记系列 -- [kernel]workqueue
linux·笔记·学习
wdfk_prog3 小时前
[Linux]学习笔记系列 -- [kernel]usermode_helper
linux·笔记·学习
一只爱做笔记的码农3 小时前
【BootstrapBlazor】移植BootstrapBlazor VS工程到Vscode工程,报error blazor106的问题
笔记·学习·c#