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;
            }
        }
相关推荐
摇滚侠2 小时前
《On Java 中文版 基础卷》阅读笔记 接口 19
java·开发语言·笔记
虎符饼干2 小时前
用WebHook把AI文章推送到自建官网,接收端需要具备哪些处理与发布能力?
笔记
吃我一窝jio3 小时前
Java多线程核心知识点梳理
java·开发语言·笔记
星恒随风3 小时前
从0实现C++ AI大模型接入SDK(二):AI知识科普——从图灵测试到ChatGPT,人工智能的发展历程
linux·c++·人工智能·笔记·chatgpt
aaaameliaaa5 小时前
VSCode的安装与配置
ide·笔记·vscode·编辑器
一只大鸽子6 小时前
游戏开发笔记9-Godot RPG游戏基础-敌人
笔记·游戏·godot
紫金修道6 小时前
【机械臂视觉】学习笔记一:相机成像模型与内参标定
笔记·数码相机·学习
旖旎夜光6 小时前
【C 语言】(一)(下)指针进阶:const、二级指针、函数指针与指针题
c语言·开发语言·笔记·学习
云半S一8 小时前
Agent学习总结补充:1
经验分享·笔记·agent·学习分享
Brilliantwxx8 小时前
【STM32】 DAC 数模转换器(理论 + 外设 + 四个实验案例)
笔记·stm32·单片机·嵌入式硬件