Browse Source

延长扫描时间

lvjincheng 3 years ago
parent
commit
6b57b391d7
1 changed files with 10 additions and 3 deletions
  1. 10 3
      Assets/BowArrow/Scripts/Bluetooth/BluetoothAim.cs

+ 10 - 3
Assets/BowArrow/Scripts/Bluetooth/BluetoothAim.cs

@@ -153,6 +153,7 @@ public class BluetoothAim : MonoBehaviour
                     AimHandler.ins.OnDataReceived(bytes);
                 }
             };
+            int scanCount = 0;
             bluetoothHelper.OnScanEnded += (BluetoothHelper helper, LinkedList<BluetoothDevice> nearbyDevices) =>
             {
                 scanLock = false;
@@ -167,9 +168,15 @@ public class BluetoothAim : MonoBehaviour
                         return;
                     }
                 }
-                canConnect = true;
-                Log("没有发现设备");
-                SetStatus(BluetoothStatusEnum.ConnectFail);
+                if (scanCount < 3) { //如果没扫描到,则重新扫描,达到延迟提示失败的效果
+                    scanCount++;
+                    scanLock = true;
+                    bluetoothHelper.ScanNearbyDevices();
+                } else {
+                    canConnect = true;
+                    Log("没有发现设备");
+                    SetStatus(BluetoothStatusEnum.ConnectFail);
+                }
             };
 
             bluetoothHelper.ScanNearbyDevices();