划船机暂存
This commit is contained in:
1 parent
1c73701e73
commit
c73545d912
164 files changed
+38281
-2181
No files matched your search
@@ -24,9 +24,10 @@ namespace Assets.Scripts.Apis
|
||||
return jsonResult;
|
||||
}
|
||||
|
||||
public async Task<JsonResult<List<RouteResult>>> GetMapInterruptRecord(string keyword, int pageIndex, int pageSize, string type)
|
||||
public async Task<JsonResult<List<JObject>>> GetMapInterruptRecord(string keyword, int pageIndex, int pageSize, string type)
|
||||
{
|
||||
return await GetAsync<JsonResult<List<RouteResult>>>($"MapRecord/v1/GetList?keyword={keyword}&pageIndex={pageIndex}&pageSize={pageSize}&type={type}");
|
||||
//RouteResult
|
||||
return await GetAsync<JsonResult<List<JObject>>>($"MapRecord/v1/GetList?keyword={keyword}&pageIndex={pageIndex}&pageSize={pageSize}&type={type}");
|
||||
}
|
||||
/// <summary>
|
||||
/// 通过ID获取设备商
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Assets.Scripts.Apis.Models
|
||||
{
|
||||
public class RowerRecordModel
|
||||
{
|
||||
public string Id { get; set; }
|
||||
|
||||
public string ManufacturerName { get; set; }
|
||||
|
||||
public string DeviceNumber { get; set; }
|
||||
public double? Kj { get; set; }
|
||||
public int Ticks { get; set; }
|
||||
public double Weight { get; set; }
|
||||
public DateTime StartTime { get; set; }
|
||||
public DateTime CreateTime { get; set; }
|
||||
public int MaxPower { get; set; }
|
||||
public ushort MaxPace { get; set; }
|
||||
public uint MaxRate { get; set; }
|
||||
public double AvgPace { get; set; }
|
||||
public double AvgPower { get; set; }
|
||||
public double AvgRate { get; set; }
|
||||
public int MaxHeartRate { get; set; }
|
||||
public int AvgHeartRate { get; set; }
|
||||
public ushort StrokeCount { get; set; }
|
||||
public uint TotalDistance { get; set; }
|
||||
public int TotalTime { get; set; }
|
||||
}
|
||||
public class RowerChartModel
|
||||
{
|
||||
public int Power { get; set; }
|
||||
public ushort Pace { get; set; }
|
||||
public uint Rate { get; set; }
|
||||
public int HeartRate { get; set; }
|
||||
}
|
||||
public class RowerResultModel
|
||||
{
|
||||
public string Id { get; set; }
|
||||
|
||||
public string ManufacturerName { get; set; }
|
||||
|
||||
public string DeviceNumber { get; set; }
|
||||
public double? Kj { get; set; }
|
||||
public DateTime StartTime { get; set; }
|
||||
public DateTime CreateTime { get; set; }
|
||||
public int MaxPower { get; set; }
|
||||
public ushort MaxPace { get; set; }
|
||||
public uint MaxRate { get; set; }
|
||||
public double AvgPace { get; set; }
|
||||
public double AvgPower { get; set; }
|
||||
public double AvgRate { get; set; }
|
||||
public int MaxHeartRate { get; set; }
|
||||
public int AvgHeartRate { get; set; }
|
||||
public ushort StrokeCount { get; set; }
|
||||
public uint TotalDistance { get; set; }
|
||||
public int TotalTime { get; set; }
|
||||
public List<RowerChartModel> ChartList { get; set; }
|
||||
public string Cover { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e4f2fe5f1bd49b143bbbca0b57371de9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,40 @@
|
||||
using Assets.Scripts.Apis.Models;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Assets.Scripts.Apis
|
||||
{
|
||||
public class RowerApi : ApiBase
|
||||
{
|
||||
/// <summary>
|
||||
/// 上传划船记录到服务端
|
||||
/// </summary>
|
||||
/// <param name="interruptRecord"></param>
|
||||
public JsonResult<object> Add(RowerRecordModel record, List<string> fileNames)
|
||||
{
|
||||
var result = Upload("Rower/AddRecord", record, fileNames);
|
||||
var jsonResult = JsonConvert.DeserializeObject<JsonResult<object>>(result);
|
||||
return jsonResult;
|
||||
}
|
||||
|
||||
public async Task<JsonResult<List<JObject>>> GetList(int pageIndex, int pageSize)
|
||||
{
|
||||
return await GetAsync<JsonResult<List<JObject>>>($"Rower/GetList?pageIndex={pageIndex}&pageSize={pageSize}");
|
||||
}
|
||||
|
||||
public async Task<JsonResult<RowerResultModel>> GetDetail(string id)
|
||||
{
|
||||
return await GetAsync<JsonResult<RowerResultModel>>($"Rower/GetDetail?Id={id}");
|
||||
}
|
||||
|
||||
public async Task<JsonResult<object>> Delete(string Id)
|
||||
{
|
||||
return await PostAsync<JsonResult<object>>($"Rower/Delete",new { Id});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 41164280104edad45bc16ffa81b9ab9f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+26
-13
@@ -9,10 +9,11 @@ using System.Globalization;
|
||||
using System.Threading;
|
||||
using Assets.Scripts.Devices;
|
||||
using Assets.Scripts;
|
||||
using System;
|
||||
|
||||
public static class App
|
||||
{
|
||||
public static string Host = "http://192.168.0.102:5082/";
|
||||
public static string Host = "http://192.168.0.101:5085/";
|
||||
|
||||
public static string AppVersion = Application.version;
|
||||
|
||||
@@ -30,7 +31,17 @@ public static class App
|
||||
public static double latitude { get; internal set; }
|
||||
public static double longitude { get; internal set; }
|
||||
|
||||
public static bool FromLogin = false;
|
||||
public static bool FromLogin => false;
|
||||
private static bool _IsRowerMode = false;
|
||||
public static bool IsRowerMode
|
||||
{
|
||||
get => _IsRowerMode;
|
||||
set
|
||||
{
|
||||
PlayerPrefs.SetString("IsRowerMode",value.ToString());
|
||||
_IsRowerMode = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 场景跳转传值
|
||||
@@ -38,7 +49,7 @@ public static class App
|
||||
/// xxx,bbb
|
||||
/// </summary>
|
||||
public static System.Collections.Generic.Dictionary<string, string> MainSceneParam = new Dictionary<string, string>();
|
||||
public static IDictionary<string,Texture> TextureCache = new Dictionary<string, Texture>();
|
||||
public static IDictionary<string, Texture> TextureCache = new Dictionary<string, Texture>();
|
||||
public static Texture CurrentUserHeadTexture;
|
||||
public static RouteResult routeResult;//骑行记录向骑行场景传值
|
||||
public static Texture DefaultRotateTexture;
|
||||
@@ -65,7 +76,7 @@ public static class App
|
||||
{
|
||||
get
|
||||
{
|
||||
if(mainDeviceAdapter == null)
|
||||
if (mainDeviceAdapter == null)
|
||||
{
|
||||
mainDeviceAdapter = new MainDeviceAdapter();
|
||||
}
|
||||
@@ -83,19 +94,21 @@ public static class App
|
||||
public static int autoClearTimes = 30;
|
||||
public readonly static double width = Screen.width;
|
||||
public readonly static double height = Screen.height;
|
||||
public readonly static bool isFullScreen = width/height>1.8;
|
||||
public readonly static bool isFullScreen = width / height > 1.8;
|
||||
public static float canvasWidth { get; set; }
|
||||
static App()
|
||||
{
|
||||
#if !UNITY_EDITOR
|
||||
//Host = "http://pf.juze.pro/";
|
||||
//UdpAddress = new IPEndPoint(IPAddress.Parse("47.97.84.8"), 21000);
|
||||
//TcpAddress = new IPEndPoint(IPAddress.Parse("47.97.84.8"), 21001);
|
||||
Host = "https://wx.powerfun.com.cn/";
|
||||
UdpAddress = new IPEndPoint(IPAddress.Parse("47.97.84.8"), 11000);
|
||||
TcpAddress = new IPEndPoint(IPAddress.Parse("47.97.84.8"), 11001);
|
||||
|
||||
Host = "http://192.168.0.101:5085/";
|
||||
UdpAddress = new IPEndPoint(IPAddress.Parse("47.97.84.8"), 21000);
|
||||
TcpAddress = new IPEndPoint(IPAddress.Parse("47.97.84.8"), 21001);
|
||||
//Host = "https://wx.powerfun.com.cn/";
|
||||
//UdpAddress = new IPEndPoint(IPAddress.Parse("47.97.84.8"), 11000);
|
||||
//TcpAddress = new IPEndPoint(IPAddress.Parse("47.97.84.8"), 11001);
|
||||
#endif
|
||||
Debug.Log(PlayerPrefs.GetString("IsRowerMode"));
|
||||
App._IsRowerMode = bool.Parse(PlayerPrefs.GetString("IsRowerMode"));
|
||||
Screen.sleepTimeout = SleepTimeout.NeverSleep;
|
||||
Debug.Log(SystemInfo.deviceModel);
|
||||
//Debug.Log(TimeSpan.FromSeconds(1).ToString(@"mm\:ss"));
|
||||
}
|
||||
}
|
||||
@@ -60,6 +60,14 @@ namespace Assets.Scripts
|
||||
return _mapCompetitionApi;
|
||||
}
|
||||
}
|
||||
|
||||
private static RowerApi _rowerApi;
|
||||
internal static RowerApi rowerApi
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_rowerApi == null) _rowerApi = new RowerApi();
|
||||
return _rowerApi;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using Assets.Scripts.Devices.Ble.Characteristic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Assets.Scripts.Devices.Ant.Interfaces
|
||||
{
|
||||
interface IRowerDevice
|
||||
{
|
||||
FtmsRowerData rowerData { get; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c4094cd7dbe5f1a489e9bdf431722ddc
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -38,6 +38,7 @@ namespace Assets.Scripts.Devices.Ant
|
||||
SpeedCadence,
|
||||
Trainer,
|
||||
VirtualPower,
|
||||
Rower
|
||||
}
|
||||
|
||||
public enum NetworkType
|
||||
|
||||
@@ -44,5 +44,9 @@ namespace Assets.Scripts
|
||||
{
|
||||
return BitConverter.ToUInt32(bytes, startIndex);
|
||||
}
|
||||
public static uint ToUInt24(byte[] bytes, int startIndex)
|
||||
{
|
||||
return (uint)((int)bytes[startIndex] | (int)bytes[startIndex + 1] << 8 | (int)bytes[startIndex + 2] << 16);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -68,29 +68,48 @@ namespace Assets.Scripts.Devices.Ble
|
||||
{
|
||||
return;
|
||||
}
|
||||
if(device.SensorType == Ant.SensorType.Trainer)
|
||||
if (device.SensorType == Ant.SensorType.Trainer)
|
||||
{
|
||||
//var device1 = new Ftms(device.Peripheral, hwInterface);
|
||||
//discoveredDevices.Add(device.Peripheral.Address, device1);
|
||||
|
||||
//var device0 = new Ftms(device.Peripheral, hwInterface);
|
||||
//discoveredDevices.Add(device.Peripheral.Address, device0);
|
||||
|
||||
var device1 = new Tacx(device.Peripheral, hwInterface);
|
||||
discoveredDevices.Add(device.Peripheral.Address, device1);
|
||||
if (discoveredDevices.ContainsKey(device.Peripheral.Address))
|
||||
{
|
||||
discoveredDevices[device.Peripheral.Address] = device1;
|
||||
}
|
||||
else
|
||||
{
|
||||
discoveredDevices.Add(device.Peripheral.Address, device1);
|
||||
}
|
||||
}
|
||||
else if(device.SensorType == Ant.SensorType.HeartRate)
|
||||
else if (device.SensorType == Ant.SensorType.HeartRate)
|
||||
{
|
||||
var device1 = new HeartRate(device.Peripheral, hwInterface);
|
||||
discoveredDevices.Add(device.Peripheral.Address, device1);
|
||||
}
|
||||
else if(device.SensorType == Ant.SensorType.Power)
|
||||
else if (device.SensorType == Ant.SensorType.Power)
|
||||
{
|
||||
var device1 = new CyclingPower(device.Peripheral, hwInterface);
|
||||
discoveredDevices.Add(device.Peripheral.Address, device1);
|
||||
}
|
||||
else if(device.SensorType == Ant.SensorType.SpeedCadence)
|
||||
else if (device.SensorType == Ant.SensorType.SpeedCadence)
|
||||
{
|
||||
var device1 = new SpeedCadence(device.Peripheral, hwInterface);
|
||||
discoveredDevices.Add(device.Peripheral.Address, device1);
|
||||
}
|
||||
else if (device.SensorType == Ant.SensorType.Rower)
|
||||
{
|
||||
var device1 = new FtmsRower(device.Peripheral, hwInterface);
|
||||
if (discoveredDevices.ContainsKey(device.Peripheral.Address))
|
||||
{
|
||||
discoveredDevices[device.Peripheral.Address] = device1;
|
||||
}
|
||||
else
|
||||
{
|
||||
discoveredDevices.Add(device.Peripheral.Address, device1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
|
||||
@@ -0,0 +1,344 @@
|
||||
using Assets.Scripts.Ble;
|
||||
using Assets.Scripts.Devices.Ble.Interfaces;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Assets.Scripts.Devices.Ble.Characteristic
|
||||
{
|
||||
public class FtmsRowerData : ICharacteristic
|
||||
{
|
||||
/// <summary>
|
||||
/// 划桨频率
|
||||
/// </summary>
|
||||
public uint StrokeRate { get; private set; } = 0;
|
||||
/// <summary>
|
||||
/// 划桨次数
|
||||
/// </summary>
|
||||
public UInt16 StrokeCount { get; private set; } = 0;
|
||||
/// <summary>
|
||||
/// 平均划桨频率
|
||||
/// </summary>
|
||||
public int AverageStrokeRate { get; private set; } = 0;
|
||||
|
||||
public UInt32 TotalDistance { get; private set; } = 0;
|
||||
/// <summary>
|
||||
/// 即时配速
|
||||
/// </summary>
|
||||
public UInt16 InstantaneousPace { get; private set; } = 0;
|
||||
/// <summary>
|
||||
/// 平均配速
|
||||
/// </summary>
|
||||
public UInt16 AveragePace { get; private set; } = 0;
|
||||
|
||||
public int InstantaneousPower { get; private set; } = 0;
|
||||
|
||||
public int AveragePower { get; private set; } = 0;
|
||||
|
||||
public int ResistanceLevel { get; private set; } = 0;
|
||||
/// <summary>
|
||||
/// 运行时间
|
||||
/// </summary>
|
||||
public int ElapsedTime { get; private set; } = 0;
|
||||
|
||||
public int TotalEnergy { get; private set; } = 0;
|
||||
|
||||
public int EnergyPerHour { get; private set; } = 0;
|
||||
|
||||
public int EnergyPerMinute { get; private set; } = 0;
|
||||
|
||||
public Guid Uuid => ServiceUuids.Characteristics.RowerData;
|
||||
|
||||
public Guid ServiceUuid => ServiceUuids.Get(ServiceUuids.Ftms).IdGuid;
|
||||
|
||||
public bool IsOptional => false;
|
||||
|
||||
public RowerDataFlag Flags;
|
||||
//拉力相关
|
||||
public event EventHandler PullChanged;
|
||||
private ushort _pullValue;
|
||||
public ushort PullValue
|
||||
{
|
||||
get { return _pullValue; }
|
||||
set
|
||||
{
|
||||
_pullValue = value;
|
||||
if (this.PullChanged != null)
|
||||
{
|
||||
this.PullChanged(this, new EventArgs());
|
||||
}
|
||||
}
|
||||
}
|
||||
public bool MoreDataFlag
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.Flags.HasFlag(RowerDataFlag.MoreData);
|
||||
}
|
||||
}
|
||||
|
||||
public void HandleAttributeReceived(byte[] data)
|
||||
{
|
||||
if (data == null || data.Length < 2)
|
||||
{
|
||||
throw new ArgumentException("数据异常" + string.Join(",", data));
|
||||
}
|
||||
//throw new NotImplementedException();
|
||||
//if(data[0] == 1)
|
||||
//{
|
||||
// return;
|
||||
//}
|
||||
var output = "";
|
||||
output += "收到消息:" + string.Join("\t", data);
|
||||
|
||||
|
||||
this.Flags = (RowerDataFlag)BitConverter.ToUInt16(data, 0);
|
||||
int b = 2;
|
||||
if (!this.MoreDataFlag)
|
||||
{
|
||||
//this.instantSpeed = new double?((double)BitConverter.ToUInt16(data, (int)b) * 0.01);
|
||||
this.StrokeRate = (uint)Math.Round(BitConvertHelper.ToUInt8(data, b) / 2d);
|
||||
b += 1;
|
||||
this.StrokeCount = BitConvertHelper.ToUInt16(data, b);
|
||||
b += 2;
|
||||
b += this.SizeOfDataForFlag(RowerDataFlag.MoreData);
|
||||
}
|
||||
//平均浆频
|
||||
if (this.Flags.HasFlag(RowerDataFlag.AverageStrokeRate))
|
||||
{
|
||||
var vvv = BitConvertHelper.ToUInt8(data, (int)b) / 2;
|
||||
//Debug.WriteLine($"平均浆频:{ vvv }");
|
||||
output += $" 平均浆频:{ vvv }";
|
||||
this.AverageStrokeRate = vvv;
|
||||
b += this.SizeOfDataForFlag(RowerDataFlag.AverageStrokeRate);
|
||||
|
||||
//output += $" 次数:{ BitConvertHelper.ToUInt16(data, b) }";
|
||||
//b += 3;
|
||||
}
|
||||
if (this.Flags.HasFlag(RowerDataFlag.TotalDistance))
|
||||
{
|
||||
var vvv = BitConvertHelper.ToUInt24(data, (int)b);
|
||||
output += $" 总距离{ vvv }米";
|
||||
b += this.SizeOfDataForFlag(RowerDataFlag.TotalDistance);
|
||||
|
||||
this.TotalDistance = vvv;
|
||||
}
|
||||
if (this.Flags.HasFlag(RowerDataFlag.InstantaneousPace))
|
||||
{
|
||||
//this.InstantCadence = new int?((int)(BitConvertHelper.ToUInt16(data, (int)b) / 2));
|
||||
this.InstantaneousPace = BitConvertHelper.ToUInt16(data, b);
|
||||
b += this.SizeOfDataForFlag(RowerDataFlag.InstantaneousPace);
|
||||
}
|
||||
if (this.Flags.HasFlag(RowerDataFlag.AveragePace))
|
||||
{
|
||||
this.AveragePace = BitConvertHelper.ToUInt16(data, b);
|
||||
b += this.SizeOfDataForFlag(RowerDataFlag.AveragePace);
|
||||
}
|
||||
if (this.Flags.HasFlag(RowerDataFlag.InstantPower))
|
||||
{
|
||||
var power = new int?((int)BitConvertHelper.ToInt16(data, (int)b));
|
||||
output += $" 功率:{ power }";
|
||||
this.InstantaneousPower = power.GetValueOrDefault(0);
|
||||
b += this.SizeOfDataForFlag(RowerDataFlag.InstantPower);
|
||||
}
|
||||
if (this.Flags.HasFlag(RowerDataFlag.AveragePower))
|
||||
{
|
||||
//var power = new int?((int)BitConverter.ToInt16(data, (int)b));
|
||||
this.AveragePower = BitConvertHelper.ToInt16(data, b);
|
||||
b += this.SizeOfDataForFlag(RowerDataFlag.AveragePower);
|
||||
}
|
||||
if (this.Flags.HasFlag(RowerDataFlag.ResistanceLevel))
|
||||
{
|
||||
this.ResistanceLevel = BitConvertHelper.ToInt16(data, b);
|
||||
b += this.SizeOfDataForFlag(RowerDataFlag.ResistanceLevel);
|
||||
}
|
||||
if (this.Flags.HasFlag(RowerDataFlag.ExpendedEnergy))
|
||||
{
|
||||
this.TotalEnergy = BitConvertHelper.ToInt16(data, b);
|
||||
b += 2;
|
||||
this.EnergyPerHour = BitConvertHelper.ToInt16(data, b);
|
||||
b += 2;
|
||||
this.EnergyPerMinute = data[b];
|
||||
b += 1;
|
||||
//b += this.SizeOfDataForFlag(RowerDataFlag.ExpendedEnergy);
|
||||
}
|
||||
if (this.Flags.HasFlag(RowerDataFlag.HeartRate))
|
||||
{
|
||||
//this.HeartRate = new int?((int)BitConverter.ToUInt8(data, (int)b));
|
||||
//(int)data[(int)b];
|
||||
b += this.SizeOfDataForFlag(RowerDataFlag.HeartRate);
|
||||
}
|
||||
if (this.Flags.HasFlag(RowerDataFlag.MetabolicEquivalent))
|
||||
{
|
||||
b += this.SizeOfDataForFlag(RowerDataFlag.MetabolicEquivalent);
|
||||
}
|
||||
if (this.Flags.HasFlag(RowerDataFlag.ElapsedTime))
|
||||
{
|
||||
this.ElapsedTime = BitConvertHelper.ToInt16(data, b);
|
||||
b += this.SizeOfDataForFlag(RowerDataFlag.ElapsedTime);
|
||||
}
|
||||
if (this.Flags.HasFlag(RowerDataFlag.RemainingTime))
|
||||
{
|
||||
b += this.SizeOfDataForFlag(RowerDataFlag.RemainingTime);
|
||||
}
|
||||
if (this.Flags.HasFlag(RowerDataFlag.Pull))
|
||||
{
|
||||
List<ushort> list = new List<ushort>();
|
||||
for (int pullB = 4; pullB < data.Length; pullB += 2)
|
||||
{
|
||||
var val = BitConverter.ToUInt16(data, pullB);
|
||||
list.Add(val);
|
||||
PullValue = val;
|
||||
}
|
||||
}
|
||||
Debug.Log("原始数据:" + string.Join(",", data));
|
||||
}
|
||||
public void Reset()
|
||||
{
|
||||
this.StrokeRate = 0;
|
||||
this.StrokeCount = 0;
|
||||
this.AverageStrokeRate = 0;
|
||||
this.TotalDistance = 0;
|
||||
this.InstantaneousPace = 0;
|
||||
this.AveragePace = 0;
|
||||
this.InstantaneousPower = 0;
|
||||
this.AveragePower = 0;
|
||||
this.ResistanceLevel = 0;
|
||||
this.TotalEnergy = 0;
|
||||
this.EnergyPerHour = 0;
|
||||
this.EnergyPerMinute = 0;
|
||||
this.ElapsedTime = 0;
|
||||
}
|
||||
|
||||
public int SizeOfDataForFlag(RowerDataFlag flag)
|
||||
{
|
||||
int num = 0;
|
||||
switch (flag)
|
||||
{
|
||||
//case RowerDataFlag.MoreData:
|
||||
// break;
|
||||
case RowerDataFlag.AverageStrokeRate:
|
||||
num = 1;
|
||||
break;
|
||||
case RowerDataFlag.TotalDistance:
|
||||
num = 3;
|
||||
break;
|
||||
case RowerDataFlag.InstantaneousPace:
|
||||
num = 2;
|
||||
break;
|
||||
case RowerDataFlag.AveragePace:
|
||||
num = 2;
|
||||
break;
|
||||
case RowerDataFlag.InstantPower:
|
||||
num = 2;
|
||||
break;
|
||||
case RowerDataFlag.AveragePower:
|
||||
num = 2;
|
||||
break;
|
||||
case RowerDataFlag.ResistanceLevel:
|
||||
num = 2;
|
||||
break;
|
||||
case RowerDataFlag.ExpendedEnergy:
|
||||
num = 5;
|
||||
break;
|
||||
case RowerDataFlag.HeartRate:
|
||||
num = 1;
|
||||
break;
|
||||
case RowerDataFlag.MetabolicEquivalent:
|
||||
num = 1;
|
||||
break;
|
||||
case RowerDataFlag.ElapsedTime:
|
||||
num = 2;
|
||||
break;
|
||||
case RowerDataFlag.RemainingTime:
|
||||
num = 2;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return num;
|
||||
}
|
||||
|
||||
public void SetUnavailable()
|
||||
{
|
||||
//throw new NotImplementedException();
|
||||
}
|
||||
//254 0是前七字節 1 41是第二包 1 64是拉力
|
||||
[Flags]
|
||||
public enum RowerDataFlag
|
||||
{
|
||||
MoreData = 1,
|
||||
AverageStrokeRate = 2,
|
||||
TotalDistance = 4,
|
||||
InstantaneousPace = 8,
|
||||
AveragePace = 16,
|
||||
InstantPower = 32,
|
||||
AveragePower = 64,
|
||||
ResistanceLevel = 128,
|
||||
ExpendedEnergy = 256,
|
||||
HeartRate = 512,
|
||||
MetabolicEquivalent = 1024,
|
||||
ElapsedTime = 2048,
|
||||
RemainingTime = 4096,
|
||||
//单周期能耗
|
||||
SingleEnergy = 8192,
|
||||
//拉力曲綫
|
||||
Pull = 16384
|
||||
}
|
||||
|
||||
|
||||
|
||||
private byte SizeOfDataForFlag1(RowerDataFlag flag)
|
||||
{
|
||||
if (flag <= RowerDataFlag.InstantPower)
|
||||
{
|
||||
//if (flag <= RowerDataFlag.AverageCadence)
|
||||
//{
|
||||
// if (flag - RowerDataFlag.MoreData > 1 && flag != RowerDataFlag.InstantCadence && flag != RowerDataFlag.AverageCadence)
|
||||
// {
|
||||
// return 0;
|
||||
// }
|
||||
//}
|
||||
//else
|
||||
{
|
||||
if (flag == RowerDataFlag.TotalDistance)
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
if (flag != RowerDataFlag.ResistanceLevel && flag != RowerDataFlag.InstantPower)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (flag <= RowerDataFlag.HeartRate)
|
||||
{
|
||||
if (flag != RowerDataFlag.AveragePower)
|
||||
{
|
||||
if (flag == RowerDataFlag.ExpendedEnergy)
|
||||
{
|
||||
return 5;
|
||||
}
|
||||
if (flag != RowerDataFlag.HeartRate)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (flag != RowerDataFlag.MetabolicEquivalent && flag != RowerDataFlag.ElapsedTime && flag != RowerDataFlag.RemainingTime)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 87207b21c4f11ef4b866ac490a88620f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -7,6 +7,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Assets.Scripts.Devices.Ble.Devices
|
||||
{
|
||||
@@ -16,21 +17,22 @@ namespace Assets.Scripts.Devices.Ble.Devices
|
||||
public int Power { get => _ftmsIndoorBikeData.InstantPower.GetValueOrDefault(0); set => throw new NotImplementedException(); }
|
||||
public double Speed { get => _ftmsIndoorBikeData.InstantSpeed.GetValueOrDefault(0); set => throw new NotImplementedException(); }
|
||||
public int Cadence { get => _ftmsIndoorBikeData.InstantCadence.GetValueOrDefault(0); set => throw new NotImplementedException(); }
|
||||
private FtmsRowerData _rowerData;
|
||||
public FtmsRowerData rowerData { get => _rowerData; }
|
||||
|
||||
private FtmsIndoorBikeData _ftmsIndoorBikeData;
|
||||
|
||||
private List<BleServiceInfo> Services;
|
||||
private BleCharacteristicInfo controlPointCharacteristic;
|
||||
|
||||
public Ftms(BlePeripheralInfo peripheralInfo, IBleWinHwInterface bleWinHwInterface) :base(peripheralInfo, bleWinHwInterface, Ant.SensorType.Trainer)
|
||||
{
|
||||
this._ftmsIndoorBikeData = new FtmsIndoorBikeData();
|
||||
base.Characteristics.Add(this._ftmsIndoorBikeData);
|
||||
|
||||
base.Characteristics.Add(new FtmsFitnessMachineFeature());
|
||||
|
||||
//划船机
|
||||
this._rowerData = new FtmsRowerData();
|
||||
base.Characteristics.Add(rowerData);
|
||||
bleWinHwInterface.CharacteristicReadEvent += CharacteristicReadMainCallback;
|
||||
|
||||
}
|
||||
|
||||
protected override void CreateServices(List<BleServiceInfo> discoveredServices)
|
||||
@@ -56,6 +58,17 @@ namespace Assets.Scripts.Devices.Ble.Devices
|
||||
{
|
||||
this.controlPointCharacteristic = character;
|
||||
}
|
||||
else if (character.MatchGuid(ServiceUuids.Characteristics.RowerData))
|
||||
{
|
||||
Debug.Log("划船机");
|
||||
this.hwInterface.SubscribeCharacteristic(character, (hw, cha, res) =>
|
||||
{
|
||||
//Debug.Log("1111111111111111111111");
|
||||
//Debug.WriteLine(res.ToString());
|
||||
var res1 = (res as BleResponse<byte[]>);
|
||||
Debug.Log("收到消息划船机:" + string.Join(",", res1));
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
using Assets.Scripts.Ble;
|
||||
using Assets.Scripts.Devices.Ant.Interfaces;
|
||||
using Assets.Scripts.Devices.Ble.Characteristic;
|
||||
using Assets.Scripts.Devices.Ble.Interfaces;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Assets.Scripts.Devices.Ble.Devices
|
||||
{
|
||||
public class FtmsRower : BleDevice, IRowerDevice
|
||||
{
|
||||
private FtmsRowerData _rowerData;
|
||||
public FtmsRowerData rowerData { get => _rowerData; }
|
||||
|
||||
|
||||
private List<BleServiceInfo> Services;
|
||||
private BleCharacteristicInfo controlPointCharacteristic;
|
||||
public FtmsRower(BlePeripheralInfo peripheralInfo, IBleWinHwInterface bleWinHwInterface) :base(peripheralInfo, bleWinHwInterface, Ant.SensorType.Rower)
|
||||
{
|
||||
Debug.Log(24);
|
||||
base.Characteristics.Add(new FtmsFitnessMachineFeature());
|
||||
//划船机
|
||||
this._rowerData = new FtmsRowerData();
|
||||
base.Characteristics.Add(rowerData);
|
||||
bleWinHwInterface.CharacteristicReadEvent += CharacteristicReadMainCallback;
|
||||
}
|
||||
|
||||
protected override void CreateServices(List<BleServiceInfo> discoveredServices)
|
||||
{
|
||||
this.Services = discoveredServices;
|
||||
|
||||
foreach (var service in this.Services)
|
||||
{
|
||||
hwInterface.DiscoverCharacteristic(service, (hwInterface, service1, response) =>
|
||||
{
|
||||
foreach (var character in response.Data)
|
||||
{
|
||||
if (character.MatchGuid(ServiceUuids.Characteristics.RowerData))
|
||||
{
|
||||
Debug.Log("划船机");
|
||||
this.hwInterface.SubscribeCharacteristic(character, (hw, cha, res) =>
|
||||
{
|
||||
//Debug.Log("1111111111111111111111");
|
||||
//Debug.WriteLine(res.ToString());
|
||||
var res1 = (res as BleResponse<byte[]>);
|
||||
Debug.Log("收到消息划船机:" + string.Join(",", res1));
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void CharacteristicReadMainCallback(IBleWinHwInterface hwInterface, BleCharacteristicInfo characteristic, BleResponse<byte[]> response)
|
||||
{
|
||||
foreach (var item in base.Characteristics)
|
||||
{
|
||||
if (characteristic.MatchGuid(item.Uuid))
|
||||
{
|
||||
//Debug.Log(string.Join(",", response.Data));
|
||||
item.HandleAttributeReceived(response.Data);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e62cf4fc3378d5c4eb76643a9d3ca528
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -365,6 +365,8 @@ namespace Assets.Scripts.Ble
|
||||
|
||||
// Token: 0x04002908 RID: 10504
|
||||
public static Guid WahooFitnessSensorMeasurementInput = new Guid("A026E016-0A7D-4AB3-97FA-F1500F9FEB8B");
|
||||
|
||||
public static Guid RowerData = new Guid("00002AD1-0000-1000-8000-00805F9B34FB");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -134,9 +134,17 @@ namespace Assets.Scripts.Ble
|
||||
{
|
||||
continue;
|
||||
}
|
||||
Debug.Log($"設備信息,{item.IdGuid},{string.Join(";",item.IdByteArray)}" );
|
||||
if (item.IdByteArray == ServiceUuids.Ftms)
|
||||
{
|
||||
sensor = SensorType.Trainer;
|
||||
if (App.IsRowerMode)
|
||||
{
|
||||
sensor = SensorType.Rower;
|
||||
}
|
||||
else
|
||||
{
|
||||
sensor = SensorType.Trainer;
|
||||
}
|
||||
}
|
||||
else if (item.IdByteArray == ServiceUuids.HeartRate)
|
||||
{
|
||||
|
||||
@@ -8,6 +8,21 @@ using UnityEngine;
|
||||
|
||||
public static class PFConstants
|
||||
{
|
||||
/// <summary>
|
||||
/// 划船机训练保存在本地的路径
|
||||
/// </summary>
|
||||
public static string RowerRecordFolder
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!Directory.Exists(Application.persistentDataPath + "/RowerRecords/"))
|
||||
{
|
||||
Directory.CreateDirectory(Application.persistentDataPath + "/RowerRecords/");
|
||||
}
|
||||
|
||||
return Application.persistentDataPath + "/RowerRecords/";
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 课程训练保存在本地的路径
|
||||
/// </summary>
|
||||
|
||||
@@ -37,15 +37,14 @@ public class MainController : BaseScene
|
||||
//rect1.offsetMax = Vector2.zero;
|
||||
//transform.Find("ModalPanel").GetComponent<RectTransform>().sizeDelta = new Vector2(844, 390);
|
||||
#endif
|
||||
//StartCoroutine(setWidth());
|
||||
//App.MainDeviceAdapter.StartScan();
|
||||
|
||||
}
|
||||
|
||||
// Start is called before the first frame update
|
||||
async void Start()
|
||||
{
|
||||
|
||||
|
||||
{
|
||||
|
||||
UIManager.Instance.Root = root;
|
||||
UIManager.Instance.MainPanel = this.transform.Find("Panel").GetComponent<PFUIPanel>();
|
||||
UIManager.Instance.ModalsPanel = this.transform.Find("ModalPanel").GetComponent<PFUIPanel>();
|
||||
@@ -63,6 +62,11 @@ public class MainController : BaseScene
|
||||
//{
|
||||
// UIManager.ShowHomePanel();
|
||||
//});
|
||||
if (App.IsRowerMode)
|
||||
{
|
||||
UIManager.ShowRowerPanel();
|
||||
return;
|
||||
}
|
||||
if (App.MainSceneParam.ContainsKey("Name") && !string.IsNullOrEmpty(App.MainSceneParam["Name"]))
|
||||
{
|
||||
UIManager.ShowHomePanel();
|
||||
@@ -90,6 +94,7 @@ public class MainController : BaseScene
|
||||
//UIManager.ShowBigMapPanel();
|
||||
//UIManager.ShowEarthPanel();
|
||||
}
|
||||
|
||||
Task.Run(() => {
|
||||
UIManager.UpdateJoinCompetition();//查询当前我参加的赛事
|
||||
});
|
||||
@@ -101,6 +106,12 @@ public class MainController : BaseScene
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
if (App.canvasWidth != transform.GetComponent<RectTransform>().sizeDelta.x)
|
||||
{
|
||||
App.canvasWidth = transform.GetComponent<RectTransform>().sizeDelta.x;
|
||||
Debug.Log(App.canvasWidth);
|
||||
}
|
||||
//Debug.Log(transform.GetComponent<RectTransform>().sizeDelta.x);
|
||||
t -= Time.deltaTime;
|
||||
while (t <= 0)
|
||||
{
|
||||
|
||||
@@ -13,6 +13,9 @@ public class Confirm : PFUIPanel
|
||||
private PFUIText _content;
|
||||
private PfUIButton _ok;
|
||||
private UnityAction _callback;
|
||||
|
||||
public UnityAction _cancelCallback;
|
||||
|
||||
private PfUIButton _cancel;
|
||||
protected override void Awake()
|
||||
{
|
||||
@@ -47,6 +50,10 @@ public class Confirm : PFUIPanel
|
||||
});
|
||||
UIManager.AddEvent(_cancel.gameObject, EventTriggerType.PointerClick, (e) =>
|
||||
{
|
||||
if (_cancelCallback != null)
|
||||
{
|
||||
_cancelCallback();
|
||||
}
|
||||
this.Close();
|
||||
});
|
||||
}
|
||||
@@ -57,7 +64,7 @@ public class Confirm : PFUIPanel
|
||||
|
||||
}
|
||||
|
||||
public void Set(string title, string content, UnityAction callback)
|
||||
public void Set(string title, string content, UnityAction callback,UnityAction cancelCallback)
|
||||
{
|
||||
//if(text == null)
|
||||
//{
|
||||
@@ -67,6 +74,7 @@ public class Confirm : PFUIPanel
|
||||
_title.Text = title;
|
||||
_content.Text = content;
|
||||
_callback = callback;
|
||||
_cancelCallback = cancelCallback;
|
||||
}
|
||||
|
||||
public void SetType(int type)
|
||||
|
||||
@@ -175,7 +175,10 @@ public class ConnectDeviceModal : PFUIPanel
|
||||
devices = App.MainDeviceAdapter.GetDevices().Where(d => d.Sensor == SensorType || (d is ISpeedDevice && d.State == DeviceState.Connected)).OrderBy(d => d.Priority).ToList();
|
||||
break;
|
||||
case SensorType.Trainer:
|
||||
devices = App.MainDeviceAdapter.GetDevices().Where(d => d.Sensor == SensorType).ToList();
|
||||
devices = App.MainDeviceAdapter.GetDevices().Where(d => d.Sensor == SensorType && d is ITrainerDevice).ToList();
|
||||
break;
|
||||
case SensorType.Rower:
|
||||
devices = App.MainDeviceAdapter.GetDevices().Where(d => d.Sensor == SensorType && d is IRowerDevice).ToList();
|
||||
break;
|
||||
case SensorType.VirtualPower:
|
||||
break;
|
||||
|
||||
@@ -13,12 +13,13 @@ using Assets.Scripts;
|
||||
using DG.Tweening;
|
||||
using Assets.Scripts.UI.Prefab.Device;
|
||||
using Assets.Scripts.Devices;
|
||||
using Assets.Scripts.Devices.Ble;
|
||||
|
||||
public class DeviceView : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private SensorType mType;
|
||||
|
||||
|
||||
private SensorType SensorType
|
||||
{
|
||||
get
|
||||
@@ -162,7 +163,7 @@ public class DeviceView : MonoBehaviour
|
||||
{
|
||||
if (SensorType == SensorType.Power)
|
||||
{
|
||||
sprite0 = Resources.Load<Sprite>("Images/Devices/Power_0");
|
||||
sprite0 = Resources.Load<Sprite>("Images/Devices/Power_1");
|
||||
sprite1 = Resources.Load<Sprite>("Images/Devices/Power_1");
|
||||
sprite3 = Resources.Load<Sprite>("Images/Devices/Power_4");
|
||||
|
||||
@@ -170,7 +171,7 @@ public class DeviceView : MonoBehaviour
|
||||
}
|
||||
else if (SensorType == SensorType.Speed)
|
||||
{
|
||||
sprite0 = Resources.Load<Sprite>("Images/Devices/Speed_0");
|
||||
sprite0 = Resources.Load<Sprite>("Images/Devices/Speed_1");
|
||||
sprite1 = Resources.Load<Sprite>("Images/Devices/Speed_1");
|
||||
sprite3 = Resources.Load<Sprite>("Images/Devices/Speed_4");
|
||||
|
||||
@@ -178,7 +179,7 @@ public class DeviceView : MonoBehaviour
|
||||
}
|
||||
else if (SensorType == SensorType.Cadence || SensorType == SensorType.SpeedCadence)
|
||||
{
|
||||
sprite0 = Resources.Load<Sprite>("Images/Devices/Cadence_0");
|
||||
sprite0 = Resources.Load<Sprite>("Images/Devices/Cadence_1");
|
||||
sprite1 = Resources.Load<Sprite>("Images/Devices/Cadence_1");
|
||||
sprite3 = Resources.Load<Sprite>("Images/Devices/Cadence_4");
|
||||
|
||||
@@ -186,18 +187,24 @@ public class DeviceView : MonoBehaviour
|
||||
}
|
||||
else if (SensorType == SensorType.HeartRate)
|
||||
{
|
||||
sprite0 = Resources.Load<Sprite>("Images/Devices/Heart Rate_0");
|
||||
sprite0 = Resources.Load<Sprite>("Images/Devices/Heart Rate_1");
|
||||
sprite1 = Resources.Load<Sprite>("Images/Devices/Heart Rate_1");
|
||||
sprite3 = Resources.Load<Sprite>("Images/Devices/Heart Rate_4");
|
||||
|
||||
powerUnit.text = "BPM";
|
||||
}
|
||||
else if(SensorType == SensorType.Trainer)
|
||||
else if (SensorType == SensorType.Trainer)
|
||||
{
|
||||
sprite0 = Resources.Load<Sprite>("Images/Devices/Trainer_0");
|
||||
sprite0 = Resources.Load<Sprite>("Images/Devices/Trainer_1");
|
||||
sprite1 = Resources.Load<Sprite>("Images/Devices/Trainer_1");
|
||||
sprite3 = Resources.Load<Sprite>("Images/Devices/Trainer_4");
|
||||
}
|
||||
else if (SensorType == SensorType.Rower)
|
||||
{
|
||||
sprite0 = Resources.Load<Sprite>("Images/Rower/设备 - 划船机 - 未连接");
|
||||
sprite1 = Resources.Load<Sprite>("Images/Rower/设备 - 划船机 - 未连接");
|
||||
sprite3 = Resources.Load<Sprite>("Images/Rower/设备 - 划船机");
|
||||
}
|
||||
}
|
||||
|
||||
// Start is called before the first frame update
|
||||
@@ -304,10 +311,7 @@ public class DeviceView : MonoBehaviour
|
||||
//}
|
||||
});
|
||||
DeviceCache.Add(connectedDevice);
|
||||
|
||||
Debug.Log("connected");
|
||||
|
||||
|
||||
}
|
||||
|
||||
logo.sprite = sprite3;
|
||||
@@ -351,6 +355,8 @@ public class DeviceView : MonoBehaviour
|
||||
return "Speed Meter";
|
||||
case SensorType.Trainer:
|
||||
return "Smart Trainer";
|
||||
case SensorType.Rower:
|
||||
return "Rower Machine";
|
||||
case SensorType.VirtualPower:
|
||||
break;
|
||||
default:
|
||||
@@ -424,6 +430,8 @@ public class DeviceView : MonoBehaviour
|
||||
return item;
|
||||
case SensorType.Speed:
|
||||
return devices.FirstOrDefault(d => d is ISpeedDevice);
|
||||
case SensorType.Rower:
|
||||
return devices.FirstOrDefault(d => d.Sensor == SensorType.Rower);
|
||||
case SensorType.Trainer:
|
||||
var item3 = devices.FirstOrDefault(d => d.Sensor == SensorType.Trainer);
|
||||
return item3;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Collections;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
@@ -50,6 +51,14 @@ public class MainNav : MonoBehaviour
|
||||
});
|
||||
}
|
||||
|
||||
public void HideDevice()
|
||||
{
|
||||
if (transform.Find("Device"))
|
||||
{
|
||||
transform.Find("Device").gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
@@ -64,7 +73,13 @@ public class MainNav : MonoBehaviour
|
||||
|
||||
public void ShowExit()
|
||||
{
|
||||
exit.SetActive(true);
|
||||
home.SetActive(false);
|
||||
if (exit)
|
||||
{
|
||||
exit.SetActive(true);
|
||||
}
|
||||
if (home)
|
||||
{
|
||||
home.SetActive(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -71,6 +71,14 @@ public class HomeController : PFUIPanel
|
||||
UIManager.ShowUserInfoPanel();
|
||||
//UIManager.ShowConfirm("Quit", "Do you want to quit PowerFun?", null);
|
||||
});
|
||||
if (transform.Find("Other/BtnRower"))
|
||||
{
|
||||
UIManager.AddEvent(transform.Find("Other/BtnRower").gameObject, EventTriggerType.PointerClick, b =>
|
||||
{
|
||||
UIManager.ShowRowerPanel();
|
||||
});
|
||||
}
|
||||
|
||||
//GetSummary();
|
||||
dict = new Dictionary<string, Sprite[]>
|
||||
{
|
||||
|
||||
@@ -0,0 +1,347 @@
|
||||
using Assets.Scenes.Ride.Scripts;
|
||||
using Assets.Scripts;
|
||||
using Assets.Scripts.Apis.Models;
|
||||
using Assets.Scripts.Devices.Ant;
|
||||
using Assets.Scripts.Devices.Ant.Interfaces;
|
||||
using Assets.Scripts.Devices.Ble;
|
||||
using Assets.Scripts.Devices.Ble.Characteristic;
|
||||
using Assets.Scripts.Devices.Ble.Devices;
|
||||
using ChartAndGraph;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class RowerHomeScript : PFUIPanel
|
||||
{
|
||||
private class TempRowerCalc
|
||||
{
|
||||
public int power { get; set; }
|
||||
public ushort pace { get; set; }
|
||||
public uint rate { get; set; }
|
||||
public int heartRate { get; set; }
|
||||
}
|
||||
/// <summary>
|
||||
/// 划船机数据
|
||||
/// </summary>
|
||||
private FtmsRowerData RowerData
|
||||
{
|
||||
get
|
||||
{
|
||||
var device = App.MainDeviceAdapter.GetDevices().FirstOrDefault(d => (d.State == DeviceState.Connected || d.State == DeviceState.Connecting) && d.Sensor == SensorType.Rower);
|
||||
if (device != null)
|
||||
{
|
||||
return ((IRowerDevice)device).rowerData;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 心率数据
|
||||
/// </summary>
|
||||
private int? HeartRate
|
||||
{
|
||||
get
|
||||
{
|
||||
var device = App.MainDeviceAdapter.GetDevices().FirstOrDefault(d => (d.State == DeviceState.Connected || d.State == DeviceState.Connecting) && d.Sensor == SensorType.HeartRate);
|
||||
if (device != null)
|
||||
{
|
||||
return ((IHeartRateDevice)device).HeartRate;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
GameObject btnStart;
|
||||
Transform left, bottom;
|
||||
float timer = 1.0f;
|
||||
EventHandler PaintPullCurveDelegate;
|
||||
List<DoubleVector2> pullList = new List<DoubleVector2>();
|
||||
Dictionary<object, Sprite> spriteDict;
|
||||
List<string> records;
|
||||
List<TempRowerCalc> values;
|
||||
DateTime startTime,createTime;
|
||||
double Kj = 0;
|
||||
protected override void Awake()
|
||||
{
|
||||
spriteDict = new Dictionary<object, Sprite>()
|
||||
{
|
||||
{"Start",Resources.Load<Sprite>("Images/Rower/System_play")},
|
||||
{"Untagged",Resources.Load<Sprite>("Images/Rower/System_pause")},
|
||||
{0,Resources.Load<Sprite>("Images/Rower/序列帧/划船机0001") },
|
||||
{1,Resources.Load<Sprite>("Images/Rower/序列帧/划船机0002") },
|
||||
{2,Resources.Load<Sprite>("Images/Rower/序列帧/划船机0003") },
|
||||
{3,Resources.Load<Sprite>("Images/Rower/序列帧/划船机0004") },
|
||||
{4,Resources.Load<Sprite>("Images/Rower/序列帧/划船机0005") },
|
||||
{5,Resources.Load<Sprite>("Images/Rower/序列帧/划船机0006") },
|
||||
{6,Resources.Load<Sprite>("Images/Rower/序列帧/划船机0007") },
|
||||
{7,Resources.Load<Sprite>("Images/Rower/序列帧/划船机0008") },
|
||||
{8,Resources.Load<Sprite>("Images/Rower/序列帧/划船机0009") },
|
||||
{9,Resources.Load<Sprite>("Images/Rower/序列帧/划船机0010") },
|
||||
{10,Resources.Load<Sprite>("Images/Rower/序列帧/划船机0011") },
|
||||
{11,Resources.Load<Sprite>("Images/Rower/序列帧/划船机0012") },
|
||||
{12,Resources.Load<Sprite>("Images/Rower/序列帧/划船机0013") },
|
||||
{13,Resources.Load<Sprite>("Images/Rower/序列帧/划船机0014") },
|
||||
{14,Resources.Load<Sprite>("Images/Rower/序列帧/划船机0015") },
|
||||
};
|
||||
GetComponent<RectTransform>().localScale = Vector3.one;
|
||||
GetComponent<RectTransform>().localPosition = Vector3.zero;
|
||||
var mainNav = this.transform.Find("MainNav").GetComponent<MainNav>();
|
||||
mainNav.ShowExit();
|
||||
mainNav.HideDevice();
|
||||
var btnHome = transform.Find("Other/BtnHome").gameObject;
|
||||
UIManager.AddEvent(btnHome, UnityEngine.EventSystems.EventTriggerType.PointerClick, b => ReturnHome());
|
||||
btnStart = transform.Find("Other1/BtnStart").gameObject;
|
||||
UIManager.AddEvent(btnStart, UnityEngine.EventSystems.EventTriggerType.PointerClick, b => HandleStartOrPause());
|
||||
left = transform.Find("Left");
|
||||
bottom = transform.Find("Bottom");
|
||||
PaintPullCurveDelegate = new EventHandler(PaintPullCurve);
|
||||
Init();
|
||||
}
|
||||
|
||||
public override void Show()
|
||||
{
|
||||
base.Show();
|
||||
Init();
|
||||
//transform.Find("Left/Rower").GetComponent<RowerAnimation>().StartAnimation();
|
||||
}
|
||||
private void HandleStartOrPause()
|
||||
{
|
||||
//UIManager.ShowRowerResult();
|
||||
//return;
|
||||
if (btnStart.CompareTag("Start"))
|
||||
{
|
||||
if (RowerData == null)
|
||||
{
|
||||
Utils.showToast(null, "Please connect the device!");
|
||||
return;
|
||||
}
|
||||
if (RowerData != null)
|
||||
{
|
||||
RowerData.PullChanged += PaintPullCurveDelegate;
|
||||
}
|
||||
btnStart.GetComponent<Image>().sprite = spriteDict["Untagged"];
|
||||
startTime = UIManager.Now.GetDateTime();
|
||||
TimerTicks();
|
||||
openTimer = true;
|
||||
timer = 1.0f;
|
||||
btnStart.tag = "Untagged";
|
||||
}
|
||||
else
|
||||
{
|
||||
UIManager.ShowConfirm("Quit", "Do you want to keep the record?", () =>
|
||||
{
|
||||
UIManager.CloseConfirm();
|
||||
Save();
|
||||
Init();
|
||||
},cancel:()=>
|
||||
{
|
||||
Init();
|
||||
});
|
||||
}
|
||||
Debug.Log(RowerData);
|
||||
//StartCoroutine();
|
||||
}
|
||||
|
||||
private void Save()
|
||||
{
|
||||
createTime = UIManager.Now.GetDateTime();
|
||||
var bleDevice = App.MainDeviceAdapter.GetDevices().FirstOrDefault(d => (d.State == DeviceState.Connected || d.State == DeviceState.Connecting) && d.Sensor == SensorType.Rower) as BleDevice;
|
||||
RowerRecordModel model = new RowerRecordModel();
|
||||
model.Ticks = records.Count;
|
||||
if (bleDevice != null)
|
||||
{
|
||||
model.ManufacturerName = bleDevice.Name + " " + bleDevice.Network + " " + bleDevice.Sensor;
|
||||
model.DeviceNumber = $"{ bleDevice.Address },{ bleDevice.Sensor }";
|
||||
}
|
||||
model.Id = Guid.NewGuid().ToString();
|
||||
model.Weight = App.CurrentUser.Weight;
|
||||
model.Kj = RowerData.TotalEnergy;
|
||||
model.StartTime = startTime;
|
||||
model.CreateTime = createTime;
|
||||
Debug.Log(values.Count);
|
||||
if (values.Count > 0)
|
||||
{
|
||||
model.MaxPower = values.Max(x => x.power);
|
||||
model.MaxPace = values.Min(x => x.pace);
|
||||
model.MaxRate = values.Max(x => x.rate);
|
||||
model.MaxHeartRate = values.Max(x => x.heartRate);
|
||||
model.AvgPower = values.Average(x => x.power);
|
||||
model.AvgPace = values.Average(x => x.pace);
|
||||
model.AvgRate = values.Average(x => x.rate);
|
||||
model.AvgHeartRate = (int)values.Average(x => x.heartRate);
|
||||
}
|
||||
model.StrokeCount = RowerData.StrokeCount;
|
||||
model.TotalTime = RowerData.ElapsedTime;
|
||||
model.TotalDistance = RowerData.TotalDistance;
|
||||
var path = PFConstants.RowerRecordFolder + "/" + model.Id;
|
||||
Helper.CreateDirectoryIfNotExsit(path);
|
||||
var files = new List<string>();
|
||||
try
|
||||
{
|
||||
var fname = path + "/" + model.Id + ".txt";
|
||||
using (var fs = new FileInfo(fname).OpenWrite())
|
||||
{
|
||||
var stream = new StreamWriter(fs);
|
||||
stream.BaseStream.Seek(0, SeekOrigin.End);
|
||||
foreach (var item in records)
|
||||
{
|
||||
stream.Write(item + "\r\n");
|
||||
}
|
||||
stream.Flush();
|
||||
stream.Close();
|
||||
files.Add(fname);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Helper.DelectDir(path);
|
||||
Debug.Log(ex.Message);
|
||||
}
|
||||
UIManager.ShowRowerWelldone(model);
|
||||
Task.Run(()=>
|
||||
{
|
||||
var res = ConfigHelper.rowerApi.Add(model, files);
|
||||
});
|
||||
}
|
||||
|
||||
private void Init()
|
||||
{
|
||||
if (RowerData != null)
|
||||
{
|
||||
RowerData.PullChanged -= PaintPullCurveDelegate;
|
||||
RowerData.Reset();
|
||||
}
|
||||
btnStart.tag = "Start";
|
||||
btnStart.GetComponent<Image>().sprite = spriteDict["Start"];
|
||||
left.Find("Rower").GetComponent<Image>().sprite = spriteDict[0];
|
||||
left.Find("LeftImage/Value").GetComponent<Image>().fillAmount = 0;
|
||||
left.Find("RightImage/Value").GetComponent<Image>().fillAmount = 0;
|
||||
left.Find("Times/Value").GetComponent<Text>().text = "---";
|
||||
left.Find("Calories/Value").GetComponent<Text>().text = "---";
|
||||
pullList = new List<DoubleVector2>();
|
||||
transform.Find("Mid/GraphChart").GetComponent<RowerGraphChartFeed>().SetData(pullList);
|
||||
openTimer = false;
|
||||
bottom.Find("Time/Value").GetComponent<Text>().text = "---";
|
||||
bottom.Find("KM/Value").GetComponent<Text>().text = "---";
|
||||
bottom.Find("W/Value").GetComponent<Text>().text = "---";
|
||||
bottom.Find("W/AvgValue").GetComponent<Text>().text = "---";
|
||||
bottom.Find("500/Value").GetComponent<Text>().text = "---";
|
||||
bottom.Find("500/AvgValue").GetComponent<Text>().text = "---";
|
||||
bottom.Find("MS/Value").GetComponent<Text>().text = "---";
|
||||
bottom.Find("MS/AvgValue").GetComponent<Text>().text = "---";
|
||||
bottom.Find("BPM/Value").GetComponent<Text>().text = "---";
|
||||
records = new List<string>();
|
||||
values = new List<TempRowerCalc>();
|
||||
Kj = 0;
|
||||
x = 0;
|
||||
}
|
||||
private void ReturnHome()
|
||||
{
|
||||
UIManager.ShowHomePanel();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
bool openTimer = false;
|
||||
double x = 0f;
|
||||
//List<ushort> tempList = new List<ushort>()
|
||||
//{
|
||||
// 0,1,4,5,12,13,16,20,30,40,50,60,500
|
||||
//};
|
||||
//int tempx = 0;
|
||||
void TimerTicks()
|
||||
{
|
||||
//Debug.Log(123);
|
||||
//PaintPullCurve(tempList[(tempx++) % tempList.Count]);
|
||||
if (RowerData == null) return;
|
||||
|
||||
bottom.Find("Time/Value").GetComponent<Text>().text = TimeSpan.FromSeconds(RowerData.ElapsedTime).ToString();
|
||||
bottom.Find("KM/Value").GetComponent<Text>().text = RowerData.TotalDistance.ToString();
|
||||
var power = RowerData.InstantaneousPower;
|
||||
bottom.Find("W/Value").GetComponent<Text>().text = power.ToString();
|
||||
bottom.Find("W/AvgValue").GetComponent<Text>().text = RowerData.AveragePower.ToString();
|
||||
var pace = RowerData.InstantaneousPace;
|
||||
bottom.Find("500/Value").GetComponent<Text>().text = TimeSpan.FromSeconds(pace).ToString(@"mm\:ss");
|
||||
bottom.Find("500/AvgValue").GetComponent<Text>().text = TimeSpan.FromSeconds(RowerData.AveragePace).ToString(@"mm\:ss");
|
||||
var rate = RowerData.StrokeRate;
|
||||
bottom.Find("MS/Value").GetComponent<Text>().text = rate.ToString();
|
||||
bottom.Find("MS/AvgValue").GetComponent<Text>().text = RowerData.AverageStrokeRate.ToString();
|
||||
var heartRate = HeartRate ?? 0;
|
||||
bottom.Find("BPM/Value").GetComponent<Text>().text = heartRate.ToString();
|
||||
left.Find("Times/Value").GetComponent<Text>().text = RowerData.StrokeCount.ToString();
|
||||
left.Find("Calories/Value").GetComponent<Text>().text = RowerData.TotalEnergy.ToString();
|
||||
records.Add($"{RowerData.StrokeCount},{RowerData.ElapsedTime},{RowerData.TotalDistance},{RowerData.InstantaneousPower},{RowerData.InstantaneousPace},{RowerData.StrokeRate},{RowerData.ResistanceLevel},{heartRate}");
|
||||
values.Add(new TempRowerCalc() { pace = pace, power = power, rate = rate,heartRate = heartRate });
|
||||
//Debug.Log(1);
|
||||
}
|
||||
|
||||
|
||||
void PaintPullCurve(object sender, EventArgs e)
|
||||
{
|
||||
var ftms = (FtmsRowerData)sender;
|
||||
Debug.Log(ftms.PullValue);
|
||||
PaintPullCurve(ftms.PullValue);
|
||||
}
|
||||
void PaintPullCurve(ushort y)
|
||||
{
|
||||
if (y > 1000) y = 1000;
|
||||
//拉力条
|
||||
left.Find("LeftImage/Value").GetComponent<Image>().fillAmount = ((float)y) / 1000;
|
||||
left.Find("RightImage/Value").GetComponent<Image>().fillAmount = ((float)y) / 1000;
|
||||
//动画
|
||||
left.Find("Rower").GetComponent<Image>().sprite = spriteDict[y / 67];
|
||||
//曲线
|
||||
if (y == 0)
|
||||
{
|
||||
if (pullList.Count == 0)
|
||||
{
|
||||
x = 0;
|
||||
pullList.Add(new DoubleVector2(x, y));
|
||||
transform.Find("Mid/GraphChart").GetComponent<RowerGraphChartFeed>().SetData(pullList);
|
||||
}
|
||||
else
|
||||
{
|
||||
x += 0.1;
|
||||
pullList.Add(new DoubleVector2(x, y));
|
||||
transform.Find("Mid/GraphChart").GetComponent<RowerGraphChartFeed>().SetData(pullList);
|
||||
pullList.Clear();
|
||||
x = 0;
|
||||
pullList.Add(new DoubleVector2(x, y));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
x += 0.1;
|
||||
pullList.Add(new DoubleVector2(x, y));
|
||||
transform.Find("Mid/GraphChart").GetComponent<RowerGraphChartFeed>().SetData(pullList);
|
||||
}
|
||||
Debug.Log($"{x},{y}");
|
||||
//transform.Find("Mid/GraphChart").GetComponent<RowerGraphChartFeed>().SetData(pullList);
|
||||
//pullList.Add(new DoubleVector2(x, y));
|
||||
//if (pullList.Count >= 75)
|
||||
//{
|
||||
// pullList.RemoveAt(0);
|
||||
// pullList = pullList.Select(val => new DoubleVector2(val.x - 0.1, val.y)).ToList();
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// x += 0.1f;
|
||||
//}
|
||||
}
|
||||
void Update()
|
||||
{
|
||||
if (openTimer)
|
||||
{
|
||||
timer -= Time.deltaTime;
|
||||
if (timer <= 0)
|
||||
{
|
||||
TimerTicks();
|
||||
timer = 1f + timer;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 406120aa4593dd340844428cea64a7bc
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -13,7 +13,7 @@ public class BigLeftController : MonoBehaviour
|
||||
{
|
||||
route.OnPointerExit(null);
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
route.OnPointerEnter(null);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
using Assets.Scripts;
|
||||
using Assets.Scripts.Apis;
|
||||
using Assets.Scripts.Apis.Models;
|
||||
using DG.Tweening;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
@@ -14,20 +16,23 @@ public class ResultListController : PFUIPanel
|
||||
[SerializeField]Transform routeResult;
|
||||
Transform localRouteItem;
|
||||
Transform scrollContent;
|
||||
Transform routeScroll, matchScroll;
|
||||
Transform routeContent, matchContent;
|
||||
Transform btnRoute, btnMatch,searchInput;
|
||||
Transform routeScroll, matchScroll, rowerScroll;
|
||||
Transform routeContent, matchContent, rowerContent;
|
||||
Transform btnRoute, btnMatch ,btnRower, searchInput;
|
||||
Color c1, c2;
|
||||
// Start is called before the first frame update
|
||||
int pageSize = 20;
|
||||
string name = "";
|
||||
Transform[] contents,scrolls;
|
||||
Transform[] contents,scrolls,btns;
|
||||
Dictionary<int, string> filterOptionDict = new Dictionary<int, string>
|
||||
{
|
||||
{0,"routes" },{1,"competition" }
|
||||
};
|
||||
//交互用
|
||||
public Transform currentItem { get; set; }
|
||||
|
||||
int scrollIndex = 0;
|
||||
ScrollRect scroll;
|
||||
void Awake()
|
||||
{
|
||||
//ApiBase.SetCookie("73385F5F719B610D132C1ECF3E9143272BF15214D57ED91CD7A9DFD832407471535112AAEB8E9271F75D54FBBF2D99F18FA313C1EEA5676F5D722D7FBB07C926BEC5905591BF9AFDDC6336552DF273112C2DA1794E6FA2F465B11FECD2E82E52");
|
||||
@@ -40,30 +45,41 @@ public class ResultListController : PFUIPanel
|
||||
scroll = transform.Find("ListPanel").Find("Scroll").GetComponent<ScrollRect>();
|
||||
btnMatch = transform.Find("ListPanel").Find("BtnMatch");
|
||||
btnRoute = transform.Find("ListPanel").Find("BtnRoute");
|
||||
btnRower = transform.Find("ListPanel").Find("BtnRower");
|
||||
searchInput = transform.Find("ListPanel").Find("SearchInput");
|
||||
scrollContent = scroll.transform.Find("Viewport").Find("Content");
|
||||
routeScroll = scrollContent.Find("RouteList");
|
||||
routeContent = routeScroll.Find("Viewport").Find("Content");
|
||||
matchScroll = scrollContent.Find("MatchList");
|
||||
matchContent = matchScroll.Find("Viewport").Find("Content");
|
||||
contents = new Transform[] { routeContent, matchContent};
|
||||
rowerScroll = scrollContent.Find("RowerList");
|
||||
rowerContent = rowerScroll.Find("Viewport").Find("Content");
|
||||
contents = new Transform[] { routeContent, matchContent, rowerContent};
|
||||
|
||||
if (btnMatch != null)
|
||||
{
|
||||
UIManager.AddEvent(btnMatch.gameObject, EventTriggerType.PointerClick, (b) =>
|
||||
{
|
||||
StartScroll(0);
|
||||
});
|
||||
//btnMatch.GetComponent<Button>().onClick.AddListener(() => StartScroll(0));
|
||||
}
|
||||
if (btnRoute != null)
|
||||
{
|
||||
UIManager.AddEvent(btnRoute.gameObject, EventTriggerType.PointerClick, (b) =>
|
||||
{
|
||||
StartScroll(1);
|
||||
StartScroll(0);
|
||||
});
|
||||
//btnRoute.GetComponent<Button>().onClick.AddListener(() => StartScroll(1));
|
||||
}
|
||||
if (btnMatch != null)
|
||||
{
|
||||
UIManager.AddEvent(btnMatch.gameObject, EventTriggerType.PointerClick, (b) =>
|
||||
{
|
||||
StartScroll(1);
|
||||
});
|
||||
//btnMatch.GetComponent<Button>().onClick.AddListener(() => StartScroll(0));
|
||||
}
|
||||
if (btnRower != null)
|
||||
{
|
||||
UIManager.AddEvent(btnRower.gameObject, EventTriggerType.PointerClick, (b) =>
|
||||
{
|
||||
StartScroll(2);
|
||||
});
|
||||
}
|
||||
btns = new Transform[] { btnRoute,btnMatch,btnRower };
|
||||
if (searchInput != null)
|
||||
{
|
||||
UIManager.AddEvent(searchInput.Find("Button").gameObject, EventTriggerType.PointerClick, (b) =>
|
||||
@@ -88,15 +104,22 @@ public class ResultListController : PFUIPanel
|
||||
{
|
||||
UIManager.AddEvent(matchScroll.gameObject, UnityEngine.EventSystems.EventTriggerType.EndDrag, OnEndDrag);
|
||||
}
|
||||
scrolls = new Transform[] { routeScroll, matchScroll };
|
||||
if (rowerScroll != null)
|
||||
{
|
||||
UIManager.AddEvent(rowerScroll.gameObject, UnityEngine.EventSystems.EventTriggerType.EndDrag, OnEndDrag);
|
||||
|
||||
}
|
||||
scrolls = new Transform[] { routeScroll, matchScroll, rowerScroll };
|
||||
//GetList(0);
|
||||
GetList(1);
|
||||
GetList(2);
|
||||
}
|
||||
|
||||
public void Load()
|
||||
{
|
||||
Debug.Log("刷新show");
|
||||
if (contents != null && contents.Length == 2)
|
||||
//Refresh(contents[0]);
|
||||
if (contents != null && contents.Length == 3)
|
||||
{
|
||||
Debug.Log("刷新show进入");
|
||||
Refresh(contents[scrollIndex]);
|
||||
@@ -151,19 +174,26 @@ public class ResultListController : PFUIPanel
|
||||
}
|
||||
Dictionary<int, bool> isEnd = new Dictionary<int, bool>
|
||||
{
|
||||
{0,false },{1,false }
|
||||
{0,false },{1,false },{2,false }
|
||||
};
|
||||
Dictionary<int, int> pageIndex = new Dictionary<int, int>
|
||||
{
|
||||
{0,0 },{1,0 }
|
||||
{0,0 },{1,0 },{2,0 }
|
||||
};
|
||||
async void GetList(int? sindex = null)
|
||||
{
|
||||
var index = sindex ?? scrollIndex;
|
||||
if (isEnd[index]) return;
|
||||
Debug.Log(sindex);
|
||||
var r = await ConfigHelper.mapInterruptRecordApi.GetMapInterruptRecord(name, pageIndex[index], 20,filterOptionDict[index]);
|
||||
|
||||
JsonResult<List<JObject>> r = null;
|
||||
if (index == 0 || index == 1)
|
||||
{
|
||||
r = await ConfigHelper.mapInterruptRecordApi.GetMapInterruptRecord(name, pageIndex[index], 20, filterOptionDict[index]);
|
||||
}
|
||||
else
|
||||
{
|
||||
r = await ConfigHelper.rowerApi.GetList(pageIndex[index], 20);
|
||||
}
|
||||
if (r.result)
|
||||
{
|
||||
if (r.data.Count == 0)
|
||||
@@ -173,10 +203,10 @@ public class ResultListController : PFUIPanel
|
||||
isEnd[index] = true;
|
||||
scroll.transform.Find("Error").gameObject.SetActive(false);
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
//contents[index];
|
||||
if (!sindex.HasValue ||(sindex.HasValue && sindex.Value == scrollIndex))
|
||||
if (!sindex.HasValue || (sindex.HasValue && sindex.Value == scrollIndex))
|
||||
{
|
||||
scroll.transform.Find("Error").gameObject.SetActive(true);
|
||||
}
|
||||
@@ -185,25 +215,32 @@ public class ResultListController : PFUIPanel
|
||||
else
|
||||
{
|
||||
isEnd[index] = false;
|
||||
DisplayRouteResult(r.data, contents[index],index);
|
||||
DisplayRouteResult(r.data, contents[index], index);
|
||||
scroll.transform.Find("Error").gameObject.SetActive(false);
|
||||
//DisplayRouteResult(r.data, matchContent);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
Utils.showToast(gameObject, r.errMsg);
|
||||
}
|
||||
}
|
||||
void DisplayRouteResult(List<RouteResult> list,Transform content,int index)
|
||||
void DisplayRouteResult(List<JObject> list,Transform content,int index)
|
||||
{
|
||||
if (routeResult != null)
|
||||
{
|
||||
foreach (var item in list)
|
||||
{
|
||||
var obj = Instantiate(routeResult);
|
||||
obj.GetComponent<RouteItem>().Initial(item, index, transform);
|
||||
if (index == 0 || index == 1)
|
||||
{
|
||||
obj.GetComponent<RouteItem>().Initial(item.ToObject<RouteResult>(), index, transform, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
obj.GetComponent<RouteItem>().Initial(item.ToObject<RowerResultModel>(), index, transform,true);
|
||||
}
|
||||
//obj.SendMessage("Initial", );
|
||||
obj.transform.parent = content;
|
||||
obj.transform.localScale = new Vector3(1, 1, 1);
|
||||
@@ -249,7 +286,7 @@ public class ResultListController : PFUIPanel
|
||||
bool startMouse = false;
|
||||
void Update()
|
||||
{
|
||||
GoScroll();
|
||||
//GoScroll();
|
||||
if (Input.GetAxis("Mouse ScrollWheel") != 0)
|
||||
{
|
||||
if (scrolls[scrollIndex].GetComponent<ScrollRect>().verticalNormalizedPosition <= 0 ||
|
||||
@@ -273,88 +310,42 @@ public class ResultListController : PFUIPanel
|
||||
}
|
||||
void StartScroll(int index)
|
||||
{
|
||||
if (startScroll) return;
|
||||
if (index == 0)
|
||||
#if UNITY_ANDROID || UNITY_IOS
|
||||
scrollContent.DOLocalMoveX(674*index*-1,0.3f);
|
||||
#else
|
||||
scrollContent.DOLocalMoveX(1158*index*-1,0.3f);
|
||||
#endif
|
||||
scrollIndex = index;
|
||||
for (int i = 0; i < btns.Length; i++)
|
||||
{
|
||||
//翻到比赛页,比赛按钮变白,线路按钮变灰
|
||||
scrollIndex = 1;
|
||||
startScroll = true;
|
||||
btnRoute.GetComponent<Text>().color = c2;
|
||||
btnMatch.GetComponent<Text>().color = c1;
|
||||
}
|
||||
else if (index == 1)
|
||||
{
|
||||
//反过来
|
||||
scrollIndex = 0;
|
||||
startScroll = true;
|
||||
btnRoute.GetComponent<Text>().color = c1;
|
||||
btnMatch.GetComponent<Text>().color = c2;
|
||||
}
|
||||
scroll.transform.Find("Error").gameObject.SetActive(contents[scrollIndex].childCount == 0);
|
||||
}
|
||||
#region 主页面滑动逻辑
|
||||
int scrollIndex = 0;
|
||||
bool startScroll = false;
|
||||
ScrollRect scroll;
|
||||
//private float scrollValue = 0.5f;
|
||||
int pageNums = 2;
|
||||
void GoScroll()
|
||||
{
|
||||
var index = scrollIndex;
|
||||
var scrollValue = 1f / (pageNums - 1);
|
||||
var value = index * scrollValue;
|
||||
if (scroll != null && startScroll)
|
||||
{
|
||||
if (scroll.horizontalNormalizedPosition >= value)
|
||||
if (!btns[i]) continue;
|
||||
if (i == index)
|
||||
{
|
||||
scroll.horizontalNormalizedPosition -= (scrollValue / 20);
|
||||
if (scroll.horizontalNormalizedPosition <= value)
|
||||
{
|
||||
Debug.Log(index);
|
||||
scroll.horizontalNormalizedPosition = value;
|
||||
startScroll = false;
|
||||
}
|
||||
btns[i].GetComponent<Text>().color = c1;
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
scroll.horizontalNormalizedPosition += (scrollValue / 20);
|
||||
if (scroll.horizontalNormalizedPosition >= value)
|
||||
{
|
||||
Debug.Log(index);
|
||||
scroll.horizontalNormalizedPosition = value;
|
||||
startScroll = false;
|
||||
}
|
||||
btns[i].GetComponent<Text>().color = c2;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
//float scrollIndex = 0;
|
||||
//bool startScroll = false;
|
||||
//ScrollRect scroll;
|
||||
//void GoScroll()
|
||||
//{
|
||||
// float value = scrollIndex;
|
||||
// if (scroll != null && startScroll)
|
||||
// {
|
||||
// if (scrollIndex == 0)
|
||||
// {
|
||||
// scroll.horizontalNormalizedPosition -= (1f / 20);
|
||||
// if (scroll.horizontalNormalizedPosition <= 0)
|
||||
// {
|
||||
// scroll.horizontalNormalizedPosition = 0;
|
||||
// startScroll = false;
|
||||
|
||||
//if (startScroll) return;
|
||||
//if (index == 0)
|
||||
//{
|
||||
// //翻到比赛页,比赛按钮变白,线路按钮变灰
|
||||
// scrollIndex = 1;
|
||||
// startScroll = true;
|
||||
// btnRoute.GetComponent<Text>().color = c2;
|
||||
// btnMatch.GetComponent<Text>().color = c1;
|
||||
//}
|
||||
//else if (index == 1)
|
||||
//{
|
||||
// //反过来
|
||||
// scrollIndex = 0;
|
||||
// startScroll = true;
|
||||
// btnRoute.GetComponent<Text>().color = c1;
|
||||
// btnMatch.GetComponent<Text>().color = c2;
|
||||
//}
|
||||
|
||||
// }
|
||||
// }
|
||||
// else if (scrollIndex == 1)
|
||||
// {
|
||||
// scroll.horizontalNormalizedPosition += (1f / 20);
|
||||
// if (scroll.horizontalNormalizedPosition >= 1)
|
||||
// {
|
||||
// scroll.horizontalNormalizedPosition = 1;
|
||||
// startScroll = false;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using Assets.Scripts;
|
||||
using Assets.Scripts.Apis;
|
||||
using Assets.Scripts.Apis.Models;
|
||||
using System;
|
||||
using System.Collections;
|
||||
@@ -14,6 +15,7 @@ public class RouteItem : MonoBehaviour
|
||||
#endif
|
||||
{
|
||||
RouteResult routeResult;
|
||||
RowerResultModel rowerResult;
|
||||
// Start is called before the first frame update
|
||||
Transform left,row1,row2,right,rightDot;
|
||||
Transform btnReRide, btnContinue, btnDelete;
|
||||
@@ -22,6 +24,7 @@ public class RouteItem : MonoBehaviour
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
@@ -33,18 +36,97 @@ public class RouteItem : MonoBehaviour
|
||||
int index;
|
||||
//交互用
|
||||
private Transform parent { get; set; }
|
||||
public void Initial(RouteResult result,int index,Transform parent = null)
|
||||
public void Initial(object result, int index, Transform parent = null,bool top = false)
|
||||
{
|
||||
if (parent)
|
||||
this.index = index;
|
||||
if (parent)
|
||||
{
|
||||
this.parent = parent;
|
||||
}
|
||||
routeResult = result;
|
||||
this.index = index;
|
||||
left = transform.Find("BigLeft/Left");
|
||||
row1 = left.Find("Main").Find("Row1");
|
||||
row2 = left.Find("Main").Find("Row2");
|
||||
rightDot = transform.Find("RightDot");
|
||||
if (rightDot != null)
|
||||
{
|
||||
UIManager.AddEvent(rightDot.Find("BtnDot").gameObject, EventTriggerType.PointerClick, (b) => OnPointerEnter(null));
|
||||
UIManager.AddEvent(rightDot.Find("BtnDelete").gameObject, EventTriggerType.PointerClick, (b) => Delete());
|
||||
}
|
||||
|
||||
//right.gameObject.SetActive(true);
|
||||
#if !(UNITY_ANDROID || UNITY_IOS)
|
||||
gameObject.GetComponent<Button>().onClick.AddListener(() =>
|
||||
{
|
||||
Detail();
|
||||
});
|
||||
#else
|
||||
gameObject.GetComponent<Button>().enabled = false;
|
||||
#endif
|
||||
if (result is RouteResult)
|
||||
{
|
||||
Initial((RouteResult)result, index, parent);
|
||||
}
|
||||
else
|
||||
{
|
||||
Initial((RowerResultModel)result, index, parent);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 划船机初始化
|
||||
/// </summary>
|
||||
/// <param name="result"></param>
|
||||
/// <param name="index"></param>
|
||||
/// <param name="parent"></param>
|
||||
public void Initial(RowerResultModel result, int index, Transform parent = null)
|
||||
{
|
||||
rowerResult = result;
|
||||
row1.Find("Rank").gameObject.SetActive(false);
|
||||
row1.Find("Times").gameObject.SetActive(false);
|
||||
var raw = transform.Find("BigLeft/CoverImage").GetComponent<RawImage>();
|
||||
if (string.IsNullOrEmpty(result.Cover))
|
||||
{
|
||||
raw.texture = Resources.Load<Texture>("Images/Rower/地图1");
|
||||
}
|
||||
else
|
||||
{
|
||||
Utils.DisplayImage(raw, result.Cover, true);
|
||||
}
|
||||
row1.Find("Time").GetComponent<Text>().text = $"<color=#5c5c6e>Rowing time:</color>{TimeSpan.FromSeconds(result.TotalTime).ToString()}";
|
||||
row1.Find("Distance").GetComponent<Text>().text = $"<color=#5c5c6e>Distance:</color>{result.TotalDistance}M";
|
||||
row2.Find("Device").GetComponent<Text>().text = $"<color=#5c5c6e>Rowing equipment:</color>{result.ManufacturerName}";
|
||||
left.Find("Progress").gameObject.SetActive(false);
|
||||
left.Find("Main/Name").GetComponent<Text>().text = "Free rowing";
|
||||
left.Find("Main/Time").GetComponent<Text>().text = $"{result.StartTime.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss")} ~ {result.CreateTime.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss")}";
|
||||
var rect = left.Find("Main").GetComponent<RectTransform>();
|
||||
rect.sizeDelta = new Vector2(399,rect.sizeDelta.y);
|
||||
SetButtonColor(false);
|
||||
right = transform.Find("RightRower");
|
||||
if (right != null)
|
||||
{
|
||||
btnDetail = right.Find("BtnDetail");
|
||||
if (btnDetail)
|
||||
{
|
||||
UIManager.AddEvent(btnDetail.gameObject, EventTriggerType.PointerClick, b =>
|
||||
{
|
||||
UIManager.ShowRowerResult(result.Id);
|
||||
});
|
||||
}
|
||||
btnReRide = right.Find("BtnRide");
|
||||
if (btnReRide)
|
||||
{
|
||||
UIManager.AddEvent(btnReRide.gameObject, EventTriggerType.PointerClick, b =>
|
||||
{
|
||||
UIManager.ShowRowerPanel();
|
||||
});
|
||||
}
|
||||
}
|
||||
//UIManager.AddEvent(transform.gameObject, EventTriggerType.PointerClick, b => UIManager.ShowRowerResult(result.Id));
|
||||
}
|
||||
|
||||
public void Initial(RouteResult result,int index,Transform parent = null)
|
||||
{
|
||||
routeResult = result;
|
||||
|
||||
Utils.DisplayImage(transform.Find("BigLeft/CoverImage").GetComponent<RawImage>(), result.RouteImage, true);
|
||||
|
||||
left.Find("Main").Find("Name").GetComponent<Text>().text = result.RouteName;
|
||||
@@ -107,22 +189,7 @@ public class RouteItem : MonoBehaviour
|
||||
SetButtonColor(false);
|
||||
transform.Find("Right").gameObject.SetActive(false);
|
||||
}
|
||||
rightDot = transform.Find("RightDot");
|
||||
if (rightDot != null)
|
||||
{
|
||||
UIManager.AddEvent(rightDot.Find("BtnDot").gameObject, EventTriggerType.PointerClick, (b) => OnPointerEnter(null));
|
||||
UIManager.AddEvent(rightDot.Find("BtnDelete").gameObject, EventTriggerType.PointerClick, (b) => Delete());
|
||||
}
|
||||
|
||||
//right.gameObject.SetActive(true);
|
||||
#if !(UNITY_ANDROID || UNITY_IOS)
|
||||
gameObject.GetComponent<Button>().onClick.AddListener(() =>
|
||||
{
|
||||
Detail();
|
||||
});
|
||||
#else
|
||||
gameObject.GetComponent<Button>().enabled = false;
|
||||
#endif
|
||||
|
||||
}
|
||||
void Detail()
|
||||
{
|
||||
@@ -148,13 +215,21 @@ public class RouteItem : MonoBehaviour
|
||||
{
|
||||
UIManager.ShowConfirm("Delete", "Delete this record?", async () =>
|
||||
{
|
||||
var r = await ConfigHelper.mapApi.DeleteRecord(routeResult.Id);
|
||||
JsonResult<object> r = null;
|
||||
if (index != 2)
|
||||
{
|
||||
r = await ConfigHelper.mapApi.DeleteRecord(routeResult.Id);
|
||||
}
|
||||
else
|
||||
{
|
||||
r = await ConfigHelper.rowerApi.Delete(rowerResult.Id);
|
||||
}
|
||||
UIManager.CloseConfirm();
|
||||
if (r.result)
|
||||
{
|
||||
DestroyImmediate(gameObject);
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
Utils.showToast(gameObject, r.errMsg);
|
||||
}
|
||||
@@ -245,6 +320,7 @@ public class RouteItem : MonoBehaviour
|
||||
{
|
||||
if (!f)
|
||||
{
|
||||
transform.Find("RightRower").gameObject.SetActive(false);
|
||||
transform.Find("Right").gameObject.SetActive(false);
|
||||
transform.Find("RightMatch").gameObject.SetActive(false);
|
||||
transform.Find("RightDot").gameObject.SetActive(true);
|
||||
@@ -262,6 +338,7 @@ public class RouteItem : MonoBehaviour
|
||||
}
|
||||
|
||||
transform.Find("RightMatch").gameObject.SetActive(index == 1);
|
||||
transform.Find("RightRower").gameObject.SetActive(index == 2);
|
||||
transform.Find("RightDot").gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 879e9656cc32a33448968cc1f71e5e10
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,81 @@
|
||||
using DG.Tweening;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class RowerAnimation : PFUIPanel
|
||||
{
|
||||
List<Sprite> sprites;
|
||||
Image image;
|
||||
|
||||
protected override void Awake()
|
||||
{
|
||||
base.Awake();
|
||||
sprites = new List<Sprite>();
|
||||
for (int i = 1; i < 26; i++)
|
||||
{
|
||||
sprites.Add(Resources.Load<Sprite>($"Images/Rower/序列帧/划船机{i.ToString("0000")}"));
|
||||
}
|
||||
image = transform.GetComponent<Image>();
|
||||
}
|
||||
|
||||
protected override void Start()
|
||||
{
|
||||
|
||||
//time = 0;
|
||||
|
||||
}
|
||||
int index = 0;
|
||||
//float time = 0;
|
||||
public override void Show()
|
||||
{
|
||||
//base.Show();
|
||||
|
||||
//index = 0;
|
||||
////time = 0;
|
||||
|
||||
//StartCoroutine(Animation());
|
||||
}
|
||||
public void StartAnimation()
|
||||
{
|
||||
index = 0;
|
||||
StartCoroutine(Animation());
|
||||
}
|
||||
|
||||
IEnumerator Animation()
|
||||
{
|
||||
for (; ; )
|
||||
{
|
||||
if (index % 25 == 0)
|
||||
{
|
||||
index = 0;
|
||||
}
|
||||
image.sprite = sprites[index];
|
||||
index++;
|
||||
yield return new WaitForSeconds(0.08f);
|
||||
}
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
//time += Time.deltaTime;
|
||||
//if (time < 0.03)
|
||||
//{
|
||||
// return;
|
||||
//}
|
||||
//time = 0;
|
||||
//if (index % 79 == 0)
|
||||
//{
|
||||
// index = 0;
|
||||
//}
|
||||
//image.sprite = sprites[index];
|
||||
//index++;
|
||||
}
|
||||
|
||||
public override void Close()
|
||||
{
|
||||
StopCoroutine(Animation());
|
||||
base.Close();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4e84219e49caa1f46be9f0277fd3b7c5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,448 @@
|
||||
using Assets.Scripts.Devices.Ant;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.Events;
|
||||
using Assets.Scripts.Devices.Ant.Interfaces;
|
||||
using Assets.Scripts.UI.UIEffect;
|
||||
using Assets.Scripts;
|
||||
using DG.Tweening;
|
||||
using Assets.Scripts.UI.Prefab.Device;
|
||||
using Assets.Scripts.Devices;
|
||||
using Assets.Scripts.Devices.Ble;
|
||||
|
||||
public class RowerDeviceView : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private SensorType mType;
|
||||
|
||||
private SensorType SensorType
|
||||
{
|
||||
get
|
||||
{
|
||||
//Debug.Log(mType);
|
||||
//Enum.TryParse(mType, out SensorType sensorType);
|
||||
return mType;
|
||||
}
|
||||
}
|
||||
|
||||
private GameObject mSearchButton;
|
||||
private GameObject mPairButton;
|
||||
private GameObject mDisconnectButton;
|
||||
private GameObject unconnectionPanel;
|
||||
private GameObject connectionPanel;
|
||||
private Text searchState;
|
||||
private ConnectDeviceModal deviceModal;
|
||||
private Text title;
|
||||
private Text noDevice;
|
||||
private Text powerValue;
|
||||
private Text powerUnit;
|
||||
//private Text cadenceValue;
|
||||
//private Text speedValue;
|
||||
//private Text heartRateValue;
|
||||
private Image logo;
|
||||
/// <summary>
|
||||
/// 没有设备的logo
|
||||
/// </summary>
|
||||
private Sprite sprite0;
|
||||
/// <summary>
|
||||
/// 连接中的logo
|
||||
/// </summary>
|
||||
private Sprite sprite1;
|
||||
/// <summary>
|
||||
/// 已连接的logo
|
||||
/// </summary>
|
||||
private Sprite sprite3;
|
||||
|
||||
private float timer = 1.0f;
|
||||
private void Awake()
|
||||
{
|
||||
title = this.transform.Find("Title").GetComponent<Text>();
|
||||
noDevice = this.transform.Find("NoDevice").GetComponent<Text>();
|
||||
unconnectionPanel = this.transform.Find("UnconnectionPanel").gameObject;
|
||||
mSearchButton = unconnectionPanel.transform.Find("SearchButton").gameObject;
|
||||
mPairButton = unconnectionPanel.transform.Find("PairButton").gameObject;
|
||||
searchState = unconnectionPanel.transform.Find("SearchState").GetComponent<Text>();
|
||||
mPairButton.SetActive(false);
|
||||
connectionPanel = this.transform.Find("ConnectionPanel").gameObject;
|
||||
|
||||
var material = Instantiate(Resources.Load<Material>("UI/Material/RoundedCornersTextureMaterial"));
|
||||
var rect = ((RectTransform)transform).rect;
|
||||
material.SetVector(Shader.PropertyToID("_WidthHeightRadius"), new Vector4(rect.width, rect.height, rect.height * 0.2f, 0));
|
||||
this.GetComponent<Image>().material = material;
|
||||
|
||||
var img1 = unconnectionPanel.GetComponent<Image>();
|
||||
if(img1 != null)
|
||||
{
|
||||
img1.material = material;
|
||||
|
||||
//var gradient = unconnectionPanel.GetComponent<UIGradient>();
|
||||
//if (gradient != null)
|
||||
//{
|
||||
// gradient.color1 = Utils.HexToColor("353543");
|
||||
// gradient.color2 = Utils.HexToColor("23232D");
|
||||
//}
|
||||
}
|
||||
|
||||
var img2 = connectionPanel.GetComponent<Image>();
|
||||
if(img2 != null)
|
||||
{
|
||||
img2.material = material;
|
||||
|
||||
//var gradient1 = connectionPanel.GetComponent<UIGradient>();
|
||||
//if (gradient1 != null)
|
||||
//{
|
||||
// gradient1.color1 = Utils.HexToColor("FF7485");
|
||||
// gradient1.color2 = Utils.HexToColor("F93086");
|
||||
//}
|
||||
}
|
||||
|
||||
logo = this.transform.Find("Logo").GetComponent<Image>();
|
||||
|
||||
|
||||
mDisconnectButton = connectionPanel.transform.Find("DisconnectBtn").gameObject;
|
||||
var powerValueObj = connectionPanel.transform.Find("PowerValue");
|
||||
if(powerValueObj != null)
|
||||
{
|
||||
powerValue = powerValueObj.gameObject.GetComponent<Text>();
|
||||
}
|
||||
|
||||
var powerUnitObj = connectionPanel.transform.Find("PowerUnit");
|
||||
if(powerUnitObj != null)
|
||||
{
|
||||
powerUnit = powerUnitObj.gameObject.GetComponent<Text>();
|
||||
}
|
||||
|
||||
InitLogo();
|
||||
title.text = GetTitle();
|
||||
|
||||
connectionPanel.SetActive(false);
|
||||
|
||||
UIManager.AddEvent(mPairButton, EventTriggerType.PointerClick, new UnityAction<UnityEngine.EventSystems.BaseEventData>(e =>
|
||||
{
|
||||
if (deviceModal == null)
|
||||
{
|
||||
|
||||
#if UNITY_IOS || UNITY_ANDROID
|
||||
var obj = Resources.Load("UI/Prefab/Device/Mobile/ConnectDeviceModal");
|
||||
#else
|
||||
var obj = Resources.Load("UI/Prefab/Device/ConnectDeviceModal");
|
||||
#endif
|
||||
GameObject gameObject = (GameObject)Instantiate(obj);
|
||||
deviceModal = gameObject.GetComponent<ConnectDeviceModal>();
|
||||
}
|
||||
deviceModal.SensorType = this.SensorType;
|
||||
UIManager.Show(deviceModal, null, true);
|
||||
}));
|
||||
|
||||
UIManager.AddEvent(mDisconnectButton, EventTriggerType.PointerClick, new UnityEngine.Events.UnityAction<BaseEventData>(e => {
|
||||
//var device = GetDevice();
|
||||
//if(device != null && device.State == DeviceState.Connected)
|
||||
//{
|
||||
// device.Disconnect();
|
||||
//}
|
||||
|
||||
#if UNITY_IOS || UNITY_ANDROID
|
||||
var obj = Resources.Load("UI/Prefab/Device/Mobile/ConnectDeviceModal");
|
||||
#else
|
||||
var obj = Resources.Load("UI/Prefab/Device/ConnectDeviceModal");
|
||||
#endif
|
||||
GameObject gameObject = (GameObject)Instantiate(obj);
|
||||
deviceModal = gameObject.GetComponent<ConnectDeviceModal>();
|
||||
deviceModal.SensorType = this.SensorType;
|
||||
UIManager.Show(deviceModal, null, true);
|
||||
}));
|
||||
|
||||
}
|
||||
|
||||
void InitLogo()
|
||||
{
|
||||
if (SensorType == SensorType.Power)
|
||||
{
|
||||
sprite0 = Resources.Load<Sprite>("Images/Devices/Power_0");
|
||||
sprite1 = Resources.Load<Sprite>("Images/Devices/Power_1");
|
||||
sprite3 = Resources.Load<Sprite>("Images/Devices/Power_4");
|
||||
|
||||
powerUnit.text = "W";
|
||||
}
|
||||
else if (SensorType == SensorType.Speed)
|
||||
{
|
||||
sprite0 = Resources.Load<Sprite>("Images/Devices/Speed_0");
|
||||
sprite1 = Resources.Load<Sprite>("Images/Devices/Speed_1");
|
||||
sprite3 = Resources.Load<Sprite>("Images/Devices/Speed_4");
|
||||
|
||||
powerUnit.text = "KPH";
|
||||
}
|
||||
else if (SensorType == SensorType.Cadence || SensorType == SensorType.SpeedCadence)
|
||||
{
|
||||
sprite0 = Resources.Load<Sprite>("Images/Devices/Cadence_0");
|
||||
sprite1 = Resources.Load<Sprite>("Images/Devices/Cadence_1");
|
||||
sprite3 = Resources.Load<Sprite>("Images/Devices/Cadence_4");
|
||||
|
||||
powerUnit.text = "RPM";
|
||||
}
|
||||
else if (SensorType == SensorType.HeartRate)
|
||||
{
|
||||
sprite0 = Resources.Load<Sprite>("Images/Devices/Heart Rate_1");
|
||||
sprite1 = Resources.Load<Sprite>("Images/Devices/Heart Rate_1");
|
||||
sprite3 = Resources.Load<Sprite>("Images/Devices/Heart Rate_4");
|
||||
|
||||
powerUnit.text = "BPM";
|
||||
}
|
||||
else if (SensorType == SensorType.Trainer)
|
||||
{
|
||||
sprite0 = Resources.Load<Sprite>("Images/Devices/Trainer_0");
|
||||
sprite1 = Resources.Load<Sprite>("Images/Devices/Trainer_1");
|
||||
sprite3 = Resources.Load<Sprite>("Images/Devices/Trainer_4");
|
||||
}
|
||||
else if (SensorType == SensorType.Rower)
|
||||
{
|
||||
sprite0 = Resources.Load<Sprite>("Images/Rower/设备 - 划船机 - 未连接");
|
||||
sprite1 = Resources.Load<Sprite>("Images/Rower/设备 - 划船机 - 未连接");
|
||||
sprite3 = Resources.Load<Sprite>("Images/Rower/设备 - 划船机");
|
||||
powerUnit.text = "";
|
||||
}
|
||||
}
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
Main();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
//if(SensorType != SensorType.Trainer)
|
||||
//{
|
||||
// return;
|
||||
//}
|
||||
timer -= Time.deltaTime;
|
||||
if (timer <= 0)
|
||||
{
|
||||
Main();
|
||||
|
||||
timer = 1.0f;
|
||||
}
|
||||
}
|
||||
|
||||
void Main()
|
||||
{
|
||||
var connectedDevice = GetCurrentDevice();
|
||||
if(connectedDevice == null)
|
||||
{
|
||||
connectedDevice = GetDevice();
|
||||
}
|
||||
if(connectedDevice == null)
|
||||
{
|
||||
unconnectionPanel.SetActive(true);
|
||||
connectionPanel.SetActive(false);
|
||||
|
||||
logo.sprite = sprite0;
|
||||
noDevice.text = "NO DEVICE";
|
||||
searchState.text = "Searching...";
|
||||
|
||||
var hasDevice = false;
|
||||
if (SensorType == SensorType.SpeedCadence)
|
||||
{
|
||||
hasDevice = App.MainDeviceAdapter.GetDevices().Any(d => d.Sensor == SensorType.SpeedCadence || d.Sensor == SensorType.Cadence);
|
||||
}
|
||||
else
|
||||
{
|
||||
hasDevice = App.MainDeviceAdapter.GetDevices().Any(d => d.Sensor == SensorType);
|
||||
}
|
||||
if (hasDevice)
|
||||
{
|
||||
mSearchButton.SetActive(false);
|
||||
mPairButton.SetActive(true);
|
||||
#if UNITY_IOS || UNITY_ANDROID
|
||||
//searchState.gameObject.SetActive(false);
|
||||
#endif
|
||||
logo.sprite = sprite1;
|
||||
|
||||
//App.MainDeviceAdapter.GetDevices().First(d => d.Sensor == SensorType).Connect();
|
||||
}
|
||||
else
|
||||
{
|
||||
#if !(UNITY_IOS || UNITY_ANDROID)
|
||||
mSearchButton.SetActive(true);
|
||||
#endif
|
||||
mPairButton.SetActive(false);
|
||||
}
|
||||
}
|
||||
else if(connectedDevice.State == DeviceState.Connecting)
|
||||
{
|
||||
unconnectionPanel.SetActive(true);
|
||||
connectionPanel.SetActive(false);
|
||||
logo.sprite = sprite1;
|
||||
|
||||
//title.text = connectedDevice.Name;
|
||||
if (connectedDevice.Network == NetworkType.BLE)
|
||||
{
|
||||
//noDevice.enabled = false;
|
||||
noDevice.text = connectedDevice.Name;
|
||||
}
|
||||
else
|
||||
{
|
||||
//noDevice.enabled = true;
|
||||
noDevice.text = connectedDevice.Name +" "+ connectedDevice.DeviceNumber.ToString();
|
||||
}
|
||||
#if (UNITY_IOS || UNITY_ANDROID)
|
||||
mPairButton.SetActive(true);
|
||||
searchState.gameObject.SetActive(true);
|
||||
#endif
|
||||
searchState.text = "Connecting...";
|
||||
|
||||
|
||||
}
|
||||
else if (connectedDevice.State == DeviceState.Connected)
|
||||
{
|
||||
unconnectionPanel.SetActive(false);
|
||||
|
||||
if (connectionPanel.activeInHierarchy == false)
|
||||
{
|
||||
var connectionCanvasGroup = connectionPanel.GetComponent<CanvasGroup>();
|
||||
connectionCanvasGroup.alpha = 0;
|
||||
connectionPanel.SetActive(true);
|
||||
connectionCanvasGroup.DOFade(1f, .3f).OnComplete(()=> {
|
||||
//if (logoSprite != null) {
|
||||
// logo.sprite = logoSprite;
|
||||
//}
|
||||
});
|
||||
DeviceCache.Add(connectedDevice);
|
||||
Debug.Log("connected");
|
||||
}
|
||||
|
||||
logo.sprite = sprite3;
|
||||
|
||||
//title.text = connectedDevice.Name;
|
||||
if (connectedDevice.Network == NetworkType.BLE)
|
||||
{
|
||||
//noDevice.enabled = false;
|
||||
noDevice.text = connectedDevice.Name;
|
||||
}
|
||||
else
|
||||
{
|
||||
//noDevice.enabled = true;
|
||||
noDevice.text = connectedDevice.Name +" "+ connectedDevice.DeviceNumber.ToString();
|
||||
}
|
||||
noDevice.color = Color.white;
|
||||
|
||||
if (powerValue != null)
|
||||
{
|
||||
powerValue.text = GetValue(connectedDevice);
|
||||
}
|
||||
}
|
||||
|
||||
//Debug.Log(Newtonsoft.Json.JsonConvert.SerializeObject(App.MainDeviceAdapter.GetDevices().Where(d => d.Sensor == SensorType)));
|
||||
}
|
||||
|
||||
string GetTitle()
|
||||
{
|
||||
switch (SensorType)
|
||||
{
|
||||
case SensorType.None:
|
||||
break;
|
||||
case SensorType.SpeedCadence:
|
||||
case SensorType.Cadence:
|
||||
return "Cadence Sensor";
|
||||
case SensorType.HeartRate:
|
||||
return "Heart Rate Monitor";
|
||||
case SensorType.Power:
|
||||
return "Power Meter";
|
||||
case SensorType.Speed:
|
||||
return "Speed Meter";
|
||||
case SensorType.Trainer:
|
||||
return "Smart Trainer";
|
||||
case SensorType.Rower:
|
||||
return "Rower Machine";
|
||||
case SensorType.VirtualPower:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
string GetValue(AbstractDevice connectedDevice)
|
||||
{
|
||||
switch (SensorType)
|
||||
{
|
||||
case SensorType.None:
|
||||
break;
|
||||
case SensorType.SpeedCadence:
|
||||
case SensorType.Cadence:
|
||||
//cadenceValue.text = (connectedDevice as ICadenceDevice).Cadence.ToString();
|
||||
return (connectedDevice as ICadenceDevice).Cadence.ToString();
|
||||
case SensorType.HeartRate:
|
||||
return (connectedDevice as IHeartRateDevice).HeartRate.ToString();
|
||||
case SensorType.Power:
|
||||
return (connectedDevice as IPowerDevice).Power.ToString();
|
||||
case SensorType.Speed:
|
||||
return (connectedDevice as ISpeedDevice).Speed.ToString("f1");
|
||||
case SensorType.Trainer:
|
||||
//powerValue.text = (connectedDevice as IPowerDevice).Power.ToString();
|
||||
//cadenceValue.GetComponent<Text>().text = (connectedDevice as ICadenceDevice).Cadence.ToString();
|
||||
//speedValue.GetComponent<Text>().text = (connectedDevice as ISpeedDevice).Speed.ToString();
|
||||
break;
|
||||
case SensorType.VirtualPower:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
AbstractDevice GetCurrentDevice()
|
||||
{
|
||||
//return AntConnector.Instance().discoveredDevices.FirstOrDefault(d => (d.State == DeviceState.Connected || d.State == DeviceState.Connecting) && d.Sensor == SensorType);
|
||||
if(SensorType == SensorType.SpeedCadence || SensorType == SensorType.Cadence)
|
||||
{
|
||||
return App.MainDeviceAdapter.GetDevices().FirstOrDefault(d => (d.State == DeviceState.Connected || d.State == DeviceState.Connecting) && (d.Sensor == SensorType.SpeedCadence || d.Sensor == SensorType.Cadence));
|
||||
}
|
||||
return App.MainDeviceAdapter.GetDevices().FirstOrDefault(d => (d.State == DeviceState.Connected || d.State == DeviceState.Connecting) && d.Sensor == SensorType);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取已经连接的设备
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
AbstractDevice GetDevice()
|
||||
{
|
||||
//return AntConnector.Instance().discoveredDevices.FirstOrDefault(d => (d.State == DeviceState.Connected || d.State == DeviceState.Connecting) && d.Sensor == SensorType);
|
||||
var devices = App.MainDeviceAdapter.GetDevices().Where(d => (d.State == DeviceState.Connected));
|
||||
switch (SensorType)
|
||||
{
|
||||
case SensorType.None:
|
||||
break;
|
||||
case SensorType.SpeedCadence:
|
||||
case SensorType.Cadence:
|
||||
return devices.FirstOrDefault(d => d is ICadenceDevice);
|
||||
case SensorType.HeartRate:
|
||||
return devices.FirstOrDefault(d => d is IHeartRateDevice);
|
||||
case SensorType.Power:
|
||||
var item = devices.FirstOrDefault(d => d is IPowerDevice);
|
||||
//if (powerValue != null)
|
||||
//{
|
||||
// powerValue.GetComponent<Text>().text = (item as IPowerDevice).Power.ToString();
|
||||
//}
|
||||
return item;
|
||||
case SensorType.Speed:
|
||||
return devices.FirstOrDefault(d => d is ISpeedDevice);
|
||||
case SensorType.Rower:
|
||||
return devices.FirstOrDefault(d => d.Sensor == SensorType.Rower);
|
||||
case SensorType.Trainer:
|
||||
var item3 = devices.FirstOrDefault(d => d.Sensor == SensorType.Trainer);
|
||||
return item3;
|
||||
case SensorType.VirtualPower:
|
||||
break;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 954bbf32f326f684c90a328ec1db5ff9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,63 @@
|
||||
#define Graph_And_Chart_PRO
|
||||
using UnityEngine;
|
||||
using ChartAndGraph;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class RowerGraphChartFeed : MonoBehaviour
|
||||
{
|
||||
void Start ()
|
||||
{
|
||||
//GraphChartBase graph = GetComponent<GraphChartBase>();
|
||||
//if (graph != null)
|
||||
//{
|
||||
// graph.Scrollable = false;
|
||||
// graph.HorizontalValueToStringMap[0.0] = "Zero"; // example of how to set custom axis strings
|
||||
// graph.DataSource.StartBatch();
|
||||
// graph.DataSource.ClearCategory("Player 1");
|
||||
// graph.DataSource.ClearAndMakeBezierCurve("Player 2");
|
||||
|
||||
// for (int i = 0; i <10000; i++)
|
||||
// {
|
||||
// graph.DataSource.AddPointToCategory("Player 1",i*5,Random.value*10f + 20f);
|
||||
// if (i == 0)
|
||||
// graph.DataSource.SetCurveInitialPoint("Player 2",i*5, Random.value * 10f + 10f);
|
||||
// else
|
||||
// graph.DataSource.AddLinearCurveToCategory("Player 2",
|
||||
// new DoubleVector2(i*5 , Random.value * 10f + 10f));
|
||||
// }
|
||||
// graph.DataSource.MakeCurveCategorySmooth("Player 2");
|
||||
// graph.DataSource.EndBatch();
|
||||
//}
|
||||
// StartCoroutine(ClearAll());
|
||||
}
|
||||
|
||||
public void SetData(List<DoubleVector2> list)
|
||||
{
|
||||
GraphChartBase graph = GetComponent<GraphChartBase>();
|
||||
if (graph != null)
|
||||
{
|
||||
graph.Scrollable = false;
|
||||
//graph.HorizontalValueToStringMap[0.0] = "Zero"; // example of how to set custom axis strings
|
||||
graph.DataSource.StartBatch();
|
||||
graph.DataSource.ClearAndMakeBezierCurve("Player 1");
|
||||
for (int i = 0; i < list.Count; i++)
|
||||
{
|
||||
var item = list[i];
|
||||
if (i == 0)
|
||||
graph.DataSource.SetCurveInitialPoint("Player 1", item.x, item.y);
|
||||
else
|
||||
graph.DataSource.AddLinearCurveToCategory("Player 1", new DoubleVector2(item.x, item.y));
|
||||
}
|
||||
graph.DataSource.MakeCurveCategorySmooth("Player 1");
|
||||
graph.DataSource.EndBatch();
|
||||
}
|
||||
}
|
||||
IEnumerator ClearAll()
|
||||
{
|
||||
yield return new WaitForSeconds(5f);
|
||||
GraphChartBase graph = GetComponent<GraphChartBase>();
|
||||
|
||||
graph.DataSource.Clear();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: aa4e07579b1f9574788e0b83b1fac799
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,254 @@
|
||||
#define Graph_And_Chart_PRO
|
||||
using UnityEngine;
|
||||
using ChartAndGraph;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
public partial class RowerLargeDataFeed : MonoBehaviour, IComparer<DoubleVector2>
|
||||
{
|
||||
public string Category = "Player 1";
|
||||
public int DownSampleToPoints = 100;
|
||||
List<DoubleVector2> mData = new List<DoubleVector2>(); // the data held by the chart
|
||||
double pageSize = 2f;
|
||||
double currentPagePosition = 0.0;
|
||||
double currentZoom = 0f;
|
||||
GraphChartBase graph;
|
||||
double mCurrentPageSizeFactor = double.NegativeInfinity;
|
||||
void Start()
|
||||
{
|
||||
graph = GetComponent<GraphChartBase>();
|
||||
//SetInitialData();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// called with Start(). These will be used to load the data into the large data feed. You should replace this with your own loading logic.
|
||||
/// </summary>
|
||||
void SetInitialData()
|
||||
{
|
||||
List<DoubleVector2> data = new List<DoubleVector2>(75);
|
||||
double x = 0f;
|
||||
double y = 20f;
|
||||
for (int i = 0; i < 75; i++) // initialize with random data
|
||||
{
|
||||
y = 20 + UnityEngine.Random.value * 80;
|
||||
Debug.Log(y);
|
||||
x += 1;
|
||||
data.Add(new DoubleVector2(x, y));
|
||||
}
|
||||
SetData(data);
|
||||
}
|
||||
|
||||
public void SaveToFile(string path)
|
||||
{
|
||||
using (StreamWriter file = new StreamWriter(path))
|
||||
{
|
||||
file.WriteLine(mData.Count);
|
||||
for (int i = 0; i < mData.Count; i++)
|
||||
{
|
||||
DoubleVector2 item = mData[i];
|
||||
file.WriteLine(item.x);
|
||||
file.WriteLine(item.y);
|
||||
}
|
||||
}
|
||||
}
|
||||
public void LoadFromFile(string path)
|
||||
{
|
||||
try
|
||||
{
|
||||
List<DoubleVector2> data = new List<DoubleVector2>();
|
||||
using (StreamReader file = new StreamReader(path))
|
||||
{
|
||||
int count = int.Parse(file.ReadLine());
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
double x = double.Parse(file.ReadLine());
|
||||
double y = double.Parse(file.ReadLine());
|
||||
data.Add(new DoubleVector2(x, y));
|
||||
}
|
||||
}
|
||||
SetData(data);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw new Exception("Invalid file format");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// vertify's that the graph data is sorted so it can be searched using a binary search.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
bool VerifySorted(List<DoubleVector2> data)
|
||||
{
|
||||
if (data == null)
|
||||
return true;
|
||||
for (int i = 1; i < data.Count; i++)
|
||||
{
|
||||
if (data[i].x < data[i - 1].x)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// set the data of the large data graph
|
||||
/// </summary>
|
||||
/// <param name="data"></param>
|
||||
public void SetData(List<DoubleVector2> data)
|
||||
{
|
||||
if (data == null)
|
||||
data = new List<DoubleVector2>(); // set up an empty list instead of null
|
||||
if (VerifySorted(data) == false)
|
||||
{
|
||||
Debug.LogWarning("The data used with large data feed must be sorted acoording to the x value, aborting operation");
|
||||
return;
|
||||
}
|
||||
mData = data;
|
||||
LoadPage(currentPagePosition); // load the page at position 0
|
||||
}
|
||||
|
||||
int FindClosestIndex(double position) // if you want to know what is index is currently displayed . use binary search to find it
|
||||
{
|
||||
//NOTE :: this method assumes your data is sorted !!!
|
||||
int res = mData.BinarySearch(new DoubleVector2(position, 0.0), this);
|
||||
if (res >= 0)
|
||||
return res;
|
||||
return ~res;
|
||||
}
|
||||
|
||||
double PageSizeFactor
|
||||
{
|
||||
get
|
||||
{
|
||||
return pageSize * graph.DataSource.HorizontalViewSize;
|
||||
}
|
||||
}
|
||||
|
||||
void findPointsForPage(double position, out int start, out int end) // given a page position , find the right most and left most indices in the data for that page.
|
||||
{
|
||||
int index = FindClosestIndex(position); // use binary search to find the closest position to the current scroll point
|
||||
|
||||
double endPosition = position + PageSizeFactor;
|
||||
double startPosition = position - PageSizeFactor;
|
||||
|
||||
//starting from the current index , we find the page boundries
|
||||
for (start = index; start > 0; start--)
|
||||
{
|
||||
if (mData[start].x < startPosition) // take the first point that is out of the page. so the graph doesn't break at the edge
|
||||
break;
|
||||
}
|
||||
|
||||
for (end = index; end < mData.Count; end++)
|
||||
{
|
||||
if (mData[end].x > endPosition) // take the first point that is out of the page
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
if (graph != null)
|
||||
{
|
||||
//check the scrolling position of the graph. if we are past the view size , load a new page
|
||||
double pageStartThreshold = currentPagePosition - mCurrentPageSizeFactor;
|
||||
double pageEndThreshold = currentPagePosition + mCurrentPageSizeFactor - graph.DataSource.HorizontalViewSize;
|
||||
|
||||
if (graph.HorizontalScrolling < pageStartThreshold || graph.HorizontalScrolling > pageEndThreshold || currentZoom >= graph.DataSource.HorizontalViewSize * 2f)
|
||||
{
|
||||
currentZoom = graph.DataSource.HorizontalViewSize;
|
||||
mCurrentPageSizeFactor = PageSizeFactor * 0.9f;
|
||||
LoadPage(graph.HorizontalScrolling);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void LoadWithoutDownSampling(int start, int end)
|
||||
{
|
||||
for (int i = start; i < end; i++) // load the data
|
||||
{
|
||||
if (i == 0)
|
||||
{
|
||||
graph.DataSource.SetCurveInitialPoint(Category, mData[i].x, mData[i].y);
|
||||
}
|
||||
else
|
||||
{
|
||||
graph.DataSource.AddLinearCurveToCategory(Category, new DoubleVector2(mData[i].x, mData[i].y));
|
||||
}
|
||||
//graph.DataSource.AddPointToCategory(Category, mData[i].x, mData[i].y);
|
||||
}
|
||||
}
|
||||
|
||||
void LoadWithDownSampling(int start, int end)
|
||||
{
|
||||
int total = end - start;
|
||||
|
||||
if (DownSampleToPoints >= total)
|
||||
{
|
||||
LoadWithoutDownSampling(start, end);
|
||||
return;
|
||||
}
|
||||
|
||||
double sampleCount = ((double)total) / (double)DownSampleToPoints;
|
||||
// graph.DataSource.AddPointToCategory(Category, mData[start].x, mData[start].y);
|
||||
for (int i = 0; i < DownSampleToPoints; i++)
|
||||
{
|
||||
int fractionStart = start + (int)(i * sampleCount); // the first point with a fraction
|
||||
int fractionEnd = start + (int)((i + 1) * sampleCount); // the first point with a fraction
|
||||
fractionEnd = Math.Min(fractionEnd, mData.Count - 1);
|
||||
double x = 0, y = 0;
|
||||
double divide = 0.0;
|
||||
for (int j = fractionStart; j < fractionEnd; j++) // avarge the poins
|
||||
{
|
||||
x += mData[j].x;
|
||||
y += mData[j].y;
|
||||
divide++;
|
||||
}
|
||||
if (divide > 0.0)
|
||||
{
|
||||
x /= divide;
|
||||
y /= divide;
|
||||
graph.DataSource.AddPointToCategory(Category, x, y);
|
||||
}
|
||||
else
|
||||
Debug.Log("error");
|
||||
}
|
||||
// graph.DataSource.AddPointToCategory(Category, mData[last].x, mData[last].y);
|
||||
}
|
||||
|
||||
void LoadPage(double pagePosition)
|
||||
{
|
||||
if (graph != null)
|
||||
{
|
||||
|
||||
Debug.Log("Loading page :" + pagePosition);
|
||||
graph.DataSource.StartBatch(); // call start batch
|
||||
graph.DataSource.HorizontalViewOrigin = 0;
|
||||
int start, end;
|
||||
findPointsForPage(pagePosition, out start, out end); // get the page edges
|
||||
graph.DataSource.ClearAndMakeBezierCurve(Category); // clear the cateogry
|
||||
|
||||
if (DownSampleToPoints <= 0)
|
||||
LoadWithoutDownSampling(start, end);
|
||||
else
|
||||
LoadWithDownSampling(start, end);
|
||||
graph.DataSource.MakeCurveCategorySmooth(Category);
|
||||
graph.DataSource.EndBatch();
|
||||
graph.HorizontalScrolling = pagePosition;
|
||||
}
|
||||
currentPagePosition = pagePosition;
|
||||
}
|
||||
|
||||
|
||||
public int Compare(DoubleVector2 x, DoubleVector2 y)
|
||||
{
|
||||
if (x.x < y.x)
|
||||
return -1;
|
||||
if (x.x > y.x)
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7916cf3d11e8e7b4ebd8712801923455
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,103 @@
|
||||
using Assets.Scripts;
|
||||
using Assets.Scripts.Apis.Models;
|
||||
using ChartAndGraph;
|
||||
using DG.Tweening;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class RowerResult : PFUIPanel
|
||||
{
|
||||
RowerResultModel _model;
|
||||
private GraphChart chartPace, chartRate, chartHR;
|
||||
Transform dataContent;
|
||||
// Start is called before the first frame update
|
||||
void Awake()
|
||||
{
|
||||
var grid = transform.Find("Scroll View/Viewport/Content/Content/Table").GetComponent<GridLayoutGroup>();
|
||||
float width = (App.canvasWidth - 60 - 3) / 4;
|
||||
grid.cellSize = new Vector2(width, 37);
|
||||
var grid1 = transform.Find("Scroll View/Viewport/Content/Content/Other/Datas").GetComponent<GridLayoutGroup>();
|
||||
grid1.cellSize = new Vector2(width, 53);
|
||||
chartPace = transform.Find("Scroll View/Viewport/Content/Content/ChartPace/Chart").GetComponent<GraphChart>();
|
||||
chartPace.DataSource.VerticalViewOrigin = ChartDateUtility.TimeSpanToValue(TimeSpan.FromHours(15));
|
||||
chartPace.DataSource.VerticalViewSize = ChartDateUtility.TimeSpanToValue(TimeSpan.FromHours(15)) * -1;
|
||||
chartRate = transform.Find("Scroll View/Viewport/Content/Content/ChartRate/Chart").GetComponent<GraphChart>();
|
||||
chartHR = transform.Find("Scroll View/Viewport/Content/Content/ChartHeartRate/Chart").GetComponent<GraphChart>();
|
||||
dataContent = transform.Find("Scroll View/Viewport/Content/Content");
|
||||
UIManager.AddEvent(transform.Find("Exit").gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, b =>
|
||||
{
|
||||
Close();
|
||||
});
|
||||
//var a = new List<ChartAndGraph.DoubleVector2>();
|
||||
//for (int i = 0; i < 100; i++)
|
||||
//{
|
||||
// a.Add(new ChartAndGraph.DoubleVector2(i, ChartDateUtility.TimeSpanToValue(TimeSpan.FromMinutes(300))));
|
||||
//}
|
||||
//transform.Find("Scroll View/Viewport/Content/Content/ChartPace/Chart").GetComponent<RowerLargeDataFeed>().SetData(a);
|
||||
}
|
||||
|
||||
public async void Initial(string id)
|
||||
{
|
||||
GetComponent<CanvasGroup>().alpha = 0;
|
||||
var res = await ConfigHelper.rowerApi.GetDetail(id);
|
||||
if (res.result)
|
||||
{
|
||||
_model = res.data;
|
||||
dataContent.Find("Time").GetComponent<Text>().text = $"{_model.StartTime.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss")} ~ {_model.CreateTime.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss")}";
|
||||
dataContent.Find("TitleContent/Duration").GetComponent<Text>().text
|
||||
= $"<color=#5c5c6e>Rowing time :</color> {TimeSpan.FromSeconds(_model.TotalTime).ToString()}";
|
||||
dataContent.Find("TitleContent/Distance").GetComponent<Text>().text
|
||||
= $"<color=#5c5c6e>Distance :</color> {_model.TotalDistance}M";
|
||||
dataContent.Find("TitleContent/Device").GetComponent<Text>().text
|
||||
= $"<color=#5c5c6e>Rowing equipment :</color> {_model.ManufacturerName}";
|
||||
dataContent.Find("Table/AvgPower/Text").GetComponent<Text>().text
|
||||
= $"{_model.AvgPower.ToString("#0")} W";
|
||||
dataContent.Find("Table/AvgHR/Text").GetComponent<Text>().text
|
||||
= $"{_model.AvgHeartRate} BPM";
|
||||
dataContent.Find("Table/AvgRate/Text").GetComponent<Text>().text
|
||||
= $"{_model.AvgRate.ToString("#0")} W";
|
||||
dataContent.Find("Table/MaxPower/Text").GetComponent<Text>().text
|
||||
= $"{_model.MaxPower.ToString("#0")} W";
|
||||
dataContent.Find("Table/AvgHR/Text").GetComponent<Text>().text
|
||||
= $"{_model.MaxHeartRate} BPM";
|
||||
dataContent.Find("Table/AvgRate/Text").GetComponent<Text>().text
|
||||
= $"{_model.MaxRate.ToString("#0")} W";
|
||||
dataContent.Find("ChartPace/Avg/Value").GetComponent<Text>().text
|
||||
= $"{TimeSpan.FromSeconds(_model.AvgPace).ToString(@"mm\:ss")} /500M";
|
||||
dataContent.Find("ChartRate/Avg/Value").GetComponent<Text>().text
|
||||
= $"{_model.AvgRate.ToString("#0")} SPM";
|
||||
dataContent.Find("ChartHeartRate/Avg/Value").GetComponent<Text>().text
|
||||
= $"{_model.AvgHeartRate.ToString("#0")} BPM";
|
||||
dataContent.Find("ChartPace/Max/Value").GetComponent<Text>().text
|
||||
= $"{TimeSpan.FromSeconds(_model.MaxPace).ToString(@"mm\:ss")} /500M";
|
||||
dataContent.Find("ChartRate/Max/Value").GetComponent<Text>().text
|
||||
= $"{_model.MaxRate.ToString("#0")} SPM";
|
||||
dataContent.Find("ChartHeartRate/Max/Value").GetComponent<Text>().text
|
||||
= $"{_model.MaxHeartRate.ToString("#0")} BPM";
|
||||
dataContent.Find("Other/Datas/Calories/Value").GetComponent<Text>().text
|
||||
= $"{(_model.Kj ?? 0).ToString("#0")} KCAL";
|
||||
dataContent.Find("Other/Datas/StrokeCount/Value").GetComponent<Text>().text
|
||||
= _model.StrokeCount.ToString();
|
||||
//var b = _model.ChartList.Select((x, i) => new DoubleVector2(i, ChartDateUtility.TimeSpanToValue(TimeSpan.FromMinutes(x.Pace + UnityEngine.Random.value * 300)))).ToList();
|
||||
//Debug.Log(_model.ChartList.Select((x, i) => new DoubleVector2(i, ChartDateUtility.TimeSpanToValue(TimeSpan.FromMinutes(x.Pace + UnityEngine.Random.value * 300)))).ToList());
|
||||
chartPace.GetComponent<RowerLargeDataFeed>()
|
||||
.SetData(_model.ChartList.Select((x, i) => new DoubleVector2(i, ChartDateUtility.TimeSpanToValue(TimeSpan.FromMinutes(x.Pace)))).ToList());
|
||||
chartRate.GetComponent<RowerLargeDataFeed>()
|
||||
.SetData(_model.ChartList.Select((x, i) => new DoubleVector2(i, x.Rate)).ToList());
|
||||
chartHR.GetComponent<RowerLargeDataFeed>()
|
||||
.SetData(_model.ChartList.Select((x, i) => new DoubleVector2(i, x.HeartRate)).ToList());
|
||||
}
|
||||
GetComponent<CanvasGroup>().DOFade(1, 0.3f);
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: aa3ab67bcc540104589072a282858e44
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,49 @@
|
||||
using Assets.Scripts.Apis.Models;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class RowerWelldone : PFUIPanel
|
||||
{
|
||||
public override void Show()
|
||||
{
|
||||
base.Show();
|
||||
Debug.Log("well done show");
|
||||
}
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
UIManager.AddEvent(transform.Find("BtnDefine").gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, b =>
|
||||
{
|
||||
gameObject.SetActive(false);
|
||||
});
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
RowerRecordModel model;
|
||||
public void Initial(RowerRecordModel model)
|
||||
{
|
||||
Debug.Log("Initial");
|
||||
if (model == null) return;
|
||||
this.model = model;
|
||||
transform.Find("Time/Value1").GetComponent<Text>().text = model.CreateTime.ToLocalTime().ToString("yyyy-MM-dd");
|
||||
transform.Find("Time/Value2").GetComponent<Text>().text = model.CreateTime.ToLocalTime().ToString("HH:mm:ss");
|
||||
transform.Find("RowingTime/Value").GetComponent<Text>().text = TimeSpan.FromSeconds(model.TotalTime).ToString();
|
||||
transform.Find("Distance/Value").GetComponent<Text>().text = $"{model.TotalDistance.ToString()}M";
|
||||
var datas = transform.Find("Other/Datas");
|
||||
datas.Find("AvgRate/Value").GetComponent<Text>().text = $"{model.AvgRate.ToString("#0")}";
|
||||
datas.Find("MaxRate/Value").GetComponent<Text>().text = $"{model.MaxRate.ToString()}";
|
||||
datas.Find("AvgPower/Value").GetComponent<Text>().text = $"{model.AvgPower.ToString("#0")}";
|
||||
datas.Find("MaxPower/Value").GetComponent<Text>().text = $"{model.MaxPower.ToString()}";
|
||||
datas.Find("MaxPace/Value").GetComponent<Text>().text = $"{TimeSpan.FromSeconds(model.MaxPace).ToString(@"mm\:ss")}";
|
||||
datas.Find("AvgPace/Value").GetComponent<Text>().text = $"{TimeSpan.FromSeconds(model.AvgPace).ToString(@"mm\:ss")}";
|
||||
datas.Find("Calories/Value").GetComponent<Text>().text = $"{(model.Kj ?? 0).ToString("#0")}";
|
||||
datas.Find("StrokeCount/Value").GetComponent<Text>().text = $"{model.StrokeCount}";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a0932c4066cf3c24da73e66759aaec1f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -202,6 +202,62 @@ public class UIManager : MonoBehaviour
|
||||
//UIManager.Show(UIManager.Instance.RaceListPanel, UIManager.Instance.MainPanel);
|
||||
}
|
||||
/*比赛列表*/
|
||||
/*划船机页面*/
|
||||
//自由滑
|
||||
private RowerHomeScript mRowerHomeScript;
|
||||
public RowerHomeScript RowerHomeScript
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.GetPanelInstance("RowerPanel", ref this.mRowerHomeScript);
|
||||
}
|
||||
}
|
||||
public static void ShowRowerPanel()
|
||||
{
|
||||
App.IsRowerMode = true;
|
||||
App.MainDeviceAdapter.ClearDevice();
|
||||
#if UNITY_ANDROID || UNITY_IOS
|
||||
App.MainDeviceAdapter.StartScan();
|
||||
#endif
|
||||
stack.Clear();
|
||||
UIManager.Show(UIManager.Instance.RowerHomeScript, UIManager.Instance.MainPanel);
|
||||
}
|
||||
//结束页
|
||||
private RowerWelldone mRowerWelldone;
|
||||
public RowerWelldone RowerWelldone
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.GetPanelInstance("RowerWelldone", ref this.mRowerWelldone);
|
||||
}
|
||||
}
|
||||
public static void ShowRowerWelldone(RowerRecordModel model)
|
||||
{
|
||||
Debug.Log("進入welldone");
|
||||
UIManager.Show(UIManager.Instance.RowerWelldone, null, true);
|
||||
if (UIManager.Instance.RowerWelldone)
|
||||
{
|
||||
UIManager.Instance.RowerWelldone.Initial(model);
|
||||
}
|
||||
}
|
||||
//结果页
|
||||
private RowerResult mRowerResult;
|
||||
public RowerResult RowerResult
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.GetPanelInstance("RowerResult", ref this.mRowerResult);
|
||||
}
|
||||
}
|
||||
public static void ShowRowerResult(string id)
|
||||
{
|
||||
UIManager.Show(UIManager.Instance.RowerResult, null, true);
|
||||
if (UIManager.Instance.RowerResult)
|
||||
{
|
||||
UIManager.Instance.RowerResult.Initial(id);
|
||||
}
|
||||
}
|
||||
/*划船机页面*/
|
||||
#region 比赛点击弹窗
|
||||
private RaceModalScript mRaceModalScript;
|
||||
public RaceModalScript RaceDetailModal
|
||||
@@ -535,6 +591,7 @@ public class UIManager : MonoBehaviour
|
||||
|
||||
public static void ShowHomePanel()
|
||||
{
|
||||
App.IsRowerMode = false;
|
||||
stack.Clear();
|
||||
UIManager.Instance.MainPanel.GetComponent<Image>().sprite =
|
||||
Resources.Load<Sprite>("Images/main-bg");
|
||||
@@ -815,7 +872,7 @@ public class UIManager : MonoBehaviour
|
||||
}
|
||||
|
||||
Confirm confirm = null;
|
||||
public static void ShowConfirm(string title, string content, UnityAction action,int type = 2)
|
||||
public static void ShowConfirm(string title, string content, UnityAction action,int type = 2,UnityAction cancel = null)
|
||||
{
|
||||
if (UIManager.Instance == null)
|
||||
{
|
||||
@@ -825,12 +882,12 @@ public class UIManager : MonoBehaviour
|
||||
{
|
||||
UIManager.Instance.confirm = UIManager.Instance.GetInstance<Confirm>("Confirm", ref UIManager.Instance.confirm);
|
||||
UIManager.Show(UIManager.Instance.confirm, null, true);
|
||||
UIManager.Instance.confirm.Set(title, content, action);
|
||||
UIManager.Instance.confirm.Set(title, content, action, cancel);
|
||||
}
|
||||
else
|
||||
{
|
||||
UIManager.Instance.confirm.Show();
|
||||
UIManager.Instance.confirm.Set(title, content, action);
|
||||
UIManager.Instance.confirm.Set(title, content, action, cancel);
|
||||
}
|
||||
UIManager.Instance.confirm.SetType(type);
|
||||
}
|
||||
|
||||
@@ -124,7 +124,8 @@ namespace Assets.Scripts
|
||||
{"Cadence","Cadence Sensor|Images/Devices/Cadence_3" },
|
||||
{"HeartRate","Heart Rate Monitor|Images/Devices/Heart Rate_3" },
|
||||
{"SpeedCadence","Cadence Sensor|Images/Devices/Cadence_3" },
|
||||
{"Speed","Speed Meter|Images/Devices/Speed_3" }
|
||||
{"Speed","Speed Meter|Images/Devices/Speed_3" },
|
||||
{"Rower","Rower Machine|Images/Rower/设备 - 划船机" }
|
||||
};
|
||||
}
|
||||
return _deviceDict;
|
||||
|
||||
Reference in new issue
Block a user