在Unity中,Android设备相机无法正常工作

时间:2016-04-01 12:57:46

标签: unity3d

当我建立我的团结项目时,它安装到我的手机上,我需要使用手机摄像头,但相机不工作,实际上没有打开。 enter image description here

enter image description here

AndroidManifest

<activity android:name="com.unity3d.player.UnityPlayerActivity" android:label="@string/app_name" android:screenOrientation="fullSensor" android:launchMode="singleTask" android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|fontScale">
  <intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.LAUNCHER" />
    <category android:name="android.intent.category.LEANBACK_LAUNCHER" />
  </intent-filter>
  <meta-data android:name="unityplayer.UnityActivity" android:value="true" />
</activity>
</application>
<uses-sdk android:minSdkVersion="9" android:targetSdkVersion="23" />
<uses-feature android:glEsVersion="0x00020000" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-feature android:name="android.hardware.camera" android:required="true" />
<uses-feature android:name="android.hardware.camera.autofocus"     android:required="false" />

此外,我查看了使用 adb设备的设备,它显示了我的设备,我的意思是手机

C#脚本 enter image description here

我尝试在设备管理器中更新USB驱动程序,在9-23之间安装了Android SDK API,我的手机 USB调试已启用。 还有一件事,如果我试图在统一控制台中查看设备

WebCamDevice[] devices = WebCamTexture.devices;
    for( var i = 0 ; i < devices.Length ; i++ )
        Debug.Log(devices[i].name);
它显示的只是我的笔记本电脑相机,它打开笔记本电脑的相机。有什么建议吗?

2 个答案:

答案 0 :(得分:2)

等一下。如果您使用Unity Remote调试应用程序,它将无法正常工作。

Unity远程应用程序实际上是一种流媒体服务:它获取用户输入,将其发送到统一,播放全部内容,然后流回视频。

这就是为什么它不起作用:您的设备上实际上没有执行任何操作。

只需进行构建即可对其进行调试。

P.S。这就是为什么Unity Remote的性能非常糟糕。

P.P.S。 :Unity Remote下的压缩和质量设置是指视频流压缩和质量。这非常LOL

答案 1 :(得分:0)

问题已解决。 :)以下解决方案对我有用..我认为它对您也有帮助。只是把这个脚本放在相机上 使用UnityEngine; 使用UnityEngine.Android;

public class permissionscript : MonoBehaviour
{
    GameObject dialog = null;
    void Start()
    {
#if PLATFORM_ANDROID
        if (!Permission.HasUserAuthorizedPermission(Permission.Camera))
        {
            Permission.RequestUserPermission(Permission.Camera);
        }
#endif
    }
}

//这是我的设备摄像头脚本

using UnityEngine;
using UnityEngine.UI;

public class simplecamera : MonoBehaviour
{
    static WebCamTexture backCam;

    void Start()
    {
        WebCamDevice[] devices = WebCamTexture.devices;
        if(backCam == null)
        {
            backCam = new WebCamTexture();
        }
        GetComponent<RawImage>().texture = backCam;
        backCam.Play();
    }
}
相关问题