c# - 在 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()
{
}
}
解决方案
所以我发现你只能在第 1 帧过去后切换相机。根据下面derHugo的评论,我认为最好的解决方案是协程,如下所示:
IEnumerator switchCamera()
{
yield return null;
yield return null;
camManager.requestedFacingDirection = CameraFacingDirection.World;
}
推荐阅读
- audio - 采样率、比特率和比特深度之间的差异
- knex.js - 如何在 Knex 迁移中设置默认值?
- mongodb - mongodb查询字符串分隔的整数列包含与其他集合匹配的特定整数值的数据连接
- sql - 如何使用联合从另一个表中添加新行?
- typescript - 打字稿中的抽象函数返回类型
- sql - 从表中插入数据时,临时表列中的“9.67609e+008”值得到更新
- powershell - Powershell中Windows调度程序中计划任务状态的表格格式
- c# - 应用代码混淆后 exe 需要 1-3 分钟才能运行
- sql - SQL - 如何在特定列中选择具有最大值的数据行?[第2部分]
- python - 将 SSH 与应用程序服务器一起使用时 libcrypto.so 中的段错误