I would like to access the android defined class
Camera.Parameters.getHorizontalViewAngle()
from a Unity3D c# script but my java skills are limited. Can anybody offer any help? I have this code:
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
but not even the getNumberOfCameras()
call works.