在 Unity 中,为什么我可以通过按下按钮将相机切换到 WorldView,但不能在同时使用 Face Manager 的同时在 Start 或 Update 循环中执行此操作?

In Unity, why can I switch the Camera to WorldView with a button press but cannot do it in the Start or Update loop while also using Face Manager?

我正在开发一款 Unity AR 游戏,我想开始使用面部管理器在面向世界的相机上跟踪面部姿势。我知道您可以使用世界相机跟踪面部姿势,因为我在 ar-foundation-samples 项目中看到过它。需要注意的是,您必须先以面向用户的模式启动,然后在应用程序 运行 后按一个按钮切换到面向世界的模式。我希望它从 World-Facing 相机开始,但每次我尝试使用 Face Manager 运行 执行此操作时,它都不起作用;相机根本不亮。我的问题是,为什么我可以通过单击按钮将我的面部姿势跟踪从面向用户切换到面向世界,但我不能通过 Start() 或 Update() 方法执行相同的操作?

public class FaceController : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        /*This won't switch the camera*/        
        camManager.requestedFacingDirection = CameraFacingDirection.World;
    }

    private void OnEnable()
    {
        
    }

    public ARCameraManager camManager;
    public ARSession aRSession;
    bool trigger;
    bool trigger2;

    public void SwitchMode()
    {
        /*This will switch the camera when called by a button press */
        camManager.requestedFacingDirection = CameraFacingDirection.World;
    }

    // Update is called once per frame
    void Update()
    {
      
      
    }
}

所以我发现你只能在第 1 帧通过后才能切换相机。根据下面 derHugo 的评论,我认为最好的解决方案是如下协程:

IEnumerator switchCamera()
{

    yield return null;
    yield return null;
    camManager.requestedFacingDirection = CameraFacingDirection.World;
    
}