蓝牙停止扫描和一些bug修复

This commit is contained in:
lishuo committed 2021-08-26 19:33:43 +08:00
1 parent 0139cbc173
commit d8927ceca5
16 files changed
+137 -71

No files matched your search

+15 -11
View File
@@ -23,8 +23,9 @@ public class BluetoothDeviceScript : MonoBehaviour
public Action<string, string> RetrievedConnectedPeripheralAction;
public Action<string, byte[]> PeripheralReceivedWriteDataAction;
public Action<string> ConnectedPeripheralAction;
public Action<string> ConnectedDisconnectPeripheralAction;
public Action<string> ConnectedDisconnectPeripheralAction { get; set; }
public Action<string> DisconnectedPeripheralAction;
public Action<string> DeviceBleStatusDisconnectedAction;
public Action<string, string> DiscoveredServiceAction;
public Action<string, string, string> DiscoveredCharacteristicAction;
public Action<string> DidWriteCharacteristicAction;
@@ -80,11 +81,14 @@ public class BluetoothDeviceScript : MonoBehaviour
{
char[] delim = new char[] { '~' };
string[] parts = message.Split (delim);
if (parts[0].Equals("DeviceStateChanged"))
{
//throw new Exception("test");
}
if (parts[0].Equals(bleStatusChanged))
if (parts[0].Equals("DeviceStateChanged"))
{
if (DeviceBleStatusDisconnectedAction != null && parts[1].Equals("0"))
{
DeviceBleStatusDisconnectedAction(parts[2]);
}
}
if (parts[0].Equals(bleStatusChanged))
{
if (BleStatusChangedAction != null)
{
@@ -231,12 +235,12 @@ public class BluetoothDeviceScript : MonoBehaviour
{
if (parts.Length >= 2)
{
if (ConnectedDisconnectPeripheralAction != null)
ConnectedDisconnectPeripheralAction (parts[1]);
if (ConnectedDisconnectPeripheralAction != null)
ConnectedDisconnectPeripheralAction(parts[1]);
if (DisconnectedPeripheralAction != null)
DisconnectedPeripheralAction (parts[1]);
}
if (DisconnectedPeripheralAction != null)
DisconnectedPeripheralAction(parts[1]);
}
}
else if (message.Length >= deviceDiscoveredService.Length && message.Substring (0, deviceDiscoveredService.Length) == deviceDiscoveredService)
{
+4 -1
View File
@@ -26,6 +26,7 @@ using UnityEngine;
using System;
using System.Runtime.InteropServices;
using System.Collections.Generic;
using System.Threading;
#if UNITY_2018_3_OR_NEWER
#if UNITY_ANDROID
@@ -605,6 +606,7 @@ public class BluetoothLEHardwareInterface
public static void ConnectToPeripheral (string name, Action<string> connectAction, Action<string, string> serviceAction, Action<string, string, string> characteristicAction, Action<string> disconnectAction = null)
{
#if !UNITY_EDITOR_OSX || !EXPERIMENTAL_MACOS_EDITOR
if (!Application.isEditor)
{
@@ -614,7 +616,8 @@ public class BluetoothLEHardwareInterface
bluetoothDeviceScript.ConnectedPeripheralAction = connectAction;
bluetoothDeviceScript.DiscoveredServiceAction = serviceAction;
bluetoothDeviceScript.DiscoveredCharacteristicAction = characteristicAction;
bluetoothDeviceScript.ConnectedDisconnectPeripheralAction = disconnectAction;
//bluetoothDeviceScript.ConnectedDisconnectPeripheralAction = disconnectAction;
bluetoothDeviceScript.DeviceBleStatusDisconnectedAction = disconnectAction;
}
#if EXPERIMENTAL_MACOS_EDITOR && (UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX)
+3 -3
View File
@@ -12,19 +12,19 @@ PluginImporter:
validateReferences: 1
platformData:
- first:
'': Linux
: Linux
second:
enabled: 0
settings:
CPU: x86
- first:
'': OSXIntel
: OSXIntel
second:
enabled: 0
settings:
CPU: AnyCPU
- first:
'': OSXIntel64
: OSXIntel64
second:
enabled: 0
settings:
+1 -1
View File
@@ -47,7 +47,7 @@ PluginImporter:
second:
enabled: 0
settings:
CPU: x86_64
CPU: AnyCPU
- first:
Standalone: OSXUniversal
second: