241 lines
9.6 KiB
C#
241 lines
9.6 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 UnityEngine.SceneManagement;
|
|
|
|
namespace Assets.Scenes.Ride.Scripts
|
|
{
|
|
public class CompetitionUIManager : BaseUIManager
|
|
{
|
|
protected override void Awake()
|
|
{
|
|
base.Awake();
|
|
}
|
|
GameObject countDownPanel { get; set; }
|
|
Text title { get; set; }
|
|
Text timer { get; set; }
|
|
GameObject raceViewBtn { get; set; }
|
|
GameObject timerIcon { get; set; }
|
|
protected override void Start()
|
|
{
|
|
base.Start();
|
|
|
|
reviewPanel.SetActive(false);
|
|
//隐藏单人骑行时间
|
|
var spilitLineH2 = uipanel.transform.Find("ComputerPanel/SpilitLineH2").gameObject;
|
|
raceViewBtn = uipanel.transform.Find("RaceViewButton").gameObject;
|
|
#if UNITY_IOS || UNITY_ANDROID
|
|
timerIcon = uipanel.transform.Find("ComputerPanel/TimerIcon").gameObject;
|
|
timerIcon.SetActive(false);
|
|
#else
|
|
viewButton.gameObject.SetActive(false);
|
|
#endif
|
|
|
|
UIManager.AddEvent(raceViewBtn, UnityEngine.EventSystems.EventTriggerType.PointerClick, ChangeView);
|
|
|
|
spilitLineH2.SetActive(false);
|
|
timerTxt.gameObject.SetActive(false);
|
|
timerTxtTitle.gameObject.SetActive(false);
|
|
//countDownPanel.SetActive(false);
|
|
//观察者模式隐藏坡度
|
|
if (mainController.isWatch)
|
|
{
|
|
nextSlopePanel.SetActive(false);
|
|
currentSlopePanel.SetActive(false);
|
|
}
|
|
altitudeGraph.gameObject.SetActive(false);
|
|
//暂停按钮禁用
|
|
pauseButton.interactable = false;
|
|
}
|
|
protected override void Update()
|
|
{
|
|
base.Update();
|
|
CountDown();
|
|
}
|
|
|
|
//开始游戏触发事件
|
|
public void StartRide(BaseEventData baseEventData)
|
|
{
|
|
this.StartRide();
|
|
}
|
|
CompetitionModel competitionModel;
|
|
bool canStart = false;
|
|
GameObject watchPanel { get; set; }
|
|
//开始骑行-加个5秒钟倒计时
|
|
public override void StartRide()
|
|
{
|
|
competitionModel = mainController.cyclingController as CompetitionModel;
|
|
|
|
#if UNITY_IOS || UNITY_ANDROID
|
|
countDownPanel = Instantiate(Resources.Load<GameObject>("UI/Prefab/Match/Mobile/CountDownPanel"), uipanel.transform);
|
|
title = countDownPanel.transform.Find("Title").GetComponent<Text>();
|
|
timer = countDownPanel.transform.Find("Timer").GetComponent<Text>();
|
|
competitionRankingList = Instantiate(Resources.Load<GameObject>("UI/Prefab/Match/Mobile/CompetitionRankingPanel"), uipanel.transform);
|
|
topRankPanel = Instantiate(Resources.Load<GameObject>("UI/Prefab/Match/Mobile/TopRankPanel"), uipanel.transform);
|
|
watchPanel = Instantiate(Resources.Load<GameObject>("UI/Prefab/Match/Mobile/WatcherPanel"), uipanel.transform);
|
|
#else
|
|
countDownPanel = Instantiate(Resources.Load<GameObject>("UI/Prefab/Match/CountDownPanel"), uipanel.transform);
|
|
title = countDownPanel.transform.Find("Title").GetComponent<Text>();
|
|
timer = countDownPanel.transform.Find("Timer").GetComponent<Text>();
|
|
competitionRankingList = Instantiate(Resources.Load<GameObject>("UI/Prefab/Match/CompetitionRankingPanel"), uipanel.transform);
|
|
topRankPanel = Instantiate(Resources.Load<GameObject>("UI/Prefab/Match/TopRankPanel"), uipanel.transform);
|
|
watchPanel = Instantiate(Resources.Load<GameObject>("UI/Prefab/Match/WatcherPanel"), uipanel.transform);
|
|
|
|
#endif
|
|
}
|
|
|
|
private void CountDown()
|
|
{
|
|
raceViewBtn.SetActive(mainController.isWatch);
|
|
#if UNITY_IOS || UNITY_ANDROID
|
|
raceViewBtn.SetActive(false);
|
|
#endif
|
|
miniMap.SetActive(false); //隐藏小地图
|
|
//viewButton.gameObject.SetActive(false);//隐藏切换视角
|
|
headPanel.SetActive(!mainController.isWatch); //隐藏海拔图观察者的头像
|
|
|
|
if (competitionModel == null)
|
|
return;
|
|
|
|
#region 赛事状态改变时间
|
|
canStart = competitionModel.CanStart();
|
|
//比赛开始
|
|
if (count <= 0 && canStart)
|
|
{
|
|
if (!mainController.isStart && !mainController.isQuit)
|
|
{
|
|
mainController.SetStart();
|
|
}
|
|
}
|
|
//赛事结束,自动保存
|
|
var s = competitionModel.EndCountDown();
|
|
if (s.Item1 <= 0 && !mainController.cyclingController.recorderData.Saved && !mainController.isWatch)
|
|
{
|
|
SaveRide(null);
|
|
}
|
|
////显示结果(观察者要等到赛事结束才弹出)
|
|
var ishowResult = ((competitionModel.mapCompetition?.HasRecord ?? false) || competitionModel.recorderData.Saved) || (mainController.isWatch && competitionModel.CanQuit());
|
|
if (ishowResult)
|
|
{
|
|
ShowResultList();
|
|
}
|
|
//显示观众
|
|
var watchList = mainController.GetWatcherList();
|
|
watchPanel.SetActive(watchList.Count > 0);
|
|
#endregion
|
|
|
|
}
|
|
|
|
public override void SaveRide(BaseEventData baseEventData)
|
|
{
|
|
//观察者退出
|
|
if (mainController.isWatch)
|
|
{
|
|
SceneManager.LoadScene("MainScene");
|
|
return;
|
|
}
|
|
//参赛者保存并弹出赛事结果
|
|
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)
|
|
{
|
|
#if UNITY_IOS || UNITY_ANDROID
|
|
competitionRankingList = Instantiate(Resources.Load<GameObject>("UI/Prefab/Match/Mobile/CompetitionRankingPanel"), uipanel.transform);
|
|
#else
|
|
competitionRankingList = Instantiate(Resources.Load<GameObject>("UI/Prefab/Match/CompetitionRankingPanel"), uipanel.transform);
|
|
#endif
|
|
}
|
|
if (topRankPanel == null)
|
|
{
|
|
#if UNITY_IOS || UNITY_ANDROID
|
|
topRankPanel = Instantiate(Resources.Load<GameObject>("UI/Prefab/Match/Mobile/TopRankPanel"), uipanel.transform);
|
|
#else
|
|
topRankPanel = Instantiate(Resources.Load<GameObject>("UI/Prefab/Match/TopRankPanel"), uipanel.transform);
|
|
#endif
|
|
}
|
|
}
|
|
GameObject competitionResultPanel;
|
|
GameObject topRankPanel;
|
|
//实时刷新显示比赛结果
|
|
public void ShowResultList()
|
|
{
|
|
if (competitionResultPanel == null)
|
|
{
|
|
#if UNITY_IOS || UNITY_ANDROID
|
|
competitionResultPanel = Instantiate(Resources.Load<GameObject>("UI/Prefab/Match/Mobile/CompetitionResultPanel"), uipanel.transform);
|
|
#else
|
|
competitionResultPanel = Instantiate(Resources.Load<GameObject>("UI/Prefab/Match/CompetitionResultPanel"), uipanel.transform);
|
|
#endif
|
|
}
|
|
}
|
|
|
|
//极简模式
|
|
public override void ClearPanel(BaseEventData baseEventData)
|
|
{
|
|
if (clearLock)
|
|
{
|
|
base.ClearPanel(baseEventData);
|
|
countDownPanel.transform.DOLocalMove(new Vector3(countDownPanel.transform.localPosition.x + isSimple * -430f, countDownPanel.transform.localPosition.y, countDownPanel.transform.localPosition.z), 1);
|
|
topRankPanel.transform.DOLocalMove(new Vector3(topRankPanel.transform.localPosition.x + isSimple * -430f, topRankPanel.transform.localPosition.y, topRankPanel.transform.localPosition.z), 1);
|
|
competitionRankingList.transform.DOLocalMove(new Vector3(competitionRankingList.transform.localPosition.x + isSimple * 430f, competitionRankingList.transform.localPosition.y, competitionRankingList.transform.localPosition.z), 1);
|
|
watchPanel.transform.DOLocalMove(new Vector3(watchPanel.transform.localPosition.x, watchPanel.transform.localPosition.y + isSimple * 260f, watchPanel.transform.localPosition.z), 1);
|
|
}
|
|
}
|
|
|
|
public void SetMobileViewButton(bool enabled)
|
|
{
|
|
#if UNITY_IOS || UNITY_ANDROID
|
|
//viewButton.enabled = enabled;
|
|
viewButton.interactable = enabled;
|
|
#endif
|
|
}
|
|
|
|
protected override void StopRide(BaseEventData baseEventData)
|
|
{
|
|
if (!App.MainSceneParam.ContainsKey("Name"))
|
|
{
|
|
App.MainSceneParam.Add("Name", "RaceHomePanel");
|
|
}
|
|
else
|
|
{
|
|
App.MainSceneParam["Name"] = "RaceHomePanel";
|
|
}
|
|
if (mainController.isWatch)
|
|
{
|
|
UIManager.ShowConfirm("Quit", "Do you want to quit?", async () =>
|
|
{
|
|
SceneManager.LoadScene("MainScene");
|
|
UIManager.CloseConfirm();
|
|
});
|
|
}
|
|
//参赛者:提醒是否退出并保存赛事结果
|
|
else
|
|
{
|
|
base.StopRide(baseEventData);
|
|
}
|
|
}
|
|
}
|
|
}
|