划船机暂存
This commit is contained in:
1 parent
1c73701e73
commit
c73545d912
164 files changed
+38281
-2181
No files matched your search
@@ -0,0 +1,81 @@
|
||||
using DG.Tweening;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class RowerAnimation : PFUIPanel
|
||||
{
|
||||
List<Sprite> sprites;
|
||||
Image image;
|
||||
|
||||
protected override void Awake()
|
||||
{
|
||||
base.Awake();
|
||||
sprites = new List<Sprite>();
|
||||
for (int i = 1; i < 26; i++)
|
||||
{
|
||||
sprites.Add(Resources.Load<Sprite>($"Images/Rower/序列帧/划船机{i.ToString("0000")}"));
|
||||
}
|
||||
image = transform.GetComponent<Image>();
|
||||
}
|
||||
|
||||
protected override void Start()
|
||||
{
|
||||
|
||||
//time = 0;
|
||||
|
||||
}
|
||||
int index = 0;
|
||||
//float time = 0;
|
||||
public override void Show()
|
||||
{
|
||||
//base.Show();
|
||||
|
||||
//index = 0;
|
||||
////time = 0;
|
||||
|
||||
//StartCoroutine(Animation());
|
||||
}
|
||||
public void StartAnimation()
|
||||
{
|
||||
index = 0;
|
||||
StartCoroutine(Animation());
|
||||
}
|
||||
|
||||
IEnumerator Animation()
|
||||
{
|
||||
for (; ; )
|
||||
{
|
||||
if (index % 25 == 0)
|
||||
{
|
||||
index = 0;
|
||||
}
|
||||
image.sprite = sprites[index];
|
||||
index++;
|
||||
yield return new WaitForSeconds(0.08f);
|
||||
}
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
//time += Time.deltaTime;
|
||||
//if (time < 0.03)
|
||||
//{
|
||||
// return;
|
||||
//}
|
||||
//time = 0;
|
||||
//if (index % 79 == 0)
|
||||
//{
|
||||
// index = 0;
|
||||
//}
|
||||
//image.sprite = sprites[index];
|
||||
//index++;
|
||||
}
|
||||
|
||||
public override void Close()
|
||||
{
|
||||
StopCoroutine(Animation());
|
||||
base.Close();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4e84219e49caa1f46be9f0277fd3b7c5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,448 @@
|
||||
using Assets.Scripts.Devices.Ant;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.Events;
|
||||
using Assets.Scripts.Devices.Ant.Interfaces;
|
||||
using Assets.Scripts.UI.UIEffect;
|
||||
using Assets.Scripts;
|
||||
using DG.Tweening;
|
||||
using Assets.Scripts.UI.Prefab.Device;
|
||||
using Assets.Scripts.Devices;
|
||||
using Assets.Scripts.Devices.Ble;
|
||||
|
||||
public class RowerDeviceView : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private SensorType mType;
|
||||
|
||||
private SensorType SensorType
|
||||
{
|
||||
get
|
||||
{
|
||||
//Debug.Log(mType);
|
||||
//Enum.TryParse(mType, out SensorType sensorType);
|
||||
return mType;
|
||||
}
|
||||
}
|
||||
|
||||
private GameObject mSearchButton;
|
||||
private GameObject mPairButton;
|
||||
private GameObject mDisconnectButton;
|
||||
private GameObject unconnectionPanel;
|
||||
private GameObject connectionPanel;
|
||||
private Text searchState;
|
||||
private ConnectDeviceModal deviceModal;
|
||||
private Text title;
|
||||
private Text noDevice;
|
||||
private Text powerValue;
|
||||
private Text powerUnit;
|
||||
//private Text cadenceValue;
|
||||
//private Text speedValue;
|
||||
//private Text heartRateValue;
|
||||
private Image logo;
|
||||
/// <summary>
|
||||
/// 没有设备的logo
|
||||
/// </summary>
|
||||
private Sprite sprite0;
|
||||
/// <summary>
|
||||
/// 连接中的logo
|
||||
/// </summary>
|
||||
private Sprite sprite1;
|
||||
/// <summary>
|
||||
/// 已连接的logo
|
||||
/// </summary>
|
||||
private Sprite sprite3;
|
||||
|
||||
private float timer = 1.0f;
|
||||
private void Awake()
|
||||
{
|
||||
title = this.transform.Find("Title").GetComponent<Text>();
|
||||
noDevice = this.transform.Find("NoDevice").GetComponent<Text>();
|
||||
unconnectionPanel = this.transform.Find("UnconnectionPanel").gameObject;
|
||||
mSearchButton = unconnectionPanel.transform.Find("SearchButton").gameObject;
|
||||
mPairButton = unconnectionPanel.transform.Find("PairButton").gameObject;
|
||||
searchState = unconnectionPanel.transform.Find("SearchState").GetComponent<Text>();
|
||||
mPairButton.SetActive(false);
|
||||
connectionPanel = this.transform.Find("ConnectionPanel").gameObject;
|
||||
|
||||
var material = Instantiate(Resources.Load<Material>("UI/Material/RoundedCornersTextureMaterial"));
|
||||
var rect = ((RectTransform)transform).rect;
|
||||
material.SetVector(Shader.PropertyToID("_WidthHeightRadius"), new Vector4(rect.width, rect.height, rect.height * 0.2f, 0));
|
||||
this.GetComponent<Image>().material = material;
|
||||
|
||||
var img1 = unconnectionPanel.GetComponent<Image>();
|
||||
if(img1 != null)
|
||||
{
|
||||
img1.material = material;
|
||||
|
||||
//var gradient = unconnectionPanel.GetComponent<UIGradient>();
|
||||
//if (gradient != null)
|
||||
//{
|
||||
// gradient.color1 = Utils.HexToColor("353543");
|
||||
// gradient.color2 = Utils.HexToColor("23232D");
|
||||
//}
|
||||
}
|
||||
|
||||
var img2 = connectionPanel.GetComponent<Image>();
|
||||
if(img2 != null)
|
||||
{
|
||||
img2.material = material;
|
||||
|
||||
//var gradient1 = connectionPanel.GetComponent<UIGradient>();
|
||||
//if (gradient1 != null)
|
||||
//{
|
||||
// gradient1.color1 = Utils.HexToColor("FF7485");
|
||||
// gradient1.color2 = Utils.HexToColor("F93086");
|
||||
//}
|
||||
}
|
||||
|
||||
logo = this.transform.Find("Logo").GetComponent<Image>();
|
||||
|
||||
|
||||
mDisconnectButton = connectionPanel.transform.Find("DisconnectBtn").gameObject;
|
||||
var powerValueObj = connectionPanel.transform.Find("PowerValue");
|
||||
if(powerValueObj != null)
|
||||
{
|
||||
powerValue = powerValueObj.gameObject.GetComponent<Text>();
|
||||
}
|
||||
|
||||
var powerUnitObj = connectionPanel.transform.Find("PowerUnit");
|
||||
if(powerUnitObj != null)
|
||||
{
|
||||
powerUnit = powerUnitObj.gameObject.GetComponent<Text>();
|
||||
}
|
||||
|
||||
InitLogo();
|
||||
title.text = GetTitle();
|
||||
|
||||
connectionPanel.SetActive(false);
|
||||
|
||||
UIManager.AddEvent(mPairButton, EventTriggerType.PointerClick, new UnityAction<UnityEngine.EventSystems.BaseEventData>(e =>
|
||||
{
|
||||
if (deviceModal == null)
|
||||
{
|
||||
|
||||
#if UNITY_IOS || UNITY_ANDROID
|
||||
var obj = Resources.Load("UI/Prefab/Device/Mobile/ConnectDeviceModal");
|
||||
#else
|
||||
var obj = Resources.Load("UI/Prefab/Device/ConnectDeviceModal");
|
||||
#endif
|
||||
GameObject gameObject = (GameObject)Instantiate(obj);
|
||||
deviceModal = gameObject.GetComponent<ConnectDeviceModal>();
|
||||
}
|
||||
deviceModal.SensorType = this.SensorType;
|
||||
UIManager.Show(deviceModal, null, true);
|
||||
}));
|
||||
|
||||
UIManager.AddEvent(mDisconnectButton, EventTriggerType.PointerClick, new UnityEngine.Events.UnityAction<BaseEventData>(e => {
|
||||
//var device = GetDevice();
|
||||
//if(device != null && device.State == DeviceState.Connected)
|
||||
//{
|
||||
// device.Disconnect();
|
||||
//}
|
||||
|
||||
#if UNITY_IOS || UNITY_ANDROID
|
||||
var obj = Resources.Load("UI/Prefab/Device/Mobile/ConnectDeviceModal");
|
||||
#else
|
||||
var obj = Resources.Load("UI/Prefab/Device/ConnectDeviceModal");
|
||||
#endif
|
||||
GameObject gameObject = (GameObject)Instantiate(obj);
|
||||
deviceModal = gameObject.GetComponent<ConnectDeviceModal>();
|
||||
deviceModal.SensorType = this.SensorType;
|
||||
UIManager.Show(deviceModal, null, true);
|
||||
}));
|
||||
|
||||
}
|
||||
|
||||
void InitLogo()
|
||||
{
|
||||
if (SensorType == SensorType.Power)
|
||||
{
|
||||
sprite0 = Resources.Load<Sprite>("Images/Devices/Power_0");
|
||||
sprite1 = Resources.Load<Sprite>("Images/Devices/Power_1");
|
||||
sprite3 = Resources.Load<Sprite>("Images/Devices/Power_4");
|
||||
|
||||
powerUnit.text = "W";
|
||||
}
|
||||
else if (SensorType == SensorType.Speed)
|
||||
{
|
||||
sprite0 = Resources.Load<Sprite>("Images/Devices/Speed_0");
|
||||
sprite1 = Resources.Load<Sprite>("Images/Devices/Speed_1");
|
||||
sprite3 = Resources.Load<Sprite>("Images/Devices/Speed_4");
|
||||
|
||||
powerUnit.text = "KPH";
|
||||
}
|
||||
else if (SensorType == SensorType.Cadence || SensorType == SensorType.SpeedCadence)
|
||||
{
|
||||
sprite0 = Resources.Load<Sprite>("Images/Devices/Cadence_0");
|
||||
sprite1 = Resources.Load<Sprite>("Images/Devices/Cadence_1");
|
||||
sprite3 = Resources.Load<Sprite>("Images/Devices/Cadence_4");
|
||||
|
||||
powerUnit.text = "RPM";
|
||||
}
|
||||
else if (SensorType == SensorType.HeartRate)
|
||||
{
|
||||
sprite0 = Resources.Load<Sprite>("Images/Devices/Heart Rate_1");
|
||||
sprite1 = Resources.Load<Sprite>("Images/Devices/Heart Rate_1");
|
||||
sprite3 = Resources.Load<Sprite>("Images/Devices/Heart Rate_4");
|
||||
|
||||
powerUnit.text = "BPM";
|
||||
}
|
||||
else if (SensorType == SensorType.Trainer)
|
||||
{
|
||||
sprite0 = Resources.Load<Sprite>("Images/Devices/Trainer_0");
|
||||
sprite1 = Resources.Load<Sprite>("Images/Devices/Trainer_1");
|
||||
sprite3 = Resources.Load<Sprite>("Images/Devices/Trainer_4");
|
||||
}
|
||||
else if (SensorType == SensorType.Rower)
|
||||
{
|
||||
sprite0 = Resources.Load<Sprite>("Images/Rower/设备 - 划船机 - 未连接");
|
||||
sprite1 = Resources.Load<Sprite>("Images/Rower/设备 - 划船机 - 未连接");
|
||||
sprite3 = Resources.Load<Sprite>("Images/Rower/设备 - 划船机");
|
||||
powerUnit.text = "";
|
||||
}
|
||||
}
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
Main();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
//if(SensorType != SensorType.Trainer)
|
||||
//{
|
||||
// return;
|
||||
//}
|
||||
timer -= Time.deltaTime;
|
||||
if (timer <= 0)
|
||||
{
|
||||
Main();
|
||||
|
||||
timer = 1.0f;
|
||||
}
|
||||
}
|
||||
|
||||
void Main()
|
||||
{
|
||||
var connectedDevice = GetCurrentDevice();
|
||||
if(connectedDevice == null)
|
||||
{
|
||||
connectedDevice = GetDevice();
|
||||
}
|
||||
if(connectedDevice == null)
|
||||
{
|
||||
unconnectionPanel.SetActive(true);
|
||||
connectionPanel.SetActive(false);
|
||||
|
||||
logo.sprite = sprite0;
|
||||
noDevice.text = "NO DEVICE";
|
||||
searchState.text = "Searching...";
|
||||
|
||||
var hasDevice = false;
|
||||
if (SensorType == SensorType.SpeedCadence)
|
||||
{
|
||||
hasDevice = App.MainDeviceAdapter.GetDevices().Any(d => d.Sensor == SensorType.SpeedCadence || d.Sensor == SensorType.Cadence);
|
||||
}
|
||||
else
|
||||
{
|
||||
hasDevice = App.MainDeviceAdapter.GetDevices().Any(d => d.Sensor == SensorType);
|
||||
}
|
||||
if (hasDevice)
|
||||
{
|
||||
mSearchButton.SetActive(false);
|
||||
mPairButton.SetActive(true);
|
||||
#if UNITY_IOS || UNITY_ANDROID
|
||||
//searchState.gameObject.SetActive(false);
|
||||
#endif
|
||||
logo.sprite = sprite1;
|
||||
|
||||
//App.MainDeviceAdapter.GetDevices().First(d => d.Sensor == SensorType).Connect();
|
||||
}
|
||||
else
|
||||
{
|
||||
#if !(UNITY_IOS || UNITY_ANDROID)
|
||||
mSearchButton.SetActive(true);
|
||||
#endif
|
||||
mPairButton.SetActive(false);
|
||||
}
|
||||
}
|
||||
else if(connectedDevice.State == DeviceState.Connecting)
|
||||
{
|
||||
unconnectionPanel.SetActive(true);
|
||||
connectionPanel.SetActive(false);
|
||||
logo.sprite = sprite1;
|
||||
|
||||
//title.text = connectedDevice.Name;
|
||||
if (connectedDevice.Network == NetworkType.BLE)
|
||||
{
|
||||
//noDevice.enabled = false;
|
||||
noDevice.text = connectedDevice.Name;
|
||||
}
|
||||
else
|
||||
{
|
||||
//noDevice.enabled = true;
|
||||
noDevice.text = connectedDevice.Name +" "+ connectedDevice.DeviceNumber.ToString();
|
||||
}
|
||||
#if (UNITY_IOS || UNITY_ANDROID)
|
||||
mPairButton.SetActive(true);
|
||||
searchState.gameObject.SetActive(true);
|
||||
#endif
|
||||
searchState.text = "Connecting...";
|
||||
|
||||
|
||||
}
|
||||
else if (connectedDevice.State == DeviceState.Connected)
|
||||
{
|
||||
unconnectionPanel.SetActive(false);
|
||||
|
||||
if (connectionPanel.activeInHierarchy == false)
|
||||
{
|
||||
var connectionCanvasGroup = connectionPanel.GetComponent<CanvasGroup>();
|
||||
connectionCanvasGroup.alpha = 0;
|
||||
connectionPanel.SetActive(true);
|
||||
connectionCanvasGroup.DOFade(1f, .3f).OnComplete(()=> {
|
||||
//if (logoSprite != null) {
|
||||
// logo.sprite = logoSprite;
|
||||
//}
|
||||
});
|
||||
DeviceCache.Add(connectedDevice);
|
||||
Debug.Log("connected");
|
||||
}
|
||||
|
||||
logo.sprite = sprite3;
|
||||
|
||||
//title.text = connectedDevice.Name;
|
||||
if (connectedDevice.Network == NetworkType.BLE)
|
||||
{
|
||||
//noDevice.enabled = false;
|
||||
noDevice.text = connectedDevice.Name;
|
||||
}
|
||||
else
|
||||
{
|
||||
//noDevice.enabled = true;
|
||||
noDevice.text = connectedDevice.Name +" "+ connectedDevice.DeviceNumber.ToString();
|
||||
}
|
||||
noDevice.color = Color.white;
|
||||
|
||||
if (powerValue != null)
|
||||
{
|
||||
powerValue.text = GetValue(connectedDevice);
|
||||
}
|
||||
}
|
||||
|
||||
//Debug.Log(Newtonsoft.Json.JsonConvert.SerializeObject(App.MainDeviceAdapter.GetDevices().Where(d => d.Sensor == SensorType)));
|
||||
}
|
||||
|
||||
string GetTitle()
|
||||
{
|
||||
switch (SensorType)
|
||||
{
|
||||
case SensorType.None:
|
||||
break;
|
||||
case SensorType.SpeedCadence:
|
||||
case SensorType.Cadence:
|
||||
return "Cadence Sensor";
|
||||
case SensorType.HeartRate:
|
||||
return "Heart Rate Monitor";
|
||||
case SensorType.Power:
|
||||
return "Power Meter";
|
||||
case SensorType.Speed:
|
||||
return "Speed Meter";
|
||||
case SensorType.Trainer:
|
||||
return "Smart Trainer";
|
||||
case SensorType.Rower:
|
||||
return "Rower Machine";
|
||||
case SensorType.VirtualPower:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
string GetValue(AbstractDevice connectedDevice)
|
||||
{
|
||||
switch (SensorType)
|
||||
{
|
||||
case SensorType.None:
|
||||
break;
|
||||
case SensorType.SpeedCadence:
|
||||
case SensorType.Cadence:
|
||||
//cadenceValue.text = (connectedDevice as ICadenceDevice).Cadence.ToString();
|
||||
return (connectedDevice as ICadenceDevice).Cadence.ToString();
|
||||
case SensorType.HeartRate:
|
||||
return (connectedDevice as IHeartRateDevice).HeartRate.ToString();
|
||||
case SensorType.Power:
|
||||
return (connectedDevice as IPowerDevice).Power.ToString();
|
||||
case SensorType.Speed:
|
||||
return (connectedDevice as ISpeedDevice).Speed.ToString("f1");
|
||||
case SensorType.Trainer:
|
||||
//powerValue.text = (connectedDevice as IPowerDevice).Power.ToString();
|
||||
//cadenceValue.GetComponent<Text>().text = (connectedDevice as ICadenceDevice).Cadence.ToString();
|
||||
//speedValue.GetComponent<Text>().text = (connectedDevice as ISpeedDevice).Speed.ToString();
|
||||
break;
|
||||
case SensorType.VirtualPower:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
AbstractDevice GetCurrentDevice()
|
||||
{
|
||||
//return AntConnector.Instance().discoveredDevices.FirstOrDefault(d => (d.State == DeviceState.Connected || d.State == DeviceState.Connecting) && d.Sensor == SensorType);
|
||||
if(SensorType == SensorType.SpeedCadence || SensorType == SensorType.Cadence)
|
||||
{
|
||||
return App.MainDeviceAdapter.GetDevices().FirstOrDefault(d => (d.State == DeviceState.Connected || d.State == DeviceState.Connecting) && (d.Sensor == SensorType.SpeedCadence || d.Sensor == SensorType.Cadence));
|
||||
}
|
||||
return App.MainDeviceAdapter.GetDevices().FirstOrDefault(d => (d.State == DeviceState.Connected || d.State == DeviceState.Connecting) && d.Sensor == SensorType);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取已经连接的设备
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
AbstractDevice GetDevice()
|
||||
{
|
||||
//return AntConnector.Instance().discoveredDevices.FirstOrDefault(d => (d.State == DeviceState.Connected || d.State == DeviceState.Connecting) && d.Sensor == SensorType);
|
||||
var devices = App.MainDeviceAdapter.GetDevices().Where(d => (d.State == DeviceState.Connected));
|
||||
switch (SensorType)
|
||||
{
|
||||
case SensorType.None:
|
||||
break;
|
||||
case SensorType.SpeedCadence:
|
||||
case SensorType.Cadence:
|
||||
return devices.FirstOrDefault(d => d is ICadenceDevice);
|
||||
case SensorType.HeartRate:
|
||||
return devices.FirstOrDefault(d => d is IHeartRateDevice);
|
||||
case SensorType.Power:
|
||||
var item = devices.FirstOrDefault(d => d is IPowerDevice);
|
||||
//if (powerValue != null)
|
||||
//{
|
||||
// powerValue.GetComponent<Text>().text = (item as IPowerDevice).Power.ToString();
|
||||
//}
|
||||
return item;
|
||||
case SensorType.Speed:
|
||||
return devices.FirstOrDefault(d => d is ISpeedDevice);
|
||||
case SensorType.Rower:
|
||||
return devices.FirstOrDefault(d => d.Sensor == SensorType.Rower);
|
||||
case SensorType.Trainer:
|
||||
var item3 = devices.FirstOrDefault(d => d.Sensor == SensorType.Trainer);
|
||||
return item3;
|
||||
case SensorType.VirtualPower:
|
||||
break;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 954bbf32f326f684c90a328ec1db5ff9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,63 @@
|
||||
#define Graph_And_Chart_PRO
|
||||
using UnityEngine;
|
||||
using ChartAndGraph;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class RowerGraphChartFeed : MonoBehaviour
|
||||
{
|
||||
void Start ()
|
||||
{
|
||||
//GraphChartBase graph = GetComponent<GraphChartBase>();
|
||||
//if (graph != null)
|
||||
//{
|
||||
// graph.Scrollable = false;
|
||||
// graph.HorizontalValueToStringMap[0.0] = "Zero"; // example of how to set custom axis strings
|
||||
// graph.DataSource.StartBatch();
|
||||
// graph.DataSource.ClearCategory("Player 1");
|
||||
// graph.DataSource.ClearAndMakeBezierCurve("Player 2");
|
||||
|
||||
// for (int i = 0; i <10000; i++)
|
||||
// {
|
||||
// graph.DataSource.AddPointToCategory("Player 1",i*5,Random.value*10f + 20f);
|
||||
// if (i == 0)
|
||||
// graph.DataSource.SetCurveInitialPoint("Player 2",i*5, Random.value * 10f + 10f);
|
||||
// else
|
||||
// graph.DataSource.AddLinearCurveToCategory("Player 2",
|
||||
// new DoubleVector2(i*5 , Random.value * 10f + 10f));
|
||||
// }
|
||||
// graph.DataSource.MakeCurveCategorySmooth("Player 2");
|
||||
// graph.DataSource.EndBatch();
|
||||
//}
|
||||
// StartCoroutine(ClearAll());
|
||||
}
|
||||
|
||||
public void SetData(List<DoubleVector2> list)
|
||||
{
|
||||
GraphChartBase graph = GetComponent<GraphChartBase>();
|
||||
if (graph != null)
|
||||
{
|
||||
graph.Scrollable = false;
|
||||
//graph.HorizontalValueToStringMap[0.0] = "Zero"; // example of how to set custom axis strings
|
||||
graph.DataSource.StartBatch();
|
||||
graph.DataSource.ClearAndMakeBezierCurve("Player 1");
|
||||
for (int i = 0; i < list.Count; i++)
|
||||
{
|
||||
var item = list[i];
|
||||
if (i == 0)
|
||||
graph.DataSource.SetCurveInitialPoint("Player 1", item.x, item.y);
|
||||
else
|
||||
graph.DataSource.AddLinearCurveToCategory("Player 1", new DoubleVector2(item.x, item.y));
|
||||
}
|
||||
graph.DataSource.MakeCurveCategorySmooth("Player 1");
|
||||
graph.DataSource.EndBatch();
|
||||
}
|
||||
}
|
||||
IEnumerator ClearAll()
|
||||
{
|
||||
yield return new WaitForSeconds(5f);
|
||||
GraphChartBase graph = GetComponent<GraphChartBase>();
|
||||
|
||||
graph.DataSource.Clear();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: aa4e07579b1f9574788e0b83b1fac799
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,254 @@
|
||||
#define Graph_And_Chart_PRO
|
||||
using UnityEngine;
|
||||
using ChartAndGraph;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
public partial class RowerLargeDataFeed : MonoBehaviour, IComparer<DoubleVector2>
|
||||
{
|
||||
public string Category = "Player 1";
|
||||
public int DownSampleToPoints = 100;
|
||||
List<DoubleVector2> mData = new List<DoubleVector2>(); // the data held by the chart
|
||||
double pageSize = 2f;
|
||||
double currentPagePosition = 0.0;
|
||||
double currentZoom = 0f;
|
||||
GraphChartBase graph;
|
||||
double mCurrentPageSizeFactor = double.NegativeInfinity;
|
||||
void Start()
|
||||
{
|
||||
graph = GetComponent<GraphChartBase>();
|
||||
//SetInitialData();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// called with Start(). These will be used to load the data into the large data feed. You should replace this with your own loading logic.
|
||||
/// </summary>
|
||||
void SetInitialData()
|
||||
{
|
||||
List<DoubleVector2> data = new List<DoubleVector2>(75);
|
||||
double x = 0f;
|
||||
double y = 20f;
|
||||
for (int i = 0; i < 75; i++) // initialize with random data
|
||||
{
|
||||
y = 20 + UnityEngine.Random.value * 80;
|
||||
Debug.Log(y);
|
||||
x += 1;
|
||||
data.Add(new DoubleVector2(x, y));
|
||||
}
|
||||
SetData(data);
|
||||
}
|
||||
|
||||
public void SaveToFile(string path)
|
||||
{
|
||||
using (StreamWriter file = new StreamWriter(path))
|
||||
{
|
||||
file.WriteLine(mData.Count);
|
||||
for (int i = 0; i < mData.Count; i++)
|
||||
{
|
||||
DoubleVector2 item = mData[i];
|
||||
file.WriteLine(item.x);
|
||||
file.WriteLine(item.y);
|
||||
}
|
||||
}
|
||||
}
|
||||
public void LoadFromFile(string path)
|
||||
{
|
||||
try
|
||||
{
|
||||
List<DoubleVector2> data = new List<DoubleVector2>();
|
||||
using (StreamReader file = new StreamReader(path))
|
||||
{
|
||||
int count = int.Parse(file.ReadLine());
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
double x = double.Parse(file.ReadLine());
|
||||
double y = double.Parse(file.ReadLine());
|
||||
data.Add(new DoubleVector2(x, y));
|
||||
}
|
||||
}
|
||||
SetData(data);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw new Exception("Invalid file format");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// vertify's that the graph data is sorted so it can be searched using a binary search.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
bool VerifySorted(List<DoubleVector2> data)
|
||||
{
|
||||
if (data == null)
|
||||
return true;
|
||||
for (int i = 1; i < data.Count; i++)
|
||||
{
|
||||
if (data[i].x < data[i - 1].x)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// set the data of the large data graph
|
||||
/// </summary>
|
||||
/// <param name="data"></param>
|
||||
public void SetData(List<DoubleVector2> data)
|
||||
{
|
||||
if (data == null)
|
||||
data = new List<DoubleVector2>(); // set up an empty list instead of null
|
||||
if (VerifySorted(data) == false)
|
||||
{
|
||||
Debug.LogWarning("The data used with large data feed must be sorted acoording to the x value, aborting operation");
|
||||
return;
|
||||
}
|
||||
mData = data;
|
||||
LoadPage(currentPagePosition); // load the page at position 0
|
||||
}
|
||||
|
||||
int FindClosestIndex(double position) // if you want to know what is index is currently displayed . use binary search to find it
|
||||
{
|
||||
//NOTE :: this method assumes your data is sorted !!!
|
||||
int res = mData.BinarySearch(new DoubleVector2(position, 0.0), this);
|
||||
if (res >= 0)
|
||||
return res;
|
||||
return ~res;
|
||||
}
|
||||
|
||||
double PageSizeFactor
|
||||
{
|
||||
get
|
||||
{
|
||||
return pageSize * graph.DataSource.HorizontalViewSize;
|
||||
}
|
||||
}
|
||||
|
||||
void findPointsForPage(double position, out int start, out int end) // given a page position , find the right most and left most indices in the data for that page.
|
||||
{
|
||||
int index = FindClosestIndex(position); // use binary search to find the closest position to the current scroll point
|
||||
|
||||
double endPosition = position + PageSizeFactor;
|
||||
double startPosition = position - PageSizeFactor;
|
||||
|
||||
//starting from the current index , we find the page boundries
|
||||
for (start = index; start > 0; start--)
|
||||
{
|
||||
if (mData[start].x < startPosition) // take the first point that is out of the page. so the graph doesn't break at the edge
|
||||
break;
|
||||
}
|
||||
|
||||
for (end = index; end < mData.Count; end++)
|
||||
{
|
||||
if (mData[end].x > endPosition) // take the first point that is out of the page
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
if (graph != null)
|
||||
{
|
||||
//check the scrolling position of the graph. if we are past the view size , load a new page
|
||||
double pageStartThreshold = currentPagePosition - mCurrentPageSizeFactor;
|
||||
double pageEndThreshold = currentPagePosition + mCurrentPageSizeFactor - graph.DataSource.HorizontalViewSize;
|
||||
|
||||
if (graph.HorizontalScrolling < pageStartThreshold || graph.HorizontalScrolling > pageEndThreshold || currentZoom >= graph.DataSource.HorizontalViewSize * 2f)
|
||||
{
|
||||
currentZoom = graph.DataSource.HorizontalViewSize;
|
||||
mCurrentPageSizeFactor = PageSizeFactor * 0.9f;
|
||||
LoadPage(graph.HorizontalScrolling);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void LoadWithoutDownSampling(int start, int end)
|
||||
{
|
||||
for (int i = start; i < end; i++) // load the data
|
||||
{
|
||||
if (i == 0)
|
||||
{
|
||||
graph.DataSource.SetCurveInitialPoint(Category, mData[i].x, mData[i].y);
|
||||
}
|
||||
else
|
||||
{
|
||||
graph.DataSource.AddLinearCurveToCategory(Category, new DoubleVector2(mData[i].x, mData[i].y));
|
||||
}
|
||||
//graph.DataSource.AddPointToCategory(Category, mData[i].x, mData[i].y);
|
||||
}
|
||||
}
|
||||
|
||||
void LoadWithDownSampling(int start, int end)
|
||||
{
|
||||
int total = end - start;
|
||||
|
||||
if (DownSampleToPoints >= total)
|
||||
{
|
||||
LoadWithoutDownSampling(start, end);
|
||||
return;
|
||||
}
|
||||
|
||||
double sampleCount = ((double)total) / (double)DownSampleToPoints;
|
||||
// graph.DataSource.AddPointToCategory(Category, mData[start].x, mData[start].y);
|
||||
for (int i = 0; i < DownSampleToPoints; i++)
|
||||
{
|
||||
int fractionStart = start + (int)(i * sampleCount); // the first point with a fraction
|
||||
int fractionEnd = start + (int)((i + 1) * sampleCount); // the first point with a fraction
|
||||
fractionEnd = Math.Min(fractionEnd, mData.Count - 1);
|
||||
double x = 0, y = 0;
|
||||
double divide = 0.0;
|
||||
for (int j = fractionStart; j < fractionEnd; j++) // avarge the poins
|
||||
{
|
||||
x += mData[j].x;
|
||||
y += mData[j].y;
|
||||
divide++;
|
||||
}
|
||||
if (divide > 0.0)
|
||||
{
|
||||
x /= divide;
|
||||
y /= divide;
|
||||
graph.DataSource.AddPointToCategory(Category, x, y);
|
||||
}
|
||||
else
|
||||
Debug.Log("error");
|
||||
}
|
||||
// graph.DataSource.AddPointToCategory(Category, mData[last].x, mData[last].y);
|
||||
}
|
||||
|
||||
void LoadPage(double pagePosition)
|
||||
{
|
||||
if (graph != null)
|
||||
{
|
||||
|
||||
Debug.Log("Loading page :" + pagePosition);
|
||||
graph.DataSource.StartBatch(); // call start batch
|
||||
graph.DataSource.HorizontalViewOrigin = 0;
|
||||
int start, end;
|
||||
findPointsForPage(pagePosition, out start, out end); // get the page edges
|
||||
graph.DataSource.ClearAndMakeBezierCurve(Category); // clear the cateogry
|
||||
|
||||
if (DownSampleToPoints <= 0)
|
||||
LoadWithoutDownSampling(start, end);
|
||||
else
|
||||
LoadWithDownSampling(start, end);
|
||||
graph.DataSource.MakeCurveCategorySmooth(Category);
|
||||
graph.DataSource.EndBatch();
|
||||
graph.HorizontalScrolling = pagePosition;
|
||||
}
|
||||
currentPagePosition = pagePosition;
|
||||
}
|
||||
|
||||
|
||||
public int Compare(DoubleVector2 x, DoubleVector2 y)
|
||||
{
|
||||
if (x.x < y.x)
|
||||
return -1;
|
||||
if (x.x > y.x)
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7916cf3d11e8e7b4ebd8712801923455
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,103 @@
|
||||
using Assets.Scripts;
|
||||
using Assets.Scripts.Apis.Models;
|
||||
using ChartAndGraph;
|
||||
using DG.Tweening;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class RowerResult : PFUIPanel
|
||||
{
|
||||
RowerResultModel _model;
|
||||
private GraphChart chartPace, chartRate, chartHR;
|
||||
Transform dataContent;
|
||||
// Start is called before the first frame update
|
||||
void Awake()
|
||||
{
|
||||
var grid = transform.Find("Scroll View/Viewport/Content/Content/Table").GetComponent<GridLayoutGroup>();
|
||||
float width = (App.canvasWidth - 60 - 3) / 4;
|
||||
grid.cellSize = new Vector2(width, 37);
|
||||
var grid1 = transform.Find("Scroll View/Viewport/Content/Content/Other/Datas").GetComponent<GridLayoutGroup>();
|
||||
grid1.cellSize = new Vector2(width, 53);
|
||||
chartPace = transform.Find("Scroll View/Viewport/Content/Content/ChartPace/Chart").GetComponent<GraphChart>();
|
||||
chartPace.DataSource.VerticalViewOrigin = ChartDateUtility.TimeSpanToValue(TimeSpan.FromHours(15));
|
||||
chartPace.DataSource.VerticalViewSize = ChartDateUtility.TimeSpanToValue(TimeSpan.FromHours(15)) * -1;
|
||||
chartRate = transform.Find("Scroll View/Viewport/Content/Content/ChartRate/Chart").GetComponent<GraphChart>();
|
||||
chartHR = transform.Find("Scroll View/Viewport/Content/Content/ChartHeartRate/Chart").GetComponent<GraphChart>();
|
||||
dataContent = transform.Find("Scroll View/Viewport/Content/Content");
|
||||
UIManager.AddEvent(transform.Find("Exit").gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, b =>
|
||||
{
|
||||
Close();
|
||||
});
|
||||
//var a = new List<ChartAndGraph.DoubleVector2>();
|
||||
//for (int i = 0; i < 100; i++)
|
||||
//{
|
||||
// a.Add(new ChartAndGraph.DoubleVector2(i, ChartDateUtility.TimeSpanToValue(TimeSpan.FromMinutes(300))));
|
||||
//}
|
||||
//transform.Find("Scroll View/Viewport/Content/Content/ChartPace/Chart").GetComponent<RowerLargeDataFeed>().SetData(a);
|
||||
}
|
||||
|
||||
public async void Initial(string id)
|
||||
{
|
||||
GetComponent<CanvasGroup>().alpha = 0;
|
||||
var res = await ConfigHelper.rowerApi.GetDetail(id);
|
||||
if (res.result)
|
||||
{
|
||||
_model = res.data;
|
||||
dataContent.Find("Time").GetComponent<Text>().text = $"{_model.StartTime.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss")} ~ {_model.CreateTime.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss")}";
|
||||
dataContent.Find("TitleContent/Duration").GetComponent<Text>().text
|
||||
= $"<color=#5c5c6e>Rowing time :</color> {TimeSpan.FromSeconds(_model.TotalTime).ToString()}";
|
||||
dataContent.Find("TitleContent/Distance").GetComponent<Text>().text
|
||||
= $"<color=#5c5c6e>Distance :</color> {_model.TotalDistance}M";
|
||||
dataContent.Find("TitleContent/Device").GetComponent<Text>().text
|
||||
= $"<color=#5c5c6e>Rowing equipment :</color> {_model.ManufacturerName}";
|
||||
dataContent.Find("Table/AvgPower/Text").GetComponent<Text>().text
|
||||
= $"{_model.AvgPower.ToString("#0")} W";
|
||||
dataContent.Find("Table/AvgHR/Text").GetComponent<Text>().text
|
||||
= $"{_model.AvgHeartRate} BPM";
|
||||
dataContent.Find("Table/AvgRate/Text").GetComponent<Text>().text
|
||||
= $"{_model.AvgRate.ToString("#0")} W";
|
||||
dataContent.Find("Table/MaxPower/Text").GetComponent<Text>().text
|
||||
= $"{_model.MaxPower.ToString("#0")} W";
|
||||
dataContent.Find("Table/AvgHR/Text").GetComponent<Text>().text
|
||||
= $"{_model.MaxHeartRate} BPM";
|
||||
dataContent.Find("Table/AvgRate/Text").GetComponent<Text>().text
|
||||
= $"{_model.MaxRate.ToString("#0")} W";
|
||||
dataContent.Find("ChartPace/Avg/Value").GetComponent<Text>().text
|
||||
= $"{TimeSpan.FromSeconds(_model.AvgPace).ToString(@"mm\:ss")} /500M";
|
||||
dataContent.Find("ChartRate/Avg/Value").GetComponent<Text>().text
|
||||
= $"{_model.AvgRate.ToString("#0")} SPM";
|
||||
dataContent.Find("ChartHeartRate/Avg/Value").GetComponent<Text>().text
|
||||
= $"{_model.AvgHeartRate.ToString("#0")} BPM";
|
||||
dataContent.Find("ChartPace/Max/Value").GetComponent<Text>().text
|
||||
= $"{TimeSpan.FromSeconds(_model.MaxPace).ToString(@"mm\:ss")} /500M";
|
||||
dataContent.Find("ChartRate/Max/Value").GetComponent<Text>().text
|
||||
= $"{_model.MaxRate.ToString("#0")} SPM";
|
||||
dataContent.Find("ChartHeartRate/Max/Value").GetComponent<Text>().text
|
||||
= $"{_model.MaxHeartRate.ToString("#0")} BPM";
|
||||
dataContent.Find("Other/Datas/Calories/Value").GetComponent<Text>().text
|
||||
= $"{(_model.Kj ?? 0).ToString("#0")} KCAL";
|
||||
dataContent.Find("Other/Datas/StrokeCount/Value").GetComponent<Text>().text
|
||||
= _model.StrokeCount.ToString();
|
||||
//var b = _model.ChartList.Select((x, i) => new DoubleVector2(i, ChartDateUtility.TimeSpanToValue(TimeSpan.FromMinutes(x.Pace + UnityEngine.Random.value * 300)))).ToList();
|
||||
//Debug.Log(_model.ChartList.Select((x, i) => new DoubleVector2(i, ChartDateUtility.TimeSpanToValue(TimeSpan.FromMinutes(x.Pace + UnityEngine.Random.value * 300)))).ToList());
|
||||
chartPace.GetComponent<RowerLargeDataFeed>()
|
||||
.SetData(_model.ChartList.Select((x, i) => new DoubleVector2(i, ChartDateUtility.TimeSpanToValue(TimeSpan.FromMinutes(x.Pace)))).ToList());
|
||||
chartRate.GetComponent<RowerLargeDataFeed>()
|
||||
.SetData(_model.ChartList.Select((x, i) => new DoubleVector2(i, x.Rate)).ToList());
|
||||
chartHR.GetComponent<RowerLargeDataFeed>()
|
||||
.SetData(_model.ChartList.Select((x, i) => new DoubleVector2(i, x.HeartRate)).ToList());
|
||||
}
|
||||
GetComponent<CanvasGroup>().DOFade(1, 0.3f);
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: aa3ab67bcc540104589072a282858e44
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,49 @@
|
||||
using Assets.Scripts.Apis.Models;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class RowerWelldone : PFUIPanel
|
||||
{
|
||||
public override void Show()
|
||||
{
|
||||
base.Show();
|
||||
Debug.Log("well done show");
|
||||
}
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
UIManager.AddEvent(transform.Find("BtnDefine").gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, b =>
|
||||
{
|
||||
gameObject.SetActive(false);
|
||||
});
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
RowerRecordModel model;
|
||||
public void Initial(RowerRecordModel model)
|
||||
{
|
||||
Debug.Log("Initial");
|
||||
if (model == null) return;
|
||||
this.model = model;
|
||||
transform.Find("Time/Value1").GetComponent<Text>().text = model.CreateTime.ToLocalTime().ToString("yyyy-MM-dd");
|
||||
transform.Find("Time/Value2").GetComponent<Text>().text = model.CreateTime.ToLocalTime().ToString("HH:mm:ss");
|
||||
transform.Find("RowingTime/Value").GetComponent<Text>().text = TimeSpan.FromSeconds(model.TotalTime).ToString();
|
||||
transform.Find("Distance/Value").GetComponent<Text>().text = $"{model.TotalDistance.ToString()}M";
|
||||
var datas = transform.Find("Other/Datas");
|
||||
datas.Find("AvgRate/Value").GetComponent<Text>().text = $"{model.AvgRate.ToString("#0")}";
|
||||
datas.Find("MaxRate/Value").GetComponent<Text>().text = $"{model.MaxRate.ToString()}";
|
||||
datas.Find("AvgPower/Value").GetComponent<Text>().text = $"{model.AvgPower.ToString("#0")}";
|
||||
datas.Find("MaxPower/Value").GetComponent<Text>().text = $"{model.MaxPower.ToString()}";
|
||||
datas.Find("MaxPace/Value").GetComponent<Text>().text = $"{TimeSpan.FromSeconds(model.MaxPace).ToString(@"mm\:ss")}";
|
||||
datas.Find("AvgPace/Value").GetComponent<Text>().text = $"{TimeSpan.FromSeconds(model.AvgPace).ToString(@"mm\:ss")}";
|
||||
datas.Find("Calories/Value").GetComponent<Text>().text = $"{(model.Kj ?? 0).ToString("#0")}";
|
||||
datas.Find("StrokeCount/Value").GetComponent<Text>().text = $"{model.StrokeCount}";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a0932c4066cf3c24da73e66759aaec1f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in new issue
Block a user