2021-07-06 18:24:15 +08:00
|
|
|
|
using Assets.Scenes.Ride.Scripts.Model;
|
|
|
|
|
|
using Assets.Scenes.Ride.Scripts.Model.CyclingModels;
|
2021-07-29 20:01:38 +08:00
|
|
|
|
using Assets.Scripts;
|
2021-07-06 18:24:15 +08:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Assets.Scenes.Ride.Scripts
|
|
|
|
|
|
{
|
|
|
|
|
|
public class TopRankingFactory : BaseListFactory
|
|
|
|
|
|
{
|
2021-07-23 09:04:56 +08:00
|
|
|
|
private List<CompetitionTopModel> rankingList {get;set;}
|
2021-07-06 18:24:15 +08:00
|
|
|
|
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;
|
2021-09-03 13:06:26 +08:00
|
|
|
|
#if UNITY_IOS || UNITY_ANDROID
|
|
|
|
|
|
nearByItem = Resources.Load<GameObject>("UI/Prefab/Match/Mobile/TopRankingItem");
|
|
|
|
|
|
nearByMajorItem = Resources.Load<GameObject>("UI/Prefab/Match/Mobile/CompetitionRankingMajorItem");
|
|
|
|
|
|
#else
|
2021-07-06 18:24:15 +08:00
|
|
|
|
nearByItem = Resources.Load<GameObject>("UI/Prefab/Match/TopRankingItem");
|
|
|
|
|
|
nearByMajorItem = Resources.Load<GameObject>("UI/Prefab/Match/CompetitionRankingMajorItem");
|
2021-09-03 13:06:26 +08:00
|
|
|
|
#endif
|
2021-07-06 18:24:15 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected override void CreateList()
|
|
|
|
|
|
{
|
|
|
|
|
|
CompetitionModel s = cyclingController.cyclingController as CompetitionModel;
|
|
|
|
|
|
var ss = s?.competitionRankingModel;
|
2021-07-23 09:04:56 +08:00
|
|
|
|
rankingList = ss?.TopList;
|
2021-07-06 18:24:15 +08:00
|
|
|
|
if (rankingList == null) return;
|
2021-07-29 16:13:23 +08:00
|
|
|
|
|
2021-07-29 20:01:38 +08:00
|
|
|
|
////删除
|
|
|
|
|
|
//var currentTopRankingList = FindObjectsOfType<TopRankingItem>();
|
|
|
|
|
|
//foreach (var o in currentTopRankingList)
|
|
|
|
|
|
//{
|
|
|
|
|
|
// var e = rankingList.Where(c => c.UserId == o.UserId).FirstOrDefault();
|
|
|
|
|
|
// if (e == null)
|
|
|
|
|
|
// {
|
|
|
|
|
|
// o.transform.gameObject.SetActive(false);//TODO:这里暂时不删除,删除对应的图片和脚本依赖这个对象;脚本提供一个dispose
|
|
|
|
|
|
// bufferSize--;
|
|
|
|
|
|
// }
|
|
|
|
|
|
//}
|
|
|
|
|
|
Utils.DestroyChildren(parent);
|
2021-07-23 09:04:56 +08:00
|
|
|
|
for (int i = 0; i < rankingList.Count(); i++)
|
2021-07-06 18:24:15 +08:00
|
|
|
|
{
|
2021-07-23 09:04:56 +08:00
|
|
|
|
Create(rankingList[i]);
|
2021-07-06 18:24:15 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2021-07-23 09:04:56 +08:00
|
|
|
|
private void Create(CompetitionTopModel item)
|
2021-07-06 18:24:15 +08:00
|
|
|
|
{
|
2021-07-29 20:01:38 +08:00
|
|
|
|
//var rankingList = FindObjectsOfType<TopRankingItem>();
|
|
|
|
|
|
//var competitionRankingItem = rankingList.Where(c => c.rank == item.Index).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();
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
|
GameObject newObj = (GameObject)Instantiate(nearByItem, parent);
|
|
|
|
|
|
var competitionRankingItem = newObj.GetComponent<TopRankingItem>();
|
|
|
|
|
|
|
2021-07-27 19:34:33 +08:00
|
|
|
|
competitionRankingItem.setHead(item.Head);
|
2021-07-23 09:04:56 +08:00
|
|
|
|
competitionRankingItem.setTimer(item.TripTime);
|
2021-07-06 18:24:15 +08:00
|
|
|
|
competitionRankingItem.SetRank(item.Index);
|
|
|
|
|
|
competitionRankingItem.setName(item.Name);
|
2021-07-23 09:04:56 +08:00
|
|
|
|
competitionRankingItem.setUserId(item.UserId);
|
2021-07-27 19:34:33 +08:00
|
|
|
|
var countryTexture = cyclingController.GetCountryImageByName(item.Country);
|
|
|
|
|
|
competitionRankingItem.setCountry(countryTexture);
|
2021-07-06 18:24:15 +08:00
|
|
|
|
competitionRankingItem.transform.SetSiblingIndex(item.Index);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|