首页 > 解决方案 > 在 Unity 中,为什么我可以通过按下按钮将相机切换到 WorldView,但在使用人脸管理器的同时无法在开始或更新循环中执行此操作?

问题描述

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

标签: c#unity3dmobileaugmented-realityarcore

解决方案


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

IEnumerator switchCamera()
{

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

推荐阅读