划船机其他细节

This commit is contained in:
CaiYanPeng 2021-10-22 16:21:00 +08:00
parent a4e17a56d0
commit eb21914fb7
8 changed files with 1949 additions and 1667 deletions

File diff suppressed because it is too large Load Diff

View File

@ -107,7 +107,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: adb30198aa32dd140b5750692dd48104, type: 3}
m_Name:
m_EditorClassIdentifier:
radius: 48
radius: 24
--- !u!225 &1578934454411558168
CanvasGroup:
m_ObjectHideFlags: 0
@ -195,7 +195,7 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 78, y: 0}
m_AnchoredPosition: {x: 20, y: 0}
m_SizeDelta: {x: 0, y: 36}
m_Pivot: {x: 0, y: 0.5}
--- !u!222 &5181308658082223272
@ -262,7 +262,7 @@ GameObject:
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
m_IsActive: 0
--- !u!224 &2903393643563272319
RectTransform:
m_ObjectHideFlags: 0
@ -277,9 +277,9 @@ RectTransform:
m_Father: {fileID: 1673166913076064936}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 0, y: 0}
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 1}
m_AnchoredPosition: {x: 44, y: -48}
m_SizeDelta: {x: 48, y: 48}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!222 &7027635956731480168

View File

@ -107,7 +107,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: adb30198aa32dd140b5750692dd48104, type: 3}
m_Name:
m_EditorClassIdentifier:
radius: 23
radius: 12
--- !u!225 &1578934454411558168
CanvasGroup:
m_ObjectHideFlags: 0
@ -195,7 +195,7 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 54, y: 0}
m_AnchoredPosition: {x: 20, y: 0}
m_SizeDelta: {x: 0, y: 19}
m_Pivot: {x: 0, y: 0.5}
--- !u!222 &5181308658082223272
@ -262,7 +262,7 @@ GameObject:
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
m_IsActive: 0
--- !u!224 &2903393643563272319
RectTransform:
m_ObjectHideFlags: 0
@ -277,9 +277,9 @@ RectTransform:
m_Father: {fileID: 1673166913076064936}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 0, y: 0}
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 1}
m_AnchoredPosition: {x: 32, y: -24}
m_SizeDelta: {x: 24, y: 24}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!222 &7027635956731480168

View File

@ -192,9 +192,11 @@ namespace Assets.Scripts.Devices.Ble.Characteristic
var val = BitConverter.ToUInt16(data, pullB);
list.Add(val);
PullValue = val;
}
Debug.Log("拉力:" + string.Join(",",list));
}
Debug.Log("原始数据:" + string.Join(",", data));
//Debug.Log("原始数据:" + string.Join(",", data));
}
public void Reset()
{

View File

@ -34,7 +34,7 @@ public class RowerHomeScript : PFUIPanel
{
get
{
var device = App.MainDeviceAdapter.GetDevices().FirstOrDefault(d => (d.State == DeviceState.Connected || d.State == DeviceState.Connecting) && d.Sensor == SensorType.Rower);
var device = App.MainDeviceAdapter.GetDevices().FirstOrDefault(d => (d.State == DeviceState.Connected) && d.Sensor == SensorType.Rower);
if (device != null)
{
return ((IRowerDevice)device).rowerData;
@ -152,14 +152,19 @@ public class RowerHomeScript : PFUIPanel
}
App.MainDeviceAdapter.StopScan();
}
void HandleDiscardDirect()
{
openTimer = false;
isPause = true;
Debug.Log(RowerData);
btnStart.GetComponent<Image>().sprite = spriteDict["Start"];
btnStart.tag = "Start";
Init();
}
void HandleSaveDirect()
{
openTimer = false;
isPause = true;
if (RowerData != null)
{
RowerData.PullChanged -= PaintPullCurveDelegate;
}
btnStart.GetComponent<Image>().sprite = spriteDict["Start"];
btnStart.tag = "Start";
Save();
@ -182,11 +187,11 @@ public class RowerHomeScript : PFUIPanel
{
if (RowerData != null)
{
RowerData.PullChanged -= PaintPullCurveDelegate;
RowerData.PullChanged += PaintPullCurveDelegate;
}
if (!isPause)
{
startTime = UIManager.Now.GetDateTime();
}
TimerTicks();
@ -207,10 +212,6 @@ public class RowerHomeScript : PFUIPanel
{
openTimer = false;
isPause = true;
if (RowerData != null)
{
RowerData.PullChanged -= PaintPullCurveDelegate;
}
btnStart.GetComponent<Image>().sprite = spriteDict["Start"];
btnStart.tag = "Start";
UIManager.ShowConfirm3("Quit", "Do you want to keep the record?",
@ -303,7 +304,6 @@ public class RowerHomeScript : PFUIPanel
{
if (RowerData != null)
{
RowerData.PullChanged -= PaintPullCurveDelegate;
RowerData.Reset();
}
if (Rower != null)
@ -321,6 +321,7 @@ public class RowerHomeScript : PFUIPanel
transform.Find("Mid/GraphChart").GetComponent<RowerGraphChartFeed>().SetData(pullList);
openTimer = false;
bottom.Find("Time/Value").GetComponent<Text>().text = "---";
bottom.Find("TrueTime/Value").GetComponent<Text>().text = "---";
bottom.Find("KM/Value").GetComponent<Text>().text = "---";
bottom.Find("W/Value").GetComponent<Text>().text = "---";
bottom.Find("W/AvgValue").GetComponent<Text>().text = "---";
@ -354,15 +355,20 @@ public class RowerHomeScript : PFUIPanel
double x = 0f;
List<ushort> tempList = new List<ushort>()
{
0,1,4,500,12,13,16,0,0,0,20,30,40,50,60,500
};
int tempx = 0;
//List<ushort> tempList = new List<ushort>()
//{
// 0,1,4,500,12,13,16,0,0,0,20,30,40,50,60,500
//};
//int tempx = 0;
void TimerTicks()
{
//Debug.Log(123);
PaintPullCurve(tempList[(tempx++) % tempList.Count]);
//PaintPullCurve(tempList[(tempx++) % tempList.Count]);
if (Rower == null)
{
HandleDiscardDirect();
return;
}
if (RowerData == null) return;
var heartRate = HeartRate ?? 0;
bottom.Find("BPM/Value").GetComponent<Text>().text = heartRate.ToString();
@ -380,20 +386,25 @@ public class RowerHomeScript : PFUIPanel
Debug.Log("保存");
HandleSaveDirect();
return;
}
}
else if (stopSeconds == 86)
{
Utils.showToast(null, "Record will be saved", duration: 5, stopFunc: () => stopSeconds < 6, isLowest: true);
return;
}
else if (stopSeconds >= 6)
{
if (stopSeconds == 6)
if (stopSeconds == 6)
{
Utils.showToast(null, "Please keep rowing...",duration:5);
Utils.showToast(null, "Please keep rowing...", duration: 10, stopFunc: () => stopSeconds < 6, isLowest: true);
}
bottom.Find("Time/Value").GetComponent<Text>().text = TimeSpan.FromSeconds(seconds++).ToString();
bottom.Find("W/Value").GetComponent<Text>().text = "--";
bottom.Find("W/AvgValue").GetComponent<Text>().text = "--";
bottom.Find("500/Value").GetComponent<Text>().text = "--";
bottom.Find("500/AvgValue").GetComponent<Text>().text = "--";
bottom.Find("MS/Value").GetComponent<Text>().text = "--";
bottom.Find("MS/AvgValue").GetComponent<Text>().text = "--";
bottom.Find("W/Value").GetComponent<Text>().text = "---";
bottom.Find("W/AvgValue").GetComponent<Text>().text = "---";
bottom.Find("500/Value").GetComponent<Text>().text = "---";
bottom.Find("500/AvgValue").GetComponent<Text>().text = "---";
bottom.Find("MS/Value").GetComponent<Text>().text = "---";
bottom.Find("MS/AvgValue").GetComponent<Text>().text = "---";
records.Add($"{RowerData.StrokeCount},{RowerData.ElapsedTime},{RowerData.TotalDistance},0,0,0,{RowerData.ResistanceLevel},{heartRate}");
values.Add(new TempRowerCalc() { pace = 0, power = 0, rate = 0, heartRate = heartRate });
return;
@ -402,6 +413,7 @@ public class RowerHomeScript : PFUIPanel
totalDistance = RowerData.TotalDistance;
bottom.Find("Time/Value").GetComponent<Text>().text = TimeSpan.FromSeconds(seconds++).ToString();
bottom.Find("TrueTime/Value").GetComponent<Text>().text = TimeSpan.FromSeconds(RowerData.ElapsedTime).ToString();
bottom.Find("KM/Value").GetComponent<Text>().text = totalDistance.ToString();
var power = RowerData.InstantaneousPower;
bottom.Find("W/Value").GetComponent<Text>().text = power.ToString();
@ -437,6 +449,12 @@ public class RowerHomeScript : PFUIPanel
bool isPlay = false;
void PaintPullCurve(ushort y)
{
Debug.Log("收到拉力" + y);
if (!openTimer)
{
RowerData.PullChanged -= PaintPullCurveDelegate;
return;
}
if (y > 1200) y = 1200;
//拉力条
var rate = ((float)y) * 2 / 1200;
@ -465,10 +483,14 @@ public class RowerHomeScript : PFUIPanel
isPlay = true;
pullList.Add(new DoubleVector2(x, y));
}
//else
//{
// transform.Find("Mid/GraphChart").GetComponent<RowerGraphChartFeed>().SetData(new List<DoubleVector2> ());
//}
else
{
//只有0并且两秒没拉曲线消失
if (stopSeconds == 1)
{
transform.Find("Mid/GraphChart").GetComponent<RowerGraphChartFeed>().SetData(new List<DoubleVector2>());
}
}
}
else
{

View File

@ -1,5 +1,6 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
@ -28,15 +29,18 @@ public class Toast : MonoBehaviour
[SerializeField] GameObject toast;
[SerializeField] Text txt;
public void showToast(string json)
public void showToast(Assets.Scripts.Utils.ToastParams json)
{
JObject JO = (JObject)JsonConvert.DeserializeObject(json);
gameObject.SetActive(true);
StartCoroutine(showToastCOR(JO.Value<string>("text"), JO.Value<int>("duration")));
if (json.func == null)
{
json.func = () => false;
}
StartCoroutine(showToastCOR(json.text, json.duration,json.func));
}
private IEnumerator showToastCOR(string text,
int duration)
int duration, Func<bool> action)
{
gameObject.SetActive(true);
@ -46,7 +50,7 @@ public class Toast : MonoBehaviour
//Wait for the duration
float counter = 0;
while (counter < duration)
while (counter < duration && !action.Invoke())
{
counter += Time.deltaTime;
yield return null;

View File

@ -143,13 +143,13 @@ namespace Assets.Scripts
_deviceDict = value;
}
}
public static void showToast(GameObject game,string text,int duration = 2,int type = 0)
public static void showToast(GameObject game, string text, int duration = 2, int type = 0, Func<bool> stopFunc = null, bool isLowest = false)
{
//type 0错误 1正确
var parent = UIManager.Instance.ModalsPanel;
if (parent == null) return;
var toast = parent.transform.Find("ToastContainer");
if (toast != null)
if (toast != null)
{
MonoBehaviour.DestroyImmediate(toast.gameObject);
}
@ -163,13 +163,28 @@ namespace Assets.Scripts
newToast.transform.parent = parent.transform;
toast = newToast.transform;
var toastStyle = toastDict[type].Split('|');
if (isLowest)
{
toast.SetAsFirstSibling();
}
else
{
toast.SetAsLastSibling();
}
toast.Find("Image").GetComponent<Image>().sprite = Resources.Load<Sprite>(toastStyle[0]);
toast.GetComponent<Image>().color = HexToColorHtml(toastStyle[1]);
toast.GetComponent<Toast>().showToast(JsonConvert.SerializeObject(new
toast.GetComponent<Toast>().showToast(new ToastParams
{
text,
duration
}));
text = text,
duration = duration,
func = stopFunc
});
}
public class ToastParams
{
public string text { get; set; }
public int duration { get; set; }
public Func<bool> func { get; set; }
}
/*显示简略提示需要拖Toast的预制件且保证其他组件名字不是Toast,ToastContainer*/
public static void showLoading(this GameObject game)

View File

@ -38,6 +38,7 @@ GraphicsSettings:
- {fileID: 16000, guid: 0000000000000000f000000000000000, type: 0}
- {fileID: 16001, guid: 0000000000000000f000000000000000, type: 0}
- {fileID: 17000, guid: 0000000000000000f000000000000000, type: 0}
- {fileID: 16003, guid: 0000000000000000f000000000000000, type: 0}
m_PreloadedShaders: []
m_SpritesDefaultMaterial: {fileID: 10754, guid: 0000000000000000f000000000000000,
type: 0}