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;
            }
        }
相关推荐
西岸行者4 天前
学习笔记:SKILLS 能帮助更好的vibe coding
笔记·学习
多恩Stone4 天前
【C++入门扫盲1】C++ 与 Python:类型、编译器/解释器与 CPU 的关系
开发语言·c++·人工智能·python·算法·3d·aigc
starlaky4 天前
Django入门笔记
笔记·django
勇气要爆发4 天前
吴恩达《LangChain LLM 应用开发精读笔记》1-Introduction_介绍
笔记·langchain·吴恩达
悠哉悠哉愿意4 天前
【单片机学习笔记】串口、超声波、NE555的同时使用
笔记·单片机·学习
勇气要爆发4 天前
吴恩达《LangChain LLM 应用开发精读笔记》2-Models, Prompts and Parsers 模型、提示和解析器
android·笔记·langchain
qianshanxue114 天前
计算机操作的一些笔记标题
笔记
土拨鼠烧电路4 天前
笔记11:数据中台:不是数据仓库,是业务能力复用的引擎
数据仓库·笔记
土拨鼠烧电路4 天前
笔记14:集成与架构:连接孤岛,构建敏捷响应能力
笔记·架构
烟花落o5 天前
栈和队列的知识点及代码
开发语言·数据结构·笔记·栈和队列·编程学习