98 lines
4.2 KiB
C#
98 lines
4.2 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();
|
|
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 - manager.currentPlayer.TotalDistance) * 1000);
|
|
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();
|
|
//if (manager.currentPlayer == null)
|
|
|
|
//var totalDitance = manager.GetMapData().TotalDistance;
|
|
//var currentDistance = manager.currentPlayer.TotalDistance;
|
|
////var currenList = GetComponentsInChildren<ListItem>(true);
|
|
//var list = MapUDPService.GetOnlineUsers(App.RouteIdParam, manager.cyclingController.recorderData.RoomId);
|
|
//var currentPlayerInfo = list.Where(c => c.Id.ToString() == manager.currentPlayer.UserId.ToString()).FirstOrDefault();
|
|
//list = list.Where(c => c.Id != App.CurrentUser.Id).ToList();
|
|
//var currentPlayer = FindObjectOfType<AbstractPlayer>();
|
|
|
|
//foreach (ListItem o in currenList)
|
|
//{
|
|
// if (currentPlayer.UserId.ToString() == o.Id)
|
|
// continue;
|
|
// var needUpdate = list.Where(c => c.Id.ToString() == o.Id).FirstOrDefault();
|
|
// if (needUpdate != null && currentPlayerInfo != null)
|
|
// {
|
|
// var left = Math.Round((needUpdate.EndDistance - currentPlayerInfo.EndDistance) * 1000);
|
|
// o.UpdateItem(needUpdate.Name, left.ToString() + "M", needUpdate.Id.ToString());
|
|
// o.gameObject.SetActive(true);
|
|
// }
|
|
// else
|
|
// {
|
|
// o.gameObject.SetActive(false);
|
|
// }
|
|
//}
|
|
timer += 1f;
|
|
}
|
|
}
|
|
}
|
|
}
|