diff --git a/Assets/Plugins/BluetoothDeviceScript.cs b/Assets/Plugins/BluetoothDeviceScript.cs index cc3c4399..d3d25634 100644 --- a/Assets/Plugins/BluetoothDeviceScript.cs +++ b/Assets/Plugins/BluetoothDeviceScript.cs @@ -238,11 +238,14 @@ public class BluetoothDeviceScript : MonoBehaviour { if (parts.Length >= 2) { - if (ConnectedDisconnectPeripheralAction != null) - ConnectedDisconnectPeripheralAction(parts[1]); - - if (DisconnectedPeripheralAction != null) - DisconnectedPeripheralAction(parts[1]); + if (DisconnectedPeripheralAction != null) + { + DisconnectedPeripheralAction(parts[1]); + } + else if (ConnectedDisconnectPeripheralAction != null) + { + ConnectedDisconnectPeripheralAction(parts[1]); + } } } else if (message.Length > connectionError.Length && message.Substring(0,connectionError.Length) == connectionError){ diff --git a/Assets/Scripts/App.cs b/Assets/Scripts/App.cs index 27fdf926..2cd0cec5 100644 --- a/Assets/Scripts/App.cs +++ b/Assets/Scripts/App.cs @@ -104,6 +104,7 @@ public static class App public static Dictionary LanguageManager { get; set; } public static string CurrentRouteType { get; set; } + public static string CurrentSubRouteType { get; set; } #region 语言改变事件 public static event ChangeLanguageDelegate ChangeLanguageEvent; static Dictionary> dic; diff --git a/Assets/Scripts/Devices/Ble/BleDeviceAdapter.cs b/Assets/Scripts/Devices/Ble/BleDeviceAdapter.cs index f08a1881..df340422 100644 --- a/Assets/Scripts/Devices/Ble/BleDeviceAdapter.cs +++ b/Assets/Scripts/Devices/Ble/BleDeviceAdapter.cs @@ -1,14 +1,11 @@ using Assets.Scripts.Ble; -using Assets.Scripts.Ble.Service; using Assets.Scripts.Devices.Ble.Devices; using Assets.Scripts.Devices.Ble.Interfaces; using Assets.Scripts.UI.Prefab.Device; using System; using System.Collections.Generic; using System.Linq; -using System.Text; using System.Threading; -using System.Threading.Tasks; using UnityEngine; namespace Assets.Scripts.Devices.Ble @@ -20,14 +17,33 @@ namespace Assets.Scripts.Devices.Ble private IDictionary discoveredDevices = new Dictionary(); public IBleWinHwInterface hwInterface { get; private set; } + + private System.Timers.Timer timer; public BleDeviceAdapter(IBleWinHwInterface bleWinHwInterface) { - + if (timer == null) + { + timer = new System.Timers.Timer(1000); + timer.Elapsed += Timer_Elapsed; + timer.Start(); + } hwInterface = bleWinHwInterface;// BleWinHwInterface.GetInterface(); hwInterface.BluetoothStateChangedEvent += HwInterface_BluetoothStateChangedEvent; } + private void Timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) + { + //移除到3s没有扫描到的设备 + var now = DateTime.Now; + var needRemove = discoveredDevices.Where(c => (now - c.Value.LastActiveTime).TotalSeconds >= 3 && c.Value.State != Ant.DeviceState.Connected).ToList(); + foreach (var item in needRemove) + { + discoveredDevices.Remove(item.Key); + } + } + + private void HwInterface_BluetoothStateChangedEvent(IBleWinHwInterface hwInterface, BleState bleState) { if(bleState == BleState.Off) @@ -60,14 +76,10 @@ namespace Assets.Scripts.Devices.Ble { hwInterface.StartScan((device) => { - if (!discoveredDevices.ContainsKey(device.Peripheral.Address)) + if (!discoveredDevices.ContainsKey(device.Peripheral.Address)&& !string.IsNullOrWhiteSpace(device.Peripheral.Name)) { Debug.Log($"发现设备{ device.Peripheral.Address }, \t\tName:{ device.Peripheral.Name }, type:{ device.SensorType } 服务:{string.Join(",", device.Services)}"); - if (string.IsNullOrWhiteSpace(device.Peripheral.Name)) - { - return; - } if (device.SensorType == Ant.SensorType.FtmsTrainer) { var device1 = new Ftms(device.Peripheral, hwInterface); @@ -110,10 +122,6 @@ namespace Assets.Scripts.Devices.Ble var device1 = new SpeedCadence(device.Peripheral, hwInterface); discoveredDevices.Add(device.Peripheral.Address, device1); } - else - { - return; - } var device111 = discoveredDevices.Last().Value; if (device111 != null && device111.State == Ant.DeviceState.Disconnected) @@ -134,14 +142,7 @@ namespace Assets.Scripts.Devices.Ble { discoveredDevices[device.Peripheral.Address].SignalStrength = device.Rssi; discoveredDevices[device.Peripheral.Address].LastActiveTime = DateTime.Now; - //Debug.Log($"设备{ device.Peripheral.Name }信号量:{ device.Rssi }"); - } - //移除到5s没有扫描到的设备 - var now = DateTime.Now; - var needRemove = discoveredDevices.Where(c => (now - c.Value.LastActiveTime).TotalSeconds > 5 && c.Value.State == Ant.DeviceState.Disconnected).ToList(); - foreach (var item in needRemove) - { - discoveredDevices.Remove(item.Key); + Debug.Log($"设备{ device.Peripheral.Name }信号量:{ device.Rssi }"); } }); } @@ -155,6 +156,8 @@ namespace Assets.Scripts.Devices.Ble { this.ReleaseDevices(); hwInterface.Dispose(); + timer.Stop(); + timer.Dispose(); base.Dispose(); } diff --git a/Assets/Scripts/Devices/Ble/mobile/BleMobileInterface.cs b/Assets/Scripts/Devices/Ble/mobile/BleMobileInterface.cs index 50fd68f8..c1936aa5 100644 --- a/Assets/Scripts/Devices/Ble/mobile/BleMobileInterface.cs +++ b/Assets/Scripts/Devices/Ble/mobile/BleMobileInterface.cs @@ -225,7 +225,7 @@ namespace Assets.Scripts.Ble IsSuccess = true, Error = null }; - PeripheralDisconnected(address, info);//连接前断开 + //PeripheralDisconnected(address, info);//连接前断开 callback?.Invoke(self, info, s); this.callbacks.Remove(info); Debug.Log("连接成功!" + info.Name); @@ -242,8 +242,10 @@ namespace Assets.Scripts.Ble CharacteristicsDiscovered(address, service, characteristic); }, (address) => { + var ble = new WinBlePeripheralInfo(address,string.Empty); Debug.Log("disconnect device:" + address); - PeripheralDisconnected(address, info); + peripheralDisconnectedEvent(this, ble, null, false); + PeripheralDisconnected(address, ble); }, (address, error) => { diff --git a/Assets/Scripts/Devices/Ble/mobile/BleMobileThread.cs b/Assets/Scripts/Devices/Ble/mobile/BleMobileThread.cs index 909ffa7f..a367ca46 100644 --- a/Assets/Scripts/Devices/Ble/mobile/BleMobileThread.cs +++ b/Assets/Scripts/Devices/Ble/mobile/BleMobileThread.cs @@ -36,7 +36,7 @@ namespace Assets.Scripts.Devices.Ble this.managerStatusChanged -= value; } } - WclBleManagerStatus statusEnum = WclBleManagerStatus.RadioOn; + WclBleManagerStatus statusEnum = WclBleManagerStatus.RadioOff; internal BleMobileThread() { Initialize();//初始蓝牙 } @@ -45,7 +45,6 @@ namespace Assets.Scripts.Devices.Ble var self = this; if (statusEnum == WclBleManagerStatus.RadioOff) { - //Initialize(); BluetoothLEHardwareInterface.BluetoothEnable(true); } else diff --git a/Assets/Scripts/UI/Prefab/Panel/MapListExtraController.cs b/Assets/Scripts/UI/Prefab/Panel/MapListExtraController.cs index 6c31b0d7..730effb2 100644 --- a/Assets/Scripts/UI/Prefab/Panel/MapListExtraController.cs +++ b/Assets/Scripts/UI/Prefab/Panel/MapListExtraController.cs @@ -1,17 +1,7 @@ using Assets.Scripts; -using Assets.Scripts.Apis; -using Assets.Scripts.Apis.Models; -using Assets.Scripts.UI.Prefab.MapList; using DG.Tweening; -using System; -using System.Collections; -using System.Collections.Generic; -using System.Linq; -using UnityEditor; using UnityEngine; -using UnityEngine.Events; using UnityEngine.EventSystems; -using UnityEngine.SceneManagement; using UnityEngine.UI; /// @@ -38,24 +28,14 @@ public class MapListExtraController : PFUIPanel #else tmpCollectItem = Resources.Load("UI/Prefab/NewRoute/RouteItem"); #endif - + App.CurrentSubRouteType = "Route"; UIManager.AddEvent(typeSelector.Find("Container/Route").gameObject, EventTriggerType.PointerClick, b => { - typeSelector.Find("Container/Route").GetComponent().color = Utils.HexToColorHtml("#ffffff"); - typeSelector.Find("Container1/Collection").GetComponent().color = Utils.HexToColorHtml("#5c5c6e"); - SetImageStyle(true); - p1.DOLocalMoveX(p1originx, 0.5f); - p2.DOLocalMoveX(p2originx, 0.5f); - HandleMobileNavCustom(true); + ShowRouteList(); }); UIManager.AddEvent(typeSelector.Find("Container1/Collection").gameObject, EventTriggerType.PointerClick, b => { - typeSelector.Find("Container/Route").GetComponent().color = Utils.HexToColorHtml("#5c5c6e"); - typeSelector.Find("Container1/Collection").GetComponent().color = Utils.HexToColorHtml("#ffffff"); - SetImageStyle(false); - p1.DOLocalMoveX(p1originx - listWidth, 0.5f); - p2.DOLocalMoveX(p2originx - listWidth, 0.5f); - HandleMobileNavCustom(false); + ShowCollectionList(); }); } @@ -69,15 +49,30 @@ public class MapListExtraController : PFUIPanel } - void Update() + private void ShowRouteList() { - + App.CurrentSubRouteType = "Route"; + typeSelector.Find("Container/Route").GetComponent().color = Utils.HexToColorHtml("#ffffff"); + typeSelector.Find("Container1/Collection").GetComponent().color = Utils.HexToColorHtml("#5c5c6e"); + SetImageStyle(true); + p1.DOLocalMoveX(p1originx, 0.5f); + p2.DOLocalMoveX(p2originx, 0.5f); + HandleMobileNavCustom(true); + } + private void ShowCollectionList() + { + App.CurrentSubRouteType = "Collection"; + typeSelector.Find("Container/Route").GetComponent().color = Utils.HexToColorHtml("#5c5c6e"); + typeSelector.Find("Container1/Collection").GetComponent().color = Utils.HexToColorHtml("#ffffff"); + SetImageStyle(false); + p1.DOLocalMoveX(p1originx - listWidth, 0.5f); + p2.DOLocalMoveX(p2originx - listWidth, 0.5f); + HandleMobileNavCustom(false); } public override void Show() { base.Show(); - } private int pageIndex = 0; void HandleMobileNavCustom(bool b) @@ -131,6 +126,14 @@ public class MapListExtraController : PFUIPanel typeSelector.Find("Container1/Collection").GetComponent().color = Utils.HexToColorHtml("#5c5c6e"); SetImageStyle(true); HandleMobileNavCustom(true); + if (App.CurrentSubRouteType == "Route") + { + ShowRouteList(); + } + else + { + ShowCollectionList(); + } } private async void GetList() { diff --git a/Assets/Scripts/UIManager.cs b/Assets/Scripts/UIManager.cs index cbc4a9fd..bc3a1e2d 100644 --- a/Assets/Scripts/UIManager.cs +++ b/Assets/Scripts/UIManager.cs @@ -347,7 +347,8 @@ public class UIManager : MonoBehaviour } public static void ShowNewRouteDetailPanel(int areaId,string coverImage) { - App.CurrentRouteType = ""; + if(App.CurrentRouteType != "My Collection") + App.CurrentRouteType = ""; UIManager.Show(UIManager.Instance.NewRouteDetailPanel, UIManager.Instance.MainPanel); UIManager.Instance.NewRouteDetailPanel.GetComponent().Initial(areaId, coverImage); } diff --git a/ProjectSettings/EditorBuildSettings.asset b/ProjectSettings/EditorBuildSettings.asset index 9186f49d..999e430b 100644 --- a/ProjectSettings/EditorBuildSettings.asset +++ b/ProjectSettings/EditorBuildSettings.asset @@ -14,7 +14,4 @@ EditorBuildSettings: - enabled: 1 path: Assets/Scenes/Ride.unity guid: d9f6ee75d0d54714fb4d2f90016a28bc - - enabled: 1 - path: Assets/Scenes/VideoPlay.unity - guid: f25b9f482e27079448d130ae1ed0ea34 m_configObjects: {} diff --git a/ProjectSettings/GraphicsSettings.asset b/ProjectSettings/GraphicsSettings.asset index 4706883c..9b996cb4 100644 --- a/ProjectSettings/GraphicsSettings.asset +++ b/ProjectSettings/GraphicsSettings.asset @@ -38,6 +38,7 @@ GraphicsSettings: - {fileID: 16000, guid: 0000000000000000f000000000000000, type: 0} - {fileID: 16001, guid: 0000000000000000f000000000000000, type: 0} - {fileID: 17000, guid: 0000000000000000f000000000000000, type: 0} + - {fileID: 16003, guid: 0000000000000000f000000000000000, type: 0} m_PreloadedShaders: [] m_SpritesDefaultMaterial: {fileID: 10754, guid: 0000000000000000f000000000000000, type: 0} diff --git a/ProjectSettings/ProjectSettings.asset b/ProjectSettings/ProjectSettings.asset index c4963e8f..7425d41c 100644 --- a/ProjectSettings/ProjectSettings.asset +++ b/ProjectSettings/ProjectSettings.asset @@ -868,7 +868,7 @@ PlayerSettings: platformArchitecture: iPhone: 1 scriptingBackend: - Android: 0 + Android: 1 Standalone: 0 il2cppCompilerConfiguration: Standalone: 0