1

我正在尝试在 Unity 构建的 Daydream 应用程序中显示设备摄像头(Pixel 手机)实时视频。在 Unity 中我尝试了 WebCamTexture,当在 PC 上的 Unity 中测试运行时,WebCamTexture 会捕获网络摄像头源,但是当我将应用程序构建到 Daydream /Cardboard 时,没有摄像头源。但是,如果检测到任何相机,我确实放了一个画布/文本来打印出来,如果是的话,相机的名称。在 Daydream 应用程序运行时,检测到 2 个摄像头(摄像头 0、摄像头 1),但未显示图像。有没有人有想法/建议如何解决这个问题?以下是我用 C# 编写的代码,并将其附加到 Unity Plane/ Quad,并且还引用了 Canvas Text。

using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class tWebCam : MonoBehaviour
{
    public Text textPanel;
    WebCamTexture mCamera = null;

    public GameObject camPlane;
    // Use this for initialization
    void Start ()
    {
        WebCamDevice[] devices = WebCamTexture.devices;

        //camPlane = GameObject.FindWithTag("Player");

        if (devices.Length > 0)
        {
            mCamera = new WebCamTexture(devices[devices.Length-1].name, 1920, 1920, 30);
            camPlane.GetComponent<Renderer>().material.mainTexture = mCamera;

            mCamera.deviceName = devices[devices.Length - 1].name;
            Debug.Log(devices.Length);
            Debug.Log(mCamera.deviceName);
            mCamera.Play();
            textPanel.text = "# of devices: " + devices.Length.ToString() + "; Device 1: " + mCamera.deviceName;
        }
        else
        {
            textPanel.text = "No device detected...";
        }


    }

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

    }
}
4

1 回答 1

0

如果我理解您的问题,相机将无法工作,因为手机位于 Cardboard 或 Daydream 耳机内部,因此受到物理阻碍。

于 2017-02-16T02:08:29.947 回答