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 public class RowerGraphChartFeed : MonoBehaviour
{ {
void Start () GraphChartBase graph { get; set; }
void Start ()
{ {
graph = GetComponent<GraphChartBase>();
//GraphChartBase graph = GetComponent<GraphChartBase>(); //GraphChartBase graph = GetComponent<GraphChartBase>();
//if (graph != null) //if (graph != null)
//{ //{
@ -16,7 +19,7 @@ public class RowerGraphChartFeed : MonoBehaviour
// graph.DataSource.StartBatch(); // graph.DataSource.StartBatch();
// graph.DataSource.ClearCategory("Player 1"); // graph.DataSource.ClearCategory("Player 1");
// graph.DataSource.ClearAndMakeBezierCurve("Player 2"); // graph.DataSource.ClearAndMakeBezierCurve("Player 2");
// for (int i = 0; i <10000; i++) // for (int i = 0; i <10000; i++)
// { // {
// graph.DataSource.AddPointToCategory("Player 1",i*5,Random.value*10f + 20f); // 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.MakeCurveCategorySmooth("Player 2");
// graph.DataSource.EndBatch(); // graph.DataSource.EndBatch();
//} //}
// StartCoroutine(ClearAll()); // StartCoroutine(ClearAll());
} }
public void SetData(List<DoubleVector2> list,List<DoubleVector2> list2 = null) public void SetData(List<DoubleVector2> list,List<DoubleVector2> list2 = null)
{ {
GraphChartBase graph = GetComponent<GraphChartBase>();
if (graph != null) if (graph != null)
{ {
graph.Scrollable = false; graph.Scrollable = false;
//graph.HorizontalValueToStringMap[0.0] = "Zero"; // example of how to set custom axis strings //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 1");
graph.DataSource.ClearCategory("Player 2"); graph.DataSource.ClearCategory("Player 2");
for (int i = 0; i < list.Count; i++) for (int i = 0; i < list.Count; i++)
{ {
var item = list[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) //if (i == 0)
// graph.DataSource.SetCurveInitialPoint("Player 1", item.x, item.y); // graph.DataSource.SetCurveInitialPoint("Player 1", item.x, item.y);
//else //else
@ -56,11 +58,11 @@ public class RowerGraphChartFeed : MonoBehaviour
for (int i = 0; i < list2.Count; i++) for (int i = 0; i < list2.Count; i++)
{ {
var item = list2[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.MakeCurveCategorySmooth("Player 1");
graph.DataSource.EndBatch(); //graph.DataSource.EndBatch();
} }
} }
IEnumerator ClearAll() IEnumerator ClearAll()

View File

@ -43,9 +43,14 @@ public class RowerMultiModeScript : MonoBehaviour
} }
List<Trace> traceList; List<Trace> traceList;
List<float> initialPosYList; 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() void Awake()
{ {
scroll = transform.Find("Rower/Modes/Scroll"); scroll = transform.Find("Rower/Modes/Scroll");
startPosition = scroll.localPosition; startPosition = scroll.localPosition;
@ -100,8 +105,13 @@ public class RowerMultiModeScript : MonoBehaviour
// m2.Find("Track/T5").localPosition.y, // m2.Find("Track/T5").localPosition.y,
//}; //};
scrollRank = transform.Find("Rower/Modes/Scroll/M1/Rank/Scroll View").GetComponent<ScrollRect>(); scrollRank = transform.Find("Rower/Modes/Scroll/M1/Rank/Scroll View").GetComponent<ScrollRect>();
var countryJson = Resources.Load<TextAsset>("UI/flags-mini").text; //var countryJson = Resources.Load<TextAsset>("UI/flags-mini").text;
countryList = JsonConvert.DeserializeObject<List<CountryModel>>(countryJson); //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) 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) 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("Left").GetComponent<Image>().sprite = data.isMine ? bg_myself : 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("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/Boat/Head").gameObject.SetActive(data.currentDistance > 0);
t.Find("Main/Rowed").GetComponent<Image>().color = data.isMine ? Utils.HexToColorHtml("#f9308699") : Utils.HexToColorHtml("#27dfe399"); 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"); t.GetComponent<Image>().color = data.isMine ? Utils.HexToColorHtml("#f930861a") : Utils.HexToColorHtml("#27dfe31a");