设备扫描优化&我的收藏返回记忆位置
This commit is contained in:
parent
c209811f9f
commit
7f56624ec7
@ -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){
|
||||
|
||||
@ -104,6 +104,7 @@ public static class App
|
||||
|
||||
public static Dictionary<string, string> LanguageManager { get; set; }
|
||||
public static string CurrentRouteType { get; set; }
|
||||
public static string CurrentSubRouteType { get; set; }
|
||||
#region 语言改变事件
|
||||
public static event ChangeLanguageDelegate ChangeLanguageEvent;
|
||||
static Dictionary<string, Dictionary<string, string>> dic;
|
||||
|
||||
@ -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<string, BleDevice> discoveredDevices = new Dictionary<string, BleDevice>();
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
@ -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) =>
|
||||
{
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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;
|
||||
|
||||
/// <summary>
|
||||
@ -38,24 +28,14 @@ public class MapListExtraController : PFUIPanel
|
||||
#else
|
||||
tmpCollectItem = Resources.Load<Transform>("UI/Prefab/NewRoute/RouteItem");
|
||||
#endif
|
||||
|
||||
App.CurrentSubRouteType = "Route";
|
||||
UIManager.AddEvent(typeSelector.Find("Container/Route").gameObject, EventTriggerType.PointerClick, b =>
|
||||
{
|
||||
typeSelector.Find("Container/Route").GetComponent<Text>().color = Utils.HexToColorHtml("#ffffff");
|
||||
typeSelector.Find("Container1/Collection").GetComponent<Text>().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<Text>().color = Utils.HexToColorHtml("#5c5c6e");
|
||||
typeSelector.Find("Container1/Collection").GetComponent<Text>().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<Text>().color = Utils.HexToColorHtml("#ffffff");
|
||||
typeSelector.Find("Container1/Collection").GetComponent<Text>().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<Text>().color = Utils.HexToColorHtml("#5c5c6e");
|
||||
typeSelector.Find("Container1/Collection").GetComponent<Text>().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<Text>().color = Utils.HexToColorHtml("#5c5c6e");
|
||||
SetImageStyle(true);
|
||||
HandleMobileNavCustom(true);
|
||||
if (App.CurrentSubRouteType == "Route")
|
||||
{
|
||||
ShowRouteList();
|
||||
}
|
||||
else
|
||||
{
|
||||
ShowCollectionList();
|
||||
}
|
||||
}
|
||||
private async void GetList()
|
||||
{
|
||||
|
||||
@ -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<NewRouteDetailController>().Initial(areaId, coverImage);
|
||||
}
|
||||
|
||||
@ -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: {}
|
||||
|
||||
@ -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}
|
||||
|
||||
@ -868,7 +868,7 @@ PlayerSettings:
|
||||
platformArchitecture:
|
||||
iPhone: 1
|
||||
scriptingBackend:
|
||||
Android: 0
|
||||
Android: 1
|
||||
Standalone: 0
|
||||
il2cppCompilerConfiguration:
|
||||
Standalone: 0
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user