每当我将ARCore与vuforia库一起使用时,相机总是无法对焦,该如何使相机对焦?
答案 0 :(得分:1)
ARCamera控件由ARCore接管,我们必须手动将相机设置为自动对焦模式。将此脚本添加到相机对象的工作原理是连续自动对焦模式。 脚本:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Vuforia;
public class CameraFocusController : MonoBehaviour
{
void Start()
{
var vuforia = VuforiaARController.Instance;
vuforia.RegisterVuforiaStartedCallback(OnVuforiaStarted);
vuforia.RegisterOnPauseCallback(OnPaused);
}
private void OnVuforiaStarted()
{
CameraDevice.Instance.SetFocusMode(
CameraDevice.FocusMode.FOCUS_MODE_CONTINUOUSAUTO);
}
private void OnPaused(bool paused)
{
if (!paused) // resumed
{
// Set again autofocus mode when app is resumed
CameraDevice.Instance.SetFocusMode(
CameraDevice.FocusMode.FOCUS_MODE_CONTINUOUSAUTO);
}
}
}