适配c2;新版设计稿;对战切换手势;主逻辑接通;使用think的阻力值,修改影子模式船位置

This commit is contained in:
Caiyanpeng committed 2022-03-25 18:02:34 +08:00
1 parent e6f3e2ecfa
commit ab653b994f
82 files changed
+25241 -8988

No files matched your search

@@ -124,7 +124,7 @@ public class ActivityController : PFUIPanel
Application.OpenURL(System.Net.WebUtility.UrlDecode(url));
}
private void Share(int type,int id)
private void Share(int type, int id)
{
string url = $"http://pfweb.juze.pro/Activity/LightUpChina/Share?userId={App.CurrentUser.Id}";
if (type < 2)
@@ -1,4 +1,5 @@
using Assets.Scripts.Apis.Models;
using Assets.Scripts;
using Assets.Scripts.Apis.Models;
using System;
using System.Collections;
using System.Collections.Generic;
@@ -31,7 +32,8 @@ public class MailListController : PFUIPanel
private void DisplayMails(List<MailModel> list)
{
scroll.content.DetachChildren();
if (list == null) return;
scroll.content.DestroyChildren();
if (mail != null)
{
foreach (var item in list)
+48 -15
View File
@@ -16,10 +16,19 @@ public class NewMainNav : MonoBehaviour
{
public Sprite image;
public UnityAction action;
public bool isAlways;
public CustomButton(Sprite image, UnityAction action)
{
this.image = image;
this.action = action;
isAlways = true;
}
public CustomButton(Sprite image, UnityAction action,bool isAlways)
{
this.image = image;
this.action = action;
isAlways = false;
}
}
private GameObject exit;
@@ -28,18 +37,18 @@ public class NewMainNav : MonoBehaviour
float delayTime = 0;
private List<string> typeArray = new List<string>()
{
"Back","Exit","Home","Device","Delay","Setting","Support","Avatar","Custom","Custom2","Mail"
"Back","Exit","Home","Device","Delay","Setting","Support","Avatar","Custom","Custom2","Mail","Custom3"
};
private List<int> indexs = new List<int>();
private int? shrinkIndex = null;
private CustomButton custom = null,custom2 = null;
private CustomButton custom = null,custom2 = null, custom3 = null;
/// <summary>
///
/// </summary>
/// <param name="indexs">仅展开显示的按钮:1:"Exit",3:"Device",4:"Delay",5:"Setting",6:"Support",7:"Avatar"</param>
/// <param name="shrinkIndex">合上后仍显示的按钮:0:"Back",2:"Home",null:仅PF</param>
/// <param name="custom">自定义按钮 8:c1 9:c2</param>
public void SetButtonActive(List<int> indexs,int? shrinkIndex = null, CustomButton custom = null, CustomButton custom2 = null)
/// <param name="custom">自定义按钮 8:c1 9:c2 11:c3</param>
public void SetButtonActive(List<int> indexs,int? shrinkIndex = null, CustomButton custom = null, CustomButton custom2 = null,CustomButton custom3 = null)
{
this.indexs = indexs;
//邮箱常驻
@@ -47,6 +56,7 @@ public class NewMainNav : MonoBehaviour
this.shrinkIndex = shrinkIndex;
this.custom = custom;
this.custom2 = custom2;
this.custom3 = custom3;
if (custom != null)
{
transform.Find("Custom").GetComponent<Button>().onClick.RemoveAllListeners();
@@ -61,6 +71,13 @@ public class NewMainNav : MonoBehaviour
transform.Find("Custom2").GetComponent<Image>().sprite = custom2.image;
indexs.Add(9);
}
if (custom3 != null)
{
transform.Find("Custom3").GetComponent<Button>().onClick.RemoveAllListeners();
transform.Find("Custom3").GetComponent<Button>().onClick.AddListener(custom3.action);
transform.Find("Custom3").GetComponent<Image>().sprite = custom3.image;
indexs.Add(11);
}
SetExpand(false);
}
@@ -98,18 +115,27 @@ public class NewMainNav : MonoBehaviour
item.gameObject.SetActive(types.Contains(item.name));
}
}
else
else
{
item.gameObject.SetActive(item.name == "PF"|| item.name == shrinkName);
item.gameObject.SetActive(item.name == "PF" || item.name == shrinkName);
}
//自定义按钮出来
if (item.name == "Custom")
if (item.name == "Custom" || item.name == "Custom2" || item.name == "Custom3")
{
item.gameObject.SetActive(custom != null && types.Contains(item.name));
}
else if (item.name == "Custom2")
{
item.gameObject.SetActive(custom2 != null && types.Contains(item.name));
//自定义按钮出来
CustomButton c = null;
if (item.name == "Custom")
{
c = custom;
}
else if (item.name == "Custom2")
{
c = custom2;
}
else if (item.name == "Custom3")
{
c = custom3;
}
item.gameObject.SetActive(c != null && types.Contains(item.name) && (flag || !flag && c.isAlways));
}
}
}
@@ -162,7 +188,15 @@ public class NewMainNav : MonoBehaviour
UIManager.AddEvent(device.gameObject, EventTriggerType.PointerClick, x =>
{
//Debug.Log("click device");
UIManager.ShowDevicePanel();
if (App.IsRowerMode.HasValue && App.IsRowerMode.Value)
{
if (UIManager.Instance.RowerHomeScript.checkRowing()) return;
UIManager.ShowRowerDevicePanel();
}
else
{
UIManager.ShowDevicePanel();
}
});
home = this.transform.Find("Home").gameObject;
@@ -261,7 +295,6 @@ public class NewMainNav : MonoBehaviour
{
if (Input.touchCount > 0)
{
Debug.Log(235);
isTouch = true;
GetComponent<CanvasGroup>().DOFade(1, 0.5f);
}
@@ -42,9 +42,9 @@ public class HomeController : PFUIPanel
#if UNITY_ANDROID || UNITY_IOS
var nav = transform.Find("MainNav-mobile").GetComponent<NewMainNav>();
nav.SetButtonActive(new List<int> { 1, 3, 4, 6 },null,new NewMainNav.CustomButton(Resources.Load<Sprite>("Images/Rower/划船"), () =>
nav.SetButtonActive(new List<int> { 1, 3, 4, 6 },null,new NewMainNav.CustomButton(Resources.Load<Sprite>("Images/RowerNew/ICON_mode_44"), () =>
{
UIManager.ShowRowerPanel();
UIManager.ShowRowerSelector();
}));
newNav = nav;
UIManager.AddEvent(transform.Find("TodayData/Datas/Distance").gameObject, EventTriggerType.PointerClick, b =>
+365 -109
View File
@@ -8,6 +8,7 @@ using Assets.Scripts.Devices.Ant.Interfaces;
using Assets.Scripts.Devices.Ble;
using Assets.Scripts.Devices.Ble.Characteristic;
using Assets.Scripts.Devices.Ble.Devices;
using Assets.Scripts.Devices.Ble.Interfaces;
using ChartAndGraph;
using System;
using System.Collections;
@@ -17,6 +18,7 @@ using System.Linq;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.UI;
using static RowerTaskPanel;
public class RowerHomeScript : PFUIPanel
{
@@ -26,6 +28,9 @@ public class RowerHomeScript : PFUIPanel
public ushort pace { get; set; }
public uint rate { get; set; }
public int heartRate { get; set; }
public int energy { get; set; }
public int distance { get; set; }
public int strokeCount { get; set; }
}
/// <summary>
/// 划船机数据
@@ -42,6 +47,7 @@ public class RowerHomeScript : PFUIPanel
return null;
}
}
protected override void OnDestroy()
{
Debug.Log("銷毀");
@@ -75,17 +81,17 @@ public class RowerHomeScript : PFUIPanel
}
}
GameObject btnStart;
Transform left, bottom;
Transform left, bottom, mid;
float timer = 1.0f;
EventHandler PaintPullCurveDelegate;
List<DoubleVector2> pullList = new List<DoubleVector2>();
Dictionary<object, Sprite> spriteDict;
public Dictionary<object, Sprite> spriteDict;
List<string> records;
List<TempRowerCalc> values;
DateTime startTime,createTime;
double Kj = 0;
int seconds = 0;
bool isPause = false;
public RowerType rowerType = null;
/// <summary>
/// 计算停止的秒数,如果超过5秒,除了累加值都变成--,这些值记录为0,提示用户如果超过90秒,将直接保存数据
/// 如果5-90秒有拉力,则继续滑行
@@ -93,20 +99,21 @@ public class RowerHomeScript : PFUIPanel
/// </summary>
int stopSeconds = 0;
uint totalDistance = 0;
Transform slider;
protected override void Start()
{
var nav = transform.Find("MainNav-mobile").GetComponent<NewMainNav>();
nav.SetButtonActive(new List<int> {1,4,6 }, null, new NewMainNav.CustomButton(Resources.Load<Sprite>("Images/Rower/骑行"), () =>
{
ReturnHome();
}));
var rect = transform.GetComponent<RectTransform>();
rect.offsetMax = Vector2.zero;
rect.offsetMin = Vector2.zero;
}
protected override void Awake()
{
rowerType = new RowerType();
spriteDict = new Dictionary<object, Sprite>()
{
{"Start",Resources.Load<Sprite>("Images/Rower/System_play")},
{"Untagged",Resources.Load<Sprite>("Images/Rower/System_pause")},
{"Start",Resources.Load<Sprite>("Images/RowerNew/ICON_continue_44") },
{"Untagged",Resources.Load<Sprite>("Images/RowerNew/ICON_pause_44")},
{0,Resources.Load<Sprite>("Images/Rower/序列帧/划船机0001") },
{1,Resources.Load<Sprite>("Images/Rower/序列帧/划船机0002") },
{2,Resources.Load<Sprite>("Images/Rower/序列帧/划船机0003") },
@@ -128,30 +135,107 @@ public class RowerHomeScript : PFUIPanel
//mainNav.ShowExit();
var btnHome = transform.Find("Other/BtnHome").gameObject;
UIManager.AddEvent(btnHome, UnityEngine.EventSystems.EventTriggerType.PointerClick, b => ReturnHome());
btnStart = transform.Find("Other1/BtnStart").gameObject;
UIManager.AddEvent(btnStart, UnityEngine.EventSystems.EventTriggerType.PointerClick, b => HandleStartOrPause());
left = transform.Find("Left");
bottom = transform.Find("Bottom");
PaintPullCurveDelegate = new EventHandler(PaintPullCurve);
transform.Find("PFUISlider").GetComponent<PFUISlider>().SetValueChanged(r =>
left = transform.Find("Rower/Modes/Scroll/M1/Left");
bottom = transform.Find("Rower/Bottom");
mid = transform.Find("Rower/Modes/Scroll/M1/Mid");
slider = transform.Find("ResBar/PFUISlider");
UIManager.AddEvent(transform.Find("ResBar/BtnAdd").gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, b =>
{
var v = (ushort)(r * 65535);
if (RowerData != null)
{
slider.GetComponent<PFUISlider>().SetValue((RowerData.ResistanceLevel + 1 - 50) / 300f);
}
});
UIManager.AddEvent(transform.Find("ResBar/BtnSub").gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, b =>
{
if (RowerData != null)
{
slider.GetComponent<PFUISlider>().SetValue((RowerData.ResistanceLevel - 1 - 50) / 300f);
}
});
slider.GetComponent<PFUISlider>().valueHandler = (a) => 50 + a * 300;
slider.GetComponent<PFUISlider>().SetValueChanged(r =>
{
var v = (ushort)Math.Round((r * 300));
print("设置阻力" + v);
if (Rower != null)
{
Rower.SetResistanceLevel(v);
//RowerData.
}
});
//transform.Find("Ready/DeviceStatus").gameObject.SetActive(!flag);
//transform.Find("Ready/DeviceStatusConnect").gameObject.SetActive(flag);
UIManager.AddEvent(transform.Find("Ready/DeviceStatus").gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, b =>
{
if (checkRowing()) return;
UIManager.ShowRowerDevicePanel();
});
UIManager.AddEvent(transform.Find("Ready/DeviceStatusConnect").gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, b =>
{
if (checkRowing()) return;
UIManager.ShowRowerDevicePanel();
});
//手机版tab
#if UNITY_ANDROID || UNITY_IOS
var nav = transform.Find("MainNav-mobile").GetComponent<NewMainNav>();
var c1 = new NewMainNav.CustomButton(Resources.Load<Sprite>("Images/RowerNew/ICON_create_44"), () =>
{
//UIManager.ShowRowerWelldone("81A85D49-ACAA-C764-101A-02555E6AC81A");
//return;
if (checkRowing()) return;
UIManager.ShowRowerTaskPanel(type=>
{
rowerType = type;
HandleSelectType();
});
}, false);
//var c2 = new NewMainNav.CustomButton(Resources.Load<Sprite>("Images/RowerNew/ICON_continue_44"), () =>
//{
// HandleStartOrPause();
//});
btnStart = transform.Find("MainNav-mobile/Custom2").gameObject;
var c3 = new NewMainNav.CustomButton(Resources.Load<Sprite>("Images/RowerNew/ICON_mode_44"), () =>
{
ReturnHome();
}, false);
nav.SetButtonActive(new List<int> { 3, 7 }, null, c1, null, c3);
newNav = nav;
#endif
UIManager.AddEvent(transform.Find("Stopped/Confirm/BtnSave").gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, b =>
{
transform.Find("Stopped").gameObject.SetActive(false);
HandleSaveDirect();
});
UIManager.AddEvent(transform.Find("Stopped/Confirm/BtnDrop").gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, b =>
{
transform.Find("Stopped").gameObject.SetActive(false);
Init();
});
Init();
}
private void HandleSelectType()
{
if (Rower != null)
{
Rower.Reset();
}
//RowerPanel/Rower/Bottom/Expected/Title
var dw = rowerType.type == 1 ? $"{rowerType.value}M" : $"{(rowerType.value / 60).ToString("#0.00")}Min";
bottom.Find("Expected/Title").GetComponent<Text>().text = $"EST\n/ {dw}";
Init();
//Utils.showToast(null, "请滑动划船机并开始", isLowest: true, type: 1);
}
public override void Show()
{
base.Show();
var mainNav = this.transform.Find("MainNav").GetComponent<MainNav>();
mainNav.ShowRowerTab();
//var mainNav = this.transform.Find("MainNav").GetComponent<MainNav>();
//mainNav.ShowRowerTab();
transform.MyDOFade();
Debug.Log("140,开始扫描");
App.MainDeviceAdapter.StartScan();
@@ -187,10 +271,16 @@ public class RowerHomeScript : PFUIPanel
Save();
Init();
}
private IRowerCommonData RowerCommonDataInstance => Rower != null ? (C2RowerData.IsEnabled == true ? (IRowerCommonData)Rower.c2RowerData : (IRowerCommonData)Rower.rowerData) : null;
private void HandleStartOrPause()
{
//UIManager.ShowRowerResult();
//return;
if (rowerType == null)
{
Utils.showToast(null, "Please select the course!", isLowest: true);
return;
}
if (btnStart.CompareTag("Start"))
{
#if !UNITY_EDITOR
@@ -202,23 +292,18 @@ public class RowerHomeScript : PFUIPanel
#endif
UIManager.ShowCountDownAnimation(() =>
{
if (RowerData != null)
#if !UNITY_EDITOR
if (RowerCommonDataInstance != null)
{
RowerData.PullChanged -= PaintPullCurveDelegate;
RowerData.PullChanged += PaintPullCurveDelegate;
RowerCommonDataInstance.PullChanged -= PaintPullCurve;
RowerCommonDataInstance.PullChanged += PaintPullCurve;
}
if (!isPause)
{
startTime = UIManager.Now.GetDateTime();
}
TimerTicks();
openTimer = true;
timer = 1.0f;
btnStart.GetComponent<Image>().sprite = spriteDict["Untagged"];
btnStart.tag = "Untagged";
#endif
StartFunc();
},
()=>
{
Debug.Log(222);
if (Rower != null && !isPause)
{
Rower.Reset();
@@ -251,6 +336,23 @@ public class RowerHomeScript : PFUIPanel
//StartCoroutine();
}
private void StartFunc()
{
if (!isPause)
{
startTime = UIManager.Now.GetDateTime();
}
if (!openTimer)
{
TimerTicks();
openTimer = true;
timer = 1.0f;
}
transform.Find("Ready").gameObject.SetActive(false);
btnStart.GetComponent<Image>().sprite = spriteDict["Untagged"];
btnStart.tag = "Untagged";
}
private void Save()
{
createTime = UIManager.Now.GetDateTime();
@@ -285,6 +387,8 @@ public class RowerHomeScript : PFUIPanel
model.StrokeCount = RowerData.StrokeCount;
model.TotalTime = RowerData.ElapsedTime;
model.TotalDistance = RowerData.TotalDistance;
model.Type = rowerType.type == 0 ? (int?)null : rowerType.type;
model.TypeValue = rowerType.value == 0 ? (float?)null : rowerType.value;
var path = PFConstants.RowerRecordFolder + "/" + model.Id;
Helper.CreateDirectoryIfNotExsit(path);
var files = new List<string>();
@@ -295,10 +399,12 @@ public class RowerHomeScript : PFUIPanel
{
var stream = new StreamWriter(fs);
stream.BaseStream.Seek(0, SeekOrigin.End);
foreach (var item in records)
{
stream.Write(item + "\r\n");
}
print("结果数" + records.Count);
stream.Write(string.Join("\r\n", records));
//foreach (var item in records)
//{
// stream.Write(item + "\r\n");
//}
stream.Flush();
stream.Close();
files.Add(fname);
@@ -309,12 +415,9 @@ public class RowerHomeScript : PFUIPanel
Helper.DelectDir(path);
Debug.Log(ex.Message);
}
UIManager.ShowRowerWelldone(model);
Disconnect();
Task.Run(()=>
{
var res = ConfigHelper.rowerApi.Add(model, files);
});
var res = ConfigHelper.rowerApi.Add(model, files);
UIManager.ShowRowerWelldone(model.Id);
//Disconnect();
}
private void Init()
@@ -327,6 +430,7 @@ public class RowerHomeScript : PFUIPanel
{
Rower.Reset();
}
GetComponent<RowerMultiModeScript>().GetShadowList(rowerType);
btnStart.tag = "Start";
btnStart.GetComponent<Image>().sprite = spriteDict["Start"];
left.Find("Rower").GetComponent<Image>().sprite = spriteDict[0];
@@ -335,18 +439,21 @@ public class RowerHomeScript : PFUIPanel
left.Find("Times/Value").GetComponent<Text>().text = "---";
left.Find("Calories/Value").GetComponent<Text>().text = "---";
pullList = new List<DoubleVector2>();
transform.Find("Mid/GraphChart").GetComponent<RowerGraphChartFeed>().SetData(pullList);
mid.Find("GraphChart").GetComponent<RowerGraphChartFeed>().SetData(pullList);
openTimer = false;
bottom.Find("Time/Value").GetComponent<Text>().text = "---";
bottom.Find("TrueTime/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 = "---";
mid.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("500/AvgValue").GetComponent<Text>().text = "---";
bottom.Find("MS/Value").GetComponent<Text>().text = "---";
bottom.Find("MS/AvgValue").GetComponent<Text>().text = "---";
//bottom.Find("MS/AvgValue").GetComponent<Text>().text = "---";
bottom.Find("BPM/Value").GetComponent<Text>().text = "---";
bottom.Find("Expected/Value").GetComponent<Text>().text = "---";
mid.Find("AvgForce/Value").GetComponent<Text>().text = "---";
mid.Find("PeakForce/Value").GetComponent<Text>().text = "---";
records = new List<string>();
values = new List<TempRowerCalc>();
Kj = 0;
@@ -355,42 +462,78 @@ public class RowerHomeScript : PFUIPanel
totalDistance = 0;
stopSeconds = 0;
isPause = false;
#if !UNITY_EDITOR
transform.Find("Ready").gameObject.SetActive(true);
#endif
C2RowerData.EnableChanged -= ModeChanged;
C2RowerData.EnableChanged += ModeChanged;
FtmsRowerData.RowerResChanged -= ResChanged;
FtmsRowerData.RowerResChanged += ResChanged;
}
private void ModeChanged(object sender, EventArgs e)
{
print("增加服务"+RowerData.ResistanceLevel);
RowerCommonDataInstance.PullChanged -= PaintPullCurve;
RowerCommonDataInstance.PullChanged += PaintPullCurve;
slider.GetComponent<Slider>().interactable = !(bool)sender;
transform.Find("ResBar/BtnSub").GetComponent<Button>().interactable = !(bool)sender;
transform.Find("ResBar/BtnAdd").GetComponent<Button>().interactable = !(bool)sender;
}
private void ResChanged(object sender, EventArgs e)
{
print("收到阻力" + sender);
slider.GetComponent<PFUISlider>().SetValue((Convert.ToSingle(sender) - 50) / 300f);
}
public bool checkRowing()
{
if (seconds > 0)
{
Utils.showToast(null, "Please end this training.", isLowest: true);
return true;
}
return false;
}
private void ReturnHome()
{
if (seconds > 0)
{
Utils.showToast(null, "Please end this training.", isLowest: true);
return;
}
if (checkRowing()) return;
Disconnect();
UIManager.ShowHomePanel();
UIManager.ShowRowerSelector();
}
// Update is called once per frame
bool openTimer = false;
double x = 0f;
//List<ushort> tempList = new List<ushort>()
//{
// 0,1230,4,500,12,13,16,0,0,0,20,30,40,50,60,500
//};
//int tempx = 0;
void TimerTicks()
#if UNITY_EDITOR
List<ushort> tempList = new List<ushort>()
{
//Debug.Log(123);
//PaintPullCurve(tempList[(tempx++) % tempList.Count]);
0,1230,4,500,12,13,16,0,0,0,20,30,40,50,60,500
};
int tempx = 0;
#endif
void TimerTicks()
{
#if UNITY_EDITOR
PaintPullCurve(tempList[(tempx++) % tempList.Count]);
#endif
#if !UNITY_EDITOR
if (Rower == null)
{
HandleDiscardDirect();
return;
}
#endif
if (RowerData == null) return;
#endif
var heartRate = HeartRate ?? 0;
bottom.Find("BPM/Value").GetComponent<Text>().text = heartRate.ToString();
var distance = (int)RowerData.TotalDistance;
var energy = RowerData.TotalEnergy;
var strokeCount = RowerData.StrokeCount;
TempRowerCalc tmpdata = null;
if (totalDistance == RowerData.TotalDistance)
{
//判定一次停止
@@ -399,51 +542,122 @@ public class RowerHomeScript : PFUIPanel
else
{
stopSeconds = 0;
transform.Find("Stopped").gameObject.SetActive(false);
}
if (stopSeconds >= 91)
//if (stopSeconds >= 91)
//{
// Debug.Log("保存");
// HandleSaveDirect();
// return;
//}
//else if (stopSeconds == 81)
//{
// Utils.showToast(null, "Record will be saved!", duration: 10, stopFunc: () => stopSeconds < 6, isLowest: true,showSeconds:true);
// return;
//}
if (stopSeconds >= 2)
{
Debug.Log("保存");
HandleSaveDirect();
return;
}
else if (stopSeconds == 81)
{
Utils.showToast(null, "Record will be saved!", duration: 10, stopFunc: () => stopSeconds < 6, isLowest: true,showSeconds:true);
return;
}
else if (stopSeconds >= 6)
{
if (stopSeconds == 6)
transform.Find("Stopped").gameObject.SetActive(true);
//if (stopSeconds == 6)
//{
// Utils.showToast(null, "Please keep rowing...", duration: 60, stopFunc: () => stopSeconds < 6, isLowest: true);
//}
if (rowerType.type == 2)
{
Utils.showToast(null, "Please keep rowing...", duration: 60, stopFunc: () => stopSeconds < 6, isLowest: true);
var remainTime = rowerType.value - (seconds++);
if (remainTime == 0)
{
HandleSaveDirect();
return;
}
bottom.Find("Time/Value").GetComponent<Text>().text = TimeSpan.FromSeconds(remainTime).ToString();
}
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 = "---";
else
{
bottom.Find("Time/Value").GetComponent<Text>().text = TimeSpan.FromSeconds(seconds++).ToString();
}
mid.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("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 });
//bottom.Find("MS/AvgValue").GetComponent<Text>().text = "---";
bottom.Find("Expected/Value").GetComponent<Text>().text = "---";
records.Add($"{strokeCount},{RowerData.ElapsedTime},{distance},0,0,0,{RowerData.ResistanceLevel},{heartRate},{energy}");
tmpdata = new TempRowerCalc() { strokeCount = strokeCount, pace = 0, power = 0, rate = 0, heartRate = heartRate, distance = distance, energy = energy };
values.Add(tmpdata);
SendDataToRace(tmpdata);
return;
}
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();
bottom.Find("W/AvgValue").GetComponent<Text>().text = RowerData.AveragePower.ToString();
totalDistance = (uint)distance;
var pace = RowerData.InstantaneousPace;
if (rowerType.type == 2)
{
var remainTime = rowerType.value - (seconds++);
if (remainTime == 0)
{
HandleSaveDirect();
return;
}
bottom.Find("Time/Value").GetComponent<Text>().text = TimeSpan.FromSeconds(remainTime).ToString();
}
else
{
bottom.Find("Time/Value").GetComponent<Text>().text = TimeSpan.FromSeconds(seconds++).ToString();
}
//bottom.Find("TrueTime/Value").GetComponent<Text>().text = TimeSpan.FromSeconds(RowerData.ElapsedTime).ToString();
if (rowerType.type == 1)
{
var remainDistance = rowerType.value - totalDistance;
if (remainDistance < 0)
{
HandleSaveDirect();
return;
}
bottom.Find("KM/Value").GetComponent<Text>().text = remainDistance.ToString();
}
else
{
bottom.Find("KM/Value").GetComponent<Text>().text = totalDistance.ToString();
}
if (pace != 0)
{
if (rowerType.type == 1)
{
//设置里程时 显示预估时间 当前时间+剩余里程/配速(转换)
var remainDistance = rowerType.value - totalDistance;
var time = values.Count + (remainDistance / (500f / pace));
bottom.Find("Expected/Value").GetComponent<Text>().text = TimeSpan.FromSeconds(time).ToString(@"hh\:mm\:ss");
}
else if (rowerType.type == 2)
{
var remainTime = rowerType.value - values.Count;
var dis = totalDistance + (remainTime * (500f / pace));
//设置时间时 显示预估里程 当前里程+剩余时间*配速
bottom.Find("Expected/Value").GetComponent<Text>().text = $"{dis.ToString("#0")}M";
}
else
{
//自由滑 显示30min里程 当前里程+剩余时间*配速
var remainTime = 30 * 60 - values.Count;
var dis = totalDistance + (remainTime * (500f / pace));
//设置时间时 显示预估里程 当前里程+剩余时间*配速
bottom.Find("Expected/Value").GetComponent<Text>().text = $"{dis.ToString("#0")}M";
}
}
//RowerPanel/Rower/Bottom/Expected/Value
var power = RowerData.InstantaneousPower;
mid.Find("W/Value").GetComponent<Text>().text = power.ToString();
//bottom.Find("W/AvgValue").GetComponent<Text>().text = RowerData.AveragePower.ToString();
bottom.Find("500/Value").GetComponent<Text>().text = TimeSpan.FromSeconds(pace).ToString(@"mm\:ss");
bottom.Find("500/AvgValue").GetComponent<Text>().text = TimeSpan.FromSeconds(RowerData.AveragePace).ToString(@"mm\:ss");
//bottom.Find("500/AvgValue").GetComponent<Text>().text = TimeSpan.FromSeconds(RowerData.AveragePace).ToString(@"mm\:ss");
var rate = RowerData.StrokeRate;
bottom.Find("MS/Value").GetComponent<Text>().text = rate.ToString();
bottom.Find("MS/AvgValue").GetComponent<Text>().text = RowerData.AverageStrokeRate.ToString();
var strokeCount = RowerData.StrokeCount;
//bottom.Find("MS/AvgValue").GetComponent<Text>().text = RowerData.AverageStrokeRate.ToString();
//if (ushort.TryParse(left.Find("Times/Value").GetComponent<Text>().text, out ushort originStroke))
//{
// if (strokeCount != originStroke)
@@ -452,28 +666,52 @@ public class RowerHomeScript : PFUIPanel
// }
//}
left.Find("Times/Value").GetComponent<Text>().text = strokeCount.ToString();
left.Find("Calories/Value").GetComponent<Text>().text = RowerData.TotalEnergy.ToString();
records.Add($"{RowerData.StrokeCount},{RowerData.ElapsedTime},{RowerData.TotalDistance},{RowerData.InstantaneousPower},{RowerData.InstantaneousPace},{RowerData.StrokeRate},{RowerData.ResistanceLevel},{heartRate}");
values.Add(new TempRowerCalc() { pace = pace, power = power, rate = rate,heartRate = heartRate });
left.Find("Calories/Value").GetComponent<Text>().text = energy.ToString();
mid.Find("AvgForce/Value").GetComponent<Text>().text = RowerCommonDataInstance.AverageDriveForce.ToString("#0");
mid.Find("PeakForce/Value").GetComponent<Text>().text = RowerCommonDataInstance.PeakDriveForce.ToString("#0");
records.Add($"{strokeCount},{RowerData.ElapsedTime},{distance},{RowerData.InstantaneousPower},{RowerData.InstantaneousPace},{RowerData.StrokeRate},{RowerData.ResistanceLevel},{heartRate},{energy}");
print(records.Count);
tmpdata = new TempRowerCalc() { strokeCount = strokeCount, pace = pace, power = power, rate = rate, heartRate = heartRate, distance = distance, energy = energy };
values.Add(tmpdata);
SendDataToRace(tmpdata);
//Debug.Log(1);
}
void SendDataToRace(TempRowerCalc tmpdata)
{
GetComponent<RowerMultiModeScript>().HandleTimeTick(new RowerChartModel
{
Pace = tmpdata.pace,
Power = tmpdata.power,
HeartRate = tmpdata.heartRate,
Rate = tmpdata.rate,
Distance = tmpdata.distance,
StrokeCount = tmpdata.strokeCount
});
}
void PaintPullCurve(object sender, EventArgs e)
{
var ftms = (FtmsRowerData)sender;
var ftms = (IRowerCommonData)sender;
//Debug.Log(ftms.PullValue);
PaintPullCurve(ftms.PullValue);
}
bool isPlay = false;
void PaintPullCurve(ushort y)
{
Debug.Log("收到拉力" + y);
Debug.Log("收到拉力" + y + ","+ DateTime.Now.Ticks);
#if !UNITY_EDITOR
if (!openTimer)
{
RowerData.PullChanged -= PaintPullCurveDelegate;
return;
if (y > 0)
{
//RowerCommonDataInstance.PullChanged -= PaintPullCurve;
//RowerCommonDataInstance.PullChanged += PaintPullCurve;
StartFunc();
}
else
{
return;
}
}
#endif
//if (y > 1200) y = 1200;
@@ -492,13 +730,13 @@ public class RowerHomeScript : PFUIPanel
isPlay = true;
x = 0;
pullList.Add(new DoubleVector2(x, y));
transform.Find("Mid/GraphChart").GetComponent<RowerGraphChartFeed>().SetData(pullList);
mid.Find("GraphChart").GetComponent<RowerGraphChartFeed>().SetData(pullList);
}
else if (pullList.Count > 1)
{
x += 0.1;
pullList.Add(new DoubleVector2(x, y));
transform.Find("Mid/GraphChart").GetComponent<RowerGraphChartFeed>().SetData(pullList);
mid.Find("GraphChart").GetComponent<RowerGraphChartFeed>().SetData(pullList);
pullList.Clear();
x = 0;
isPlay = true;
@@ -509,7 +747,7 @@ public class RowerHomeScript : PFUIPanel
//只有0并且两秒没拉,曲线消失
if (stopSeconds == 1)
{
transform.Find("Mid/GraphChart").GetComponent<RowerGraphChartFeed>().SetData(new List<DoubleVector2>());
mid.Find("GraphChart").GetComponent<RowerGraphChartFeed>().SetData(new List<DoubleVector2>());
}
}
}
@@ -523,8 +761,7 @@ public class RowerHomeScript : PFUIPanel
isPlay = false;
left.Find("Rower").GetComponent<RowerAnimation>().StartAnimation();
}
transform.Find("Mid/GraphChart").GetComponent<RowerGraphChartFeed>().SetData(pullList);
mid.Find("GraphChart").GetComponent<RowerGraphChartFeed>().SetData(pullList);
}
//Debug.Log($"{x},{y}");
//transform.Find("Mid/GraphChart").GetComponent<RowerGraphChartFeed>().SetData(pullList);
@@ -539,6 +776,7 @@ public class RowerHomeScript : PFUIPanel
// x += 0.1f;
//}
}
float staticTimer = 1f;
void Update()
{
if (openTimer)
@@ -550,5 +788,23 @@ public class RowerHomeScript : PFUIPanel
timer = 1f + timer;
}
}
staticTimer -= Time.deltaTime;
if (staticTimer <= 0)
{
HandleStatic();
staticTimer += 1f;
}
}
void HandleStatic()
{
if (transform.Find("Ready").gameObject.activeInHierarchy)
{
var flag = Rower != null && RowerData != null;
transform.Find("Ready/DeviceStatus").gameObject.SetActive(!flag);
transform.Find("Ready/Img").gameObject.SetActive(!flag);
transform.Find("Ready/Text").gameObject.SetActive(!flag);
transform.Find("Ready/DeviceStatusConnect").gameObject.SetActive(flag);
}
}
}
@@ -108,7 +108,8 @@ public class RouteItem : MonoBehaviour
{
UIManager.AddEvent(btnDetail.gameObject, EventTriggerType.PointerClick, b =>
{
UIManager.ShowRowerResult(result.Id);
Application.OpenURL($"{App.websiteDict[App.Host]}rower/record/{result.Id}?Token={App.CurrentUser.cookie}");
//UIManager.ShowRowerResult(result.Id);
});
}
btnReRide = right.Find("BtnRide");
@@ -0,0 +1,38 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class RowerDevicePanel : PFUIPanel
{
protected override void Awake()
{
UIManager.AddEvent(transform.Find("Container/Tools/Back").gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, b =>
{
Close();
});
}
// Start is called before the first frame update
void Start()
{
}
float timer = 1f;
// Update is called once per frame
void Update()
{
timer -= Time.deltaTime;
if (timer <= 0)
{
if (App.MainDeviceAdapter.GetState(Assets.Scripts.Devices.ConnectionInterface.BLE) == Assets.Scripts.Devices.DeviceAdapterState.On)
{
transform.Find("Container/Tools/BlueTooth").GetComponent<Image>().sprite = Resources.Load<Sprite>("Images/RowerNew/ICON_bluetooth_44_on");
}
else
{
transform.Find("Container/Tools/BlueTooth").GetComponent<Image>().sprite = Resources.Load<Sprite>("Images/RowerNew/ICON_bluetooth_44");
}
timer += 1f;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 169dd57411866874882869d55e047e57
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,543 @@
using Assets.Scripts;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using DG.Tweening;
using Assets.Scripts.Apis.Models;
using System;
using System.Linq;
using UnityEngine.UI;
using Assets.Scripts.UI.Prefab.Login;
using Newtonsoft.Json;
public class RowerMultiModeScript : MonoBehaviour
{
// Start is called before the first frame update
[SerializeField]
GameObject rank;
Transform scroll,m2;
Vector3 startPosition,boatStartPosition;
TKPanRecognizer pan;
ScrollRect scrollRank;
Dictionary<string, Texture> caches;
public class Trace
{
public int userId { get; set; }
public Transform trace { get; set; }
}
public class TraceData
{
public List<RowerChartModel> list { get; set; }
public string NickName { get; set; }
public string Avatar { get; set; }
public int UserId { get; set; }
public bool isMine { get; set; }
public int currentDistance { get; set; }
public string Country { get; set; }
}
List<Trace> traceList;
List<float> initialPosYList;
void Awake()
{
scroll = transform.Find("Rower/Modes/Scroll");
startPosition = scroll.localPosition;
if (PlayerPrefs.GetFloat("RowerMultiModeLocationX") != 0f)
{
scroll.localPosition = new Vector3(PlayerPrefs.GetFloat("RowerMultiModeLocationX"), startPosition.y, startPosition.z);
}
AddTouchEvent();
m2 = transform.Find("Rower/Modes/Scroll/M2");
caches = new Dictionary<string, Texture>();
traceList = new List<Trace>()
{
new Trace{ userId=0, trace=m2.Find("Track/T1") },
new Trace{ userId=0, trace=m2.Find("Track/T2") },
new Trace{ userId=0, trace=m2.Find("Track/T3") },
new Trace{ userId=0, trace=m2.Find("Track/T4") },
new Trace{ userId=0, trace=m2.Find("Track/T5") },
};
initialPosYList = new List<float>
{
m2.Find("Track/T1").localPosition.y,
m2.Find("Track/T2").localPosition.y,
m2.Find("Track/T3").localPosition.y,
m2.Find("Track/T4").localPosition.y,
m2.Find("Track/T5").localPosition.y,
};
scrollRank = transform.Find("Rower/Modes/Scroll/M2/Rank/Scroll View").GetComponent<ScrollRect>();
var countryJson = Resources.Load<TextAsset>("UI/flags-mini").text;
countryList = JsonConvert.DeserializeObject<List<CountryModel>>(countryJson);
}
public void HandleTimeTick(RowerChartModel data)
{
currentSecond++;
myData.list.Add(data);
SortByCurrentDistance();
DisplayUserRanks();
DisplayTraces();
}
private void SortByCurrentDistance()
{
if (currentSecond >= 0)
{
userList.ForEach(x =>
{
var _list = x.list;
var _distance = 0;
if (_list.Count == 0)
{
_distance = 0;
}
else if (currentSecond >= _list.Count)
{
_distance = _list[_list.Count - 1].Distance;
}
else
{
_distance = _list[currentSecond].Distance;
}
x.currentDistance = _distance;
});
}
userList = userList.OrderByDescending(x => x.currentDistance).ToList();
}
private List<TraceData> HandleData()
{
//仅取5个
var mineIndex = userList.FindIndex(x => x.isMine);
if (mineIndex < 2)
{
return userList.Where((x, i) => i < 5).ToList();
}
else if (mineIndex > userList.Count - 3)
{
return userList.Where((x, i) => i >= userList.Count - 5).ToList();
}
else
{
return userList.Where((x, i) => i >= mineIndex - 2 && i <= mineIndex + 2).ToList();
}
}
List<TraceData> userList;
TraceData myData;
List<RowerRank> shadowList;
private async void Start()
{
rowerType = GetComponent<RowerHomeScript>().rowerType;
//#if UNITY_EDITOR
// rowerType = new RowerTaskPanel.RowerType { type = 1, value = 250 };
//#endif
GetShadowList(rowerType);
}
public async void GetShadowList(RowerTaskPanel.RowerType rowerType)
{
currentSecond = -1;
var res = await ConfigHelper.rowerApi.GetShadowList(rowerType);
shadowList = res.data;
var _tmpList = shadowList.Select(x => new TraceData
{
list = x.list,
NickName = x.NickName,
Avatar = x.WxHeadImg,
UserId = x.UserId,
isMine = false,
currentDistance = 0,
Country = x.Country
}).ToList();
myData = new TraceData();
myData.list = new List<RowerChartModel>();
myData.UserId = App.CurrentUser.Id;
myData.NickName = App.CurrentUser.Nickname;
myData.Avatar = App.CurrentUser.WxHeadImg;
myData.isMine = true;
myData.Country = App.CurrentUser.Country;
_tmpList.Add(myData);
userList = _tmpList.OrderByDescending(x => x.currentDistance).ToList();
DisplayUserRanks(true);
DisplayTraces();
}
private void DisplayTraces()
{
var list = HandleData();
//CompareTraceList(traceList, list);
int i = 0;
var mineData = list.FirstOrDefault(x => x.isMine);
for (i = 0; i < list.Count;i++)
{
var sq = DOTween.Sequence();
var item = traceList[i];
var t = item.trace;
var data = list[i];
t.gameObject.SetActive(true);
TweenCallback callback = () =>
{
Utils.DisplayImageTempDict(t.Find("Left/Avatar").GetComponent<RawImage>(), data.Avatar, caches);
var _c = countryList.SingleOrDefault(x => x.country == data.Country);
if (_c != null)
{
t.Find("Left/Avatar/Country").GetComponent<Image>().sprite = Resources.Load<Sprite>(_c.source);
}
t.Find("Left/NickName").GetComponent<Text>().text = data.NickName;
if (data.list.Count == 0)
{
t.Find("Left/Time").GetComponent<Text>().text = TimeSpan.FromSeconds(0).ToString(@"mm\:ss");
}
else if (currentSecond >= 0 && currentSecond < data.list.Count)
{
var _d = data.list[currentSecond];
t.Find("Left/Time").GetComponent<Text>().text = TimeSpan.FromSeconds(_d.Pace).ToString(@"mm\:ss");
}
else
{
var _d = data.list[data.list.Count - 1];
t.Find("Left/Time").GetComponent<Text>().text = TimeSpan.FromSeconds(_d.Pace).ToString(@"mm\:ss");
}
var diff = data.currentDistance - mineData.currentDistance;
if (diff > 0)
{
t.Find("Main/Diff").GetComponent<Text>().text = diff.ToString("+#0M");
}
else if (diff == 0)
{
t.Find("Main/Diff").GetComponent<Text>().text = data.isMine ? "" : diff.ToString("#0M");
}
else
{
t.Find("Main/Diff").GetComponent<Text>().text = diff.ToString("#0M");
}
if (data.isMine)
{
t.transform.Find("Left/Time").GetComponent<Text>().color = Utils.HexToColorHtml("#f93086");
t.transform.Find("Left/NickName").GetComponent<Text>().color = Utils.HexToColorHtml("#f93086");
}
else
{
t.transform.Find("Left/Time").GetComponent<Text>().color = Utils.HexToColorHtml("#ffffff");
t.transform.Find("Left/NickName").GetComponent<Text>().color = Utils.HexToColorHtml("#ffffff");
}
};
if (item.userId != data.UserId)
{
var sq1 = DOTween.Sequence();
var tmp = traceList[i].trace.DOLocalRotate(new Vector3(90, 0, 0), 0.3f);
tmp.onComplete = callback;
sq1.Append(tmp);
sq1.Append(traceList[i].trace.DOLocalRotate(new Vector3(0, 0, 0), 0.3f));
sq.Join(sq1);
}
else
{
sq.AppendCallback(callback);
}
item.userId = data.UserId;
if (currentSecond >= 0 && currentSecond < list[i].list.Count)
{
var _d = data.list[currentSecond];
if (currentSecond > 0)
{
var _pred = data.list[currentSecond - 1];
if (_pred.StrokeCount != _d.StrokeCount)
{
//上次划桨次数和这次不一样 说明需要划桨一次
var spDict = GetComponent<RowerHomeScript>().spriteDict;
int spDictIndex = 0;
sq.Join(DOTween.To(() => spDictIndex, x => t.Find("Main/Boat").GetComponent<Image>().sprite = spDict[x], 14, 0.3f));
sq.AppendCallback(() =>
{
int spDictIndex2 = 14;
DOTween.To(() => spDictIndex2, x => t.Find("Main/Boat").GetComponent<Image>().sprite = spDict[x], 0, 0.6f);
});
}
}
}
var width = t.Find("Main").GetComponent<RectTransform>().sizeDelta.x - t.Find("Main/Boat").GetComponent<RectTransform>().sizeDelta.x;
var diffWidth = data.currentDistance - mineData.currentDistance + 50;
if (diffWidth >= 0 && diffWidth <= 100)
{
if (data.currentDistance <= 50)
{
diffWidth = data.currentDistance;
}
else if (rowerType.type == 1 && rowerType.value - data.currentDistance <= 50)
{
diffWidth = 100 - ((int)rowerType.value - data.currentDistance);
}
var tWidth = (diffWidth / 100f) * width;
t.Find("Main/Boat").gameObject.SetActive(true);
//t.Find("Main/Boat").localPosition = new Vector3(25 + tWidth, t.Find("Main/Boat").localPosition.y, t.Find("Main/Boat").localPosition.z);
sq.Join(t.Find("Main/Boat").DOLocalMoveX(21.5f + tWidth, 0.9f));
}
else
{
t.Find("Main/Boat").localPosition = new Vector3(-21.5f, t.Find("Main/Boat").localPosition.y, t.Find("Main/Boat").localPosition.z);
t.Find("Main/Boat").gameObject.SetActive(false);
}
sq.Play();
}
for (; i < traceList.Count; i++)
{
traceList[i].userId = 0;
traceList[i].trace.gameObject.SetActive(false);
}
}
private void CompareTraceList(List<Trace> traceList, List<TraceData> list)
{
if (traceList.Count(x => x.userId == 0) == 5) return;
var originUserList = traceList.Select(x => x.userId).ToList();
var newUserList = list.Select(x => x.UserId).ToList();
if (newUserList.Count != 5)
{
for (int i = newUserList.Count; i < 5; i++)
{
newUserList.Add(0);
}
}
var diffRank = new List<int?>();
for (int i = 0; i < 5; i++)
{
int _origin = originUserList[i], _new = newUserList[i];
if (_origin == _new)
{
//相等 则排名没变化
diffRank.Add(0);
}
else
{
//不相等 分情况
var newIndex = originUserList.FindIndex(x => x == _new);
if (newIndex != -1)
{
diffRank.Add(newIndex - _origin);
}
else
{
diffRank.Add(null);
}
}
}
}
private void SetRank(GameObject game, TraceData item,int i)
{
game.transform.Find("Content/Rank").GetComponent<Text>().text = (i + 1).ToString("00");
game.transform.Find("Content/NickName").GetComponent<Text>().text = item.NickName;
Utils.DisplayImageTempDict(game.transform.Find("Content/Avatar").GetComponent<RawImage>(), item.Avatar, caches);
var _c = countryList.FirstOrDefault(x => item.Country == x.country);
if (_c != null)
{
game.transform.Find("Content/Country").GetComponent<Image>().sprite = Resources.Load<Sprite>(_c.source);
}
if (currentSecond < 0)
{
game.transform.Find("Content/Time").GetComponent<Text>().text = "0M";
game.transform.Find("Content/Power").GetComponent<Text>().text = "0W";
}
else if (currentSecond >= 0 && currentSecond < item.list.Count)
{
game.transform.Find("Content/Time").GetComponent<Text>().text = item.list[currentSecond].Distance.ToString("#0M");
game.transform.Find("Content/Power").GetComponent<Text>().text = item.list[currentSecond].Power.ToString("#0W");
}
else
{
game.transform.Find("Content/Time").GetComponent<Text>().text = item.list[item.list.Count - 1].Distance.ToString("#0M");
game.transform.Find("Content/Power").GetComponent<Text>().text = item.list[item.list.Count - 1].Power.ToString("#0W");
}
if (item.isMine)
{
game.transform.Find("Content/Time").GetComponent<Text>().color = Utils.HexToColorHtml("#f93086");
game.transform.Find("Content/Power").GetComponent<Text>().color = Utils.HexToColorHtml("#f93086");
game.transform.Find("Content/NickName").GetComponent<Text>().color = Utils.HexToColorHtml("#f93086");
game.transform.Find("Content/Rank").GetComponent<Text>().color = Utils.HexToColorHtml("#f93086");
}
else
{
game.transform.Find("Content/Time").GetComponent<Text>().color = Utils.HexToColorHtml("#ffffff");
game.transform.Find("Content/Power").GetComponent<Text>().color = Utils.HexToColorHtml("#ffffff");
game.transform.Find("Content/NickName").GetComponent<Text>().color = Utils.HexToColorHtml("#ffffff");
game.transform.Find("Content/Rank").GetComponent<Text>().color = Utils.HexToColorHtml("#ffffff");
}
}
private void DisplayUserRanks(bool isRefresh = false)
{
if (isRefresh)
{
scrollRank.content.DestroyChildren();
}
if (scrollRank.content.childCount == 0)
{
for (int i = 0; i < userList.Count; i++)
{
var item = userList[i];
var game = Instantiate<GameObject>(rank);
SetRank(game, item, i);
game.transform.SetParent(scrollRank.content);
game.transform.localScale = Vector3.one;
game.SetActive(true);
}
}
else
{
int i = 0;
foreach (Transform t in scrollRank.content)
{
var item = userList[i];
SetRank(t.gameObject, item, i);
i++;
}
}
transform.Find("Rower/Modes/Scroll/M2/Rank/MyRank").GetComponent<Text>().text = $"<color=#f93086>{userList.FindIndex(x => x.isMine) + 1}</color> / {userList.Count}";
}
private void AddTouchEvent()
{
pan = new TKPanRecognizer();
pan.gestureRecognizedEvent += (r) =>
{
var startPoint = r.startPoint;
if (((RectTransform)transform.Find("Rower/Modes")).isPointInTransfrom(startPoint))
{
if (scroll.localPosition.x < startPosition.x - (730 / 2)
&& ((RectTransform)transform.Find("RankS")).isPointInTransfrom(startPoint))
{
return;
}
var offset = pan.deltaTranslation;
scroll.localPosition += new Vector3(offset.x, 0, 0);
}
};
pan.gestureCompleteEvent += (r) =>
{
float x = 0;
if (scroll.localPosition.x >= startPosition.x - (730 / 2))
{
x = startPosition.x;
}
else
{
x = startPosition.x - 730;
}
scroll.DOLocalMoveX(x, 0.5f);
PlayerPrefs.SetFloat("RowerMultiModeLocationX", x);
};
TouchKit.addGestureRecognizer(pan);
}
//交换A,B索引的赛道
void ChangeTrace(int indexA, int indexB)
{
if (indexA >= traceList.Count || indexB >= traceList.Count)
{
return;
}
if (traceList.Count(x => x.trace.gameObject.activeInHierarchy) == 0) return;
Trace a = traceList[indexA], b = traceList[indexB];
//2个排名
//先视觉交换
float aniTime = 0.3f;
Vector3 aloc = a.trace.localPosition;
var sq = DOTween.Sequence();
sq.Join(a.trace.DOLocalMoveY(b.trace.localPosition.y, aniTime));
sq.Join(b.trace.DOLocalMoveY(aloc.y, aniTime));
//逻辑交换
var tmp = traceList[indexA];
traceList[indexA] = traceList[indexB];
traceList[indexB] = tmp;
var sq1 = DOTween.Sequence();
if (traceList.Count(x => x.trace.gameObject.activeInHierarchy) != 5) return;
if (indexA == 1 && indexB == 2)
{
for (int i = 0; i < 5; i++)
{
if (i == 4)
{
sq1.Join(traceList[i].trace.DOLocalMoveY(initialPosYList[4] - 50.4f, aniTime));
}
else
{
sq1.Join(traceList[i].trace.DOLocalMoveY(initialPosYList[i + 1], aniTime));
}
}
sq1.AppendCallback(() =>
{
traceList[4].trace.localPosition = new Vector3(traceList[0].trace.localPosition.x, initialPosYList[0] + 49.5f, traceList[0].trace.localPosition.z);
});
sq1.Append(traceList[4].trace.DOLocalMoveY(initialPosYList[0], aniTime));
sq.Append(sq1);
sq.Play().onComplete = () =>
{
tmp = traceList[4];
for (int i = 4; i >= 1; i--)
{
traceList[i] = traceList[i - 1];
}
traceList[0] = tmp;
};
}
else if (indexA == 2 && indexB == 3)
{
for (int i = 0; i < 5; i++)
{
if (i == 0)
{
sq1.Join(traceList[i].trace.DOLocalMoveY(initialPosYList[0] + 50.4f, aniTime));
}
else
{
sq1.Join(traceList[i].trace.DOLocalMoveY(initialPosYList[i - 1], aniTime));
}
}
sq1.AppendCallback(() =>
{
traceList[0].trace.localPosition = new Vector3(traceList[0].trace.localPosition.x, initialPosYList[4] - 49.5f, traceList[0].trace.localPosition.z);
});
sq1.Append(traceList[0].trace.DOLocalMoveY(initialPosYList[4], aniTime));
sq.Append(sq1);
sq.Play().onComplete = () =>
{
tmp = traceList[0];
for (int i = 0; i < 4; i++)
{
traceList[i] = traceList[i + 1];
}
traceList[4] = tmp;
};
}
}
float timer = 1f;
int currentSecond = -1;
private List<CountryModel> countryList;
public RowerTaskPanel.RowerType rowerType { get; private set; }
// Update is called once per frame
void Update()
{
#if UNITY_EDITOR
timer -= Time.deltaTime;
if (timer < 0)
{
//var r = new System.Random();
//int a = r.Next(1, 3);
//print($"{a},{a+1}");
//ChangeTrace(a, a+1);
HandleTimeTick(new RowerChartModel()
{
Distance = 0,
});
currentSecond++;
timer += 1f;
}
#endif
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ee3b67ceb2893134a887a9e30922821e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,269 @@
using Assets.Scripts;
using Assets.Scripts.UI.Control;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;
public class RowerTaskPanel : PFUIPanel
{
public class RowerType
{
/// <summary>
/// 1 里程 2 时间
/// </summary>
public int type { get; set; }
/// <summary>
/// 里程:m 时间:s
/// </summary>
public float value { get; set; }
}
Transform selector, distance, time;
RowerType rowerType;
public Action<RowerType> callBack { get; set; }
protected override void Awake()
{
distance = transform.Find("Main/Distance");
time = transform.Find("Main/Time");
rowerType = new RowerType();
UIManager.AddEvent(transform.Find("Main/BtnGo").gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, b =>
{
Go();
});
UIManager.AddEvent(transform.Find("Main/BtnCancel").gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, b =>
{
Close();
});
//var bg = transform.Find("Main/Time/Inputbg").gameObject;
//UIManager.AddEvent(bg, UnityEngine.EventSystems.EventTriggerType.PointerEnter, b =>
// {
// bg.GetComponent<Outline>().enabled = true;
// bg.GetComponent<Outline>().effectColor = Utils.HexToColorHtml("#353543");
// });
//UIManager.AddEvent(bg, UnityEngine.EventSystems.EventTriggerType.Select, b =>
//{
// bg.GetComponent<Outline>().enabled = true;
// bg.GetComponent<Outline>().effectColor = Utils.HexToColorHtml("#f93086");
//});
//UIManager.AddEvent(bg, UnityEngine.EventSystems.EventTriggerType.Deselect, b =>
//{
// bg.GetComponent<Outline>().enabled = false;
//});
formList = new List<object>
{
distance.Find("Btn500").GetComponent<Button>(),
distance.Find("Btn2000").GetComponent<Button>(),
distance.Find("Btn5000").GetComponent<Button>(),
distance.Find("Btn10000").GetComponent<Button>(),
distance.Find("Customize").GetComponent<PFUIInputField>(),
time.Find("Btn30").GetComponent<Button>(),
time.Find("CustomizeMin").GetComponent<PFUIInputField>(),
time.Find("CustomizeS").GetComponent<PFUIInputField>(),
};
InitDistance();
}
public override void Show()
{
base.Show();
InitAll();
}
private void Go()
{
if (rowerType.type == 0 || rowerType.value == 0)
{
Utils.showToast(null, "请选择课程");
return;
}
if (callBack != null)
{
callBack.Invoke(rowerType);
}
Close();
}
List<object> formList = null;
private void InitDistance()
{
Func<Transform, float, float, float> calc = (t, a, b) => t.parent.name == "Distance" ? a : a * 60 + b;
AddListener(formList, (t, v) =>
{
if (t.parent.name == "Distance")
{
rowerType.type = 1;
if (float.TryParse(v, out float f))
{
rowerType.value = f;
}
else
{
rowerType.value = 0;
}
}
else
{
rowerType.type = 2;
rowerType.value = 0;
var min = time.Find("CustomizeMin").GetComponent<InputField>().text;
var s = time.Find("CustomizeS").GetComponent<InputField>().text;
if (float.TryParse(min, out float a))
{
rowerType.value += 60 * a;
}
if (float.TryParse(s, out float b))
{
if (b < 0 || b > 59)
{
Utils.showToast(null, "Please enter an integer between 0-59.");
time.Find("CustomizeS").GetComponent<InputField>().text = "";
return;
}
rowerType.value += b;
}
}
}, calc);
}
private void AddListener(IEnumerable<object> list, UnityAction<Transform,string> inputCustomAction, Func<Transform, float,float,float> calcButton = null)
{
var btns = list.Where(x => x is Button).Select(x => x as Button);
foreach (var item in list)
{
if (item is Button)
{
var btn = item as Button;
btn.onClick.RemoveAllListeners();
btn.onClick.AddListener(() =>
{
rowerType.type = btn.transform.parent.name == "Distance" ? 1 : 2;
if (calcButton == null)
{
rowerType.value = float.Parse(btn.name.Replace("Btn", ""));
}
else
{
rowerType.value = calcButton.Invoke(btn.transform ,float.Parse(btn.name.Replace("Btn", "")), 0);
}
ClickDistanceBtn(btn, btns);
});
}
else if (item is PFUIInputField)
{
var input = item as PFUIInputField;
input.CustomSelect = () =>
{
ClickDistanceBtn(null, btns);
rowerType.type = input.transform.parent.name == "Distance" ? 1 : 2;
SetTextColor(input.gameObject, true);
SetBgColor(input,2);
};
input.CustomDeSelect = () =>
{
SetTextColor(input.gameObject, false);
SetBgColor(input, 3);
};
input.CustomEnter = () =>
{
SetBgColor(input, 1);
};
if (inputCustomAction != null)
{
input.GetComponent<InputField>().onEndEdit.RemoveAllListeners();
input.GetComponent<InputField>().onEndEdit.AddListener((v) => inputCustomAction(input.transform, v));
}
}
}
}
Dictionary<string, int> inputStatusDict = null;
private void SetBgColor(PFUIInputField input, int v)
{
if (inputStatusDict == null)
{
inputStatusDict = new Dictionary<string, int>
{
{"CustomizeMin",3 },{"CustomizeS",3 }
};
}
if (!inputStatusDict.ContainsKey(input.name)) return;
//只要有一个select,enter 常亮 两个都exit,deselect 关掉
inputStatusDict[input.name] = v;
var bg = transform.Find("Main/Time/Inputbg").gameObject;
if (inputStatusDict.Count(x=>x.Value == 1) > 0)
{
bg.GetComponent<Outline>().enabled = true;
bg.GetComponent<Outline>().effectColor = Utils.HexToColorHtml("#6E6E7D");
}
else if (inputStatusDict.Count(x => x.Value == 2) > 0)
{
bg.GetComponent<Outline>().enabled = true;
bg.GetComponent<Outline>().effectColor = Utils.HexToColorHtml("#f93086");
}
else if(inputStatusDict.Count(x => x.Value == 3) == 2)
{
bg.GetComponent<Outline>().enabled = false;
}
}
private void InitAll()
{
foreach (var item in formList)
{
if (item is Button)
{
SetButtonColor(item as Button, false);
}
else
{
var i = item as PFUIInputField;
i.Text = "";
}
}
}
private void ClickDistanceBtn(Button btn, IEnumerable<Button> list)
{
foreach (var item in list)
{
SetButtonColor(item, false);
}
if (btn)
{
SetButtonColor(btn, true);
}
}
private void SetButtonColor(Button btn, bool flag)
{
SetTextColor(btn.gameObject, flag);
btn.gameObject.GetComponent<Image>().color = flag ? Utils.HexToColorHtml("#f93086") : Utils.HexToColorHtml("#23232d");
}
private void SetTextColor(GameObject btn, bool flag)
{
if (btn.transform.Find("t1"))
{
btn.transform.Find("t1").GetComponent<Text>().color = flag ? Utils.HexToColorHtml("#ffffff") : Utils.HexToColorHtml("#9E9EAD");
}
if (btn.transform.Find("t2"))
{
btn.transform.Find("t2").GetComponent<Text>().color = flag ? Utils.HexToColorHtml("#ffffff") : Utils.HexToColorHtml("#9E9EAD");
}
}
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 11dfa3e099daeb942b6e8e105572548c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+109 -22
View File
@@ -1,4 +1,5 @@
using Assets.Scripts.Apis.Models;
using Assets.Scripts;
using Assets.Scripts.Apis.Models;
using System;
using System.Collections;
using System.Collections.Generic;
@@ -7,45 +8,131 @@ using UnityEngine.UI;
public class RowerWelldone : PFUIPanel
{
[SerializeField]
GameObject AllRecord, Record,Rank;
Dictionary<string, Texture> caches;
Transform rankContent, gradeContent;
public string id { get; private set; }
public override void Show()
{
base.Show();
Debug.Log("well done show");
}
// Start is called before the first frame update
protected override void Awake()
{
caches = new Dictionary<string, Texture>();
rankContent = transform.Find("Container/Left/Scroll View").GetComponent<ScrollRect>().content;
gradeContent = transform.Find("Container/Right/Scroll View").GetComponent<ScrollRect>().content;
}
void Start()
{
UIManager.AddEvent(transform.Find("BtnDefine").gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, b =>
UIManager.AddEvent(transform.Find("Container/BtnDefine").gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, b =>
{
startTime = false;
Close();
UIManager.ShowHomePanel();
UIManager.ShowUserInfoPanel();
//UIManager.ShowHomePanel();
//UIManager.ShowUserInfoPanel();
});
UIManager.AddEvent(transform.Find("Container/BtnView").gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, b =>
{
Close();
Application.OpenURL($"{App.websiteDict[App.Host]}rower/record/{id}?Token={App.CurrentUser.cookie}");
});
}
// Update is called once per frame
void Update()
{
if (startTime)
{
timer -= Time.deltaTime;
if (timer <= 0)
{
remainTime--;
if (remainTime == 0)
{
startTime = false;
Close();
return;
}
transform.Find("Container/BtnDefine/Text").GetComponent<Text>().text = $"{"DEFINE"}({remainTime.ToString("#0")})";
timer += 1f;
}
}
}
RowerRecordModel model;
public void Initial(RowerRecordModel model)
float timer = 1f, remainTime = 10f;
bool startTime = false;
public async void Initial(string id)
{
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}";
if (string.IsNullOrEmpty(id)) return;
this.id = id;
var res = await ConfigHelper.rowerApi.GetSegmentDataAndRanking(id);
if (res.result)
{
DisplayData(res.data, caches);
startTime = true;
remainTime = 10f;
timer = 1f;
transform.Find("Container/BtnDefine/Text").GetComponent<Text>().text = $"{"DEFINE"}({remainTime.ToString("#0")})";
}
}
private void DisplayData(RowerSegmentData data, Dictionary<string, Texture> caches)
{
rankContent.DestroyChildren();
gradeContent.DestroyChildren();
for (int i = 0; i < data.ranks.Count; i++)
{
var item = data.ranks[i];
var game = Instantiate<GameObject>(Rank);
game.transform.Find("Content/Rank").GetComponent<Text>().text = (i + 1).ToString("00");
game.transform.Find("Content/NickName").GetComponent<Text>().text = item.NickName;
Utils.DisplayImageTempDict(game.transform.Find("Content/Avatar").GetComponent<RawImage>(), item.WxHeadImg, caches);
game.transform.Find("Content/Time").GetComponent<Text>().text = data.info.Type == 1 ? TimeSpan.FromSeconds(item.Time).ToString() : item.TotalDistance.ToString("#0M");
game.transform.SetParent(rankContent);
game.transform.localScale = Vector3.one;
game.SetActive(true);
if (item.UserId == App.CurrentUser.Id)
{
game.transform.Find("Content/Rank").GetComponent<Text>().color = Utils.HexToColorHtml("#f93086");
game.transform.Find("Content/NickName").GetComponent<Text>().color = Utils.HexToColorHtml("#f93086");
game.transform.Find("Content/Time").GetComponent<Text>().color = Utils.HexToColorHtml("#f93086");
}
else
{
game.transform.Find("Content/Rank").GetComponent<Text>().color = Utils.HexToColorHtml("#ffffff");
game.transform.Find("Content/NickName").GetComponent<Text>().color = Utils.HexToColorHtml("#ffffff");
game.transform.Find("Content/Time").GetComponent<Text>().color = Utils.HexToColorHtml("#ffffff");
}
}
for (int i = 0; i < data.segmentList.Count; i++)
{
var item = data.segmentList[i];
var game = i == 0 ? Instantiate<GameObject>(AllRecord) : Instantiate<GameObject>(Record);
var content = i != 0 ? game.transform.Find("Content") : game.transform;
content.Find("Index").GetComponent<Text>().text = i == 0 ? "ALL" : i.ToString("00");
content.Find("Time").GetComponent<Text>().text = TimeSpan.FromSeconds(item.Ticks).ToString();
content.Find("Distance").GetComponent<Text>().text = item.Distance.ToString("#0");
content.Find("500").GetComponent<Text>().text = TimeSpan.FromSeconds(item.Speed).ToString();
content.Find("Power").GetComponent<Text>().text = item.Power.ToString("#0");
content.Find("HR").GetComponent<Text>().text = item.HeartRate.ToString("#0");
content.Find("Count").GetComponent<Text>().text = item.StrokeCount.ToString("#0");
content.Find("Carlories").GetComponent<Text>().text = item.Energy.ToString("#0");
//game.transform.Find("Content/Rank").GetComponent<Text>().text = (i + 1).ToString("00");
//game.transform.Find("Content/NickName").GetComponent<Text>().text = item.NickName;
//Utils.DisplayImageTempDict(game.transform.Find("Content/Avatar").GetComponent<RawImage>(), item.WxHeadImg, caches);
//game.transform.Find("Content/Time").GetComponent<Text>().text = data.info.Type == 1 ? TimeSpan.FromSeconds(item.Time).ToString() : item.TotalDistance.ToString("#0");
game.transform.SetParent(gradeContent);
game.transform.localScale = Vector3.one;
game.SetActive(true);
}
transform.Find("Container/Left/MyRank").GetComponent<Text>().text = data.info.MyRank;
transform.Find("Container/Right/Time").GetComponent<Text>().text = data.info.CreateTime;
}
}