From 1e1fd209f931da030a78de75ddfa73154edc4f43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9C=E8=99=9E=E6=B8=A0=E6=88=90=E2=80=9D?= <“yuqucheng2006@qq.com”> Date: Thu, 23 Jul 2026 16:21:24 +0800 Subject: [PATCH] =?UTF-8?q?fix(connectDevice):=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E8=B7=A8=E5=B9=B3=E5=8F=B0=E8=93=9D=E7=89=99=E8=AE=BE=E5=A4=87?= =?UTF-8?q?=E8=BF=9E=E6=8E=A5=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 适配iOS和Android不同的蓝牙地址规则,通过有效地址匹配设备后再发起连接 --- .../ConnectDevice/ConnectDevicePageCtrl.cs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/Assets/Scripts/UI/Pages/ConnectDevice/ConnectDevicePageCtrl.cs b/Assets/Scripts/UI/Pages/ConnectDevice/ConnectDevicePageCtrl.cs index b3bc866..3593d21 100644 --- a/Assets/Scripts/UI/Pages/ConnectDevice/ConnectDevicePageCtrl.cs +++ b/Assets/Scripts/UI/Pages/ConnectDevice/ConnectDevicePageCtrl.cs @@ -95,7 +95,23 @@ public class ConnectDevicePageCtrl : MonoBehaviour } } isconnecting=true; - BluetoothManager.Instance.Connect(result); + // 根据 MAC 在已扫描到的设备列表中查找对应设备 + // iOS: Address 是 UUID, MacFromBroadcast 是真实 MAC + // Android: Address 本身就是 MAC + string targetMac = result.ToUpper(); + var foundDevice = BluetoothManager.Instance.DiscoveredDevices.Find( + d => d.GetEffectiveAddress().ToUpper() == targetMac + ); + if (foundDevice != null) + { + // 找到设备,用正确的地址连接(iOS 用 UUID,Android 用 MAC) + BluetoothManager.Instance.Connect(foundDevice.Address); + } + else + { + // 未找到,设置 aimMac 让扫描到设备时自动连接 + BluetoothManager.Instance.ChangeAimMac(result); + } LoadingUI.Show(); qrCodePlane.SetActive(false); nowDeviceMac=result;