我想從android設備獲取攝像頭的數量,檢查是否有背光,並且該攝像頭的水平和垂直視角爲Camera.Parameters.getHorizontalViewAngle()
。訪問來自Unity的Android Camera.Parameters
我想從Unity3D c#腳本做到這一點,但我的Java技能是有限的。任何人都可以提供任何幫助嗎? 我有這樣的代碼:
using UnityEngine;
#if UNITY_ANDROID
public class CameraParametersAndroid
{
public static float HorizontalViewAngle { get; protected set; }
public static float VerticalViewAngle { get; protected set; }
public static int numCameras { get; protected set; }
static CameraParametersAndroid()
{
AndroidJavaClass unityPlayerClass = new AndroidJavaClass ("com.unity3d.player.UnityPlayer"),
cameraClass = new AndroidJavaClass ("android.hardware.Camera"),
cameraParametersClass = new AndroidJavaClass ("android.hardware.Camera.Parameters"),
cameraInfoClass = new AndroidJavaClass ("android.hardware.Camera.CameraInfo");
AndroidJavaObject currentActivity = unityPlayerClass.GetStatic<AndroidJavaObject>("currentActivity");
object[] args = {currentActivity};
AndroidJavaObject camera = cameraClass.CallStatic<AndroidJavaObject>("getCamera", args);
if (camera != null)
{
AndroidJavaObject cameraParameters = camera.Call<AndroidJavaObject>("getParameters");
numCameras = camera.Call<int>("getNumberOfCameras");
HorizontalViewAngle = cameraParameters.Call<float>("getHorizontalViewAngle");
VerticalViewAngle = cameraParameters.Call<float>("getVerticalViewAngle");
}
else
{
Debug.LogError("[CameraParametersAndroid] Camera not available");
}
}
}
#endif
但不能連getNumberOfCameras()
通話作品。
**重要**最近注意到這個非常有用的原生相機插件在資產商店... https://www.assetstore.unity3d.com/en /#!/ content/52154 – Fattie