- 最后登录
- 2021-7-6
- 注册时间
- 2012-12-27
- 阅读权限
- 90
- 积分
- 76145
- 纳金币
- 53488
- 精华
- 316
|
可以用在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();
- }
- }
- }
复制代码 |
|