移动端蓝牙优化
This commit is contained in:
1 parent
5b54255777
commit
6542dd9882
10 files changed
+84
-16
No files matched your search
@@ -107,7 +107,10 @@ public class ConnectDeviceModal : PFUIPanel
|
||||
var dd = deviceList.Select(d => d.Value).Where(d => d.GetStatus()).FirstOrDefault();
|
||||
if (dd != null)
|
||||
{
|
||||
dd.DeviceInfo.Connect();
|
||||
var modal = this.gameObject;
|
||||
dd.DeviceInfo.Connect((error)=> {
|
||||
Utils.showToast(modal, error);
|
||||
});
|
||||
DeviceCache.Add(dd.DeviceInfo);
|
||||
}
|
||||
}
|
||||
@@ -215,6 +218,21 @@ public class ConnectDeviceModal : PFUIPanel
|
||||
|
||||
deviceList.Add(device.Id, deviceItemObj);
|
||||
}
|
||||
//删除扫描不到的设备
|
||||
var needRemove = deviceList.Where(q => !devices.Select(n => n.Id).Contains(q.Key)).ToList();
|
||||
if (needRemove.Count > 0)
|
||||
{
|
||||
var currentlist = FindObjectsOfType<DeviceItem>();
|
||||
foreach (var item in needRemove)
|
||||
{
|
||||
deviceList.Remove(item.Key);
|
||||
var current = currentlist.Where(e => e.Id == item.Key).FirstOrDefault();
|
||||
if (current != null)
|
||||
{
|
||||
current.gameObject.Destroy(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(deviceList.All(d=>d.Value.GetStatus() == false))
|
||||
{
|
||||
|
||||
@@ -13,6 +13,7 @@ public class DeviceItem : Selectable, IEventSystemHandler, IPointerClickHandler
|
||||
private Image network;
|
||||
private Image signal;
|
||||
private float timer = 0f;
|
||||
public string Id { get; set; }
|
||||
public AbstractDevice DeviceInfo
|
||||
{
|
||||
get;set;
|
||||
@@ -31,6 +32,7 @@ public class DeviceItem : Selectable, IEventSystemHandler, IPointerClickHandler
|
||||
//this.currentSelectionState = SelectionState.Selected
|
||||
if (DeviceInfo == null)
|
||||
return;
|
||||
Id = DeviceInfo.Id;
|
||||
mText.text = DeviceInfo.Name;// + "-" + DeviceInfo.DeviceNumber;
|
||||
if(DeviceInfo.Network == NetworkType.ANT)
|
||||
{
|
||||
@@ -49,9 +51,14 @@ public class DeviceItem : Selectable, IEventSystemHandler, IPointerClickHandler
|
||||
{
|
||||
signal.enabled = false;
|
||||
}
|
||||
Signal_1 = Resources.Load<Sprite>("Images/Signal_1");
|
||||
Signal_2 = Resources.Load<Sprite>("Images/Signal_2");
|
||||
Signal_3 = Resources.Load<Sprite>("Images/Signal_3");
|
||||
SetSignal();
|
||||
}
|
||||
|
||||
Sprite Signal_1;
|
||||
Sprite Signal_2;
|
||||
Sprite Signal_3;
|
||||
|
||||
private void SetSignal()
|
||||
{
|
||||
@@ -66,15 +73,15 @@ public class DeviceItem : Selectable, IEventSystemHandler, IPointerClickHandler
|
||||
var signalValue = DeviceInfo.SignalStrength * -1;
|
||||
if (signalValue >= 0 && signalValue <= 20)
|
||||
{
|
||||
signal.sprite = Resources.Load<Sprite>("Images/Signal_1");
|
||||
signal.sprite = Signal_1;
|
||||
}
|
||||
else if (signalValue > 20 && signalValue <= 60)
|
||||
{
|
||||
signal.sprite = Resources.Load<Sprite>("Images/Signal_2");
|
||||
signal.sprite = Signal_2;
|
||||
}
|
||||
else if (signalValue > 60)//&& signalValue <= 97
|
||||
{
|
||||
signal.sprite = Resources.Load<Sprite>("Images/Signal_3");
|
||||
signal.sprite = Signal_3;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class MailReceiver : MonoBehaviour
|
||||
@@ -47,7 +48,10 @@ public class MailReceiver : MonoBehaviour
|
||||
timer -= Time.deltaTime;
|
||||
if (timer < 0)
|
||||
{
|
||||
GetMessage();
|
||||
if (!SceneManager.GetActiveScene().name.Contains("Login"))
|
||||
{
|
||||
GetMessage();
|
||||
}
|
||||
timer += 10;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,10 +23,10 @@ public class RowerDevicePanel : PFUIPanel
|
||||
base.Show();
|
||||
print("开启扫描");
|
||||
#if UNITY_ANDROID || UNITY_IOS
|
||||
App.MainDeviceAdapter.StartScan();
|
||||
#if UNITY_ANDROID
|
||||
Utils.CallAndroidMethod("OpenLocationService");
|
||||
#endif
|
||||
App.MainDeviceAdapter.StartScan();
|
||||
#endif
|
||||
}
|
||||
float timer = 1f;
|
||||
@@ -47,4 +47,13 @@ public class RowerDevicePanel : PFUIPanel
|
||||
timer += 1f;
|
||||
}
|
||||
}
|
||||
protected override void OnDisable()
|
||||
{
|
||||
App.MainDeviceAdapter.StopScan();
|
||||
}
|
||||
|
||||
protected override void OnDestroy()
|
||||
{
|
||||
App.MainDeviceAdapter.StopScan();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user