using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
namespace Nxr.Internal
{
///
///
///
public class NibiruService
{
private const string NibiruSDKClassName = "com.nibiru.lib.vr.NibiruVR";
private const string ServiceClassName = "com.nibiru.service.NibiruService";
protected AndroidJavaObject androidActivity;
protected AndroidJavaClass nibiruSDKClass;
protected AndroidJavaObject nibiruOsServiceObject;
protected AndroidJavaObject nibiruSensorServiceObject;
protected AndroidJavaObject nibiruVoiceServiceObject;
protected AndroidJavaObject nibiruGestureServiceObject;
protected AndroidJavaObject nibiruVRServiceObject;
protected AndroidJavaObject nibiruCameraServiceObject;
protected AndroidJavaObject nibiruMarkerServiceObject;
protected CameraPreviewHelper cameraPreviewHelper;
protected AndroidJavaObject cameraDeviceObject;
protected AndroidJavaObject audioManager;
public int HMDCameraId;
public int ControllerCameraId;
private bool isCameraPreviewing = false;
private string systemDevice = "";
public void Init()
{
#if UNITY_ANDROID
try
{
using (AndroidJavaClass player = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
{
androidActivity = player.GetStatic("currentActivity");
audioManager = androidActivity.Call("getSystemService",
new AndroidJavaObject("java.lang.String", "audio"));
}
}
catch (AndroidJavaException e)
{
androidActivity = null;
Debug.LogError("Exception while connecting to the Activity: " + e);
return;
}
nibiruSDKClass = BaseAndroidDevice.GetClass(NibiruSDKClassName);
//
// systemDevice = nibiruSDKClass.CallStatic("getSystemProperty", "ro.product.device", "");
nibiruOsServiceObject = nibiruSDKClass.CallStatic("getNibiruOSService", androidActivity);
nibiruSensorServiceObject =
nibiruSDKClass.CallStatic("getNibiruSensorService", androidActivity);
nibiruVoiceServiceObject =
nibiruSDKClass.CallStatic("getNibiruVoiceService", androidActivity);
nibiruGestureServiceObject =
nibiruSDKClass.CallStatic("getNibiruGestureService", androidActivity);
nibiruVRServiceObject = nibiruSDKClass.CallStatic("getUsingNibiruVRServiceGL");
nibiruCameraServiceObject =
nibiruSDKClass.CallStatic("getNibiruCameraService", androidActivity);
nibiruMarkerServiceObject =
nibiruSDKClass.CallStatic("getNibiruMarkerService", androidActivity);
HMDCameraId = nibiruCameraServiceObject.Call("getHMDCameraId");
ControllerCameraId = nibiruCameraServiceObject.Call("getControllerCameraId");
UpdateVoiceLanguage();
// Debug.Log("nibiruOsServiceObject is "+ nibiruOsServiceObject.Call("getClass").Call("getName"));
// Debug.Log("nibiruSensorServiceObject is " + nibiruSensorServiceObject.Call("getClass").Call("getName"));
NibiruTask.NibiruTaskApi.Init();
IsCaptureEnabled = -1;
// 默认触发请求权限:
RequsetPermission(new string[]
{
NxrGlobal.Permission.CAMERA,
NxrGlobal.Permission.WRITE_EXTERNAL_STORAGE,
NxrGlobal.Permission.READ_EXTERNAL_STORAGE,
NxrGlobal.Permission.ACCESS_NETWORK_STATE,
NxrGlobal.Permission.ACCESS_COARSE_LOCATION,
NxrGlobal.Permission.BLUETOOTH,
NxrGlobal.Permission.BLUETOOTH_ADMIN,
NxrGlobal.Permission.INTERNET,
NxrGlobal.Permission.GET_TASKS,
});
#endif
}
public static int NKEY_SYS_HANDLE = 0;
public static int NKEY_APP_HANDLE = 1;
///
/// Handle N key event
/// 0=system handle
/// 1=app handle
///
///
public void RegHandleNKey(int mode)
{
if (nibiruVRServiceObject != null)
{
RunOnUIThread(androidActivity,
new AndroidJavaRunnable(() => { nibiruVRServiceObject.Call("regHandleNKey", mode); }));
}
else
{
Debug.LogError("regHandleNKey failed, nibiruVRServiceObject is null !!!");
}
}
///
/// Enable fps statistics
///
///
public void SetEnableFPS(bool isEnabled)
{
if (nibiruVRServiceObject != null)
{
nibiruVRServiceObject.Call("setEnableFPS", isEnabled);
}
else
{
Debug.LogError("SetEnableFPS failed, nibiruVRServiceObject is null !!!");
}
}
///
/// Get fps : 0=app,1=dtr
///
///
public float[] GetFPS()
{
if (nibiruVRServiceObject != null)
{
return nibiruVRServiceObject.Call("getFPS");
}
else
{
Debug.LogError("SetEnableFPS failed, nibiruVRServiceObject is null !!!");
}
return new float[] {-1, -1};
}
///
/// Register virtual mouse service
///
///
public void RegisterVirtualMouseService(OnVirtualMouseServiceStatus serviceStatus)
{
if (nibiruOsServiceObject != null)
{
nibiruOsServiceObject.Call("registerVirtualMouseManagerService",
new NibiruVirtualMouseServiceListener(serviceStatus));
}
else
{
Debug.LogError("RegisterVirtualMouseService failed, nibiruOsServiceObject is null !!!");
}
}
///
/// UnRegister virtual mouse service
///
public void UnRegisterVirtualMouseService()
{
if (nibiruOsServiceObject != null)
{
nibiruOsServiceObject.Call("unRegisterVirtaulMouseManagerService");
}
else
{
Debug.LogError("UnRegisterVirtualMouseService failed, nibiruOsServiceObject is null !!!");
}
}
///
/// Set enable virtual mouse
///
///
///
public bool SetEnableVirtualMouse(bool enabled)
{
if (nibiruOsServiceObject != null)
{
return nibiruOsServiceObject.Call("setEnableVirtualMouse", enabled);
}
else
{
Debug.LogError("SetEnableVirtualMouse failed, nibiruOsServiceObject is null !!!");
return false;
}
}
public CameraPreviewHelper InitCameraPreviewHelper()
{
cameraPreviewHelper = new CameraPreviewHelper();
return cameraPreviewHelper;
}
public CameraPreviewHelper CameraPreviewHelper
{
get { return cameraPreviewHelper; }
}
///
/// Get camera status async
///
public void GetCameraStatus()
{
int cameraId = HMDCameraId;
if (nibiruCameraServiceObject != null)
{
nibiruCameraServiceObject.Call("getCameraStatus", cameraId, new CameraStatusCallback());
}
else
{
Debug.LogError("GetCameraStatus failed, because nibiruCameraServiceObject is null !!!");
}
}
///
/// Open camera
///
/// NibiruCameraDevice
private AndroidJavaObject OpenCamera()
{
int cameraId = HMDCameraId;
if (nibiruCameraServiceObject != null && cameraDeviceObject == null)
{
cameraDeviceObject = nibiruCameraServiceObject.Call("openCamera", cameraId);
return cameraDeviceObject;
}
else if (cameraDeviceObject != null)
{
return cameraDeviceObject;
}
else
{
Debug.LogError("OpenCamera failed, because nibiruCameraServiceObject is null !!!");
return null;
}
}
///
/// Get current cameraId
///
///
public CAMERA_ID GetCurrentCameraId()
{
return (CAMERA_ID) HMDCameraId;
}
///
/// Start camera preView
///
public void StartCameraPreView()
{
StartCameraPreView(false);
}
///
/// Start camera preView
///
/// trigger focus
public void StartCameraPreView(bool triggerFocus)
{
OpenCamera();
AndroidJavaObject surfaceTextureObject = cameraPreviewHelper.GetSurfaceTexture();
cameraDeviceObject.Call("startPreviewWithBestSize", surfaceTextureObject);
if (triggerFocus)
{
DoCameraAutoFocus();
}
isCameraPreviewing = true;
}
///
/// Stop camera preView
///
public void StopCamereaPreView()
{
if (nibiruCameraServiceObject != null)
{
isCameraPreviewing = false;
nibiruCameraServiceObject.Call("stopPreview");
cameraDeviceObject = null;
}
else
{
Debug.LogError("StopCamereaPreView failed, because nibiruCameraServiceObject is null !!!");
}
}
///
/// Determine whether the camera is in preview.
///
///
public bool IsCameraPreviewing()
{
return isCameraPreviewing;
}
public void SetCameraPreviewing(bool enabled)
{
isCameraPreviewing = true;
}
public void DoCameraAutoFocus()
{
if (cameraDeviceObject != null)
{
cameraDeviceObject.Call("doAutoFocus");
}
else
{
Debug.LogError("DoCameraAutoFocus failed, because cameraDeviceObject is null !!!");
}
}
public void EnableVoiceService(bool enabled)
{
if (nibiruVoiceServiceObject != null)
{
nibiruVoiceServiceObject.Call("setEnableVoice", enabled);
}
else
{
Debug.LogError("EnableVoiceService failed, because nibiruVoiceServiceObject is null !!!");
}
}
///
/// Start voice recording
///
public void StartVoiceRecording()
{
if (nibiruVoiceServiceObject != null)
{
nibiruVoiceServiceObject.Call("startRecording");
}
else
{
Debug.LogError("StartVoiceRecording failed, because nibiruVoiceServiceObject is null !!!");
}
}
///
/// Stop voice recording
///
public void StopVoiceRecording()
{
if (nibiruVoiceServiceObject != null)
{
nibiruVoiceServiceObject.Call("stopRecording");
}
else
{
Debug.LogError("StopVoiceRecording failed, because nibiruVoiceServiceObject is null !!!");
}
}
///
/// Cancel voice recognizer
///
public void CancelVoiceRecognizer()
{
if (nibiruVoiceServiceObject != null)
{
nibiruVoiceServiceObject.Call("cancelRecognizer");
}
else
{
Debug.LogError("CancelVoiceRecognizer failed, because nibiruVoiceServiceObject is null !!!");
}
}
public bool IsSupportVoice()
{
if (nibiruVoiceServiceObject != null)
{
return nibiruVoiceServiceObject.Call("isMicrophoneVoice");
}
else
{
Debug.LogError("IsSupportVoice failed, because nibiruVoiceServiceObject is null !!!");
}
return false;
}
public bool IsSupport6DOF()
{
if (nibiruVRServiceObject != null)
{
return nibiruVRServiceObject.Call("isSupport6Dof");
}
else
{
Debug.LogError("IsSupport6DOF failed, because nibiruVRServiceObject is null !!!");
}
return false;
}
public bool IsSupportGesture()
{
if (nibiruGestureServiceObject != null)
{
return nibiruGestureServiceObject.Call("isCameraGesture");
}
else
{
Debug.LogError("isSupportGesture failed, because nibiruGestureServiceObject is null !!!");
}
return false;
}
public void UpdateVoiceLanguage()
{
if (nibiruVoiceServiceObject != null)
{
nibiruVoiceServiceObject.Call("setVoicePID", (int) NxrGlobal.voiceLanguage);
}
else
{
Debug.LogError("UpdateVoiceLanguage failed, because nibiruVoiceServiceObject is null !!!");
}
}
///
/// Control camera status of gesture service:false-Turn off camera occupation,true-Turn on camera occupation
///
///
public void EnableGestureService(bool enabled)
{
if (nibiruGestureServiceObject != null)
{
nibiruGestureServiceObject.Call("setEnableGesture", enabled);
}
else
{
Debug.LogError("EnableGestureService failed, because nibiruGestureServiceObject is null !!!");
}
}
public bool IsCameraGesture()
{
if (nibiruGestureServiceObject != null)
{
return nibiruGestureServiceObject.Call("isCameraGesture");
}
return false;
}
public delegate void OnSensorDataChanged(NibiruSensorEvent sensorEvent);
///
/// The callback when sensor data changes.
///
public static OnSensorDataChanged OnSensorDataChangedHandler;
class NibiruSensorDataListenerCallback : AndroidJavaProxy
{
public NibiruSensorDataListenerCallback() : base(
"com.nibiru.service.NibiruSensorService$INibiruSensorDataListener")
{
}
public void onSensorDataChanged(AndroidJavaObject sensorEventObject)
{
float x = sensorEventObject.Get("x");
float y = sensorEventObject.Get("y");
float z = sensorEventObject.Get("z");
long timestamp = sensorEventObject.Get("timestamp");
AndroidJavaObject locationObject = sensorEventObject.Get("sensorLocation");
AndroidJavaObject typeObject = sensorEventObject.Get("sensorType");
SENSOR_LOCATION sensorLocation = (SENSOR_LOCATION) locationObject.Call("ordinal");
SENSOR_TYPE sensorType = (SENSOR_TYPE) typeObject.Call("ordinal");
NibiruSensorEvent sensorEvent = new NibiruSensorEvent(x, y, z, timestamp, sensorType, sensorLocation);
// sensorEvent.printLog();
// 用Loom的方法在Unity主线程中调用Text组件
Loom.QueueOnMainThread((param) =>
{
if (OnSensorDataChangedHandler != null)
{
OnSensorDataChangedHandler((NibiruSensorEvent) param);
}
}, sensorEvent);
}
}
private NibiruSensorDataListenerCallback nibiruSensorDataListenerCallback;
public void RegisterSensorListener(SENSOR_TYPE type, SENSOR_LOCATION location)
{
if (nibiruSensorServiceObject != null)
{
if (nibiruSensorDataListenerCallback == null)
{
nibiruSensorDataListenerCallback = new NibiruSensorDataListenerCallback();
}
// UI线程执行
RunOnUIThread(androidActivity, new AndroidJavaRunnable(() =>
{
AndroidJavaClass locationClass =
BaseAndroidDevice.GetClass("com.nibiru.service.NibiruSensorService$SENSOR_LOCATION");
AndroidJavaObject locationObj =
locationClass.CallStatic("valueOf", location.ToString());
AndroidJavaClass typeClass =
BaseAndroidDevice.GetClass("com.nibiru.service.NibiruSensorService$SENSOR_TYPE");
AndroidJavaObject typeObj = typeClass.CallStatic("valueOf", type.ToString());
nibiruSensorServiceObject.Call("registerSensorListener", typeObj, locationObj,
nibiruSensorDataListenerCallback);
Debug.Log("registerSensorListener=" + type.ToString() + "," + location.ToString());
}
));
}
else
{
Debug.LogError("RegisterControllerSensor failed, nibiruSensorServiceObject is null !");
}
}
public void UnRegisterSensorListener()
{
if (nibiruSensorServiceObject != null)
{
// UI线程执行
RunOnUIThread(androidActivity, new AndroidJavaRunnable(() =>
{
nibiruSensorServiceObject.Call("unregisterSensorListenerAll");
}
));
}
else
{
Debug.LogError("UnRegisterSensorListener failed, nibiruSensorServiceObject is null !");
}
}
//4.1 获取屏幕亮度值:
///
/// Get system's brightness value
///
///
public int GetBrightnessValue()
{
int BrightnessValue = 0;
#if UNITY_ANDROID
BaseAndroidDevice.CallObjectMethod(ref BrightnessValue, nibiruOsServiceObject, "getBrightnessValue");
#endif
return BrightnessValue;
}
//4.2 调节屏幕亮度:
///
/// Set system's brightness value
///
///
public void SetBrightnessValue(int value)
{
if (nibiruOsServiceObject == null) return;
#if UNITY_ANDROID
RunOnUIThread(androidActivity,
new AndroidJavaRunnable(() =>
{
BaseAndroidDevice.CallObjectMethod(nibiruOsServiceObject, "setBrightnessValue", value, 200.01f);
}));
#endif
}
//4.3 获取当前2D/3D显示模式:
///
/// Get display mode 2d/3d
///
///
public DISPLAY_MODE GetDisplayMode()
{
if (nibiruOsServiceObject == null) return DISPLAY_MODE.MODE_2D;
AndroidJavaObject androidObject = nibiruOsServiceObject.Call("getDisplayMode");
int mode = androidObject.Call("ordinal");
return (DISPLAY_MODE) mode;
}
//4.4 切换2D/3D显示模式:
///
/// Set display mode 2d/3d
///
///
public void SetDisplayMode(DISPLAY_MODE displayMode)
{
if (nibiruOsServiceObject != null)
{
RunOnUIThread(androidActivity,
new AndroidJavaRunnable(() =>
{
nibiruOsServiceObject.Call("setDisplayMode", (int) displayMode);
}));
}
}
// 渠道ID
///
/// Get system's channel code
///
///
public string GetChannelCode()
{
if (nibiruOsServiceObject == null) return "NULL";
return nibiruOsServiceObject.Call("getChannelCode");
}
// 型号
///
/// Get device's model
///
///
public string GetModel()
{
if (nibiruOsServiceObject == null) return "NULL";
return nibiruOsServiceObject.Call("getModel");
}
// 系统OS版本
///
/// Get system's os version
///
///
public string GetOSVersion()
{
if (nibiruOsServiceObject == null) return "NULL";
return nibiruOsServiceObject.Call("getOSVersion");
}
// 系统OS版本号
///
/// Get system's service version
///
///
public int GetOSVersionCode()
{
if (nibiruOsServiceObject == null) return -1;
return nibiruOsServiceObject.Call("getOSVersionCode");
}
// 系统服务版本
///
/// Get system's service version code
///
///
public string GetServiceVersionCode()
{
if (nibiruOsServiceObject == null) return "NULL";
return nibiruOsServiceObject.Call("getServiceVersionCode");
}
// 获取厂家软件版本:(对应驱动板软件版本号)
///
/// Get system's vendor SW version
///
///
public string GetVendorSWVersion()
{
if (nibiruOsServiceObject == null) return "NULL";
return nibiruOsServiceObject.Call("getVendorSWVersion");
}
// 控制touchpad是否显示 value为true表示显示,false表示不显示
///
/// Control whether touchpad is displayed. true-display false-not display
///
///
public void SetEnableTouchCursor(bool isEnable)
{
RunOnUIThread(androidActivity, new AndroidJavaRunnable(() =>
{
if (nibiruOsServiceObject != null)
{
nibiruOsServiceObject.Call("setEnableTouchCursor", isEnable);
}
}));
}
///
/// Get the value of the distance sensor.
///
///
public int GetProximityValue()
{
if (nibiruSensorServiceObject == null) return -1;
return nibiruSensorServiceObject.Call("getProximityValue");
}
///
/// Get the value of light perception.
///
///
public int GetLightValue()
{
if (nibiruSensorServiceObject == null) return -1;
return nibiruSensorServiceObject.Call("getLightValue");
}
// UI线程中运行
public void RunOnUIThread(AndroidJavaObject activityObj, AndroidJavaRunnable r)
{
activityObj.Call("runOnUiThread", r);
}
public delegate void CameraIdle();
public delegate void CameraBusy();
///
/// The callback when Camera is idle.
///
public static CameraIdle OnCameraIdle;
///
/// The callback when Camera is busy.
///
public static CameraBusy OnCameraBusy;
public delegate void OnRecorderSuccess();
public delegate void OnRecorderFailed();
public static OnRecorderSuccess OnRecorderSuccessHandler;
public static OnRecorderFailed OnRecorderFailedHandler;
class CameraStatusCallback : AndroidJavaProxy
{
public CameraStatusCallback() : base("com.nibiru.lib.vr.listener.NVRCameraStatusListener")
{
}
public void cameraBusy()
{
// 从Android UI线程回调过来的,加入到Unity主线程处理
// NxrViewer.Instance.TriggerCameraStatus(1);
Loom.QueueOnMainThread((param) =>
{
if (OnCameraBusy != null)
{
OnCameraBusy();
}
}, 1);
Debug.Log("cameraBusy");
}
public void cameraIdle()
{
// 从Android UI线程回调过来的,加入到Unity主线程处理
// NxrViewer.Instance.TriggerCameraStatus(0);
Loom.QueueOnMainThread((param) =>
{
if (OnCameraIdle != null)
{
OnCameraIdle();
}
}, 0);
Debug.Log("cameraIdle");
}
}
class CaptureCallback : AndroidJavaProxy
{
public CaptureCallback() : base("com.nibiru.lib.vr.listener.NVRVideoCaptureListener")
{
}
public void onSuccess()
{
// 从Android UI线程回调过来的,加入到Unity主线程处理
// NxrViewer.Instance.TriggerCaptureStatus(1);
Loom.QueueOnMainThread((param) =>
{
if (OnRecorderSuccessHandler != null)
{
OnRecorderSuccessHandler();
}
}, 1);
}
public void onFailed()
{
// 从Android UI线程回调过来的,加入到Unity主线程处理
// NxrViewer.Instance.TriggerCaptureStatus(0);
Loom.QueueOnMainThread((param) =>
{
if (OnRecorderFailedHandler != null)
{
OnRecorderFailedHandler();
}
}, 0);
}
}
public int IsCaptureEnabled { set; get; }
public static int BIT_RATE = 4000000;
///
/// Start capture
///
///
public void StartCapture(string path)
{
StartCapture(path, -1);
}
///
/// Start capture
///
///
///
public void StartCapture(string path, int seconds)
{
StartCapture(path, BIT_RATE, seconds);
}
private static int videoSize = (int) VIDEO_SIZE.V720P;
// private static int captureCameraId = (int)CAMERA_ID.FRONT;
///
/// Start capture
///
///
///
///
public void StartCapture(string path, int bitRate, int seconds)
{
IsCaptureEnabled = 1;
nibiruSDKClass.CallStatic("startCaptureForUnity", new CaptureCallback(), path, bitRate, seconds, videoSize,
HMDCameraId);
}
public static void SetCaptureVideoSize(VIDEO_SIZE video_Size)
{
videoSize = (int) video_Size;
}
///
/// Stop capture
///
public void StopCapture()
{
nibiruSDKClass.CallStatic("stopCaptureForUnity");
IsCaptureEnabled = 0;
}
public bool CaptureDrawFrame(int textureId, int frameId)
{
if (IsCaptureEnabled <= -3)
{
return false;
}
else if (IsCaptureEnabled <= 0 && IsCaptureEnabled >= -2)
{
// 在stop后,多执行3次,用于内部处理stop的逻辑。
IsCaptureEnabled--;
}
return nibiruSDKClass.CallStatic("onDrawFrameForUnity", textureId, frameId);
}
private const int STREAM_VOICE_CALL = 0;
private const int STREAM_SYSTEM = 1;
private const int STREAM_RING = 2;
private const int STREAM_MUSIC = 3;
private const int STREAM_ALARM = 4;
private const int STREAM_NOTIFICATION = 5;
private const string currentVolume = "getStreamVolume"; //当前音量
private const string maxVolume = "getStreamMaxVolume"; //最大音量
public int GetVolumeValue()
{
if (audioManager == null) return 0;
return audioManager.Call(currentVolume, STREAM_MUSIC);
}
public int GetMaxVolume()
{
if (audioManager == null) return 1;
return audioManager.Call(maxVolume, STREAM_MUSIC);
}
public void EnabledMarkerAutoFocus(bool enabled)
{
if (nibiruMarkerServiceObject == null)
{
Debug.LogError("nibiruMarkerServiceObject is null");
}
else if (isMarkerRecognizeRunning)
{
nibiruMarkerServiceObject.Call(enabled ? "doAutoFocus" : "stopAutoFocus");
}
}
///
/// Set marker recognize cameraId
///
///
private void SetMarkerRecognizeCameraId(int cameraID)
{
if (nibiruMarkerServiceObject == null)
{
Debug.LogError("nibiruMarkerServiceObject is null");
}
else
{
nibiruMarkerServiceObject.Call("setCameraId", cameraID);
}
}
private bool isMarkerRecognizeRunning;
public bool IsMarkerRecognizeRunning
{
get { return isMarkerRecognizeRunning; }
set { isMarkerRecognizeRunning = value; }
}
///
/// Start marker recognize
///
public void StartMarkerRecognize()
{
if (nibiruMarkerServiceObject == null)
{
Debug.LogError("nibiruMarkerServiceObject is null");
}
else if (!isMarkerRecognizeRunning)
{
// 默认使用前置相机
SetMarkerRecognizeCameraId(HMDCameraId);
// 焦距,具体不同机器可以需要微调 16 , 640 * 480
nibiruMarkerServiceObject.Call("setCameraZoom", NxrGlobal.GetMarkerCameraZoom());
nibiruMarkerServiceObject.Call("setPreviewSize", 640, 480);
nibiruMarkerServiceObject.Call("startMarkerRecognize");
isMarkerRecognizeRunning = true;
}
}
///
/// Stop marker recognize
///
public void StopMarkerRecognize()
{
if (nibiruMarkerServiceObject == null)
{
Debug.LogError("nibiruMarkerServiceObject is null");
}
else if (isMarkerRecognizeRunning)
{
nibiruMarkerServiceObject.Call("stopMarkerRecognize");
isMarkerRecognizeRunning = false;
}
}
///
/// Get the ViewMatrix of Marker.
///
///
public float[] GetMarkerViewMatrix()
{
if (nibiruMarkerServiceObject == null)
{
Debug.LogError("nibiruMarkerServiceObject is null");
return null;
}
else
{
float[] result = nibiruMarkerServiceObject.Call("getMarkerViewMatrix");
if (result == null || result.Length == 0) return null;
// 全是0
if (IsAllZero(result)) return null;
return result;
}
}
public static bool IsAllZero(float[] array)
{
for (int i = 0, l = array.Length; i < l; i++)
{
if (array[i] != 0) return false;
}
return true;
}
public float[] GetMarkerViewMatrix(int eyeType)
{
if (nibiruMarkerServiceObject == null)
{
Debug.LogError("nibiruMarkerServiceObject is null");
return null;
}
else
{
float[] result = nibiruMarkerServiceObject.Call("getMarkerViewMatrix", eyeType);
if (result == null || result.Length == 0) return null;
// 全是0
if (IsAllZero(result)) return null;
return result;
}
}
public float[] GetMarkerProjectionMatrix()
{
if (nibiruMarkerServiceObject == null)
{
Debug.LogError("nibiruMarkerServiceObject is null");
return null;
}
else
{
float[] projArr = nibiruMarkerServiceObject.Call("getProjection");
if (projArr == null || projArr.Length == 0)
return null;
return projArr;
}
}
public string GetMarkerDetectStatus()
{
if (nibiruMarkerServiceObject == null)
{
Debug.LogError("GetMarkerDetectStatus failed, nibiruMarkerServiceObject is null");
return "-1";
}
string res = nibiruMarkerServiceObject.Call("getParameters", "p_detect_status");
return res == null ? "-1" : res;
}
public delegate void OnVirtualMouseServiceStatus(bool succ);
public class NibiruVirtualMouseServiceListener : AndroidJavaProxy
{
OnVirtualMouseServiceStatus _OnVirtualMouseServiceStatus;
public NibiruVirtualMouseServiceListener(OnVirtualMouseServiceStatus onVirtualMouseServiceStatus) : base(
"com.nibiru.service.NibiruVirtualMouseManager$VirtualMouseServiceListener")
{
_OnVirtualMouseServiceStatus = onVirtualMouseServiceStatus;
}
public void onServiceRegisterResult(bool succ)
{
if (_OnVirtualMouseServiceStatus != null)
{
_OnVirtualMouseServiceStatus(succ);
}
}
}
public void PauseGestureService()
{
if (nibiruGestureServiceObject != null)
{
nibiruGestureServiceObject.Call("onPause");
}
else
{
Debug.LogError("onPause failed, because nibiruGestureServiceObject is null !!!");
}
}
public void ResumeGestureService()
{
if (nibiruGestureServiceObject != null)
{
nibiruGestureServiceObject.Call("onResume");
}
else
{
Debug.LogError("onResume failed, because nibiruGestureServiceObject is null !!!");
}
}
private AndroidJavaObject javaArrayFromCS(string[] values)
{
AndroidJavaClass arrayClass = new AndroidJavaClass("java.lang.reflect.Array");
AndroidJavaObject arrayObject = arrayClass.CallStatic("newInstance",
new AndroidJavaClass("java.lang.String"), values.Count());
for (int i = 0; i < values.Count(); ++i)
{
arrayClass.CallStatic("set", arrayObject, i, new AndroidJavaObject("java.lang.String", values[i]));
}
return arrayObject;
}
///
/// Request permission
///
/// NxrGlobal.Permission
public void RequsetPermission(string[] names)
{
if (nibiruOsServiceObject != null)
{
nibiruOsServiceObject.Call("requestPermission", javaArrayFromCS(names));
}
}
///
/// Get QCOM of product device.
///
///
public QCOMProductDevice GetQCOMProductDevice()
{
if ("msm8996".Equals(systemDevice))
{
return QCOMProductDevice.QCOM_820;
}
else if ("msm8998".Equals(systemDevice))
{
return QCOMProductDevice.QCOM_835;
}
else if ("sdm710".Equals(systemDevice))
{
return QCOMProductDevice.QCOM_XR1;
}
else if ("sdm845".Equals(systemDevice))
{
return QCOMProductDevice.QCOM_845;
}
return QCOMProductDevice.QCOM_UNKNOW;
}
public void LockToCur()
{
if (nibiruVRServiceObject != null)
{
RunOnUIThread(androidActivity,
new AndroidJavaRunnable(() => { nibiruVRServiceObject.Call("lockTracker"); }));
}
else
{
Debug.LogError("LockToCur failed, nibiruVRServiceObject is null !!!");
}
}
public void LockToFront()
{
if (nibiruVRServiceObject != null)
{
RunOnUIThread(androidActivity,
new AndroidJavaRunnable(() => { nibiruVRServiceObject.Call("lockTrackerToFront"); }));
}
else
{
Debug.LogError("LockToFront failed, nibiruVRServiceObject is null !!!");
}
}
public void UnLock()
{
if (nibiruVRServiceObject != null)
{
RunOnUIThread(androidActivity,
new AndroidJavaRunnable(() => { nibiruVRServiceObject.Call("unlockTracker"); }));
}
else
{
Debug.LogError("UnLock failed, nibiruVRServiceObject is null !!!");
}
}
}
}