移动相机,使所有物体都在相机的视野中

Move the camera so that all objects are in the camera's field of view

select objects

Camera is moved but top cut 移动相机,使所有物体都在相机的视野中

我想让非选中的对象不可见,尽量放大,同时让所有可见的对象都可见

Vector3 averagePos=Vector3.zero;
    for (int i = 0; i < set[num].Count; i++)
    {
        objectManager.SetActive(set[num][i], true);
        averagePos += objectManager.ReturnPos(set[num][i]);
    }
    averagePos /= set[num].Count; 

如果(move_On) {

        angle += Time.deltaTime;
        if (angle > 0.01)
            angle = 0.009f;
        //   transform.position = Vector3.SmoothDamp(transform.position, destPos, ref velocity, smoothTime);
        Vector3 ve3=Vector3.Lerp(transform.position, destPos, angle);
        Debug.Log(Vector3.Distance(ve3, destPos));
        if (Vector3.Distance(ve3,destPos)>1)
            transform.position = Vector3.Lerp(transform.position, destPos, angle);
    } 
    centerOfPos = new Vector3((maxPosX + minPosX) / 2, (maxPosY + minPosY) / 2, 0);
    Camera.main.transform.LookAt(centerOfPos);
    float hoizontalCamZ = (maxPosY + 1 - minPosY) / Mathf.Cos(Camera.main.fieldOfView / 2 * Mathf.Deg2Rad);
    float verticalCamZ = (maxPosX + 1 - minPosX) / Mathf.Cos
        (Mathf.Atan(Mathf.Tan(Camera.main.fieldOfView / 2 * Mathf.Deg2Rad)));


    if (hoizontalCamZ < verticalCamZ)
        camZ = verticalCamZ;
    else
        camZ = hoizontalCamZ;


    Vector3 newCamPos = new Vector3(0, 0, -camZ);