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:
commit
ae9cefc645
144 files changed
+32337
-8064
No files matched your search
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5b590b8b6670b334ea1953fea1deba17
|
||||
guid: 2a0878e6d65232b4eb49c2aa886ab9da
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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()
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
//}
|
||||
Reference in new issue
Block a user