如果是UI_2D的话,是这样的
var uif = node.getComponent(cc.UITransform)
var rect = uif.getBoundingBoxToWorld()
但如果是3D的话,翻了一下文件大致是这样
var sr = node.getComponent("cc.MeshRenderer")
var mb = sr?.model?.worldBounds
const minPos = new cc.Vec3(0, 0, 0);
const maxPos = new cc.Vec3(0, 0, 0);
mb.getBoundary(minPos, maxPos);
var min = new cc.Vec3(0,0,0)
var max = new cc.Vec3(0,0,0)
camera.worldToScreen(min,minPos)
camera.worldToScreen(max,maxPos)
return cc.rect(min.x*2,min.y*2,(max.x-min.x),(max.y-min.y))
这个rect,转换到UI上时,坐标跟视角的坐标总是有差距,哪位大佬清楚的,求解答。