Merge remote-tracking branch 'origin/dev' into dev_lishuo

# Conflicts:
#	Assets/Cyp/Prefab.meta
#	Assets/Mapbox/Core/Plugins/Android.meta
#	Assets/Mapbox/Core/Plugins/Mapbox.meta
#	Assets/Mapbox/Core/Plugins/Mapbox/MapboxAccounts.meta
#	Assets/Plugins/Circle/ImageWithRoundedCorners.cs
#	Assets/Resources/Images/Devices.meta
#	Assets/Resources/UI/Prefab/Item.meta
#	Assets/Scripts/Devices/Ant/LegacyPages.meta
#	Assets/Scripts/UI/Prefab/Item.meta
#	Assets/StreamingAssets.meta
#	ProjectSettings/EditorBuildSettings.asset
This commit is contained in:
lishuo committed 2021-04-01 14:09:23 +08:00
commit ae9cefc645
144 files changed
+32337 -8064

No files matched your search

+2 -2
View File
@@ -4,9 +4,9 @@ using UnityEngine;
public static class App
{
public static string Host = "http://192.168.0.101:5087/";
public static string Host = "http://192.168.0.97:5082/";
public static string AppVersion = "1.0.0";
public static int RouteIdParam = 0;
}
@@ -6,6 +6,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
namespace Assets.Scripts.Devices.Ant
{
@@ -91,6 +92,11 @@ namespace Assets.Scripts.Devices.Ant
public bool pairingEnabled;
}
public virtual int Priority
{
get; protected set;
}
//private readonly Rhino.PowerFun.Services.DeviceService deviceService;
//private readonly DeviceDetailService _deviceDetailService;
//private readonly AntManufacturerService antManufacturerService;
@@ -172,6 +178,7 @@ namespace Assets.Scripts.Devices.Ant
{
if (State == DeviceState.Connected || State == DeviceState.Connecting)
return;
Debug.Log("连接" + this.DeviceNumber);
AntConnector.Instance().ConnectDevice(this);
}
@@ -179,6 +186,7 @@ namespace Assets.Scripts.Devices.Ant
{
if (State == DeviceState.Disconnected || State == DeviceState.Disconnecting)
return;
Debug.Log(this.DeviceNumber + "断开连接");
AntConnector.Instance().DisconnectDevice(this, save);
}
+8 -8
View File
@@ -68,10 +68,10 @@ namespace Assets.Scripts.Devices.Ant
//CheckStatus();
deviceList.Add(new FitDevice());
//deviceList.Add(new ds_AntPlus_Power());
//deviceList.Add(new ds_AntPlus_Cadence());
//deviceList.Add(new ds_AntPlus_HeartRate());
//deviceList.Add(new ds_AntPlus_BikeSpdCad());
deviceList.Add(new PowerDevice());
deviceList.Add(new CadenceDevice());
deviceList.Add(new HeartRateDevice());
deviceList.Add(new BikeSpdCadDevice());
var timer = new System.Timers.Timer(1000);
timer.AutoReset = true;
@@ -322,18 +322,18 @@ namespace Assets.Scripts.Devices.Ant
case SensorType.None:
break;
case SensorType.Cadence:
//device = new ds_AntPlus_Cadence();
device = new CadenceDevice();
break;
case SensorType.HeartRate:
//device = new ds_AntPlus_HeartRate();
device = new HeartRateDevice();
break;
case SensorType.Power:
//device = new ds_AntPlus_Power();
device = new PowerDevice();
break;
case SensorType.Speed:
break;
case SensorType.SpeedCadence:
//device = new ds_AntPlus_BikeSpdCad();
device = new BikeSpdCadDevice();
break;
case SensorType.Trainer:
device = new FitDevice();
@@ -0,0 +1,87 @@
using Assets.Scripts.Devices.Ant.Interfaces;
using Assets.Scripts.Devices.Ant.LegacyPages;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Assets.Scripts.Devices.Ant
{
public class BikeSpdCadDevice : AbstractAntDevice, ISpeedDevice, ICadenceDevice
{
public const int MAX_NO_EVENT_STOP_COUNT = 12;
public const double DEFAULT_WHEEL_CIRCUMFERENCE_m = 2096; //Average 700cx23mm road tire
public readonly double wheelCircumfrence_m;
private RotationData _speedData = new RotationData();
private RotationData _cadenceData = new RotationData();
public BikeSpdCadDevice(double wheelCircumfrence_m = DEFAULT_WHEEL_CIRCUMFERENCE_m)
: base("Ant+ Speed&Cadence", racerSportType.Biking, SensorType.SpeedCadence)
{
Priority = 1;
this.wheelCircumfrence_m = wheelCircumfrence_m;
}
public double Speed { get; set; }
private int _Cadence;
public int Cadence
{
get
{
return _Cadence;
}
set
{
_Cadence = DeviceValueFilter.Cadence(value);
}
}
DateTime now = DateTime.Now;
protected override AntChannelProfile getDefaultSearchProfile()
{
return new AntChannelProfile()
{
rfOffset = 57,
transType = 0,
deviceType = 121,
deviceNumber = 0,
messagePeriod = 8086,
pairingEnabled = false,
};
}
public override void handleChannelResponse(ANT_Managed_Library.ANT_Response response)
{
//商品Manufacturer Information
if (response.messageContents[1] == 2)
{
//Console.WriteLine(string.Join(",",response.messageContents));
base.ManufacturerId = response.messageContents[2];
}
if (response.responseID == (byte)ANT_Managed_Library.ANT_ReferenceLibrary.ANTMessageID.BROADCAST_DATA_0x4E)
{
var dataPayload = response.messageContents.Skip(1).ToArray();
int newUpdate1 = (int)dataPayload[0] | (int)dataPayload[1] << 8;
int newCount1 = (int)dataPayload[2] | (int)dataPayload[3] << 8;
int newUpdate2 = (int)dataPayload[4] | (int)dataPayload[5] << 8;
int newCount2 = (int)dataPayload[6] | (int)dataPayload[7] << 8;
var cadence = this._cadenceData.CalculateRpm(now, newUpdate1, newCount1);
if (cadence.HasValue)
{
Cadence = cadence.Value;
}
var a2 = this._speedData.CalculateRpm(now, newUpdate2, newCount2);
if (a2.HasValue)
{
Speed = DoubleExtensions.CalculateSpeed(a2.Value, this.wheelCircumfrence_m);
}
}
}
}
}
@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 5b590b8b6670b334ea1953fea1deba17
guid: 3c53c916c5ea88d42921b701c66a8b2d
MonoImporter:
externalObjects: {}
serializedVersion: 2
@@ -0,0 +1,96 @@
using Assets.Scripts.Devices.Ant.Interfaces;
using Assets.Scripts.Devices.Ant.LegacyPages;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Assets.Scripts.Devices.Ant
{
public class CadenceDevice : AbstractAntDevice, ICadenceDevice
{
public const int MAX_NO_EVENT_STOP_COUNT = 12;
private int _Cadence;
public int Cadence
{
get
{
return _Cadence;
}
set
{
_Cadence = DeviceValueFilter.Cadence(value);
}
}
private DateTime _now = DateTime.Now;
private RotationData _rotationData = new RotationData();
public CadenceDevice()
: base("Ant+ Cadence", racerSportType.Biking, SensorType.Cadence)
{
Priority = 2;
//if (speedSensor.isInUse)
// throw new ArgumentException("Can't use a Speed Sensor that is already in use.");
//speedSensor.customSourceName = "Spd used by Cad w/Spd";
//speedSensor.isInUse = true;
//this.speedSensor = speedSensor;
//speedSensor.start(newSpeedSensorPacket); //Ensure speed sensor is always running so we can always get the values
}
//public override void start(Action<DataSourcePacket> distanceUpdateHandler)
//{
// //Reset the speed sensor first so we get back to a zero distance
// //speedSensor.stop();
// //lastDistance = 0;
// //speedSensor.reset();
// //speedSensor.start(newSpeedSensorPacket);
// base.start(distanceUpdateHandler);
//}
//public void newSpeedSensorPacket(DataSourcePacket pckt)
//{
// double distDiff = pckt.distance - lastDistance;
// if(distDiff > 0)
// incrementDistanceAndUpdate(distDiff, speedMs: pckt.speed_ms, cadence: calculatedCadence);
// lastDistance = pckt.distance;
//}
protected override AntChannelProfile getDefaultSearchProfile()
{
return new AntChannelProfile()
{
rfOffset = 57,
transType = 0,
deviceType = 122,
deviceNumber = 0,
messagePeriod = 8102,
pairingEnabled = false,
};
}
public override void handleChannelResponse(ANT_Managed_Library.ANT_Response response)
{
//商品Manufacturer Information
if (response.messageContents[1] == 2)
{
//Console.WriteLine(string.Join(",",response.messageContents));
base.ManufacturerId = response.messageContents[2];
}
if (response.responseID == (byte)ANT_Managed_Library.ANT_ReferenceLibrary.ANTMessageID.BROADCAST_DATA_0x4E)
{
//In this decode we ignore page change toggle and page type, since the info we need is transmitted on every page
var page = response.messageContents.Skip(1).ToArray();
var cadence = this._rotationData.CalculateRpm(_now, (int)page[4] | (int)page[5] << 8, (int)page[6] | (int)page[7] << 8);
Cadence = cadence.GetValueOrDefault(0);
}
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 992e04a304393e841ad0d13498a74587
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+2 -2
View File
@@ -20,7 +20,6 @@ namespace Assets.Scripts.Devices.Ant
int lastInstCadence = -1;
ushort lastInstPower = 0xFFFF;
/// <summary>
/// 当前坡度,当切换到其他模式的时候,需要把坡度设置为0
/// </summary>
@@ -29,6 +28,7 @@ namespace Assets.Scripts.Devices.Ant
public FitDevice()
: base("Ant+ Trainer", racerSportType.Unknown, SensorType.Trainer)
{
Priority = 0;
this.StateChange = (state) =>
{
if (state == DeviceState.Connected)
@@ -85,7 +85,7 @@ namespace Assets.Scripts.Devices.Ant
set
{
_Power = DeviceValueFilter.Power(value);
Debug.Log(_Power);
//Debug.Log(_Power);
}
}
@@ -0,0 +1,66 @@
using Assets.Scripts.Devices.Ant.Interfaces;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Assets.Scripts.Devices.Ant
{
public class HeartRateDevice : AbstractAntDevice, IHeartRateDevice
{
//public const int MAX_NO_EVENT_STOP_COUNT = 12;
private int _HeartRate;
public int HeartRate
{
get
{
return _HeartRate;
}
set
{
_HeartRate = DeviceValueFilter.HeartRate(value);
}
}
//ds_AntPlus_BikeSpd speedSensor;
public HeartRateDevice()
: base("Ant+ HeartRate", racerSportType.Unknown, SensorType.HeartRate)
{
Priority = 2;
}
protected override AntChannelProfile getDefaultSearchProfile()
{
return new AntChannelProfile()
{
rfOffset = 57,
transType = 0,
deviceType = 120,
deviceNumber = 0,
messagePeriod = 8070,
pairingEnabled = false,
};
}
public override void handleChannelResponse(ANT_Managed_Library.ANT_Response response)
{
//Console.WriteLine(string.Join(",", response.messageContents));
//商品Manufacturer Information
if (response.messageContents[1] == 2)
{
base.ManufacturerId = response.messageContents[2];
}
if (response.responseID == (byte)ANT_Managed_Library.ANT_ReferenceLibrary.ANTMessageID.BROADCAST_DATA_0x4E)
{
var num = response.messageContents[8];
//PubCommData.HeartRate = num;
HeartRate = num;
}
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ab69ac4f4621acc409ac4c6a29893f9f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 93809400c8fb6fb41aa3cb44471bf185
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,112 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Assets.Scripts.Devices.Ant.LegacyPages
{
public class RotationData
{
private static readonly TimeSpan TimeBeforeRollover = TimeSpan.FromSeconds(63.0);
private const int MaxUpdateValue = 65535;
private const int MaxCountValue = 65535;
private int? _update;
private int? _count;
private DateTimeOffset? _lastUpdatedTime;
private int _rpm;
public int? CalculateRpm(DateTimeOffset now, int newUpdate, int newCount)
{
DateTimeOffset time = now;
if (!this._lastUpdatedTime.HasValue)
{
this._update = new int?(newUpdate);
this._count = new int?(newCount);
this._lastUpdatedTime = new DateTimeOffset?(now);
return new int?();
}
if (this.HasNotMoved(newUpdate, time))
return new int?(0);
if (this.HasMoreThanOneRolloverOccurred(time))
{
this._lastUpdatedTime = new DateTimeOffset?(time);
this._update = new int?(newUpdate);
this._count = new int?(newCount);
return new int?();
}
if (this.HasNotUpdated(newUpdate))
return new int?(this._rpm);
if (this.HasUpdateRolledOver(newUpdate))
{
int? nullable = this._update;
this._update = nullable.HasValue ? new int?(nullable.GetValueOrDefault() - (int)ushort.MaxValue) : new int?();
}
if (this.HasCountRolledOver(newCount))
{
int? nullable = this._count;
this._count = nullable.HasValue ? new int?(nullable.GetValueOrDefault() - (int)ushort.MaxValue) : new int?();
}
this._rpm = (int)Math.Round((double)(newCount - this._count.Value) / (double)(newUpdate - this._update.Value) * 1024.0 * 60.0);
this._lastUpdatedTime = new DateTimeOffset?(time);
this._update = new int?(newUpdate);
this._count = new int?(newCount);
return new int?(this._rpm);
}
private bool HasMoreThanOneRolloverOccurred(DateTimeOffset time)
{
DateTimeOffset dateTimeOffset = time;
DateTimeOffset? nullable1 = this._lastUpdatedTime;
TimeSpan? nullable2 = nullable1.HasValue ? new TimeSpan?(dateTimeOffset - nullable1.GetValueOrDefault()) : new TimeSpan?();
TimeSpan timeSpan = RotationData.TimeBeforeRollover;
if (!nullable2.HasValue)
return false;
return nullable2.GetValueOrDefault() > timeSpan;
}
private bool HasCountRolledOver(int newCount)
{
int num = newCount;
int? nullable = this._count;
int valueOrDefault = nullable.GetValueOrDefault();
if (num >= valueOrDefault)
return false;
return nullable.HasValue;
}
private bool HasUpdateRolledOver(int newUpdate)
{
int num = newUpdate;
int? nullable = this._update;
int valueOrDefault = nullable.GetValueOrDefault();
if (num >= valueOrDefault)
return false;
return nullable.HasValue;
}
private bool HasNotUpdated(int newUpdate)
{
int num = newUpdate;
int? nullable = this._update;
int valueOrDefault = nullable.GetValueOrDefault();
if (num != valueOrDefault)
return false;
return nullable.HasValue;
}
private bool HasNotMoved(int newUpdate, DateTimeOffset time)
{
DateTimeOffset dateTimeOffset = time - TimeSpan.FromSeconds(4.0);
DateTimeOffset? nullable1 = this._lastUpdatedTime;
if ((nullable1.HasValue ? (dateTimeOffset >= nullable1.GetValueOrDefault() ? 1 : 0) : 0) == 0)
return false;
int num = newUpdate;
int? nullable2 = this._update;
int valueOrDefault = nullable2.GetValueOrDefault();
if (num != valueOrDefault)
return false;
return nullable2.HasValue;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 057a1149cfd54d24bb329df54a9c9dfa
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,35 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Assets.Scripts.Devices.Ant.Messages
{
/// <summary>
/// 手动校准命令
/// </summary>
public class ManualCalibrate : BaseMessage
{
public ManualCalibrate(byte channel)
: base(channel)
{
}
public override ANTMessage GetMessage()
{
return new ANTMessage()
{
Id = (byte)79,
Size = (byte)3,
Data = new byte[3]
{
this.Channel,
(byte) 1,
(byte) 170
}
};
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 30adc878ef1c2cb4fb944e55b2d3d439
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,41 @@
using Assets.Scripts.Devices.Ant.Pages.CalibrationPages;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Assets.Scripts.Devices.Ant.Pages
{
/// <summary>
/// 设备校准的处理函数
/// </summary>
public class CalibrationPageHandler : IPageHandler
{
private readonly IList<ICalibrationPage> _calibrationPageHandlers = new List<ICalibrationPage>()
{
new CtfCalibrationPage(),
new FecCalibrationPage(),
new FailureCalibrationPage(),
new SuccessCalibrationPage()
};
public bool CanHandle(byte pageNumber)
{
if ((int)pageNumber != 1)
{
return (int)pageNumber == 240;
}
return true;
}
public void Handle(byte[] dataPayload, AbstractAntDevice device)
{
var calibrationPage = this._calibrationPageHandlers.FirstOrDefault(ph => ph.CanHandle(dataPayload[1]));
if (calibrationPage == null)
return;
calibrationPage.Handle(dataPayload, device);
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 75c5b210cd34db1498a311b6656f9ad4
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Assets.Scripts.Devices.Ant.Pages.CalibrationPages
{
public class CtfCalibrationPage : ICalibrationPage
{
public bool CanHandle(byte calibrationId)
{
return (int)calibrationId == 16;
}
public void Handle(byte[] dataPayload, AbstractAntDevice device)
{
var powerDevice = device as PowerDevice;
if (powerDevice == null || (int)dataPayload[2] != 1)
return;
//参考类CtfCalibrationResult
var offset = (int)((int)dataPayload[7] | (int)dataPayload[6] << 8);
powerDevice.DoCalibrationSuccess(offset, AutoZeroStatus.NotSupported);
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 14c60f86d0918cf4d9656359561b9c7d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Assets.Scripts.Devices.Ant.Pages.CalibrationPages
{
/// <summary>
/// 校准失败的处理函数
/// </summary>
public class FailureCalibrationPage : ICalibrationPage
{
public bool CanHandle(byte calibrationId)
{
return (int)calibrationId == 175;
}
public void Handle(byte[] dataPayload, AbstractAntDevice device)
{
var powerDevice = device as PowerDevice;
if (powerDevice == null)
return;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 87c2482dbcf031e488a6dd7cfc3b475b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Assets.Scripts.Devices.Ant.Pages.CalibrationPages
{
/// <summary>
/// 校准成功的处理函数
/// </summary>
public class SuccessCalibrationPage : ICalibrationPage
{
public bool CanHandle(byte calibrationId)
{
return (int)calibrationId == 172;
}
public void Handle(byte[] dataPayload, AbstractAntDevice device)
{
//throw new NotImplementedException();
var powerDevice = device as PowerDevice;
if (powerDevice == null)
return;
var autoZeroStatus = (AutoZeroStatus)dataPayload[2];
var offset = (int)((int)dataPayload[7] << 8 | (int)dataPayload[6]);
powerDevice.DoCalibrationSuccess(offset, autoZeroStatus);
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c45f42f53396ece499b5153107ab46da
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Assets.Scripts.Devices.Ant.Pages
{
public class CrankPowerPageHandler : IPageHandler
{
private readonly TorquePowerDataCalculator _torquePowerDataCalculator = new TorquePowerDataCalculator();
public bool CanHandle(byte pageNumber)
{
return (int)pageNumber == 18;
}
public void Handle(byte[] dataPayload, AbstractAntDevice device)
{
var powerDevice = device as PowerDevice;
if (powerDevice == null)
return;
byte eventCount = dataPayload[1];
int num = (int)dataPayload[3];
ushort period = (ushort)((uint)dataPayload[4] | (uint)dataPayload[5] << 8);
ushort accumulatedTorque = (ushort)(dataPayload[6] | (uint)dataPayload[7] << 8);
this._torquePowerDataCalculator.Update(eventCount, period, accumulatedTorque);
//powerDevice.UpdateCadence(new int?(this._torquePowerDataCalculator.Rpm));
//powerDevice.UpdatePower(new int?(this._torquePowerDataCalculator.Power));
powerDevice.Cadence = this._torquePowerDataCalculator.Rpm;
powerDevice.Power = this._torquePowerDataCalculator.Power;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: cb07cd617b03b2b4eb8df137b07ae7fc
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,52 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Assets.Scripts.Devices.Ant.Pages
{
/// <summary>
/// Crank Torque-Frequency Message 曲柄功率计的消息
/// </summary>
public class CtfPageHandler : IPageHandler
{
private readonly CrankTorqueFrequencyData _crankTorqueFrequency = new CrankTorqueFrequencyData();
public bool CanHandle(byte pageNumber)
{
return (int)pageNumber == 32;
}
public void Handle(byte[] dataPayload, AbstractAntDevice device)
{
var powerDevice = device as PowerDevice;
if (powerDevice == null)
{
return;
}
byte num1 = dataPayload[1];
ushort num2 = (ushort)((uint)dataPayload[3] | (uint)dataPayload[2] << 8);
ushort num3 = (ushort)((uint)dataPayload[5] | (uint)dataPayload[4] << 8);
ushort num4 = (ushort)((uint)dataPayload[7] | (uint)dataPayload[6] << 8);
if (powerDevice.Offset.HasValue)
{
int offset = powerDevice.Offset.GetValueOrDefault(0);
CrankTorqueFrequencyData torqueFrequencyData = this._crankTorqueFrequency;
int num5 = (int)num1;
int num6 = (int)num3;
int num7 = (int)num4;
int num8 = (int)num2;
torqueFrequencyData.Update((byte)num5, (ushort)num6, (ushort)num7, (ushort)num8, offset);
Console.WriteLine("offset:" + offset);
powerDevice.Power = this._crankTorqueFrequency.Power.GetValueOrDefault();
}
powerDevice.Cadence = this._crankTorqueFrequency.Cadence;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 20f678fa75e9edb48a11bed1c1284daf
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,50 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Assets.Scripts.Devices.Ant.Pages
{
public class PowerOnlyPageHandler : IPageHandler
{
private DateTime _lastEventChange = DateTime.UtcNow;
private byte _previousEventCount;
public bool CanHandle(byte pageNumber)
{
return (int)pageNumber == 16;
}
public void Handle(byte[] dataPayload, AbstractAntDevice device)
{
var powerDevice = device as PowerDevice;
if (powerDevice == null)
{
return;
}
//var dataPayload = response.messageContents.Skip(1).ToArray();
byte currentVal = dataPayload[1];
if ((int)ByteExtensions.GetDifference(currentVal, this._previousEventCount) > 0) //ByteExtensions
this._lastEventChange = DateTime.UtcNow;
this._previousEventCount = currentVal;
powerDevice.Power = this.IsNotMovingDueToNoEventChanges() ? 0 : (ushort)((uint)dataPayload[6] | (uint)dataPayload[7] << 8);
if ((int)dataPayload[3] != (int)byte.MaxValue)
powerDevice.Cadence = (this.IsNotMovingDueToNoEventChanges() ? 0 : (int)dataPayload[3]);
else
powerDevice.Cadence = 0;
//int num1 = (int)dataPayload[2];
//int num2 = 128;
//bool flag = (uint)(num1 & num2) > 0U;
//int num3 = (int)sbyte.MaxValue;
//int num4 = num1 & num3;
//int num5 = (int)byte.MaxValue;
}
private bool IsNotMovingDueToNoEventChanges()
{
return this._lastEventChange.AddSeconds(3.0) <= DateTime.UtcNow;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 267f065da5b080847b6c2354e6af58f2
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,43 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Assets.Scripts.Devices.Ant.Pages
{
/// <summary>
/// 轮盘功率计
/// </summary>
public class WheelPowerPageHandler : IPageHandler
{
private readonly TorquePowerDataCalculator _torquePowerDataCalculator = new TorquePowerDataCalculator();
public bool CanHandle(byte pageNumber)
{
return pageNumber == 17;
}
public void Handle(byte[] dataPayload, AbstractAntDevice device)
{
//throw new NotImplementedException();
var powerDevice = device as PowerDevice;
if (powerDevice == null)
return;
var eventCount = dataPayload[1];
var num = dataPayload[3];
var period = (ushort)((uint)dataPayload[4] | (uint)dataPayload[5] << 8);
var accumulatedTorque = (ushort)((uint)dataPayload[6] | (uint)dataPayload[7] << 8);
_torquePowerDataCalculator.Update(eventCount, period, accumulatedTorque);
powerDevice.Power = _torquePowerDataCalculator.Power;
powerDevice.Cadence = num;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 399061526025e6148ba3f55a5800ed56
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+316
View File
@@ -0,0 +1,316 @@
using Assets.Scripts.Devices.Ant.Interfaces;
using Assets.Scripts.Devices.Ant.Messages;
using Assets.Scripts.Devices.Ant.Pages;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Timers;
namespace Assets.Scripts.Devices.Ant
{
/// <summary>
/// 功率计
/// </summary>
public class PowerDevice : AbstractAntDevice, IPowerDevice //, ICadenceDevice
{
private DateTime _lastEventChange = DateTime.UtcNow;
//private byte _previousEventCount;
private readonly TorquePowerDataCalculator _torquePowerDataCalculator = new TorquePowerDataCalculator();
private readonly CrankTorqueFrequencyData _crankTorqueFrequency = new CrankTorqueFrequencyData();
private System.Timers.Timer timer;
//List<IPageHandler> pageHandlers;
public PowerDevice()
: base("Ant+ Power", racerSportType.Biking, SensorType.Power)
{
Priority = 2;
//pageHandlers = new List<IPageHandler>();
//pageHandlers.Add(new ManufacturerDataPageHandler());
pageHandlers.Add(new PowerOnlyPageHandler());
pageHandlers.Add(new CrankPowerPageHandler());
pageHandlers.Add(new CtfPageHandler());
pageHandlers.Add(new WheelPowerPageHandler());
pageHandlers.Add(new CalibrationPageHandler());
this.StateChange = (state) =>
{
if (state == DeviceState.Connected)
{
Calibrate();
}
else if (state == DeviceState.Disconnected)
{
count = 0;
if (timer != null)
{
timer.Stop();
timer = null;
DoCalibrationFailure();
}
}
};
}
private int _Power;
public int Power
{
get
{
return _Power;
}
set
{
_Power = DeviceValueFilter.Power(value);
}
}
private int _Cadence;
public int Cadence
{
get
{
return _Cadence;
}
set
{
_Cadence = DeviceValueFilter.Cadence(value);
}
}
public DateTime LastCalibration { get; protected set; }
public int? Offset { get; set; }
public AutoZeroStatus AutoZeroStatus { get; private set; }
public bool IsCalibrating { get; set; }
public bool IsCalibrationReady { get; set; }
public bool CalibrationCompleted { get; set; }
protected override AntChannelProfile getDefaultSearchProfile()
{
return new AntChannelProfile()
{
rfOffset = 57,
transType = 0,
deviceType = 11,
deviceNumber = 0,
messagePeriod = 8182,
pairingEnabled = false,
};
}
//List<int> list = new List<int>();
public override void handleChannelResponse(ANT_Managed_Library.ANT_Response response)
{
//if (!list.Contains(response.messageContents[1]))
//{
// list.Add(response.messageContents[1]);
// Console.WriteLine(response.messageContents[1]);
//}
//Console.WriteLine(string.Join(",", response.messageContents));
if (response.responseID == (byte)ANT_Managed_Library.ANT_ReferenceLibrary.ANTMessageID.BROADCAST_DATA_0x4E)
{
var pageNumber = response.messageContents[1];
foreach (var handler in pageHandlers)
{
if (handler.CanHandle(pageNumber))
{
handler.Handle(response.messageContents.Skip(1).ToArray(), this);
}
}
}
//System.IO.File.AppendAllText(System.Environment.CurrentDirectory + "\\data.txt", string.Join(",", response.messageContents) + ";" + Power+"\r\n");
//Console.WriteLine();
}
internal void DoCalibrationSuccess(int? offset, AutoZeroStatus autoZeroStatus)
{
this.AutoZeroStatus = autoZeroStatus;
this.LastCalibration = DateTime.UtcNow;
if (this.Offset.HasValue == false)
{
this.Offset = offset;
//this.Offset = 570;
}
this.IsCalibrating = false;
this.CalibrationCompleted = true;
//Trace.WriteLine($"校准成功:{ offset }");
}
internal void DoCalibrationFailure()
{
this.IsCalibrating = false;
this.CalibrationCompleted = false;
}
/// <summary>
/// 发送校准命令
/// </summary>
public void Calibrate()
{
if (this.IsCalibrating)
return;
this.IsCalibrating = true;
var channelId = GetChannelId();
base.SendMessage(new ManualCalibrate(channelId));
if (timer == null)
{
timer = new System.Timers.Timer(10000);
timer.Elapsed += Timer_Elapsed;
timer.Start();
}
}
int count = 0;
/// <summary>
/// 检查是否已自动校准,自动发送3次
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Timer_Elapsed(object sender, ElapsedEventArgs e)
{
if (count > 3)
{
timer.Stop();
return;
}
if (this.CalibrationCompleted)
{
timer.Stop();
return;
}
count++;
this.IsCalibrating = false;
this.Calibrate();
}
}
public class TorquePowerDataCalculator
{
private DateTime _lastEventChange = DateTime.UtcNow;
private byte _previousEventCount;
private ushort _previousPeriod;
private ushort _previousAccumulatedTorque;
public int Power { get; private set; }
public int Rpm { get; private set; }
public DateTime LastUpdatedTime { get; private set; }
public TorquePowerDataCalculator()
{
this.LastUpdatedTime = DateTime.MinValue;
}
public void Update(byte eventCount, ushort period, ushort accumulatedTorque)
{
byte difference1 = ByteExtensions.GetDifference(eventCount, this._previousEventCount);
ushort difference2 = UshortExtensions.GetDifference(period, this._previousPeriod);
if ((int)difference1 > 0)
this._lastEventChange = DateTime.UtcNow;
if (this.PeriodRolloverPossible() || this.IsNotMovingDueToNoEventChanges() || (int)difference2 == 0 && (int)difference1 > 0)
{
this.Power = 0;
this.Rpm = 0;
}
else if ((int)difference1 > 0)
{
this.Power = (int)(402.123859659494 * ((double)UshortExtensions.GetDifference(accumulatedTorque, this._previousAccumulatedTorque) / (double)difference2));
this.Rpm = 122880 * (int)difference1 / (int)difference2;
}
this.LastUpdatedTime = DateTime.UtcNow;
this._previousEventCount = eventCount;
this._previousPeriod = period;
this._previousAccumulatedTorque = accumulatedTorque;
}
private bool PeriodRolloverPossible()
{
return DateTime.UtcNow - this.LastUpdatedTime > TimeSpan.FromSeconds(32.0);
}
private bool IsNotMovingDueToNoEventChanges()
{
return this._lastEventChange.AddSeconds(3.0) <= DateTime.UtcNow;
}
}
public class CrankTorqueFrequencyData
{
private byte _previousEventCount;
private ushort _previousTimestamp;
private ushort _previousTorqueTicksStamp;
private int _noEventCount;
public int? Power { get; private set; }
public int Cadence { get; private set; }
public DateTime LastUpdatedTime { get; set; }
public CrankTorqueFrequencyData()
{
this.LastUpdatedTime = DateTime.MinValue;
}
public void Update(byte eventCount, ushort timestamp, ushort torqueTicksStamp, ushort slope, int offset)
{
byte difference1 = ByteExtensions.GetDifference(eventCount, this._previousEventCount);
ushort difference2 = UshortExtensions.GetDifference(timestamp, this._previousTimestamp);
ushort difference3 = UshortExtensions.GetDifference(torqueTicksStamp, this._previousTorqueTicksStamp);
this._previousEventCount = eventCount;
this._previousTimestamp = timestamp;
this._previousTorqueTicksStamp = torqueTicksStamp;
if (this.HasMoreThanOneRolloverOccured())
{
this.LastUpdatedTime = DateTime.UtcNow;
this.Power = new int?(0);
this.Cadence = 0;
}
else
{
this.LastUpdatedTime = DateTime.UtcNow;
if ((int)difference1 > 0)
{
this._noEventCount = 0;
double num = (double)difference2 / (double)difference1 * 0.0005;
if ((int)difference2 == 0)
return;
this.Cadence = (int)Math.Round(60.0 / num);
if ((int)difference3 == 0)
this.Power = new int?();
else
this.Power = new int?((int)((1.0 / ((double)difference2 * 0.0005 / (double)difference3) - (double)offset) / ((double)slope / 10.0) * (double)this.Cadence * 3.14159265358979 / 30.0));
}
else
{
int num = this._noEventCount + 1;
this._noEventCount = num;
if (num < 12)
return;
this.Power = new int?(0);
this.Cadence = 0;
}
}
}
private bool HasMoreThanOneRolloverOccured()
{
return DateTime.UtcNow - this.LastUpdatedTime > TimeSpan.FromSeconds(32.7);
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 0ffde5f7de300274b8b12fe730cb7de1
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+15
View File
@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Assets.Scripts.Devices
{
public enum AutoZeroStatus
{
Off = 0,
On = 1,
NotSupported = 255,
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 990ecf923f6a62740920e907a9cc3c7c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+34
View File
@@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Assets.Scripts.Devices
{
public static class ByteExtensions
{
public static byte GetDifference(this byte currentVal, byte previousVal)
{
byte num = (byte)((uint)currentVal - (uint)previousVal);
if ((int)previousVal > (int)currentVal)
num = (byte)((int)byte.MaxValue + (int)num + 1);
return num;
}
public static bool Contains(this IEnumerable<byte[]> enumerable, byte[] bytes)
{
return Enumerable.Any<byte[]>(enumerable, (Func<byte[], bool>)(x => Enumerable.SequenceEqual<byte>((IEnumerable<byte>)x, (IEnumerable<byte>)bytes)));
}
public static bool IsFlagSet(this byte value, byte flag)
{
return ((uint)value & (uint)flag) > 0U;
}
public static bool IsFlagSetAtPosition(this byte value, byte position)
{
return ((uint)value & 1U << (int)position) > 0U;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 00dc0ba830758464fae2f204b6218128
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Assets.Scripts.Devices
{
public static class DoubleExtensions
{
public static double CalculateSpeed(this int wheelRpm, double wheelCircumference)
{
return (double)wheelRpm * (wheelCircumference / 1000.0) * 0.06;
}
public static double MetersPerSecondToKmh(this double metersPerSecond)
{
return metersPerSecond * 60.0 * 60.0 / 1000.0;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 364c16c31b8f7ab49a084259f04d2f09
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Assets.Scripts.Devices
{
public static class UshortExtensions
{
public static ushort GetDifference(this ushort currentVal, ushort previousVal)
{
ushort num = (ushort)((uint)currentVal - (uint)previousVal);
if ((int)previousVal > (int)currentVal)
num = (ushort)((int)ushort.MaxValue + (int)num + 1);
return num;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 083d77e46c7d43948bebc2c85b0252b5
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+110 -9
View File
@@ -8,27 +8,53 @@ using System.Collections.Generic;
using System.Reflection;
using System.Text;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.EventSystems;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
//记录:小f 是-457和-681
public class LoginForm
{
public InputField phone;
public InputField pwd;
}
public class LoginController : MonoBehaviour
{
[SerializeField] InputField phone;
[SerializeField] InputField pwd;
[SerializeField] InputField[] loginForm;
[SerializeField] Button login;
[SerializeField] Button loginNewAccount;
[SerializeField] Button loginReturn2;
[SerializeField] Button returnQuick;
[SerializeField] Button regNext;
[SerializeField] Button regPrev;
[SerializeField] Button sign;
[SerializeField] Button remember;
[SerializeField] GameObject loginScrollView;
[SerializeField] GameObject signScrollView;
[SerializeField] GameObject avatarScrollView;
[SerializeField] RawImage loading;
[SerializeField] Button exit;
private ScrollRect scrollPanel;
private ScrollRect scrollSign;
private ScrollRect scrollAvatar;
private Transform imagexf;
// Start is called before the first frame update
void Start()
{
//transform.Find("RawImage").DOMove(new Vector3(0.5f,0.5f,0),1);
if (loginForm.Length == 2 && loginForm[0]!=null && loginForm[1]!=null)
{
foreach (var ipt in loginForm)
{
UIManager.AddEvent(ipt.gameObject, EventTriggerType.PointerClick, new UnityAction<BaseEventData>
((BaseEventData arg0) => { OnLoginInputSelect(arg0, ipt.gameObject); }));
UIManager.AddEvent(ipt.gameObject, EventTriggerType.Select, new UnityAction<BaseEventData>
((BaseEventData arg0) => { OnLoginInputSelect(arg0, ipt.gameObject); }));
UIManager.AddEvent(ipt.gameObject, EventTriggerType.Deselect, new UnityAction<BaseEventData>
((BaseEventData arg0) => { OnLoginInputDeSelect(arg0, ipt.gameObject); }));
}
//loginForm[0].
}
if (login != null)
{
login.onClick.AddListener(Submit);
@@ -46,6 +72,10 @@ public class LoginController : MonoBehaviour
{
scrollSign = signScrollView.GetComponent<ScrollRect>();
}
if (avatarScrollView != null)
{
scrollAvatar = avatarScrollView.GetComponent<ScrollRect>();
}
if (loginNewAccount != null)
{
loginNewAccount.onClick.AddListener(goLogin);
@@ -58,13 +88,76 @@ public class LoginController : MonoBehaviour
{
sign.onClick.AddListener(goSign);
}
if (loginReturn2 != null)
{
loginReturn2.onClick.AddListener(goLoginReturn2);
}
if (regNext != null)
{
regNext.onClick.AddListener(goRegNext);
}
if (regPrev != null)
{
regPrev.onClick.AddListener(goRegPrev);
}
if (exit != null)
{
exit.onClick.AddListener(() => Application.Quit());
}
if (remember != null)
{
remember.onClick.AddListener(() =>
{
var gou = remember.transform.Find("Gou");
if (gou.gameObject.activeSelf)
{
gou.gameObject.SetActive(false);
}
else
{
gou.gameObject.SetActive(true);
}
});
}
imagexf = transform.Find("Panel").Find("LoginContainer").Find("Imagexf");
}
private void OnLoginInputDeSelect(BaseEventData arg0, GameObject game)
{
var image = game.transform.GetComponent<Image>();
image.sprite = Resources.Load<Sprite>("Images/gl-no");
//var rect = game.transform.GetComponent<RectTransform>();
//rect.SetSiblingIndex(rect.childCount-1);
}
private void OnLoginInputSelect(BaseEventData arg0,GameObject game)
{
var image = game.transform.GetComponent<Image>();
image.sprite = Resources.Load<Sprite>("Images/gl");
//var rect = game.transform.GetComponent<RectTransform>();
//rect.SetSiblingIndex(0);
}
private void goRegPrev()
{
StartScrollSign(0);
}
private void goRegNext()
{
StartScrollSign(1);
}
private void goLoginReturn2()
{
this.StartScrollPanel(1);
}
void ReturnQuick()
{
if (imagexf != null)
{
imagexf.DOLocalMove(new Vector3(0, -457, 0), 0.3f);
imagexf.DOLocalMove(new Vector3(0, -447, 0), 0.3f);
}
this.StartScrollPanel(0);
}
@@ -72,17 +165,18 @@ public class LoginController : MonoBehaviour
{
if (imagexf != null)
{
imagexf.DOLocalMove(new Vector3(0, -681, 0), 0.3f);
imagexf.DOLocalMove(new Vector3(0, -635, 0), 0.3f);
}
this.StartScrollPanel(1);
}
void goSign()
{
this.StartScrollPanel(2);
this.StartScrollSign(0);
}
async void Submit()
{
if (phone == null || pwd == null)
if (loginForm[0] == null || loginForm[1] == null)
{
Utils.showToast(gameObject, "未绑定", 1);
return;
@@ -109,10 +203,10 @@ public class LoginController : MonoBehaviour
// Update is called once per frame
void Update()
{
Debug.Log($"{phone.isFocused}, ${pwd != null}, ${Input.GetKeyDown(KeyCode.Tab)}");
if (phone.isFocused && pwd != null && Input.GetKeyDown(KeyCode.Tab))
//Debug.Log($"{phone.isFocused}, ${pwd != null}, ${Input.GetKeyDown(KeyCode.Tab)}");
if (loginForm[0].isFocused && loginForm[1] != null && Input.GetKeyDown(KeyCode.Tab))
{
pwd.ActivateInputField();
loginForm[1].ActivateInputField();
}
goScrollPanel();
goScrollSign();
@@ -131,7 +225,7 @@ public class LoginController : MonoBehaviour
#region 主页面滑动逻辑
private int tmpImdex = 0;
private int scrollPanelIndex = 2;
private float scrollValue = 0.5f;
//private float scrollValue = 0.5f;
private bool startScrollPanel = false;
private void StartScrollPanel(int index)
{
@@ -142,6 +236,7 @@ public class LoginController : MonoBehaviour
private void goScrollPanel()
{
var index = scrollPanelIndex;
var scrollValue = 1f/(3 - 1);
var value = index * scrollValue;
if (scrollPanel != null && startScrollPanel)
{
@@ -183,6 +278,12 @@ public class LoginController : MonoBehaviour
#region 注册页面滑动逻辑
private bool startScrollSign = false;
private int scrollSignIndex = 0;
private void StartScrollSign(int index)
{
if (startScrollSign) return;
scrollSignIndex = index;
startScrollSign = true;
}
private void goScrollSign()
{
float value = scrollSignIndex;
+1 -1
View File
@@ -8,7 +8,7 @@ public class MainController : MonoBehaviour
void Start()
{
UIManager.Instance.MainPanel = (GameObject)this.transform.Find("Panel").gameObject;
//UIManager.Instance.ModalsPanel = this.transform.Find("PanelModals").gameObject;
UIManager.Instance.ModalsPanel = this.transform.Find("ModalPanel").gameObject;
//MainMenu.transform.Find("Home").GetComponent<Button>().onClick.AddListener(() =>
+2 -2
View File
@@ -45,13 +45,13 @@ namespace Assets.Scripts.UI.Control
public void OnSelect(BaseEventData eventData)
{
var image = this.transform.GetComponent<Image>();
var png = Resources.Load<Sprite>("Images/input-bg2");
var png = Resources.Load<Sprite>("Images/ipt-1");
image.sprite = png;
}
public void OnDeselect(BaseEventData eventData)
{
var image = this.transform.GetComponent<Image>();
var png1 = Resources.Load<Sprite>("Images/input-bg1");
var png1 = Resources.Load<Sprite>("Images/ipt-0");
image.sprite = png1;
}
+2 -2
View File
@@ -32,7 +32,7 @@ namespace Assets.Scripts.UI.Control
//throw new NotImplementedException();
this.mInnerInputField.OnSelect(eventData);
var image = this.transform.GetComponent<Image>();
var png = Resources.Load<Sprite>("Images/input-bg2");
var png = Resources.Load<Sprite>("Images/ipt-1");
image.sprite = png;
}
@@ -40,7 +40,7 @@ namespace Assets.Scripts.UI.Control
{
this.mInnerInputField.OnDeselect(eventData);
var image = this.transform.GetComponent<Image>();
var png1 = Resources.Load<Sprite>("Images/input-bg1");
var png1 = Resources.Load<Sprite>("Images/ipt-0");
image.sprite = png1;
}
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 633debeb22d82eb4499126e20f36ba3a
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,149 @@
using Assets.Scripts.Devices.Ant;
using System.Collections;
using System.Collections.Generic;
using System;
using System.Linq;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
using Assets.Scripts.Devices.Ant.Interfaces;
public class ConnectDeviceModal : PFUIPanel
{
private float timer = 1.0f;
private SensorType mSensorType = SensorType.None;
public SensorType SensorType {
get {
return mSensorType;
}
set
{
Debug.Log(value);
mSensorType = value;
Logo.sprite = Resources.Load<Sprite>("Images/Devices/Trainer_3");
}
}
private Image Logo;
private UnityEngine.Object deviceItem;
private VerticalLayoutGroup content;
protected override void Awake()
{
base.Awake();
deviceList = new Dictionary<ushort, DeviceItem>();
var closeBtn = this.transform.Find("CloseBtn");
Logo = this.transform.Find("Logo").GetComponent<Image>();
content = this.transform.Find("Panel").Find("Scroll View").Find("Viewport").Find("Content").GetComponent<VerticalLayoutGroup>();
UIManager.AddEvent(closeBtn.gameObject, EventTriggerType.PointerClick, new UnityEngine.Events.UnityAction<BaseEventData>(e =>
{
//this.gameObject.SetActive(false);
this.Close();
}));
deviceItem = Resources.Load("UI/Prefab/Device/DeviceItem");
}
// Start is called before the first frame update
void Start()
{
SearchDevice();
}
private Dictionary<ushort, DeviceItem> deviceList;
// Update is called once per frame
void Update()
{
timer -= Time.deltaTime;
if(timer <= 0)
{
SearchDevice();
timer = 1.0f;
}
}
private void SearchDevice()
{
if (SensorType != SensorType.None)
{
//Debug.Log(AntConnector.Instance().discoveredDevices.Count(d => d.Sensor == SensorType));
var devices = new List<AbstractAntDevice>();
switch (SensorType)
{
case SensorType.Cadence:
devices = AntConnector.Instance().discoveredDevices.Where(d => d.Sensor == SensorType || (d is ICadenceDevice && d.State == DeviceState.Connected)).OrderBy(d=>d.Priority).ToList();
break;
case SensorType.HeartRate:
devices = AntConnector.Instance().discoveredDevices.Where(d => d.Sensor == SensorType || (d is IHeartRateDevice && d.State == DeviceState.Connected)).OrderBy(d => d.Priority).ToList();
break;
case SensorType.Power:
devices = AntConnector.Instance().discoveredDevices.Where(d => d.Sensor == SensorType || (d is IPowerDevice && d.State == DeviceState.Connected)).OrderBy(d=>d.Priority).ToList();
break;
case SensorType.Speed:
break;
case SensorType.SpeedCadence:
devices = AntConnector.Instance().discoveredDevices.Where(d => d.Sensor == SensorType || (d is ISpeedDevice && d.State == DeviceState.Connected)).OrderBy(d => d.Priority).ToList();
break;
case SensorType.Trainer:
devices = AntConnector.Instance().discoveredDevices.Where(d => d.Sensor == SensorType).ToList();
break;
case SensorType.VirtualPower:
break;
}
foreach (var device in devices)
{
if (deviceList.ContainsKey(device.DeviceNumber))
{
continue;
}
var gameObject = (GameObject)Instantiate(deviceItem);
gameObject.transform.SetParent(content.transform);
var deviceItemObj = gameObject.GetComponent<DeviceItem>();
deviceItemObj.DeviceInfo = device;
UIManager.AddEvent(deviceItemObj.gameObject, EventTriggerType.PointerClick, new UnityEngine.Events.UnityAction<BaseEventData>(e =>
{
//deviceItemObj.Select();
if(deviceItemObj.DeviceInfo.Sensor == SensorType)
{
deviceItemObj.DeviceInfo.Connect();
}
deviceItemObj.Set(true);
foreach (var item in deviceList)
{
if(item.Key != deviceItemObj.DeviceInfo.DeviceNumber)
{
item.Value.Set(false);
if(item.Value.DeviceInfo.Sensor == SensorType)
{
item.Value.DeviceInfo.Disconnect();
}
}
}
Close();
}));
//UIManager.AddEvent(deviceItemObj.gameObject, EventTriggerType.Deselect, new UnityEngine.Events.UnityAction<BaseEventData>(e =>
//{
// //Debug.Log("de select");
// if(deviceItemObj.DeviceInfo.Sensor == SensorType)
// {
// deviceItemObj.DeviceInfo.Disconnect();
// }
//}));
deviceList.Add(device.DeviceNumber, deviceItemObj);
}
var firstDevice = deviceList.Select(d => d.Value).Where(d => d.DeviceInfo.State == DeviceState.Connected).OrderByDescending(d => d.DeviceInfo.Priority).FirstOrDefault();
if(firstDevice != null)
{
firstDevice.Set(true);
}
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 2a0878e6d65232b4eb49c2aa886ab9da
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,103 @@
using Assets.Scripts.Devices.Ant;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
public class DeviceItem : Selectable, IEventSystemHandler, IPointerClickHandler
{
private bool isOn;
private Text mText;
public AbstractAntDevice DeviceInfo
{
get;set;
}
protected override void Awake()
{
mText = this.transform.Find("Name").GetComponent<Text>();
}
// Start is called before the first frame update
protected override void Start()
{
//this.currentSelectionState = SelectionState.Selected
mText.text = DeviceInfo.Name + "-" + DeviceInfo.DeviceNumber;
//if(DeviceInfo.State == DeviceState.Connected)
{
// this.SetSelectedStyle();
}
}
public override void OnPointerEnter(PointerEventData eventData)
{
//base.OnPointerEnter(eventData);
//Cursor.SetCursor(null, Vector2.zero, CursorMode.Auto);
}
private void SetSelectedStyle()
{
ColorUtility.TryParseHtmlString("#F93086", out Color color);
mText.color = color;
var shadow = mText.gameObject.GetComponent<Shadow>();
if (shadow == null)
{
shadow = mText.gameObject.AddComponent<Shadow>();
}
ColorUtility.TryParseHtmlString("#F93086", out Color color1);
shadow.effectColor = color1;
}
public override void Select()
{
//base.Select();
Debug.Log("select");
//SetSelectedStyle();
//UIManager.CloseModal();
}
public override void OnDeselect(BaseEventData eventData)
{
//base.OnDeselect(eventData);
Debug.Log("deselect");
//DeviceInfo.Disconnect();
}
// Update is called once per frame
void Update()
{
}
public void OnPointerClick(PointerEventData eventData)
{
//this.Select();
//DeviceInfo.Connect();
}
public void Set(bool value)
{
if(!this.IsActive() || this.interactable == false)
{
return;
}
this.isOn = value;
if (this.isOn)
{
SetSelectedStyle();
}
else
{
mText.color = Color.white;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d3042f871b29a2540848cd67c5e4beb8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,322 @@
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;
public class DeviceView : MonoBehaviour
{
[SerializeField]
private string mType;
private SensorType SensorType
{
get
{
//Debug.Log(mType);
Enum.TryParse(mType, out SensorType sensorType);
return sensorType;
}
}
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 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);
logo = this.transform.Find("Logo").GetComponent<Image>();
InitLogo();
connectionPanel = this.transform.Find("ConnectionPanel").gameObject;
mDisconnectButton = connectionPanel.transform.Find("DisconnectBtn").gameObject;
var powerValueObj = connectionPanel.transform.Find("PowerValue");
if(powerValueObj != null)
{
powerValue = powerValueObj.gameObject.GetComponent<Text>();
}
var cadenceValueObj = connectionPanel.transform.Find("CadenceValue");
if (cadenceValueObj != null) {
cadenceValue = cadenceValueObj.gameObject.GetComponent<Text>();
}
var speedValueObj = connectionPanel.transform.Find("SpeedValue");
if (speedValueObj != null)
{
speedValue = speedValueObj.gameObject.GetComponent<Text>();
}
var heartRateValueObj = connectionPanel.transform.Find("HeartRateValue");
if(heartRateValueObj != null)
{
heartRateValue = heartRateValueObj.gameObject.GetComponent<Text>();
}
connectionPanel.SetActive(false);
UIManager.AddEvent(mPairButton, EventTriggerType.PointerClick, new UnityAction<UnityEngine.EventSystems.BaseEventData>(e =>
{
if (deviceModal == null)
{
var obj = Resources.Load("UI/Prefab/Device/ConnectDeviceModal");
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();
//}
var obj = Resources.Load("UI/Prefab/Device/ConnectDeviceModal");
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_3");
}
else if (SensorType == SensorType.SpeedCadence)
{
sprite0 = Resources.Load<Sprite>("Images/Devices/Speed_0");
sprite1 = Resources.Load<Sprite>("Images/Devices/Speed_1");
sprite3 = Resources.Load<Sprite>("Images/Devices/Speed_3");
}
else if (SensorType == SensorType.Cadence)
{
sprite0 = Resources.Load<Sprite>("Images/Devices/Cadence_0");
sprite1 = Resources.Load<Sprite>("Images/Devices/Cadence_1");
sprite3 = Resources.Load<Sprite>("Images/Devices/Cadence_3");
}
else if (SensorType == SensorType.HeartRate)
{
sprite0 = Resources.Load<Sprite>("Images/Devices/Heart Rate_0");
sprite1 = Resources.Load<Sprite>("Images/Devices/Heart Rate_1");
sprite3 = Resources.Load<Sprite>("Images/Devices/Heart Rate_3");
}
else
{
sprite0 = Resources.Load<Sprite>("Images/Devices/Trainer_0");
sprite1 = Resources.Load<Sprite>("Images/Devices/Trainer_1");
sprite3 = Resources.Load<Sprite>("Images/Devices/Trainer_3");
}
}
// Start is called before the first frame update
void Start()
{
Main();
}
// Update is called once per frame
void Update()
{
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...";
switch (SensorType)
{
case SensorType.None:
break;
case SensorType.Cadence:
title.text = "Cadence Sensor";
break;
case SensorType.HeartRate:
title.text = "Heart Rate Monitor";
break;
case SensorType.Power:
title.text = "Power Meter";
break;
case SensorType.Speed:
break;
case SensorType.SpeedCadence:
title.text = "Speed Meter";
break;
case SensorType.Trainer:
title.text = "Smart Trainer";
break;
case SensorType.VirtualPower:
break;
default:
break;
}
var hasDevice = AntConnector.Instance().discoveredDevices.Any(d => d.Sensor == SensorType);
if (hasDevice)
{
mSearchButton.SetActive(false);
mPairButton.SetActive(true);
logo.sprite = sprite1;
}
else
{
mSearchButton.SetActive(true);
mPairButton.SetActive(false);
}
}
else if(connectedDevice.State == DeviceState.Connecting)
{
unconnectionPanel.SetActive(true);
connectionPanel.SetActive(false);
logo.sprite = sprite1;
title.text = connectedDevice.Name;
noDevice.text = connectedDevice.DeviceNumber.ToString();
searchState.text = "Connecting...";
}
else if (connectedDevice.State == DeviceState.Connected)
{
unconnectionPanel.SetActive(false);
connectionPanel.SetActive(true);
logo.sprite = sprite3;
title.text = connectedDevice.Name;
noDevice.text = connectedDevice.DeviceNumber.ToString();
noDevice.color = Color.white;
switch (SensorType)
{
case SensorType.None:
break;
case SensorType.Cadence:
cadenceValue.text = (connectedDevice as ICadenceDevice).Cadence.ToString();
break;
case SensorType.HeartRate:
heartRateValue.text = (connectedDevice as IHeartRateDevice).HeartRate.ToString();
break;
case SensorType.Power:
powerValue.text = (connectedDevice as IPowerDevice).Power.ToString();
break;
case SensorType.Speed:
break;
case SensorType.SpeedCadence:
speedValue.text = (connectedDevice as ISpeedDevice).Speed.ToString();
break;
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;
}
}
}
AbstractAntDevice GetCurrentDevice()
{
return AntConnector.Instance().discoveredDevices.FirstOrDefault(d => (d.State == DeviceState.Connected || d.State == DeviceState.Connecting) && d.Sensor == SensorType);
}
/// <summary>
/// 获取已经连接的设备
/// </summary>
/// <returns></returns>
AbstractAntDevice GetDevice()
{
//return AntConnector.Instance().discoveredDevices.FirstOrDefault(d => (d.State == DeviceState.Connected || d.State == DeviceState.Connecting) && d.Sensor == SensorType);
var devices = AntConnector.Instance().discoveredDevices.Where(d => (d.State == DeviceState.Connected));
switch (SensorType)
{
case SensorType.None:
break;
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:
case SensorType.SpeedCadence:
return devices.FirstOrDefault(d => d is ISpeedDevice);
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: 99517b2926f300845a6c118d865c4343
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,20 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class DropdownScript : MonoBehaviour
{
// Start is called before the first frame update
[SerializeField] string label;
void Start()
{
gameObject.transform.Find("Label").GetComponent<Text>().text = label;
}
// Update is called once per frame
void Update()
{
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ae819c44673b2e648813f6f57f39b4b6
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -1,21 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
public class MapListScript : MonoBehaviour, IEndDragHandler
{
public void OnEndDrag(PointerEventData eventData)
{
var sc = gameObject.transform.parent.GetComponent<MapListController>();
if (eventData.position.y < 0)
{
sc.Refresh();
}
if (eventData.position.y + Screen.height > sc.Content.GetComponent<RectTransform>().rect.height)
{
sc.pageIndex++;
sc.GetList();
}
}
}
+10 -15
View File
@@ -15,9 +15,9 @@ public class MyMap
public class MapScript : MonoBehaviour
{
// Start is called before the first frame update
[SerializeField] Text text;
[SerializeField] GameObject panel;
[SerializeField] RawImage rawImage;
//[SerializeField] Text text;
//[SerializeField] GameObject panel;
//[SerializeField] RawImage rawImage;
void Start()
{
}
@@ -31,19 +31,14 @@ public class MapScript : MonoBehaviour
{
gameObject.GetComponent<Button>().onClick.AddListener(()=>
{
UIManager.ShowMapDetailPanel(myMap.Id);
//SceneManager.LoadScene("4-Demo", LoadSceneMode.Additive);
});
text.text = myMap.Name;
Utils.DisplayImage(StartCoroutine, rawImage, myMap.CoverImage);
int i = 0;
foreach (RectTransform transform in panel.transform)
{
//if (i < myMap.rank && i < 5)
if (i < 3 && i<5)
{
transform.GetComponent<Image>().color = new Color(255, 255, 0);
i++;
}
}
transform.Find("Name").GetComponent<Text>().text = myMap.Name;
Utils.DisplayImage(StartCoroutine, transform.Find("MapTitleImg").GetComponent<RawImage>(), myMap.CoverImage);
var props = transform.Find("Props");
props.Find("DistanceText").GetComponent<Text>().text = $"{myMap.Distance.ToString("#0.00")}KM";
props.Find("EleText").GetComponent<Text>().text = $"{(myMap.TotalClimb ?? 0.0).ToString("#0.00")}M";
props.Find("SlopeText").GetComponent<Text>().text = $"{myMap.AverageGrade.ToString("#0.00")}%";
}
}
@@ -20,11 +20,11 @@ public class DeviceController : PFUIPanel
protected override void Start()
{
base.Start();
Button button = this.transform.Find("Button").GetComponent<Button>();
button.onClick.AddListener(() =>
{
UIManager.ShowHomePanel();
});
//Button button = this.transform.Find("Button").GetComponent<Button>();
//button.onClick.AddListener(() =>
//{
// UIManager.ShowHomePanel();
//});
this.toggle = this.transform.Find("Toggle").GetComponent<Toggle>();
this.toggle.onValueChanged.AddListener(s =>
@@ -46,7 +46,7 @@ public class DeviceController : PFUIPanel
timer -= Time.deltaTime;
if (timer <= 0)
{
this.toggle.isOn = AntConnector.Instance().IsAvailable;
//this.toggle.isOn = AntConnector.Instance().IsAvailable;
//foreach (var item in AntConnector.Instance().discoveredDevices)
//{
@@ -64,4 +64,9 @@ public class DeviceController : PFUIPanel
timer = 1.0f;
}
}
private void OnApplicationQuit()
{
AntConnector.Instance().Dispose();
}
}
@@ -0,0 +1,58 @@
using Assets.Scripts;
using Assets.Scripts.Apis.Models;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class MapDetailController : MonoBehaviour
{
// Start is called before the first frame update
[HideInInspector] public int id = 0;
[HideInInspector] public MapRoute map;
void Start()
{
if (id != 0)
{
var r = ConfigHelper.mapApi.GetById(id);
if (r.result)
{
map = r.data;
}
else
{
Utils.showToast(gameObject, r.errMsg, 1);
}
}
if (transform.Find("BtnGoRide") != null)
{
transform.Find("BtnGoRide").GetComponent<Button>().onClick.AddListener(GoRide);
}
if (transform.Find("Name") != null)
{
transform.Find("Name").GetComponent<Text>().text = map.Name;
}
if (transform.Find("BtnReturn") != null)
{
transform.Find("BtnReturn").GetComponent<Button>().onClick.AddListener(() =>
{
UIManager.ShowHomePanel();
});
}
}
private void GoRide()
{
//Utils.showToast(gameObject, "去骑行", 1);
App.RouteIdParam = id;
SceneManager.LoadScene("Ride");
}
// Update is called once per frame
void Update()
{
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 858ac526aed2cf641a3c0f50a8c7730d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -1,11 +1,13 @@
using Assets.Cyp.Common;
using Assets.Scripts;
using Assets.Scripts.Apis.Models;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEditor;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
@@ -14,7 +16,7 @@ public class MapListController : MonoBehaviour
// Start is called before the first frame update
[SerializeField] GameObject map;
[SerializeField] GameObject content;
[SerializeField] Dropdown hardSelector;
[SerializeField] GameObject scroll;
[HideInInspector] public int pageIndex = 0;
[HideInInspector] public int pageSize = 20;
[HideInInspector] public string hard = "全部";
@@ -27,33 +29,53 @@ public class MapListController : MonoBehaviour
private bool isEnd = false;
void Start()
{
if (hardSelector != null)
{
hardSelector.onValueChanged.AddListener(ChangeHard);
}
//if (hardSelector != null)
//{
// hardSelector.onValueChanged.AddListener(ChangeHard);
//}
if (content!=null)
{
var transform = content.transform.GetComponent<RectTransform>();
var layout = content.GetComponent<GridLayoutGroup>();
if (layout != null)
{
var width = transform.rect.width;
layout.cellSize = new Vector2((width - 120) / 5, (width - 120) / 5);
}
//var transform = content.transform.GetComponent<RectTransform>();
//var layout = content.GetComponent<GridLayoutGroup>();
//if (layout != null)
//{
// var width = transform.rect.width;
// layout.cellSize = new Vector2((width - 120) / 5, (width - 120) / 5);
//}
}
GetList();
if (scroll != null)
{
UIManager.AddEvent(scroll, UnityEngine.EventSystems.EventTriggerType.EndDrag, OnEndDrag);
}
//UIManager.AddEvent(transform.Find("Panel").Find("Panel"))
//var obj = Instantiate(Resources.Load<GameObject>("Canvas"));
//obj.transform.parent = transform.parent;
}
private void ChangeHard(int index)
private void OnEndDrag(BaseEventData arg0)
{
var text = hardSelector.options[index].text;
if (text == "全部难度")
var scrollrect = scroll.GetComponent<ScrollRect>();
if (scrollrect.verticalNormalizedPosition <= 0)
{
Debug.Log(scrollrect.verticalNormalizedPosition);
pageIndex++;
GetList();
}
if (scrollrect.verticalNormalizedPosition >= 1)
{
Refresh();
}
}
private void ChangeHard(int index)
{
//var text = hardSelector.options[index].text;
//if (text == "全部难度")
//{
//}
}
public void GetList()
+11 -6
View File
@@ -9,12 +9,17 @@ using UnityEngine.EventSystems;
//namespace Assets.Scripts.UI.Prefab.Panel
//{
public class PFUIPanel : UIBehaviour
{
public class PFUIPanel : UIBehaviour
{
public void OpenURL(string url)
{
Application.OpenURL(url);
}
public void OpenURL(string url)
{
Application.OpenURL(url);
}
public virtual void Close()
{
DestroyImmediate(this.gameObject);
}
}
//}
+44 -2
View File
@@ -55,6 +55,15 @@ public class UIManager : MonoBehaviour
}
}
private MapDetailController mMapDetailController;
public MapDetailController MapDetailPanel
{
get
{
return this.GetPanelInstance("MapDetailPanel", ref this.mMapDetailController);
}
}
private EditUserController mEditUserController;
public EditUserController EditUserPanel
{
@@ -142,8 +151,12 @@ public class UIManager : MonoBehaviour
//panelToShow.transform.position = new Vector3(0, 0, 0);
panelToShow.transform.localPosition = new Vector3(0, 0, 0);
//panelToShow.transform.localRotation = new Quaternion(0, 0, 0, 0);
panelToShow.transform.GetComponent<RectTransform>().offsetMin = new Vector2(0, 0);
panelToShow.transform.GetComponent<RectTransform>().offsetMax = new Vector2(0, 0);
if (modal == false)
{
panelToShow.transform.GetComponent<RectTransform>().offsetMin = new Vector2(0, 0);
panelToShow.transform.GetComponent<RectTransform>().offsetMax = new Vector2(0, 0);
}
panelToShow.transform.localScale = parent.transform.localScale;
}
@@ -181,6 +194,13 @@ public class UIManager : MonoBehaviour
{
UIManager.Show(UIManager.Instance.MapListPanel, UIManager.Instance.MainPanel);
}
public static void ShowMapDetailPanel(int id)
{
var ctrl = UIManager.Instance.MapDetailPanel;
ctrl.id = id;
UIManager.Show(UIManager.Instance.MapDetailPanel, UIManager.Instance.MainPanel);
}
public static void AddEvent(GameObject gameObject, EventTriggerType eventTriggerType, UnityAction<BaseEventData> call)
{
EventTrigger et = gameObject.GetComponent<EventTrigger>();
@@ -194,6 +214,28 @@ public class UIManager : MonoBehaviour
et.triggers.Add(pointerEvent);
}
public static void Close(MonoBehaviour obj)
{
obj.gameObject.SetActive(false);
}
public static void CloseModal()
{
//foreach (var item in UIManager.Instance.ModalsPanel.transform.DetachChildren)
//{
// item.
//}
//UIManager.Instance.ModalsPanel.transform.DetachChildren();
//UIManager.Instance.ModalsPanel.transform.childCount
for (int i = 0; i < 1; i++)
{
var obj = UIManager.Instance.ModalsPanel.transform.GetChild(i);
obj.gameObject.SetActive(false);
DestroyImmediate(obj.gameObject);
}
}
private void OnDestroy()
{