2021-07-09 18:16:50 +08:00

171 lines
6.1 KiB
C#

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"));
}
}
}
}