优化不在主相机视野的物体不渲染
Plane[] planes = GeometryUtility.CalculateFrustumPlanes(mainCamera);//获取该相机的剪裁锥体的6个面
Bounds bounds = target.GetComponent<Collider>().bounds();//获取物体的碰撞盒子
bounds.Expand(2.0f);//扩大一下这个碰撞盒子
bool isIn = GeometryUtility.TestPlanesAABB(planes, bound);//判断是否在相机视野内
target.SetActive(isIn);


扩大碰撞盒子是为了避免模型物体突然出现在相机视野的情况,因为视野是会移动的,留点边界预留区保留效果。


首页 我的博客
粤ICP备17103704号