修改设备图标。连接设备加缓存功能。
This commit is contained in:
1 parent
6399c26f7e
commit
9f4e446850
33 files changed
+594
-971
No files matched your search
@@ -9,6 +9,7 @@ using UnityEngine.UI;
|
||||
using Assets.Scripts.Devices.Ant.Interfaces;
|
||||
using Assets.Scripts.UI.Control;
|
||||
using Assets.Scripts;
|
||||
using Assets.Scripts.UI.Prefab.Device;
|
||||
|
||||
public class ConnectDeviceModal : PFUIPanel
|
||||
{
|
||||
@@ -83,6 +84,7 @@ public class ConnectDeviceModal : PFUIPanel
|
||||
if (item.Value.DeviceInfo.Sensor == SensorType)
|
||||
{
|
||||
item.Value.DeviceInfo.Disconnect();
|
||||
DeviceCache.Remove(item.Value.DeviceInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -90,6 +92,7 @@ public class ConnectDeviceModal : PFUIPanel
|
||||
if(dd != null)
|
||||
{
|
||||
dd.DeviceInfo.Connect();
|
||||
DeviceCache.Add(dd.DeviceInfo);
|
||||
}
|
||||
this.Close();
|
||||
}));
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
using Assets.Scripts.Devices.Ant;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Collections.Concurrent;
|
||||
using UnityEngine;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Assets.Scripts.UI.Prefab.Device
|
||||
{
|
||||
public class DeviceCache
|
||||
{
|
||||
private static Dictionary<string, ushort> dict = null;
|
||||
private static string _dataPath;
|
||||
public static void Init(string dataPath) {
|
||||
if(dict != null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_dataPath = dataPath;
|
||||
|
||||
if(!System.IO.File.Exists(_dataPath + "/Devices.txt"))
|
||||
{
|
||||
dict = new Dictionary<string, ushort>();
|
||||
return;
|
||||
}
|
||||
//var str = PlayerPrefs.GetString("DeviceCache", "");
|
||||
var str = System.IO.File.ReadAllText(_dataPath + "/Devices.txt", Encoding.UTF8);
|
||||
if (!string.IsNullOrWhiteSpace(str)) {
|
||||
dict = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, ushort>>(str);
|
||||
}
|
||||
else {
|
||||
dict = new Dictionary<string, ushort>();
|
||||
}
|
||||
}
|
||||
|
||||
public static void Add(AbstractAntDevice antDevice)
|
||||
{
|
||||
|
||||
Debug.Log("添加设备" + antDevice.DeviceNumber);
|
||||
//new System.Collections.Concurrent.ConcurrentDictionary<string, string>().AddOrUpdate
|
||||
//dict.AddOrUpdate(antDevice.Sensor.ToString(), antDevice.DeviceNumber, (key, oldValue)=> {
|
||||
|
||||
// Debug.Log("真正添加" + dict.Count);
|
||||
// Write();
|
||||
// return antDevice.DeviceNumber;
|
||||
//});
|
||||
|
||||
dict[antDevice.Sensor.ToString()] = antDevice.DeviceNumber;
|
||||
Write();
|
||||
}
|
||||
|
||||
public static bool Exist(AbstractAntDevice antDevice)
|
||||
{
|
||||
ushort a;
|
||||
if(dict.TryGetValue(antDevice.Sensor.ToString(), out a))
|
||||
{
|
||||
return a == antDevice.DeviceNumber;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void Remove(AbstractAntDevice antDevice)
|
||||
{
|
||||
if(dict == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (dict.ContainsKey(antDevice.Sensor.ToString()))
|
||||
{
|
||||
if(dict[antDevice.Sensor.ToString()] == antDevice.DeviceNumber)
|
||||
{
|
||||
dict.Remove(antDevice.Sensor.ToString());
|
||||
Write();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void Write()
|
||||
{
|
||||
//PlayerPrefs.SetString("DeviceCache", JsonConvert.SerializeObject(dict));
|
||||
System.IO.File.WriteAllText(_dataPath + "/Devices.txt", JsonConvert.SerializeObject(dict));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a2ab4d6b3530fa1409f9d132b0545357
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -11,6 +11,7 @@ using Assets.Scripts.Devices.Ant.Interfaces;
|
||||
using Assets.Scripts.UI.UIEffect;
|
||||
using Assets.Scripts;
|
||||
using DG.Tweening;
|
||||
using Assets.Scripts.UI.Prefab.Device;
|
||||
|
||||
public class DeviceView : MonoBehaviour
|
||||
{
|
||||
@@ -261,7 +262,13 @@ public class DeviceView : MonoBehaviour
|
||||
// logo.sprite = logoSprite;
|
||||
//}
|
||||
});
|
||||
DeviceCache.Add(connectedDevice);
|
||||
|
||||
Debug.Log("connected");
|
||||
|
||||
|
||||
}
|
||||
|
||||
logo.sprite = sprite3;
|
||||
|
||||
title.text = connectedDevice.Name;
|
||||
@@ -271,9 +278,8 @@ public class DeviceView : MonoBehaviour
|
||||
if (powerValue != null)
|
||||
{
|
||||
powerValue.text = GetValue(connectedDevice);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
string GetTitle()
|
||||
|
||||
Reference in new issue
Block a user