loading页&结果页面&代码结构微调
This commit is contained in:
1 parent
eb1803c9ef
commit
eed2d13624
99 files changed
+14567
-7299
No files matched your search
@@ -0,0 +1,157 @@
|
||||
using Assets.Scripts;
|
||||
using Assets.Scripts.Apis;
|
||||
using Assets.Scripts.Apis.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Assets.Scenes.Ride.Scripts
|
||||
{
|
||||
public class CompetitionLoadingController : AbstratctLoadingController
|
||||
{
|
||||
private GameObject Watch { get; set; }
|
||||
private bool _canJoin = false;
|
||||
private bool _canStart = false;
|
||||
|
||||
private RawImage CompetitionDesc;
|
||||
private Text StartTime { get; set; }
|
||||
private Text Contestant { get; set; }
|
||||
|
||||
private Transform PlayersPanel {get;set;}
|
||||
|
||||
|
||||
public override void InjectController(CyclingController controller)
|
||||
{
|
||||
cyclingController = controller;
|
||||
//渲染比赛界面
|
||||
panel = Instantiate(Resources.Load<GameObject>("UI/Prefab/Match/CompetitonPanel"), transform);
|
||||
PFUIPanel mainPanel = panel.GetComponent<PFUIPanel>();
|
||||
PFUIPanel modelPanel = transform.Find("ModalPanel").GetComponent<PFUIPanel>();
|
||||
cyclingController.SetUIManager(mainPanel, modelPanel);
|
||||
}
|
||||
protected override void Start()
|
||||
{
|
||||
base.Start();
|
||||
}
|
||||
protected override void ShowLoading()
|
||||
{
|
||||
loadingPanel = panel.transform.Find("LoadingPanel").gameObject;
|
||||
loadingPanel.showLoadingExtension();
|
||||
}
|
||||
//初始化
|
||||
public override void Init()
|
||||
{
|
||||
InitGameObject();
|
||||
InitGameObjectData();
|
||||
}
|
||||
//构建赛事界面
|
||||
protected override void InitGameObject()
|
||||
{
|
||||
base.InitGameObject();
|
||||
CompetitionDesc = panel.transform.Find("CompetitionDesc").GetComponent<RawImage>();
|
||||
StartTime = panel.transform.Find("Time").GetComponent<Text>();
|
||||
Contestant = panel.transform.Find("Contestant").GetComponent<Text>();
|
||||
Watch = panel.transform.Find("Watch").gameObject;
|
||||
PlayersPanel = panel.transform.Find("PlayersPanel/List/Viewport/Content");
|
||||
UIManager.AddEvent(Watch, EventTriggerType.PointerClick, StartWatch);
|
||||
}
|
||||
//查询赛事相关数据
|
||||
protected override void InitGameObjectData()
|
||||
{
|
||||
var route = cyclingController.mapRoute;
|
||||
var competition = cyclingController.competition;
|
||||
//赛事状态按钮控制
|
||||
_canJoin = competition.CanJoin;
|
||||
_canStart = competition.CanStart;
|
||||
|
||||
var showWatch = !_canJoin && !_canStart && !competition.HasRecord;
|
||||
Watch.SetActive(showWatch);
|
||||
rideNow.gameObject.SetActive(!showWatch);
|
||||
rideNowText.text = _canJoin ? "Apply" : "RideNow";
|
||||
|
||||
#region 赛事基本信息
|
||||
//赛事名称
|
||||
mapName.text = competition.Title;
|
||||
//距离
|
||||
distance.text = route.Distance.ToString("f1") + "KM";
|
||||
//海拔
|
||||
elevaction.text = Math.Round(route.TotalClimb.GetValueOrDefault(0), 2).ToString() + "M";
|
||||
//平均破度
|
||||
slope.text = Math.Round(route.AverageGrade, 2).ToString() + "%";
|
||||
//比赛开始时间
|
||||
StartTime.text = competition.StartTime.ToLongTimeString();
|
||||
//参赛选手
|
||||
Contestant.text = competition.UserList.Count.ToString() + "Players";
|
||||
ShowPlayers(competition.UserList);
|
||||
//路书描述
|
||||
mapDescText.text = route.Dec;
|
||||
//主办方logo
|
||||
|
||||
//赛事详情
|
||||
//异步请求mapbox画出当前路书路线图
|
||||
DrawMapRouteAsync(route.Id,1);
|
||||
AddProcess(20);
|
||||
#endregion
|
||||
|
||||
StartCoroutine(HiddenLoading());
|
||||
}
|
||||
private int maxShowCout = 15;
|
||||
private void ShowPlayers(List<CompetitionPlayer> list)
|
||||
{
|
||||
var watcher = Resources.Load<GameObject>("UI/Prefab/Match/Watcher");
|
||||
var moreHead = Resources.Load<GameObject>("UI/Prefab/Match/MoreHead");
|
||||
int index = 0;
|
||||
foreach (var item in list)
|
||||
{
|
||||
index++;
|
||||
if (index >= maxShowCout) {
|
||||
Instantiate(moreHead, PlayersPanel);
|
||||
break;
|
||||
}
|
||||
var head = Instantiate(watcher, PlayersPanel);
|
||||
var headiamge = head.GetComponent<RawImage>();
|
||||
if (!string.IsNullOrEmpty(item.WxHeadImg))
|
||||
{
|
||||
Utils.DisplayImage(headiamge, item.WxHeadImg, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
//显示比赛详情图片:如果没有比赛详情图则显示地图
|
||||
private void ShowCompetitionDescImage()
|
||||
{
|
||||
|
||||
}
|
||||
#region 事件
|
||||
//先报名后开始
|
||||
protected override void StartRide(BaseEventData baseEvent)
|
||||
{
|
||||
//先报名
|
||||
if (_canJoin)
|
||||
{
|
||||
MapCompetitionApi s = new MapCompetitionApi();
|
||||
var rrr = s.ApplyMapCompetition(cyclingController.competitionId);
|
||||
if (rrr.Result.result)
|
||||
{
|
||||
var competition = s.GetById(cyclingController.competitionId).data;
|
||||
_canStart = competition.CanStart;
|
||||
}
|
||||
rideNowText.text = "RideNow";
|
||||
}
|
||||
else
|
||||
{
|
||||
base.StartRide(baseEvent);
|
||||
}
|
||||
}
|
||||
//观察
|
||||
protected void StartWatch(BaseEventData baseEvent)
|
||||
{
|
||||
//隐藏当前用户
|
||||
cyclingController.isWatch = true;
|
||||
cyclingController.player.SetActive(false);
|
||||
base.StartRide(baseEvent);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bfe4d27e49e6bea4a88d5982e6e6aa19
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,137 @@
|
||||
using Assets.Scenes.Ride.Scripts.Model;
|
||||
using Assets.Scenes.Ride.Scripts.Model.CyclingModels;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Assets.Scenes.Ride.Scripts
|
||||
{
|
||||
public class CompetitionRankingFactory : BaseListFactory
|
||||
{
|
||||
private bool isInit = false;
|
||||
private bool isnext = false;
|
||||
private List<CompetitionRankingSortModel> rankingList {get;set;}
|
||||
private AbstractPlayer currentPlayer { get; set; }
|
||||
private Text Title { get; set; }
|
||||
private Text OnlineUserNum { get; set; }
|
||||
private Text Rank { get; set; }
|
||||
private GameObject PreBtn { get; set; }
|
||||
private GameObject NextBtn { get; set; }
|
||||
|
||||
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/CompetitionRankingItem");
|
||||
nearByMajorItem = Resources.Load<GameObject>("UI/Prefab/Match/CompetitionRankingMajorItem");
|
||||
Title = transform.Find("Title").GetComponent<Text>();
|
||||
OnlineUserNum = transform.Find("Head/OnlineUserNum").GetComponent<Text>();
|
||||
PreBtn = transform.Find("Pre").gameObject;//上一页
|
||||
NextBtn = transform.Find("Next").gameObject;//下一页
|
||||
Rank = transform.Find("Rank").GetComponent<Text>();
|
||||
UIManager.AddEvent(PreBtn, UnityEngine.EventSystems.EventTriggerType.PointerClick, PrePage);
|
||||
UIManager.AddEvent(NextBtn, UnityEngine.EventSystems.EventTriggerType.PointerClick, NextPage);
|
||||
}
|
||||
private void PrePage(BaseEventData baseEventData)
|
||||
{
|
||||
SetPreIndex();
|
||||
isInit = true;
|
||||
isnext = false;
|
||||
CreateList();
|
||||
}
|
||||
private void NextPage(BaseEventData baseEventData)
|
||||
{
|
||||
SetNextIndex();
|
||||
isInit = true;
|
||||
isnext = true;
|
||||
CreateList();
|
||||
}
|
||||
protected override void CreateList()
|
||||
{
|
||||
CompetitionModel s = cyclingController.cyclingController as CompetitionModel;
|
||||
var ss = s?.competitionRankingModel;
|
||||
rankingList = ss?.Sorts;
|
||||
|
||||
if (rankingList == null) return;
|
||||
//当前参赛总人数
|
||||
var totalCount = rankingList.Count();
|
||||
OnlineUserNum.text = totalCount.ToString();
|
||||
//当前用户排名
|
||||
var currentIndex = rankingList.Where(c => c.UserId == cyclingController.currentPlayer.UserId).FirstOrDefault()?.Index ?? 0;
|
||||
totalPages = (pageSize>0?totalCount / pageSize:0) + (totalCount % pageSize> 0? 1:0);
|
||||
if (!isInit)
|
||||
{
|
||||
//当前用户在第几页
|
||||
pageIndex = (pageSize > 0 ? currentIndex / pageSize : 0) + (totalCount % pageSize > 0 ? 1 : 0);
|
||||
}
|
||||
Rank.text = $"{pageIndex}/{totalPages}";
|
||||
var pagedList = rankingList.Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList();
|
||||
//删除
|
||||
var currentList = FindObjectsOfType<CompetitionRankingItem>();
|
||||
foreach (var item in currentList)
|
||||
{
|
||||
var e = pagedList.Where(c => c.UserId == item.UserId).FirstOrDefault();
|
||||
if (e == null)
|
||||
{
|
||||
item.transform.gameObject.SetActive(false);//TODO:这里暂时不删除,删除对应的图片和脚本依赖这个对象;脚本提供一个dispose
|
||||
bufferSize--;
|
||||
}
|
||||
}
|
||||
//创建或者新增
|
||||
for (int i = 0; i < pagedList.Count(); i++)
|
||||
{
|
||||
CreateOrUpdate(pagedList[i]);
|
||||
}
|
||||
|
||||
}
|
||||
private void CreateOrUpdate(CompetitionRankingSortModel item)
|
||||
{
|
||||
var rankingList = FindObjectsOfType<CompetitionRankingItem>();
|
||||
var competitionRankingItem = rankingList.Where(c => c.UserId == item.UserId).FirstOrDefault();
|
||||
//如果当前有这个用户则更新没有则创建并setslibingindex
|
||||
if (competitionRankingItem == null)
|
||||
{
|
||||
//创建
|
||||
if (bufferSize < pageSize)
|
||||
{
|
||||
//情况一:还有足够的buffer,直接创建
|
||||
GameObject prefabItem = item.IsSelf ? nearByMajorItem : nearByItem;
|
||||
GameObject newObj = (GameObject)Instantiate(prefabItem, parent);
|
||||
competitionRankingItem = newObj.GetComponent<CompetitionRankingItem>();
|
||||
bufferSize++;
|
||||
}
|
||||
else
|
||||
{
|
||||
//情况二:没有足够的buffer,找到要被淘汰的buffer()最后一名
|
||||
if (isnext) {
|
||||
competitionRankingItem = rankingList.OrderBy(c => c.rank).FirstOrDefault();
|
||||
}
|
||||
else
|
||||
{
|
||||
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(currentPlayer.UserId == item.UserId?"0KM": item.Near.ToString() + "KM");
|
||||
competitionRankingItem.transform.SetSiblingIndex(item.Index);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ab8fe28fa979675468c81d99ce5ad389
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,123 @@
|
||||
using Assets.Scripts;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Assets.Scenes.Ride.Scripts
|
||||
{
|
||||
public class CompetitionRankingItem : MonoBehaviour
|
||||
{
|
||||
private RawImage Head;
|
||||
private RawImage Country;
|
||||
private Image Background;
|
||||
private Text Name;
|
||||
private Text Speed;
|
||||
private Text Distance;
|
||||
private Text Ratio;//功体比
|
||||
private Text Rank;//当前排名
|
||||
private Text Timer;
|
||||
|
||||
private int _userId = 0;
|
||||
public int UserId { get { return _userId; } }
|
||||
private string _headUrl=string.Empty;
|
||||
private string _countryUrl = string.Empty;
|
||||
private string _name = string.Empty;
|
||||
private string _speed = string.Empty;
|
||||
private string _distance = string.Empty;
|
||||
private string _ratio = string.Empty;
|
||||
public int rank { get; set; }
|
||||
private Texture countryTexture;
|
||||
CyclingController cyclingController;
|
||||
Color selectedColor = new Color(0.9764706f, 0.1882353f, 0.5254902f);
|
||||
Color unselectedColor = new Color(0.2078431f, 0.2078431f, 0.2627451f);
|
||||
private void Awake()
|
||||
{
|
||||
cyclingController = FindObjectOfType<CyclingController>();
|
||||
Background = transform.GetComponent<Image>();
|
||||
Head = transform.Find("Head").GetComponent<RawImage>();
|
||||
Country = transform.Find("Country").GetComponent<RawImage>();
|
||||
Name = transform.Find("Name").GetComponent<Text>();
|
||||
Speed = transform.Find("Speed").GetComponent<Text>();
|
||||
Distance = transform.Find("Distance").GetComponent<Text>();
|
||||
Ratio = transform.Find("Ratio").GetComponent<Text>();
|
||||
Rank = transform.Find("Rank").GetComponent<Text>();
|
||||
Timer = transform.Find("Timer")?.GetComponent<Text>();
|
||||
countryTexture = Resources.Load<Sprite>("Images/flag_China_Person").texture;
|
||||
UIManager.AddEvent(this.gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, Watch);
|
||||
}
|
||||
private void Update()
|
||||
{
|
||||
if (cyclingController.currentPlayer.UserId == UserId)
|
||||
{
|
||||
Background.color = selectedColor;
|
||||
Ratio.color = Color.white;
|
||||
}
|
||||
else
|
||||
{
|
||||
Background.color = unselectedColor;
|
||||
}
|
||||
}
|
||||
|
||||
//切换到当前用户视角
|
||||
public void Watch(BaseEventData baseEventData)
|
||||
{
|
||||
cyclingController.ChangeCurrentPlayer(_userId);
|
||||
}
|
||||
public void setTimer(string timer)
|
||||
{
|
||||
Timer.text = timer;
|
||||
}
|
||||
public void setRatio(string ratio)
|
||||
{
|
||||
if (!_ratio.Equals(ratio))
|
||||
{
|
||||
Ratio.text = ratio;
|
||||
}
|
||||
}
|
||||
//设置当前排名
|
||||
public void SetRank(int rank)
|
||||
{
|
||||
Rank.text = rank.ToString().PadLeft(3,'0');
|
||||
this.rank = rank;
|
||||
}
|
||||
|
||||
public void setHead(string url)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(url))
|
||||
{
|
||||
Utils.DisplayImage(Head, url, true);
|
||||
var rect = ((RectTransform)Head.transform).rect;
|
||||
Material material = Instantiate(Resources.Load<Material>("UI/Material/RoundedCornersTextureMaterial"));
|
||||
material.SetVector(Shader.PropertyToID("_WidthHeightRadius"), new Vector4(rect.width, rect.height, rect.height, 0));
|
||||
Head.material = material;
|
||||
}
|
||||
}
|
||||
|
||||
public void setCountry(string url)
|
||||
{
|
||||
Utils.DisplayImage(Country, url, true);
|
||||
}
|
||||
public void setName(string name)
|
||||
{
|
||||
if (!_name.Equals(name))
|
||||
Name.text = name;
|
||||
}
|
||||
|
||||
public void setSpeed(string speed)
|
||||
{
|
||||
if (!_speed.Equals(speed))
|
||||
Speed.text = speed;
|
||||
}
|
||||
|
||||
public void setDistance(string distance)
|
||||
{
|
||||
if (!_distance.Equals(distance))
|
||||
Distance.text = distance;
|
||||
}
|
||||
|
||||
public void setUserId(int userId)
|
||||
{
|
||||
_userId = userId;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 897973ae3dd02d545b786cae2278c710
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,89 @@
|
||||
using Assets.Scenes.Ride.Scripts.Model.CyclingModels;
|
||||
using Assets.Scripts;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Assets.Scenes.Ride.Scripts
|
||||
{
|
||||
public class CompetitionResultFactory: MonoBehaviour
|
||||
{
|
||||
CyclingController cyclingController;
|
||||
RawImage Head;
|
||||
Text Ranking;
|
||||
Text Timer;
|
||||
private void Awake()
|
||||
{
|
||||
cyclingController = FindObjectOfType<CyclingController>();
|
||||
var closeBtn = transform.Find("Close").gameObject;
|
||||
Head = transform.Find("Mine/Head").GetComponent<RawImage>();
|
||||
Ranking = transform.Find("Mine/Ranking").GetComponent<Text>();
|
||||
Timer = transform.Find("Mine/Timer").GetComponent<Text>();
|
||||
|
||||
UIManager.AddEvent(closeBtn, UnityEngine.EventSystems.EventTriggerType.PointerClick, Close);
|
||||
}
|
||||
|
||||
float time = 1;
|
||||
private void Update()
|
||||
{
|
||||
time -= Time.deltaTime;
|
||||
while (time < 0)
|
||||
{
|
||||
Refresh();
|
||||
time = 1;
|
||||
}
|
||||
}
|
||||
|
||||
public void Refresh()
|
||||
{
|
||||
if (cyclingController.cyclingController is CompetitionModel model)
|
||||
{
|
||||
var list = model?.competitionRankingModel?.Results;
|
||||
if (list == null) return;
|
||||
|
||||
var parent = transform.Find("ScrollView/Viewport/Content");
|
||||
//当前用户排名
|
||||
var currentRanking = list.Where(c => c.UserId == cyclingController.currentPlayer.UserId).FirstOrDefault();
|
||||
if (currentRanking != null)
|
||||
{
|
||||
Utils.DisplayImage(Head, App.CurrentUser.WxHeadImg, true);//TODO:改造数据结构结果增加头像字段
|
||||
Ranking.text = currentRanking.Index.ToString().PadLeft(3,'0');
|
||||
Timer.text = currentRanking.TripTime;
|
||||
}
|
||||
//排名列表
|
||||
var rankingList = FindObjectsOfType<FinalRankingItemScript>();
|
||||
foreach (var item in list)
|
||||
{
|
||||
var finalRankingItemScript = rankingList.Where(c => c.UserId == item.UserId).FirstOrDefault();
|
||||
//没有就创建
|
||||
if (finalRankingItemScript == null)
|
||||
{
|
||||
var finalRankingItem = Instantiate(Resources.Load<GameObject>("UI/Prefab/Match/FinalRankingItem"), parent);
|
||||
finalRankingItemScript = finalRankingItem.GetComponent<FinalRankingItemScript>();
|
||||
}
|
||||
|
||||
//有就更新
|
||||
finalRankingItemScript.setGap(item.Gap);
|
||||
finalRankingItemScript.setSource(item.DeviceType);
|
||||
finalRankingItemScript.setUserId(item.UserId);
|
||||
finalRankingItemScript.setRanking(item.Index);
|
||||
finalRankingItemScript.setHeartRate(item.HeartRate.ToString("f0"));
|
||||
finalRankingItemScript.setName(item.Name);
|
||||
finalRankingItemScript.setPower(item.Power.ToString());
|
||||
finalRankingItemScript.setRatio(item.WeightKg.ToString("f2"));
|
||||
finalRankingItemScript.setTimer(item.TripTime);
|
||||
finalRankingItemScript.transform.SetSiblingIndex(item.Index);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void Close(BaseEventData baseEventData)
|
||||
{
|
||||
this.gameObject.SetActive(false);
|
||||
this.Destroy();
|
||||
//SceneManager.LoadScene("MainScene");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 53789e6465db91d43adaa58df5c0e72d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,170 @@
|
||||
using UnityEngine;
|
||||
using DG.Tweening;
|
||||
using Assets.Scenes.Ride.Scripts.Model;
|
||||
using UnityEngine.EventSystems;
|
||||
using Assets.Scenes.Ride.Scripts.Model.CyclingModels;
|
||||
using UnityEngine.UI;
|
||||
using Assets.Scripts;
|
||||
using Assets.Scripts.Apis;
|
||||
|
||||
namespace Assets.Scenes.Ride.Scripts
|
||||
{
|
||||
public class CompetitionUIManager : BaseUIManager
|
||||
{
|
||||
protected override void Awake()
|
||||
{
|
||||
base.Awake();
|
||||
}
|
||||
GameObject countDownPanel;
|
||||
Text title;
|
||||
Text timer;
|
||||
protected override void Start()
|
||||
{
|
||||
base.Start();
|
||||
//创建倒计时面板
|
||||
countDownPanel = Instantiate(Resources.Load<GameObject>("UI/Prefab/Match/CountDownPanel"), transform.Find("Panel"));
|
||||
title = countDownPanel.transform.Find("Title").GetComponent<Text>();
|
||||
timer = countDownPanel.transform.Find("Timer").GetComponent<Text>();
|
||||
reviewPanel.SetActive(false);
|
||||
countDownPanel.SetActive(false);
|
||||
ShowCurrentRanking();
|
||||
}
|
||||
protected override void Update()
|
||||
{
|
||||
base.Update();
|
||||
CountDown();
|
||||
}
|
||||
|
||||
//开始游戏触发事件
|
||||
public void StartRide(BaseEventData baseEventData)
|
||||
{
|
||||
this.StartRide();
|
||||
}
|
||||
CompetitionModel competitionModel;
|
||||
bool canStart = false;
|
||||
//开始骑行-加个5秒钟倒计时
|
||||
public override void StartRide()
|
||||
{
|
||||
competitionModel = mainController.cyclingController as CompetitionModel;
|
||||
}
|
||||
|
||||
private void CountDown()
|
||||
{
|
||||
miniMap.SetActive(false); //隐藏小地图
|
||||
viewButton.gameObject.SetActive(false);//隐藏切换视角
|
||||
headPanel.SetActive(!mainController.isWatch); //隐藏海拔图观察者的头像
|
||||
|
||||
//比赛进行中
|
||||
if (competitionModel != null)
|
||||
{
|
||||
count = competitionModel.StartCountdown();
|
||||
canStart = competitionModel.CanStart();
|
||||
//比赛开始前倒计时
|
||||
if (count >= 0 && !canStart && !competitionModel.recorderData.Saved)
|
||||
{
|
||||
//显示倒计时面板信息
|
||||
showCountDown(count, "Get ready!");
|
||||
//隐藏坡度
|
||||
currentSlopePanel.SetActive(false);
|
||||
nextSlopePanel.SetActive(false);
|
||||
}
|
||||
//比赛开始
|
||||
if (count <= 0 && canStart)
|
||||
{
|
||||
mainController.SetStart();
|
||||
countDownPanel.SetActive(false);
|
||||
}
|
||||
//显示结果(非观战到达终点弹窗)
|
||||
var ishowResult = !mainController.isWatch && (competitionModel.mapCompetition?.HasRecord ?? false) || competitionModel.recorderData.Saved;
|
||||
if (ishowResult)
|
||||
{
|
||||
ShowResultList();
|
||||
}
|
||||
var s = competitionModel?.EndCountDown();
|
||||
//显示关门时间
|
||||
if (s.Value.Item2)
|
||||
{
|
||||
if (s.Value.Item1 <= 0 && !mainController.cyclingController.recorderData.Saved)
|
||||
{
|
||||
//自动保存,游戏设置结束
|
||||
SaveRide(null);
|
||||
}
|
||||
else
|
||||
{
|
||||
//显示倒计时面板信息
|
||||
showCountDown(s.Value.Item1, "get the winner,end tance remains");
|
||||
}
|
||||
}
|
||||
else if (s.Value.Item1 > 0)
|
||||
{
|
||||
//显示倒计时面板信息
|
||||
showCountDown(s.Value.Item1, "remaining");
|
||||
}
|
||||
////显示关门时间
|
||||
//if (s.Value.Item2 && s.Value.Item1 <= 0 && !mainController.cyclingController.recorderData.Saved)
|
||||
//{
|
||||
// //自动保存,游戏设置结束
|
||||
// SaveRide(null);
|
||||
//}
|
||||
//var title = s.Value.Item2 && s.Value.Item1 <= 0 ? "finish" : "remaining";
|
||||
////显示倒计时面板信息
|
||||
//showCountDown(s.Value.Item1, title);
|
||||
//显示当前比赛进行多长时间了
|
||||
timerTxt.text = competitionModel.ShowTime;
|
||||
}
|
||||
}
|
||||
|
||||
private void showCountDown(int count,string text)
|
||||
{
|
||||
countDownPanel.SetActive(true);
|
||||
title.text = text;
|
||||
if (count >= 0)
|
||||
{
|
||||
timer.text = Helper.FormatTicks(count);
|
||||
}
|
||||
}
|
||||
|
||||
public override void SaveRide(BaseEventData baseEventData)
|
||||
{
|
||||
if (!mainController.isQuit)
|
||||
{
|
||||
mainController.SetQuit();
|
||||
playerController.Upload();
|
||||
quitPanel.SetActive(false);
|
||||
}
|
||||
ShowResultList();//保存显示当前排名
|
||||
}
|
||||
|
||||
public override void ContinueRide()
|
||||
{
|
||||
mainController.SetCyclingModel(CyclingModel.Competition);
|
||||
}
|
||||
public override void PauseRide(BaseEventData baseEventData)
|
||||
{
|
||||
return;
|
||||
}
|
||||
//实时显示当前比赛排名
|
||||
GameObject competitionRankingList;
|
||||
public void ShowCurrentRanking()
|
||||
{
|
||||
if (competitionRankingList == null)
|
||||
{
|
||||
competitionRankingList = Instantiate(Resources.Load<GameObject>("UI/Prefab/Match/CompetitionRankingPanel"), transform.Find("Panel"));
|
||||
}
|
||||
if (topRankPanel == null)
|
||||
{
|
||||
topRankPanel = Instantiate(Resources.Load<GameObject>("UI/Prefab/Match/TopRankPanel"), transform.Find("Panel"));
|
||||
}
|
||||
}
|
||||
GameObject competitionResultPanel;
|
||||
GameObject topRankPanel;
|
||||
//实时刷新显示比赛结果
|
||||
public void ShowResultList()
|
||||
{
|
||||
if (competitionResultPanel == null)
|
||||
{
|
||||
competitionResultPanel = Instantiate(Resources.Load<GameObject>("UI/Prefab/Match/CompetitionResultPanel"), transform.Find("Panel"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 56d863ea131204b4682725335a6af540
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,62 @@
|
||||
using Assets.Scenes.Ride.Scripts.Model.CyclingModels;
|
||||
using Assets.Scripts;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
namespace Assets.Scenes.Ride.Scripts
|
||||
{
|
||||
public class CompetitionWatcherFactory : MonoBehaviour
|
||||
{
|
||||
int pageIndex = 1;
|
||||
int pageSize = 8;
|
||||
CyclingController cyclingController;
|
||||
private void start()
|
||||
{
|
||||
cyclingController = FindObjectOfType<CyclingController>();
|
||||
}
|
||||
|
||||
float time = 1;
|
||||
private void Update()
|
||||
{
|
||||
time -= Time.deltaTime;
|
||||
while (time < 0)
|
||||
{
|
||||
Refresh();
|
||||
time = 1;
|
||||
}
|
||||
}
|
||||
|
||||
public void Refresh()
|
||||
{
|
||||
if (cyclingController.cyclingController is CompetitionModel model)
|
||||
{
|
||||
var list = model?.competitionRankingModel?.Results;
|
||||
if (list == null) return;
|
||||
var parent = transform.Find("ScrollView/Viewport/Content");
|
||||
Utils.DestroyChildren(parent);
|
||||
|
||||
var pagedList = list.Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList();
|
||||
foreach (var item in pagedList)
|
||||
{
|
||||
var finalRankingItem = Instantiate(Resources.Load<GameObject>("UI/Prefab/Match/FinalRankingItem"), parent);
|
||||
var finalRankingItemScript = finalRankingItem.GetComponent<FinalRankingItemScript>();
|
||||
finalRankingItemScript.setRanking(item.Index);
|
||||
finalRankingItemScript.setHeartRate(item.HeartRate.ToString("f0"));
|
||||
finalRankingItemScript.setName(item.Name);
|
||||
finalRankingItemScript.setPower(item.Power.ToString());
|
||||
finalRankingItemScript.setRatio(item.WeightKg.ToString("f2"));
|
||||
finalRankingItemScript.setTimer(item.TripTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void Close(BaseEventData baseEventData)
|
||||
{
|
||||
this.gameObject.SetActive(false);
|
||||
this.Destroy();
|
||||
//SceneManager.LoadScene("MainScene");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 911cdbf2d21e6bc4f8713d8440ea06d5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,179 @@
|
||||
using Assets.Scripts;
|
||||
using Assets.Scripts.UI.UIEffect;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Assets.Scenes.Ride.Scripts
|
||||
{
|
||||
public class FinalRankingItemScript : MonoBehaviour
|
||||
{
|
||||
private RawImage Head;
|
||||
private RawImage Country;
|
||||
private Image RankHead;
|
||||
private Text Name;
|
||||
private Text Power;
|
||||
private Text Timer;
|
||||
private Text Gap;
|
||||
private Text WKG;//功体比
|
||||
private Text Ranking;
|
||||
private Text HeartRate;
|
||||
private Text Source;
|
||||
private Outline outline;
|
||||
private Image BackGround;
|
||||
private UIGradient uIGradient;
|
||||
private UIGradient RankHeadGradient;
|
||||
|
||||
private int _userId = 0;
|
||||
public int UserId { get { return _userId; } }
|
||||
private Texture countryTexture;
|
||||
#region 颜色常量
|
||||
private Color RED = new Color(0.9764706f, 0.1882353f, 0.5254902f);
|
||||
private Color SHALLOW_RED = new Color(1f, 0.454902f, 0.5215687f);
|
||||
|
||||
private Color PURPLE = new Color(0.1568628f, 0.4431373f, 0.8745098f);
|
||||
private Color SHALLOW_PURPLE = new Color(0.3843137f, 0.7764706f, 1f);
|
||||
|
||||
private Color BLUE = new Color(0.4352941f, 0.3333333f, 0.9372549f);
|
||||
private Color SHALLOW_BLUE = new Color(0.772549f, 0.5529412f, 1f);
|
||||
|
||||
private Color GREY = new Color(0.1333333f, 0.1333333f, 0.1764706f);
|
||||
private Color SHALLOW_GREY = new Color(0.2784314f, 0.2784314f, 0.3490196f);
|
||||
|
||||
private Color WHITE = new Color(1f, 1f, 1f, 1f);
|
||||
private Color TRANSPARENT = new Color(1f, 1f, 1f, 0f);
|
||||
private Color BLACK = new Color(0.2078431f, 0.2078431f, 0.2627451f);
|
||||
private Color SHALLOW_WHITE = new Color(0.8352941f, 0.8352941f, 0.8352941f);
|
||||
#endregion
|
||||
|
||||
CyclingController cyclingController;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
cyclingController = FindObjectOfType<CyclingController>();
|
||||
RankHead = transform.Find("RankHead").GetComponent<Image>();
|
||||
RankHeadGradient = RankHead.GetComponent<UIGradient>();
|
||||
Ranking = transform.Find("Ranking").GetComponent<Text>();
|
||||
Name = transform.Find("Name").GetComponent<Text>();
|
||||
Timer = transform.Find("Timer").GetComponent<Text>();
|
||||
Gap = transform.Find("GAP").GetComponent<Text>();
|
||||
Power = transform.Find("Power").GetComponent<Text>();
|
||||
WKG = transform.Find("WKG").GetComponent<Text>();
|
||||
HeartRate = transform.Find("Heart").GetComponent<Text>();
|
||||
Source = transform.Find("Source").GetComponent<Text>();
|
||||
Head = transform.Find("Head").GetComponent<RawImage>();
|
||||
Country = transform.Find("Country").GetComponent<RawImage>();
|
||||
outline = transform.GetComponent<Outline>();
|
||||
BackGround = transform.GetComponent<Image>();
|
||||
uIGradient = transform.GetComponent<UIGradient>();
|
||||
}
|
||||
|
||||
public void setRatio(string ratio)
|
||||
{
|
||||
WKG.text = ratio +"W/KG";
|
||||
}
|
||||
|
||||
public void setSource(string device)
|
||||
{
|
||||
Source.text = device;
|
||||
}
|
||||
|
||||
public void setGap(string gap)
|
||||
{
|
||||
Gap.text = gap;
|
||||
}
|
||||
|
||||
public void setHead(string url)
|
||||
{
|
||||
Utils.DisplayImage(Head, url, true);
|
||||
var rect = ((RectTransform)Head.transform).rect;
|
||||
Material material = Instantiate(Resources.Load<Material>("UI/Material/RoundedCornersTextureMaterial"));
|
||||
material.SetVector(Shader.PropertyToID("_WidthHeightRadius"), new Vector4(rect.width, rect.height, rect.height, 0));
|
||||
Head.material = material;
|
||||
}
|
||||
|
||||
public void setCountry(Texture texture)
|
||||
{
|
||||
Country.texture = texture;
|
||||
}
|
||||
public void setName(string name)
|
||||
{
|
||||
Name.text = name;
|
||||
}
|
||||
|
||||
public void setPower(string power)
|
||||
{
|
||||
Power.text = power +"W";
|
||||
}
|
||||
public void setTimer(string timer)
|
||||
{
|
||||
Timer.text = timer;
|
||||
}
|
||||
|
||||
public void setRanking(int ranking)
|
||||
{
|
||||
switch (ranking)
|
||||
{
|
||||
//第一名的样式
|
||||
case 1:
|
||||
RankHeadGradient.color1 = RED;
|
||||
RankHeadGradient.color2 = SHALLOW_RED;
|
||||
Name.color = BLACK;
|
||||
Timer.color = BLACK;
|
||||
uIGradient.color1 = WHITE;
|
||||
uIGradient.color2 = SHALLOW_WHITE;
|
||||
break;
|
||||
//第二名的样式
|
||||
case 2:
|
||||
RankHeadGradient.color1 = PURPLE;
|
||||
RankHeadGradient.color2 = SHALLOW_PURPLE;
|
||||
Name.color = BLACK;
|
||||
Timer.color = BLACK;
|
||||
uIGradient.color1 = WHITE;
|
||||
uIGradient.color2 = SHALLOW_WHITE;
|
||||
break;
|
||||
//第三名的样式
|
||||
case 3:
|
||||
RankHeadGradient.color1 = BLUE;
|
||||
RankHeadGradient.color2 = SHALLOW_BLUE;
|
||||
Name.color = BLACK;
|
||||
Timer.color = BLACK;
|
||||
uIGradient.color1 = WHITE;
|
||||
uIGradient.color2 = SHALLOW_WHITE;
|
||||
break;
|
||||
default:
|
||||
RankHeadGradient.color1 = BLACK;
|
||||
RankHeadGradient.color2 = BLACK;
|
||||
Name.color = WHITE;
|
||||
Timer.color = WHITE;
|
||||
uIGradient.color1 = GREY;
|
||||
uIGradient.color2 = SHALLOW_GREY;
|
||||
break;
|
||||
}
|
||||
Ranking.text = ranking.ToString().PadLeft(3,'0');
|
||||
}
|
||||
|
||||
public void setHeartRate(string heartRate)
|
||||
{
|
||||
if (!heartRate.Equals("0"))
|
||||
{
|
||||
HeartRate.text = heartRate + "bpm";
|
||||
}
|
||||
else
|
||||
{
|
||||
HeartRate.text = "--bpm";
|
||||
}
|
||||
}
|
||||
|
||||
public void setUserId(int userId)
|
||||
{
|
||||
_userId = userId;
|
||||
var isself = userId == cyclingController.currentPlayer.UserId;
|
||||
//头像根据是否是自己显示
|
||||
Utils.DisplayImage(Head, App.CurrentUser.WxHeadImg, true);//TODO:改造数据结构结果增加头像字段
|
||||
Head.gameObject.SetActive(isself);
|
||||
//边框样式
|
||||
var color = isself ? WHITE : TRANSPARENT;
|
||||
outline.effectColor = color;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1e64a5b2fb6d4f3418094195460237d1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,76 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d3903e9a2640d3447af0b98a0d6ce664
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,116 @@
|
||||
using Assets.Scripts;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Assets.Scenes.Ride.Scripts
|
||||
{
|
||||
public class TopRankingItem : MonoBehaviour
|
||||
{
|
||||
private RawImage Head;
|
||||
private RawImage Country;
|
||||
private Image Background;
|
||||
private Text Name;
|
||||
private Text Speed;
|
||||
private Text Distance;
|
||||
private Text Ratio;//功体比
|
||||
private Text Rank;//当前排名
|
||||
private Text Timer;
|
||||
|
||||
private int _userId = 0;
|
||||
public int UserId { get { return _userId; } }
|
||||
private string _headUrl = string.Empty;
|
||||
private string _countryUrl = string.Empty;
|
||||
private string _name = string.Empty;
|
||||
private string _speed = string.Empty;
|
||||
private string _distance = string.Empty;
|
||||
private string _ratio = string.Empty;
|
||||
public int rank { get; set; }
|
||||
private Texture countryTexture;
|
||||
CyclingController cyclingController;
|
||||
private void Awake()
|
||||
{
|
||||
cyclingController = FindObjectOfType<CyclingController>();
|
||||
Background = transform.GetComponent<Image>();
|
||||
Head = transform.Find("Head").GetComponent<RawImage>();
|
||||
Country = transform.Find("Country").GetComponent<RawImage>();
|
||||
Name = transform.Find("Name").GetComponent<Text>();
|
||||
Speed = transform.Find("Speed").GetComponent<Text>();
|
||||
Distance = transform.Find("Distance").GetComponent<Text>();
|
||||
Ratio = transform.Find("Ratio").GetComponent<Text>();
|
||||
Rank = transform.Find("Rank").GetComponent<Text>();
|
||||
Timer = transform.Find("Timer")?.GetComponent<Text>();
|
||||
countryTexture = Resources.Load<Sprite>("Images/flag_China_Person").texture;
|
||||
var btn = this.gameObject.GetComponent<Button>();
|
||||
btn.onClick.AddListener(() =>
|
||||
{
|
||||
Watch();
|
||||
});
|
||||
///UIManager.AddEvent(this.gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, Watch);
|
||||
}
|
||||
//切换到当前用户视角
|
||||
public void Watch()
|
||||
{
|
||||
cyclingController.ChangeCurrentPlayer(_userId);
|
||||
}
|
||||
public void setTimer(string timer)
|
||||
{
|
||||
Timer.text = timer;
|
||||
}
|
||||
public void setRatio(string ratio)
|
||||
{
|
||||
if (!_ratio.Equals(ratio))
|
||||
{
|
||||
Ratio.text = ratio;
|
||||
}
|
||||
}
|
||||
//设置当前排名
|
||||
public void SetRank(int rank)
|
||||
{
|
||||
Rank.text = rank.ToString();
|
||||
this.rank = rank;
|
||||
}
|
||||
|
||||
public void setHead(string url)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(url))
|
||||
{
|
||||
Utils.DisplayImage(Head, url, true);
|
||||
var rect = ((RectTransform)Head.transform).rect;
|
||||
Material material = Instantiate(Resources.Load<Material>("UI/Material/RoundedCornersTextureMaterial"));
|
||||
material.SetVector(Shader.PropertyToID("_WidthHeightRadius"), new Vector4(rect.width, rect.height, rect.height, 0));
|
||||
Head.material = material;
|
||||
}
|
||||
}
|
||||
|
||||
public void setCountry(string url)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(url))
|
||||
{
|
||||
Utils.DisplayImage(Country, url, true);
|
||||
}
|
||||
}
|
||||
public void setName(string name)
|
||||
{
|
||||
if (!_name.Equals(name))
|
||||
Name.text = name;
|
||||
}
|
||||
|
||||
public void setSpeed(string speed)
|
||||
{
|
||||
if (!_speed.Equals(speed))
|
||||
Speed.text = speed;
|
||||
}
|
||||
|
||||
public void setDistance(string distance)
|
||||
{
|
||||
if (!_distance.Equals(distance))
|
||||
Distance.text = distance;
|
||||
}
|
||||
|
||||
public void setUserId(int userId)
|
||||
{
|
||||
_userId = userId;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2338fbdbfd33753468194151f9b88760
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,55 @@
|
||||
using Assets.Scenes.Ride.Scripts.Model;
|
||||
using Assets.Scenes.Ride.Scripts.Model.CyclingModels;
|
||||
using Assets.Scripts;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Assets.Scenes.Ride.Scripts
|
||||
{
|
||||
public class WatcherFactory : MonoBehaviour
|
||||
{
|
||||
private Transform content { get; set; }
|
||||
private CyclingController cyclingController { get;set;}
|
||||
private GameObject watcher { get; set; }
|
||||
private GameObject head { get; set; }
|
||||
private Text watchNum { get; set; }
|
||||
private void Awake()
|
||||
{
|
||||
cyclingController = FindObjectOfType<CyclingController>();
|
||||
content = transform.Find("List/Viewport/Content");
|
||||
head = transform.Find("Head").gameObject;
|
||||
watchNum = transform.Find("Head/OnlineUserNum").GetComponent<Text>();
|
||||
watcher = Resources.Load<GameObject>("UI/Prefab/Match/Watcher");
|
||||
}
|
||||
|
||||
private float t = 1f;
|
||||
private void Update()
|
||||
{
|
||||
t -= Time.deltaTime;
|
||||
while (t<=0)
|
||||
{
|
||||
CreateList();
|
||||
t = 1;
|
||||
}
|
||||
}
|
||||
|
||||
private void CreateList()
|
||||
{
|
||||
var watchList = cyclingController.GetWatcherList();
|
||||
var count = watchList.Count();
|
||||
|
||||
head.SetActive(count >= 5);
|
||||
watchNum.text = count.ToString();//绑定观看人数
|
||||
var list = watchList.Take(5);
|
||||
Utils.DestroyChildren(content);
|
||||
foreach (var item in list)
|
||||
{
|
||||
var head = Instantiate(watcher, content);
|
||||
var headiamge = head.GetComponent<RawImage>();
|
||||
Utils.DisplayImage(headiamge, item.HeadImage, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5d3a3fba34cb3db4fa7a25f6f5ca4992
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in new issue
Block a user