chart内存性能优化

This commit is contained in:
lishuo 2022-05-31 14:43:05 +08:00
parent be687d6b77
commit 95df03e540
2 changed files with 25 additions and 13 deletions

View File

@ -6,8 +6,11 @@ using System.Collections.Generic;
public class RowerGraphChartFeed : MonoBehaviour
{
void Start ()
GraphChartBase graph { get; set; }
void Start ()
{
graph = GetComponent<GraphChartBase>();
//GraphChartBase graph = GetComponent<GraphChartBase>();
//if (graph != null)
//{
@ -16,7 +19,7 @@ public class RowerGraphChartFeed : MonoBehaviour
// 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);
@ -29,23 +32,22 @@ public class RowerGraphChartFeed : MonoBehaviour
// graph.DataSource.MakeCurveCategorySmooth("Player 2");
// graph.DataSource.EndBatch();
//}
// StartCoroutine(ClearAll());
// StartCoroutine(ClearAll());
}
public void SetData(List<DoubleVector2> list,List<DoubleVector2> list2 = null)
{
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.StartBatch();
graph.DataSource.ClearCategory("Player 1");
graph.DataSource.ClearCategory("Player 2");
for (int i = 0; i < list.Count; i++)
{
var item = list[i];
graph.DataSource.AddPointToCategory("Player 2", item.x, item.y);
graph.DataSource.AddPointToCategoryRealtime("Player 2", item.x, item.y);
//if (i == 0)
// graph.DataSource.SetCurveInitialPoint("Player 1", item.x, item.y);
//else
@ -56,11 +58,11 @@ public class RowerGraphChartFeed : MonoBehaviour
for (int i = 0; i < list2.Count; i++)
{
var item = list2[i];
graph.DataSource.AddPointToCategory("Player 1", item.x, item.y);
graph.DataSource.AddPointToCategoryRealtime("Player 1", item.x, item.y);
}
}
//graph.DataSource.MakeCurveCategorySmooth("Player 1");
graph.DataSource.EndBatch();
//graph.DataSource.EndBatch();
}
}
IEnumerator ClearAll()

View File

@ -43,9 +43,14 @@ public class RowerMultiModeScript : MonoBehaviour
}
List<Trace> traceList;
List<float> initialPosYList;
Sprite bg_myself { get; set; }
Sprite bg_other { get; set; }
Sprite img_overline_myself { get; set; }
Sprite img_overline_others { get; set; }
void Awake()
{
scroll = transform.Find("Rower/Modes/Scroll");
scroll = transform.Find("Rower/Modes/Scroll");
startPosition = scroll.localPosition;
@ -100,8 +105,13 @@ public class RowerMultiModeScript : MonoBehaviour
// m2.Find("Track/T5").localPosition.y,
//};
scrollRank = transform.Find("Rower/Modes/Scroll/M1/Rank/Scroll View").GetComponent<ScrollRect>();
var countryJson = Resources.Load<TextAsset>("UI/flags-mini").text;
countryList = JsonConvert.DeserializeObject<List<CountryModel>>(countryJson);
//var countryJson = Resources.Load<TextAsset>("UI/flags-mini").text;
//countryList = JsonConvert.DeserializeObject<List<CountryModel>>(countryJson);
//UIManager.Instance.loginRegOptions.GetCountryIndexByCode();
bg_myself = Resources.Load<Sprite>("Images/RowerNew/动画用/bg_myself");
bg_other = Resources.Load<Sprite>("Images/RowerNew/动画用/bg_other");
img_overline_myself = Resources.Load<Sprite>("Images/RowerNew/动画用/img_overline_myself");
img_overline_others = Resources.Load<Sprite>("Images/RowerNew/动画用/img_overline_others");
}
public void HandleTimeTick(RowerChartModel data)
@ -246,8 +256,8 @@ public class RowerMultiModeScript : MonoBehaviour
private void DisplayTrace(Transform t,TraceData data,TraceData mineData,bool isAni = false)
{
//增加新设计稿逻辑
t.Find("Left").GetComponent<Image>().sprite = data.isMine ? Resources.Load<Sprite>("Images/RowerNew/动画用/bg_myself") : Resources.Load<Sprite>("Images/RowerNew/动画用/bg_other");
t.Find("Main/Boat/Head").GetComponent<Image>().sprite = data.isMine ? Resources.Load<Sprite>("Images/RowerNew/动画用/img_overline_myself") : Resources.Load<Sprite>("Images/RowerNew/动画用/img_overline_others");
t.Find("Left").GetComponent<Image>().sprite = data.isMine ? bg_myself : bg_other;
t.Find("Main/Boat/Head").GetComponent<Image>().sprite = data.isMine ? img_overline_myself : img_overline_others;
t.Find("Main/Boat/Head").gameObject.SetActive(data.currentDistance > 0);
t.Find("Main/Rowed").GetComponent<Image>().color = data.isMine ? Utils.HexToColorHtml("#f9308699") : Utils.HexToColorHtml("#27dfe399");
t.GetComponent<Image>().color = data.isMine ? Utils.HexToColorHtml("#f930861a") : Utils.HexToColorHtml("#27dfe31a");