public void SaveIfRankIn(int scoreNum) { var scoreEntities = ScoreRepository.GetScoreEntities(Ranking.Size); var currentScore = new Score(scoreNum); var ranking = ScoreTranslator.TranslateAsRanking(scoreEntities); var rank = ranking.GetRank(currentScore); var rankedIn = rank != -1; if (!rankedIn) { return; } // TODO: 連結リストのほうが挿入が楽かな? var currentScoreEntity = ScoreTranslator.TranslateAsScoreEntity(currentScore); var updatedScoreEntities = scoreEntities.ToList(); updatedScoreEntities.Insert(rank, currentScoreEntity); ScoreRepository.SaveScore(updatedScoreEntities.Take(5).ToArray()); Debug.Log("-----result-----"); // TODO: remove debug log var result = ScoreRepository.GetScoreEntities(Ranking.Size); foreach (var r in result) { Debug.Log(r.ScoreNum); } }
public void InitList(Transform parentTransform, RectTransform listItemPrefab) { var result = ScoreRepository.GetScoreEntities(Ranking.Size); foreach (var r in result) { var listItem = Object.Instantiate(listItemPrefab) as RectTransform; listItem.SetParent(parentTransform, false); var listText = listItem.GetComponentsInChildren <Text>().Where(x => x.name == "ScoreNum").ToList()[0]; listText.text = r.ScoreNum.ToString(); } }