Пример #1
0
    void RegisterCallbacks(GeekplayDevice _device)
    {
        Debug.Log(_device.GetType());
        if (typeof(GeekplayElite) == _device.GetType())
        {
            ((GeekplayElite)_device).Initialize(GunShoot);
        }
        else if (typeof(GeekplayPoseidon) == _device.GetType())
        {
            ((GeekplayPoseidon)_device).Initialize(GunShoot, GunPump);
        }
        else if (typeof(GeekplayHunter) == _device.GetType())
        {
            ((GeekplayHunter)_device).Initialize(BowDraw, BowShoot, ButtonPressed, ButtonReleased);
        }
        else if (typeof(GeekplayDragonbone) == _device.GetType())
        {
            ((GeekplayDragonbone)_device).Initialize(BowDraw, BowShoot);
        }
        else if (typeof(GeekplayMR_Camera) == _device.GetType())
        {
            ((GeekplayMR_Camera)_device).Initialize(m_camera, new Vector3(0, 0, 0));
        }

        m_device = _device;
    }
Пример #2
0
    void Start()
    {
        Debug.Log("Bluetooth Initializing...");
        BluetoothDeviceScript receiver = BluetoothLEHardwareInterface.Initialize(true, false, () =>
        {
            Debug.Log("Bluetooth Initialized.");
            Debug.Log("Start scanning...");
            BluetoothLEHardwareInterface.ScanForPeripheralsWithServices(null, null, (deviceID, name, rssi, adInfo) =>
            {
                //  deviceID:   安卓上是 MAC 地址,iOS 上是某一串不明代码
                //  adInfo:     广播数据,第 2-7 字节是 MAC 地址
                if (("R-ARCHER" == name) || ("GU-ARCHER" == name))
                {
                    Debug.Log("Found: " + name);
                    //BluetoothLEHardwareInterface.StopScan();

                    GeekplayDevice device = GetDeviceScript(name);
                    device.SetAppInfo("", "", "", "");
                    device.m_deviceID = deviceID;
                    device.m_MAC      = deviceID.Replace(":", "");

                    deviceList.Add(device);
                    if (typeof(GeekplayHunter) == device.GetType())
                    {
                        ((GeekplayHunter)device).Initialize(BowDraw, BowShoot);
                    }
                    else if (typeof(GeekplayDragonbone) == device.GetType())
                    {
                        ((GeekplayDragonbone)device).Initialize(BowDraw, BowShoot);
                    }
                }
            });
        }, null);
    }
Пример #3
0
    void Scan(DeviceName[] _supportedDevices)
    {
        Debug.Log("Start scanning...");
        BluetoothLEHardwareInterface.ScanForPeripheralsWithServices(null, null, (deviceID, name, rssi, adInfo) =>
        {
            for (int i = 0; i < _supportedDevices.Length; ++i)
            {
                for (int j = 0; j < m_deviceNames[_supportedDevices[i]].Length; ++j)
                {
                    string targetName = m_deviceNames[_supportedDevices[i]][j];
                    //  deviceID:   安卓上是 MAC 地址,iOS 上是某一串不明代码
                    //  adInfo:     广播数据,第 2-7 字节是 MAC 地址
                    if (name.Equals(targetName))
                    {
                        Debug.Log("Found: " + targetName);
                        BluetoothLEHardwareInterface.StopScan();

                        m_device = GetDeviceScript(_supportedDevices[i]);
                        m_device.SetAppInfo(m_userID, m_appID, m_appName, m_appDescription);
                        m_device.m_deviceID = deviceID;
#if UNITY_IPHONE
                        m_device.m_MAC = GeekplayCommon.BytesToHexString(adInfo, "").Substring(4, 12);
#elif UNITY_ANDROID
                        m_device.m_MAC = deviceID.Replace(":", "");
#endif

                        return;
                    }
                }
            }
        });
    }