77 lines
3.3 KiB
C#
77 lines
3.3 KiB
C#
|
|
using Assets.Scenes.Ride.Scripts.Model;
|
|||
|
|
using Assets.Scenes.Ride.Scripts.Model.CyclingModels;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using System.Linq;
|
|||
|
|
using UnityEngine;
|
|||
|
|
|
|||
|
|
namespace Assets.Scenes.Ride.Scripts
|
|||
|
|
{
|
|||
|
|
public class TopRankingFactory : BaseListFactory
|
|||
|
|
{
|
|||
|
|
private List<CompetitionRankingSortModel> rankingList {get;set;}
|
|||
|
|
private AbstractPlayer currentPlayer { get; set; }
|
|||
|
|
private int topSize = 6;//取前6名
|
|||
|
|
protected override void Awake()
|
|||
|
|
{
|
|||
|
|
//base.Awake();
|
|||
|
|
scroll = transform.Find("List").gameObject;
|
|||
|
|
if (scroll != null)
|
|||
|
|
{
|
|||
|
|
UIManager.AddEvent(scroll, UnityEngine.EventSystems.EventTriggerType.EndDrag, OnEndDrag);
|
|||
|
|
}
|
|||
|
|
parent = scroll.transform.Find("Viewport/Content");
|
|||
|
|
cyclingController = FindObjectOfType<CyclingController>();
|
|||
|
|
playerController = FindObjectOfType<PlayerController>();
|
|||
|
|
currentPlayer = cyclingController.currentPlayer;
|
|||
|
|
nearByItem = Resources.Load<GameObject>("UI/Prefab/Match/TopRankingItem");
|
|||
|
|
nearByMajorItem = Resources.Load<GameObject>("UI/Prefab/Match/CompetitionRankingMajorItem");
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
protected override void CreateList()
|
|||
|
|
{
|
|||
|
|
CompetitionModel s = cyclingController.cyclingController as CompetitionModel;
|
|||
|
|
var ss = s?.competitionRankingModel;
|
|||
|
|
rankingList = ss?.Sorts;
|
|||
|
|
if (rankingList == null) return;
|
|||
|
|
var pagedList = rankingList.Take(topSize).ToList();
|
|||
|
|
for (int i = 0; i < pagedList.Count(); i++)
|
|||
|
|
{
|
|||
|
|
Create(pagedList[i]);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
private void Create(CompetitionRankingSortModel item)
|
|||
|
|
{
|
|||
|
|
var rankingList = FindObjectsOfType<TopRankingItem>();
|
|||
|
|
var competitionRankingItem = rankingList.Where(c => c.UserId == item.UserId).FirstOrDefault();
|
|||
|
|
//如果当前有这个用户则更新没有则创建并setslibingindex
|
|||
|
|
if (competitionRankingItem == null)
|
|||
|
|
{
|
|||
|
|
//创建
|
|||
|
|
if (bufferSize < pageSize)
|
|||
|
|
{
|
|||
|
|
//情况一:还有足够的buffer,直接创建
|
|||
|
|
GameObject prefabItem = nearByItem;
|
|||
|
|
GameObject newObj = (GameObject)Instantiate(prefabItem, parent);
|
|||
|
|
competitionRankingItem = newObj.GetComponent<TopRankingItem>();
|
|||
|
|
bufferSize++;
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
//情况二:没有足够的buffer,找到要被淘汰的buffer()最后一名
|
|||
|
|
competitionRankingItem = rankingList.OrderByDescending(c => c.rank).FirstOrDefault();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
competitionRankingItem.setUserId(item.UserId);
|
|||
|
|
competitionRankingItem.SetRank(item.Index);
|
|||
|
|
competitionRankingItem.setName(item.Name);
|
|||
|
|
competitionRankingItem.setRatio(item.KGWeight + "W/KG");
|
|||
|
|
competitionRankingItem.setSpeed(item.Speed.ToString() + "KM/H");
|
|||
|
|
competitionRankingItem.setHead(item.Headimage);
|
|||
|
|
competitionRankingItem.setCountry(item.CountryImg);
|
|||
|
|
competitionRankingItem.setDistance(item.Near.ToString() + "KM");
|
|||
|
|
competitionRankingItem.transform.SetSiblingIndex(item.Index);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|