纳金网
标题:
unity调用Android摄像机自动调焦
[打印本页]
作者:
烟雨
时间:
2016-3-29 21:07
标题:
unity调用Android摄像机自动调焦
可以用在AR项目中
using UnityEngine;
using System.Collections;
public class Tiaojiao : MonoBehaviour
{
private bool autoFocusSet;
void Awake()
{
autoFocusSet = false;
}
public static bool enableAutoFocus()
{
AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
AndroidJavaObject currentActivity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
AndroidJavaClass metaioSDKAndroid = new AndroidJavaClass("com.metaio.sdk.jni.IMetaioSDKAndroid");
object[] args = { currentActivity };
AndroidJavaObject camera = metaioSDKAndroid.CallStatic<AndroidJavaObject>("getCamera", args);
if (camera != null)
{
AndroidJavaObject cameraParameters = camera.Call<AndroidJavaObject>("getParameters");
object[] focusMode = { cameraParameters.GetStatic<string>("FOCUS_MODE_CONTINUOUS_PICTURE") };
cameraParameters.Call("setFocusMode", focusMode);
object[] newParameters = { cameraParameters };
camera.Call("setParameters", newParameters);
return true;
}
else
{
Debug.LogError("metaioSDK.enableAutoFocus:Camera not available");
return false;
}
}
void Update()
{
if (Input.GetKeyDown(KeyCode.Escape) || Input.GetKeyDown(KeyCode.Home))
{
Application.Quit();
}
if (Time.time > 1f && !autoFocusSet)
{
autoFocusSet = enableAutoFocus();
}
}
}
复制代码
作者:
victorkin11
时间:
2017-1-15 02:43
这个真不错,收了!
欢迎光临 纳金网 (http://rs.narkii.com/club/)
Powered by Discuz! X2.5