UNITY - How to sort items in list with animation step by step (to up/down)
Hello, I created a leaderboard where i can enter new teams and scores it can sort the list it is fine. When i deactivate the sorting part then it adds as normal of course but I want to do is this way.
--> My system is working like that for now (video - https://streamable.com/0n1ozc)
lets say at first when the panel opened to player it will show 11 other teams(which are already sorted by their scores.)
and when i passed the level it will first add me on the last row of leaderboar then lets say i can be the third one this level so from the last row it will move to up with an animation. JUST LIKE THIS = https://youtu.be/fezO1wmb9v8?t=165 (head ball 2 game leaderboard) my system wont be online i mean other enemies scores will be based on a calculation.
--> ScoreUI Class < --- private void SortList() { var scores = scoreManager.GetHighScores().ToArray(); //when i click the button to add new team info it adds under the previous ones so i remove the previous ones first here if (transform.childCount > 0) { for (int j = 0; j < transform.childCount; j++) Destroy(transform.GetChild(j).gameObject); } for (int i = 0; i < scores.Length; i++) { var row = Instantiate(rowUi, transform).GetComponent (); if (i == scores.Length - 1) row.transform.localScale = Vector3.zero; row.rank.text = (i + 1).ToString(); row.name.text = scores[i].name; row.score.text = scores[i].score.ToString(); if (i == scores.Length - 1) { RectTransform rowRectTransform = row.GetComponent (); rowRectTransform.DOScale(Vector3.one, .4f).SetEase(Ease.InOutBounce); } } }
public void AddTeamInList() { int.TryParse(inputTeamScore.text, out score); scoreManager.AddScore(new Score(inputTeamName.text, score)); var scores = scoreManager.GetHighScores().ToArray(); SortList(); print(scores.Length); } -->> ScoreManager Class << -- public IEnumerable GetHighScores() { return sd.scores.OrderByDescending(x => x.score); } public void AddScore(Score score) { sd.scores.Add(score); } -->> RowUI Class << -- public class RowUI : MonoBehaviour { public Text rank; public Text name; public Text score; } -->> Score Class << -- public string name; public int score;
public Score(string name, int score) { this.name = name; this.score = score; } -->> ScoreData Class << -- public List scores;
public ScoreData() { scores = new List(); }