Vuforia前置摄像头弃用

时间:2019-04-18 01:39:42

标签: c# android unity3d vuforia

我正在一个需要前置摄像头的Unity项目中工作。更新Unity(Unity 2018.3.6)后,Vuforia已弃用前置摄像头支持。 即使回滚到以前的版本,我也无法正常工作。 我正在使用以下代码:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Vuforia;
public class CameraController : MonoBehaviour
{
    private bool lightOn = false;
    private bool frontCamera = false;

    public void CameraChange()
    {
        if (!frontCamera)
        {
            RestartCamera(CameraDevice.CameraDirection.CAMERA_FRONT);
            frontCamera = true;
            Debug.Log("Using Front Camera");
        }
        else if (frontCamera)
        {
            RestartCamera(CameraDevice.CameraDirection.CAMERA_BACK);
            frontCamera = false;
            Debug.Log("Using Back Camera");
        }
        else
        {
            Debug.Log("No camera status available.");
        }
    }

    private void RestartCamera(CameraDevice.CameraDirection newDir)
    {
        CameraDevice.Instance.Stop();
        CameraDevice.Instance.Deinit();
        CameraDevice.Instance.Init(newDir);
        CameraDevice.Instance.Start();
        VuforiaUnity.OnPause();
        VuforiaUnity.OnResume();
    }
}

当我单击按钮切换相机时,电脑屏幕变黑并显示此错误消息:

Failed to set frame format
UnityEngine.Debug:LogError(Object)
Vuforia.CameraDevice:SetFrameFormat(PIXEL_FORMAT, Boolean)
Vuforia.CameraDevice:ForceFrameFormat(PIXEL_FORMAT, Boolean)
Vuforia.CameraDevice:Start()
CameraController:RestartCamera(CameraDirection) (at Assets/CameraController.cs:37)
CameraController:CameraChange() (at Assets/CameraController.cs:16)
UnityEngine.EventSystems.EventSystem:Update()

将其加载到平板电脑中时,当我单击以切换相机时,屏幕冻结,并且该应用程序停止运行。

0 个答案:

没有答案