73 lines
2.8 KiB
C#
73 lines
2.8 KiB
C#
using Assets.Scenes.Ride.Scripts;
|
|
using System;
|
|
using System.Linq;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace Assets.Scripts.Scenes.Scripts
|
|
{
|
|
class GameRoomPlayerList : MonoBehaviour
|
|
{
|
|
private CyclingController manager { get; set; }
|
|
protected GameObject nearByItem;
|
|
protected GameObject nearByMajorItem;
|
|
public Transform parent;
|
|
|
|
private Text num;
|
|
|
|
private void Start()
|
|
{
|
|
manager = FindObjectOfType<CyclingController>();
|
|
nearByMajorItem = Resources.Load<GameObject>("UI/Prefab/Match/CompetitionRankingMajorItem");
|
|
nearByItem = Resources.Load<GameObject>("UI/Prefab/Match/CompetitionRankingItem");
|
|
num = transform.Find("Head/OnlineUserNum").GetComponent<Text>();
|
|
}
|
|
|
|
private void InitData()
|
|
{
|
|
Utils.DestroyChildren(parent);
|
|
manager = FindObjectOfType<CyclingController>();
|
|
var list = MapUDPService.GetOnlineUsers(App.RouteIdParam, manager.roomId).OrderByDescending(c=>c.EndDistance);
|
|
int index = 1;
|
|
num.text = list.Count().ToString();
|
|
var current = list.Where(c => c.Id == manager.currentPlayer.UserId).FirstOrDefault();
|
|
foreach (var item in list)
|
|
{
|
|
GameObject prefabItem = item.IsSelf ? nearByMajorItem : nearByItem;
|
|
GameObject newObj = (GameObject)Instantiate(prefabItem, parent);
|
|
var competitionRankingItem = newObj.GetComponent<CompetitionRankingItem>();
|
|
competitionRankingItem.setUserId(item.Id);
|
|
#if UNITY_IOS || UNITY_ANDROID
|
|
competitionRankingItem.SetRank(index);
|
|
#else
|
|
competitionRankingItem.SetRank(index);
|
|
#endif
|
|
competitionRankingItem.setName(item.Name);
|
|
competitionRankingItem.setRatio(item.WeightKg.ToString("f2") + "W/KG");
|
|
competitionRankingItem.setSpeed(item.Speed.ToString() + "KM/H");
|
|
competitionRankingItem.setHead(item.HeadImage);
|
|
var countryTexture = manager.GetCountryImageByName(item.Country);
|
|
competitionRankingItem.setCountry(countryTexture);
|
|
var near = Math.Round((item.EndDistance - current.EndDistance)*1000,0);
|
|
competitionRankingItem.setDistance(manager.currentPlayer.UserId == item.Id ? "0M" : near.ToString() + "M");
|
|
#if UNITY_IOS || UNITY_ANDROID
|
|
competitionRankingItem.transform.SetSiblingIndex(index);
|
|
#else
|
|
competitionRankingItem.transform.SetSiblingIndex(index);
|
|
#endif
|
|
index++;
|
|
}
|
|
}
|
|
float timer = 0f;
|
|
private void Update()
|
|
{
|
|
timer -= Time.deltaTime;
|
|
while (timer < 0)
|
|
{
|
|
InitData();
|
|
timer += 1f;
|
|
}
|
|
}
|
|
}
|
|
}
|