public static bool isDeviceConn(int noloType) { if (InteractionManager.IsInteractionSDKEnabled()) { return(InteractionManager.IsSixDofControllerConnected(NoloTypeToHandType(noloType))); } bool res = false; if (deviceConnCall[noloType] >= 250 || isDeviceConnTmp[noloType] < 0) { #if UNITY_ANDROID && !UNITY_EDITOR if (GetAndroidClass != null) { res = GetAndroidClass.CallStatic <bool>("isDeviceConn", new object[] { noloType }); } #endif isDeviceConnTmp[noloType] = res ? 1 : 0; deviceConnCall[noloType] = 0; // Debug.Log("isDeviceConn---called=" + res + "/" + noloType); } else { res = isDeviceConnTmp[noloType] == 1; } deviceConnCall[noloType] = deviceConnCall[noloType] + 1; return(res); }
public static int[] getQuatKeyAction(int deviceId) { #if UNITY_ANDROID && !UNITY_EDITOR return(GetAndroidClass.CallStatic <int[]>("getKeyAction", new object[] { deviceId })); #endif return(new int[256]); }
public static bool isQuatConn() { #if UNITY_ANDROID && !UNITY_EDITOR if (InteractionManager.Is3DofControllerConnected()) { return(true); } if (!isquated) { if (GetAndroidClass != null) { isQuat = GetAndroidClass.CallStatic <bool>("isQuatConn"); ts1 = new TimeSpan(DateTime.Now.Ticks); isquated = true; return(isQuat); } ts1 = new TimeSpan(DateTime.Now.Ticks); isquated = true; } if (ts1 != null) { ts2 = new TimeSpan(DateTime.Now.Ticks); TimeSpan ts = ts2.Subtract(ts1.Duration()); if (ts.Seconds >= checkQuatConnSeconds) { ts1 = ts2; isQuat = GetAndroidClass.CallStatic <bool>("isQuatConn"); // Debug.Log("isQuatConn---called=" + isQuat + "/" ); disconnectQuatCount = isQuat? 0 : (disconnectQuatCount + 1); if (disconnectQuatCount >= 60) { checkQuatConnSeconds = 5; } else if (disconnectQuatCount >= 120) { checkQuatConnSeconds = 8; } else { checkQuatConnSeconds = 2; } // Debug.Log("=======>CallStatic isQuatConn"); return(isQuat); } else { return(isQuat); } } #endif if (NibiruAxis.NxrPlayerCtrl.Instance != null && NibiruAxis.NxrPlayerCtrl.Instance.debugInEditor) { return(true); } return(false); }
public static void destroy() { #if UNITY_ANDROID && !UNITY_EDITOR if (GetAndroidClass != null) { GetAndroidClass.CallStatic("destroy"); } #endif }
public static void cancelVibrate() { #if UNITY_ANDROID && !UNITY_EDITOR if (GetAndroidClass != null) { GetAndroidClass.CallStatic("cancelVibrate"); } #endif }
public static void setMotionType(int motionType) { #if UNITY_ANDROID && !UNITY_EDITOR if (GetAndroidClass != null) { GetAndroidClass.CallStatic("setMotionType", new object[] { motionType }); } #endif }
// 连接回调,如果已经连接了再进入app,不会有回调,进入后如果插拔连接,还是有回调 public static void setOnDeviceListener(OnDeviceListener listener) { #if UNITY_ANDROID && !UNITY_EDITOR if (GetAndroidClass != null) { GetAndroidClass.CallStatic("setOnDeviceListener", listener); } #endif }
public static void startVibrate(int left, int right) { #if UNITY_ANDROID && !UNITY_EDITOR if (GetAndroidClass != null) { GetAndroidClass.CallStatic("startVibrate", new object[] { left, right }); } #endif }
public static void disconnect(AndroidJavaObject bluetoothDevice) { #if UNITY_ANDROID && !UNITY_EDITOR if (GetAndroidClass != null) { GetAndroidClass.CallStatic("disconnect", bluetoothDevice); } #endif }
public static void setFocus(bool focus) { #if UNITY_ANDROID && !UNITY_EDITOR if (GetAndroidClass != null) { GetAndroidClass.CallStatic("setFocus", new object[] { focus }); } #endif }
public static void enableDebug(bool debug) { #if UNITY_ANDROID && !UNITY_EDITOR if (GetAndroidClass != null) { GetAndroidClass.CallStatic("enableDebug", new object[] { debug }); } #endif }
public static void onStop() { #if UNITY_ANDROID && !UNITY_EDITOR if (GetAndroidClass != null) { GetAndroidClass.CallStatic("onStop"); } #endif }
public static void init() { #if UNITY_ANDROID && !UNITY_EDITOR if (GetAndroidClass != null) { GetAndroidClass.CallStatic("init", GetAndroidContext); } #endif }
public static int getHandMode() { #if UNITY_ANDROID && !UNITY_EDITOR if (GetAndroidClass != null) { return(GetAndroidClass.CallStatic <int>("getHandMode")); } #endif return(0); }
public static AndroidJavaObject getCDevices() { #if UNITY_ANDROID && !UNITY_EDITOR if (GetAndroidClass != null) { return(GetAndroidClass.CallStatic <AndroidJavaObject>("getCDevices")); } #endif return(null); }
public static AndroidJavaObject getCSensorEvent(int type, int deviceId) { #if UNITY_ANDROID && !UNITY_EDITOR if (GetAndroidClass != null) { return(GetAndroidClass.CallStatic <AndroidJavaObject>("getCSensorEvent2", new object[] { type, deviceId })); } #endif return(null); }
// nolo pose : {this.type, this.x, this.y, this.z, this.q1, this.q2, this.q3, this.q4 } public static float[] getCPoseEvent(int type, int deviceId) { #if UNITY_ANDROID && !UNITY_EDITOR if (GetAndroidClass != null) { return(GetAndroidClass.CallStatic <float []>("getCPoseEvent", new object[] { type, deviceId })); } #endif return(new float[8]); }
public static int getCBike(int deviceId) { #if UNITY_ANDROID && !UNITY_EDITOR if (GetAndroidClass != null) { return(GetAndroidClass.CallStatic <int>("getCBike", new object[] { deviceId })); } #endif return(0); }
// {type, action, x, y} public static float[] getTouch(int deviceId = 1) { #if UNITY_ANDROID && !UNITY_EDITOR if (GetAndroidClass != null) { return(GetAndroidClass.CallStatic <float []>("getTouch", new object[] { deviceId })); } #endif return(new float[4]); }
public static float[,] getCFiveDTechEvent(int deviceId = 1) { #if UNITY_ANDROID && !UNITY_EDITOR if (GetAndroidClass != null) { return(GetAndroidClass.CallStatic <float [, ]>("getCFiveDTechEvent", new object[] { deviceId })); } #endif return(new float[5, 4]); }
public static int[] getDeviceIds() { #if UNITY_ANDROID && !UNITY_EDITOR if (GetAndroidClass != null) { return(GetAndroidClass.CallStatic <int []>("getDeviceIds")); } #endif return(new int[] {}); }
// deviceId=1, key=键值,value=0 按下/1 抬起 public static int[] getKeyState(int type, int deviceId) { #if UNITY_ANDROID && !UNITY_EDITOR if (GetAndroidClass != null) { return(GetAndroidClass.CallStatic <int []>("getKeyState", new object[] { type, deviceId })); } #endif return(new int[256]); }
public static int[] getBrain(int deviceId) { #if UNITY_ANDROID && !UNITY_EDITOR if (GetAndroidClass != null) { return(GetAndroidClass.CallStatic <int []>("getBrain", new object[] { deviceId })); } #endif return(null); }
public static void onPause() { if (isPause) { #if UNITY_ANDROID && !UNITY_EDITOR if (GetAndroidClass != null) { GetAndroidClass.CallStatic("onPause"); } #endif } else { onResume(); } isPause = !isPause; }
// 60s更新1次 public static int getControllerPower() { bool isFirstTrigger = false; if (powerRefreshTime.Ticks == 0) { isFirstTrigger = true; // 初次触发更新 powerRefreshTime = new TimeSpan(DateTime.Now.Ticks); } TimeSpan curTime = new TimeSpan(DateTime.Now.Ticks); TimeSpan diff = curTime.Subtract(powerRefreshTime).Duration(); if (isFirstTrigger || diff.Seconds >= 50) { powerRefreshTime = curTime; try { #if UNITY_ANDROID && !UNITY_EDITOR if (GetAndroidClass != null) { cachePower = GetAndroidClass.CallStatic <int>("getControllerPower", 1); } #endif Debug.Log("cachePower=" + cachePower); } catch (Exception e) { Debug.LogError(e.Message); } } return(Math.Max(0, cachePower)); }
public static int getNoloControllerPower(CDevice.NOLO_TYPE type) { bool isFirstTrigger = false; if (powerRefreshTime.Ticks == 0) { isFirstTrigger = true; // 初次触发更新 powerRefreshTime = new TimeSpan(DateTime.Now.Ticks); } TimeSpan curTime = new TimeSpan(DateTime.Now.Ticks); TimeSpan diff = curTime.Subtract(powerRefreshTime).Duration(); if (isFirstTrigger || diff.Seconds >= 50) { powerRefreshTime = curTime; try { #if UNITY_ANDROID && !UNITY_EDITOR if (GetAndroidClass != null) { noloCachePower[(int)type] = GetAndroidClass.CallStatic <int>("getNoloBattery", (int)type); } #endif Debug.Log("nolo cachePower=" + noloCachePower[(int)type]); } catch (Exception e) { Debug.LogError(e.Message); } } return(Math.Max(0, noloCachePower[(int)type])); }
public static int[] getKeyAction(int deviceId) { #if UNITY_ANDROID //&& !UNITY_EDITOR if (GetAndroidClass != null) { bool isNoloLeft = isDeviceConn((int)CDevice.NOLO_TYPE.LEFT); bool isNoloRight = isDeviceConn((int)CDevice.NOLO_TYPE.RIGHT); if (isNoloLeft || isNoloRight) { // nolo 键值 int[] keyStateLeft = null; int[] keyStateRight = null; if (isNoloRight) { keyStateRight = getKeyState((int)CDevice.NOLO_TYPE.RIGHT, deviceId); } if (isNoloLeft) { keyStateLeft = getKeyState((int)CDevice.NOLO_TYPE.LEFT, deviceId); } int[] tempKeyAction = new int[256]; if (keyStateLeft != null && keyStateRight != null) { for (int i = 0; i < CKeyEvent.KeyCodeIds.Length; i++) { int keyCode = CKeyEvent.KeyCodeIds[i]; tempKeyAction[keyCode] = 1; if (keyStateLeft[keyCode] == 0 || keyStateRight[keyCode] == 0) { tempKeyAction[keyCode] = 0; } } } else if (keyStateLeft != null || keyStateRight != null) { int[] tempKeyState = keyStateLeft != null ? keyStateLeft : keyStateRight; for (int i = 0; i < CKeyEvent.KeyCodeIds.Length; i++) { int keyCode = CKeyEvent.KeyCodeIds[i]; tempKeyAction[keyCode] = 1; if (tempKeyState[keyCode] == 0) { tempKeyAction[keyCode] = 0; } } } return(tempKeyAction); } else { return(GetAndroidClass.CallStatic <int[]>("getKeyAction", new object[] { deviceId })); } } #endif if (keyAction == null) { keyAction = new int[256]; for (int i = 0; i < 256; i++) { keyAction[i] = 1; } } return(keyAction); }