Exemple #1
0
        //获取当前连接设备列表
        public static List <CDevice> GetCDevices()
        {
            List <CDevice>    deviceList = new List <CDevice>();
            AndroidJavaObject devices    = ControllerAndroid.getCDevices();

            if (devices != null)
            {
                int size = devices.Call <int>("size");
                for (int i = 0; i < size; i++)
                {
                    AndroidJavaObject device = devices.Call <AndroidJavaObject>("get", i);
                    if (device != null)
                    {
                        AndroidJavaObject usbDevice       = device.Call <AndroidJavaObject>("getUdevice");
                        AndroidJavaObject bluetoothDevice = device.Call <AndroidJavaObject>("getBdevice");
                        if (usbDevice != null)
                        {
                            deviceList.Add(new CDevice(usbDevice, device.Call <bool>("isQuat"), device.Call <int>("getType")));
                        }
                        else if (bluetoothDevice != null)
                        {
                            deviceList.Add(new CDevice(bluetoothDevice, device.Call <bool>("isQuat"), device.Call <int>("getType"), device.Call <int>("getMode")));
                        }
                        else
                        {
                            deviceList.Add(new CDevice(device.Call <string>("getName"), device.Call <bool>("isQuat"), device.Call <int>("getType"), device.Call <int>("getMode")));
                        }
                    }
                }
            }
            return(deviceList);
        }
Exemple #2
0
        //获取Sensor数据
        public static CSensorEvent GetCSensorEvent(int type, int deviceId = DeviceID)
        {
            AndroidJavaObject sensorEvent = ControllerAndroid.getCSensorEvent(type, deviceId);

            if (sensorEvent == null)
            {
                return(null);
            }
            return(new CSensorEvent(sensorEvent.Call <int>("getType"), sensorEvent.Call <int>("getDeviceId"), sensorEvent.Call <long>("getEventTime"), sensorEvent.Call <float[]>("getValues")));
        }
Exemple #3
0
        //获取自行车数据
        public static CBikeEvent GetCBikeEvent(int deviceId = DeviceID)
        {
            AndroidJavaObject bikeEvent = ControllerAndroid.getCBikeEvent(deviceId);

            if (bikeEvent == null)
            {
                return(null);
            }
            return(new CBikeEvent(bikeEvent.Call <int>("getDeviceId"), bikeEvent.Call <int>("getAngle"), bikeEvent.Call <long>("getEventTime")));
        }
Exemple #4
0
        //获取支持的外设设备名称
        public static List <string> getCSupportDevices()
        {
            List <string>     deviceList = new List <string>();
            AndroidJavaObject devices    = ControllerAndroid.getCSupportDevices();

            if (devices != null)
            {
                int size = devices.Call <int>("size");
                for (int i = 0; i < size; i++)
                {
                    deviceList.Add(devices.Call <string>("get", i));
                }
            }
            return(deviceList);
        }
Exemple #5
0
        public static void Init()
        {
            if (nibiruOsServiceObject != null)
            {
                return;
            }
#if UNITY_ANDROID && !UNITY_EDITOR
            Debug.Log("-------NibiruTaskLib-------Version-------" + version);
            ConnectToActivity();
            nibiruSDKClass        = GetClass(NibiruSDKClassName);
            nibiruOsServiceObject = nibiruSDKClass.CallStatic <AndroidJavaObject>("getNibiruOSService", androidActivity);

            ControllerAndroid.onStart();
#endif
        }
Exemple #6
0
        //获取外设相关信息
        //获取按键状态
        //返回值:keystate 一维数组,数组下标即为按键键值,对应的值则为按键状态
        //所有按键键值定义请参考CKeyEvent中的静态常量定义
        //例子:int action = keystate[CKeyEvent.KEYCODE_DPAD_UP];
        //action表示KEYCODE_DPAD_UP 的状态,如果为CKeyEvent.ACTION_DOWN表 示按下状态,否则为弹起状态。

        public static int[] GetKeyAction(int deviceId = DeviceID)
        {
            return(ControllerAndroid.getKeyAction(deviceId));
        }
Exemple #7
0
 public static void Destroy()
 {
     ControllerAndroid.onStop();
 }
Exemple #8
0
 //获取左右手模式 0:right, 1:left
 public static int GetHandMode()
 {
     return(ControllerAndroid.getHandMode());
 }
Exemple #9
0
 //设置遥感转键值或者 Touch 转键值,参数值motionType 在 CMotionType 类中定义,如 CMotionType.REPORT_KEY
 public static void SetMotionType(int motionType)
 {
     ControllerAndroid.setMotionType(motionType);
 }
Exemple #10
0
 //获取当前连接设备类型 返回值int 型数据,具体参考 CDevice 中静态常量,如CDevice.DEVICE_NINE_GAMEPAD
 public static int GetDeviceType()
 {
     return(ControllerAndroid.getDeviceType());
 }
Exemple #11
0
 //判断当前是否有支持四元素的设备连接
 public static bool IsQuatConn()
 {
     return(ControllerAndroid.isQuatConn());
 }
Exemple #12
0
 //获取所有连接设备 deviceId
 public static int[] GetDeviceIds()
 {
     return(ControllerAndroid.getDeviceIds());
 }
Exemple #13
0
 //获取 Touch 事件数据 返回值4维数组,对应关系为 x = touch[2] , y = touch[3]
 public static float[] GetTouch(int deviceId = DeviceID)
 {
     return(ControllerAndroid.getTouch(deviceId));
 }
Exemple #14
0
 //获取手势识别状态 返回值int 类型,具体定义在 CGestureEvent 静态常量中,例如:CGestureEvent.GESTURE_SLIP_UP
 public static int GetGesture(int deviceId = DeviceID)
 {
     return(ControllerAndroid.getGesture(deviceId));
 }
Exemple #15
0
 //断开设备连接
 public static void Disconnect(AndroidJavaObject bluetoothDevice)
 {
     ControllerAndroid.disconnect(bluetoothDevice);
 }
Exemple #16
0
 public static onDeviceConnectState deviceConnectState = null;   // 此处相当于定义函数指针了
 public static void setOnDeviceListener(onDeviceConnectState listener)
 {
     deviceConnectState = listener;
     ControllerAndroid.setOnDeviceListener(new OnDeviceListener());
 }
        private void RefreshPower()
        {
            float eulerX      = m_transform.parent.eulerAngles.x;
            bool  showBattery = (eulerX < 180 && eulerX >= 20) || (eulerX > 180 && eulerX <= 340);

            if (!showBattery && powerRenderMat.enabled)
            {
                powerRenderMat.enabled = false;
                return;
            }

            powerRenderMat.enabled = showBattery;

            int getControllerPower = 0;

            if (InteractionManager.IsControllerConnected())
            {
                getControllerPower = InteractionManager.GetControllerPower(noloType == CDevice.NOLO_TYPE.LEFT ? InteractionManager.NACTION_HAND_TYPE.HAND_LEFT :
                                                                           InteractionManager.NACTION_HAND_TYPE.HAND_RIGHT);
            }
            else
            {
                if (ControllerAndroid.isDeviceConn((int)noloType))
                {
                    getControllerPower = ControllerAndroid.getNoloControllerPower(noloType);
                }
                else if (ControllerAndroid.isQuatConn())
                {
                    getControllerPower = ControllerAndroid.getControllerPower();
                }
            }

            if (powerRenderMat.enabled && powerValue != getControllerPower)
            {
                if (getControllerPower <= 10)
                {
                    powerRenderMat.material = power1Red;
                }
                else if (getControllerPower < 20)
                {
                    powerRenderMat.material = power1;
                }
                else if (getControllerPower < 40)
                {
                    powerRenderMat.material = power2;
                }
                else if (getControllerPower < 60)
                {
                    powerRenderMat.material = power3;
                }
                else if (getControllerPower < 80)
                {
                    powerRenderMat.material = power4;
                }
                else
                {
                    powerRenderMat.material = power5;
                }

                powerValue = getControllerPower;
            }
        }