适配v1表头,性能优化一波

This commit is contained in:
Caiyanpeng committed 2022-05-11 17:11:48 +08:00
1 parent edc629ed75
commit be687d6b77
10 files changed
+282 -162

No files matched your search

+70 -115
View File
@@ -35,29 +35,30 @@ public class RowerHomeScript : PFUIPanel
/// <summary>
/// 划船机数据
/// </summary>
private FtmsRowerData RowerData
private IRowerCommonData RowerData
{
get
{
var device = App.MainDeviceAdapter.GetDevices().FirstOrDefault(d => (d.State == DeviceState.Connected) && d.Sensor == SensorType.Rower);
if (device != null)
{
return ((IRowerDevice)device).rowerData;
}
return null;
return Rower != null ? (C2RowerData.IsEnabled == true ? (IRowerCommonData)Rower.c2RowerData : (IRowerCommonData)Rower.rowerData) : null;
//var device = App.MainDeviceAdapter.GetDevices().FirstOrDefault(d => (d.State == DeviceState.Connected) && d.Sensor == SensorType.Rower);
//if (device != null)
//{
// return ((IRowerDevice)device).rowerData;
//}
//return null;
}
}
protected override void OnDestroy()
{
Debug.Log("銷毀");
if (RowerCommonDataInstance != null)
if (RowerData != null)
{
RowerCommonDataInstance.PullChanged -= PaintPullCurve;
RowerData.PullChanged -= PaintPullCurve;
RowerData.StartEvent -= StartFunc;
RowerData.RowerResChanged -= ResChanged;
}
C2RowerData.EnableChanged -= ModeChanged;
FtmsRowerData.RowerResChanged -= ResChanged;
}
private IRowerDevice Rower
{
@@ -89,7 +90,7 @@ public class RowerHomeScript : PFUIPanel
GameObject btnStart;
Transform left, bottom, mid,rmydata;
float timer = 1.0f;
List<DoubleVector2> pullList = new List<DoubleVector2>(), historyPullList = new List<DoubleVector2>();
List<DoubleVector2> pullList, historyPullList;
public Dictionary<object, Sprite> spriteDict,spriteDict2;
List<string> records;
List<TempRowerCalc> values;
@@ -157,7 +158,10 @@ public class RowerHomeScript : PFUIPanel
};
GetComponent<RectTransform>().localScale = Vector3.one;
GetComponent<RectTransform>().localPosition = Vector3.zero;
records = new List<string>();
values = new List<TempRowerCalc>();
pullList = new List<DoubleVector2>();
historyPullList = new List<DoubleVector2>();
//mainNav.ShowExit();
left = transform.Find("Rower/Modes/Scroll/M1/Left");
@@ -221,10 +225,6 @@ public class RowerHomeScript : PFUIPanel
HandleSelectType();
},rowerType);
}, 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"), () =>
{
@@ -243,10 +243,12 @@ public class RowerHomeScript : PFUIPanel
{
Discard();
});
if (RowerCommonDataInstance != null)
if (RowerData != null)
{
RowerCommonDataInstance.PullChanged -= PaintPullCurve;
RowerCommonDataInstance.PullChanged += PaintPullCurve;
RowerData.PullChanged -= PaintPullCurve;
RowerData.PullChanged += PaintPullCurve;
RowerData.StartEvent -= StartFunc;
RowerData.StartEvent += StartFunc;
}
Init();
}
@@ -385,74 +387,11 @@ public class RowerHomeScript : PFUIPanel
f.Invoke();
}
}
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
if (RowerData == null)
{
Utils.showToast(null, "Please connect the device!", isLowest: true);
return;
}
#endif
UIManager.ShowCountDownAnimation(() =>
{
#if !UNITY_EDITOR
if (RowerCommonDataInstance != null)
{
RowerCommonDataInstance.PullChanged -= PaintPullCurve;
RowerCommonDataInstance.PullChanged += PaintPullCurve;
}
#endif
StartFunc();
},
()=>
{
Debug.Log(222);
if (Rower != null && !isPause)
{
Rower.Reset();
}
});
}
else
{
openTimer = false;
isPause = true;
btnStart.GetComponent<Image>().sprite = spriteDict["Start"];
btnStart.tag = "Start";
UIManager.ShowConfirm3("Quit", "Do you want to keep the record?",
() =>
{
UIManager.CloseConfirm3();
Save();
Init();
},
()=>
{
Init();
},
()=>
{
});
}
Debug.Log(RowerData);
//StartCoroutine();
}
int truelyTime = 0;
private void StartFunc()
private void StartFunc(object sender, EventArgs e)
{
if (openTimer) return;
if (transform.parent.parent.Find("ModalPanel/RowerWelldone(Clone)") && transform.parent.parent.Find("ModalPanel/RowerWelldone(Clone)").gameObject.activeInHierarchy)
{
return;
@@ -602,8 +541,8 @@ public class RowerHomeScript : PFUIPanel
left.Find("Times/Value").GetComponent<Text>().text = "---";
left.Find("Calories/Value").GetComponent<Text>().text = "---";
rmydata.Find("Calories/Value").GetComponent<Text>().text = "---";
pullList = new List<DoubleVector2>();
historyPullList = new List<DoubleVector2>();
pullList.Clear();
historyPullList.Clear();
SetChartData(pullList, historyPullList);
//mid.Find("GraphChart").GetComponent<RowerGraphChartFeed>().SetData(pullList);
openTimer = false;
@@ -638,8 +577,9 @@ public class RowerHomeScript : PFUIPanel
rmydata.Find("AvgForce/Value").GetComponent<Text>().text = "---";
mid.Find("PeakForce/Value").GetComponent<Text>().text = "---";
rmydata.Find("PeakForce/Value").GetComponent<Text>().text = "---";
records = new List<string>();
values = new List<TempRowerCalc>();
records.Clear();// = new List<string>();
values.Clear(); //= new List<TempRowerCalc>();
Kj = 0;
x = 0;
seconds = 0;
@@ -651,8 +591,13 @@ public class RowerHomeScript : PFUIPanel
#endif
C2RowerData.EnableChanged -= ModeChanged;
C2RowerData.EnableChanged += ModeChanged;
FtmsRowerData.RowerResChanged -= ResChanged;
FtmsRowerData.RowerResChanged += ResChanged;
if (RowerData != null)
{
RowerData.RowerResChanged -= ResChanged;
RowerData.RowerResChanged += ResChanged;
}
//FtmsRowerData.RowerResChanged -= ResChanged;
//FtmsRowerData.RowerResChanged += ResChanged;
//标志线复位
Transform leftLine = transform.Find("Rower/Modes/Scroll/M2/Track/TraceContainer/LineMeterLeft"),
rightLine = transform.Find("Rower/Modes/Scroll/M2/Track/TraceContainer/LineMeterRight"),
@@ -660,14 +605,22 @@ public class RowerHomeScript : PFUIPanel
leftLine.localPosition = new Vector3(-207.5f+43, leftLine.localPosition.y, leftLine.localPosition.z);
rightLine.localPosition = new Vector3(164.5f+43, rightLine.localPosition.y, rightLine.localPosition.z);
finishLine.localPosition = new Vector3(-237.5f+43, finishLine.localPosition.y, finishLine.localPosition.z);
Resources.UnloadUnusedAssets();
GC.Collect();
}
private void ModeChanged(object sender, EventArgs e)
{
if (RowerCommonDataInstance != null)
if (RowerData != null)
{
RowerCommonDataInstance.PullChanged -= PaintPullCurve;
RowerCommonDataInstance.PullChanged += PaintPullCurve;
RowerData.PullChanged -= PaintPullCurve;
RowerData.PullChanged += PaintPullCurve;
RowerData.StartEvent -= StartFunc;
RowerData.StartEvent += StartFunc;
RowerData.RowerResChanged -= ResChanged;
RowerData.RowerResChanged += ResChanged;
}
slider.GetComponent<Slider>().interactable = !(bool)sender;
transform.Find("ResBar/BtnSub").GetComponent<Button>().interactable = !(bool)sender;
@@ -799,10 +752,10 @@ public class RowerHomeScript : PFUIPanel
left.Find("Times/Value").GetComponent<Text>().text = strokeCount.ToString();
left.Find("Calories/Value").GetComponent<Text>().text = energy.ToString();
rmydata.Find("Calories/Value").GetComponent<Text>().text = energy.ToString();
mid.Find("AvgForce/Value").GetComponent<Text>().text = RowerCommonDataInstance.AverageDriveForce.ToString("#0");
rmydata.Find("AvgForce/Value").GetComponent<Text>().text = RowerCommonDataInstance.AverageDriveForce.ToString("#0");
mid.Find("PeakForce/Value").GetComponent<Text>().text = RowerCommonDataInstance.PeakDriveForce.ToString("#0");
rmydata.Find("PeakForce/Value").GetComponent<Text>().text = RowerCommonDataInstance.PeakDriveForce.ToString("#0");
mid.Find("AvgForce/Value").GetComponent<Text>().text = RowerData.AverageDriveForce.ToString("#0");
rmydata.Find("AvgForce/Value").GetComponent<Text>().text = RowerData.AverageDriveForce.ToString("#0");
mid.Find("PeakForce/Value").GetComponent<Text>().text = RowerData.PeakDriveForce.ToString("#0");
rmydata.Find("PeakForce/Value").GetComponent<Text>().text = RowerData.PeakDriveForce.ToString("#0");
if (pace != 0)
{
if (rowerType.type == 1)
@@ -905,21 +858,19 @@ public class RowerHomeScript : PFUIPanel
void PaintPullCurve(ushort y)
{
Debug.Log("收到拉力" + y + ","+ DateTime.Now.Ticks);
#if !UNITY_EDITOR
if (!openTimer)
{
if (y > 0 && !isPause)
{
//RowerCommonDataInstance.PullChanged -= PaintPullCurve;
//RowerCommonDataInstance.PullChanged += PaintPullCurve;
StartFunc();
}
else
{
return;
}
}
#endif
//#if !UNITY_EDITOR
// if (!openTimer)
// {
// if (y > 0 && !isPause)
// {
// StartFunc();
// }
// else
// {
// return;
// }
// }
//#endif
//if (y > 1200) y = 1200;
//拉力条
var rate = ((float)y) * 2 / 120;
@@ -966,7 +917,7 @@ public class RowerHomeScript : PFUIPanel
{
Debug.Log("开始动画");
isPlay = false;
left.Find("Rower").GetComponent<RowerAnimation>().StartAnimation();
//left.Find("Rower").GetComponent<RowerAnimation>().StartAnimation();
}
SetChartData(pullList, historyPullList);
}
@@ -1028,7 +979,6 @@ public class RowerHomeScript : PFUIPanel
// shortTimer += 0.5f;
//}
}
void ShortUpdateData()
{
if (RowerData == null) return;
@@ -1058,6 +1008,7 @@ public class RowerHomeScript : PFUIPanel
rmydata.Find("W/Value").GetComponent<Text>().text = power.ToString();
bottom.Find("500/Value").GetComponent<Text>().text = TimeSpan.FromSeconds(pace).ToPFString();
bottom.Find("MS/Value").GetComponent<Text>().text = rate.ToString();
}
void HandleStatic()
{
@@ -1076,6 +1027,10 @@ public class RowerHomeScript : PFUIPanel
rowerType = C2RowerData.rowerType;
HandleSelectType();
}
//if (C2RowerData.IsEnabled)
//{
// Rower.C2GetStatus(new byte[] { 0xc1 });
//}
}
}
}