288 lines
11 KiB
C#
288 lines
11 KiB
C#
using UnityEngine;
|
|
using DG.Tweening;
|
|
using Assets.Scenes.Ride.Scripts.Model;
|
|
using UnityEngine.EventSystems;
|
|
using UnityEngine.UI;
|
|
using UnityEngine.SceneManagement;
|
|
using Assets.Scenes.Ride.Scripts.Model.CyclingModels;
|
|
using System;
|
|
|
|
namespace Assets.Scenes.Ride.Scripts
|
|
{
|
|
public class GameRoomUIManager : 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; }
|
|
|
|
GameModel model { get; set; }
|
|
Text gameTimerText { 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);
|
|
gameTimerText = uipanel.transform.Find("ComputerPanel/GameTimer").GetComponent<Text>();
|
|
gameTimerText.gameObject.SetActive(true);
|
|
//timerTxtTitle.gameObject.SetActive(false);
|
|
//观察者模式隐藏坡度
|
|
if (mainController.isWatch)
|
|
{
|
|
nextSlopePanel.SetActive(false);
|
|
currentSlopePanel.SetActive(false);
|
|
}
|
|
altitudeGraph.gameObject.SetActive(false);
|
|
//暂停按钮禁用
|
|
pauseButton.interactable = false;
|
|
InitGameObject();
|
|
}
|
|
protected override void Update()
|
|
{
|
|
base.Update();
|
|
CountDown();
|
|
}
|
|
|
|
//开始游戏触发事件
|
|
public void StartRide(BaseEventData baseEventData)
|
|
{
|
|
this.StartRide();
|
|
}
|
|
|
|
public void StartRide(int seconds)
|
|
{
|
|
mainController.SetCyclingModel(CyclingModel.GameRoom);
|
|
startPanel.SetActive(false);
|
|
startBtn.gameObject.SetActive(false);
|
|
//如果是重新连接的话就不需要倒计时
|
|
var ss = mainController.cyclingController.recorderData.RiderDatas;
|
|
if (ss.Count > 0)
|
|
{
|
|
count = 0;
|
|
startUI(0);
|
|
countDownTxt.gameObject.SetActive(true);
|
|
countDownTxt.text = count.ToString();
|
|
}
|
|
else
|
|
{
|
|
count = seconds;
|
|
countDownTxt.gameObject.SetActive(true);
|
|
countDownTxt.text = count.ToString();
|
|
}
|
|
}
|
|
bool canStart = false;
|
|
GameObject watchPanel { get; set; }
|
|
//开始骑行-加个5秒钟倒计时
|
|
public override void StartRide()
|
|
{
|
|
|
|
}
|
|
|
|
public void InitGameObject()
|
|
{
|
|
miniMap.SetActive(false); //隐藏小地图
|
|
#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/GameRoom/GameRoomRankingPanel"), 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()
|
|
{
|
|
//倒计时开始对战
|
|
if (count > 0)
|
|
{
|
|
timeRemaining -= Time.deltaTime;
|
|
if (timeRemaining <= 0)//定时器
|
|
{
|
|
count--;
|
|
startUI(count);
|
|
timeRemaining += 1.0f;
|
|
}
|
|
}
|
|
if (mainController.isStart)
|
|
{
|
|
var ticks = playerController.TotalTicks;
|
|
gameTimerText.text = Helper.FormatTicks(ticks);
|
|
}
|
|
countDownTxt.text = count <= 0 ? App.GetLocalString("GO!") : count.ToString();
|
|
model = mainController.cyclingController as GameModel;
|
|
//第一名诞生开始倒计时,倒计时结束自动保存
|
|
if (model != null && model.FirstEndTime.HasValue && !FirstCompleted && App.CurrentUser.Id != model.FirstUserId)
|
|
{
|
|
FirstCompleted = true;
|
|
var gap = model.FirstEndTime.Value - UIManager.Now.GetDateTime();
|
|
var seconds = Math.Floor(gap.TotalSeconds);
|
|
UIManager.ShowGameRoomCountDownPanel((int)seconds, () =>
|
|
{
|
|
SaveRide(null);
|
|
}, true);
|
|
}
|
|
if (mainController.isQuit && !Saved)
|
|
{
|
|
Saved = true;
|
|
UIManager.CloseGameRoomCountDownPanel();
|
|
ShowResultList();
|
|
}
|
|
}
|
|
|
|
private void startUI(int num)
|
|
{
|
|
if (num <= 0)
|
|
{
|
|
mainController.SetStart();
|
|
var canvasGroup = countDownTxt.transform.GetComponent<CanvasGroup>();
|
|
canvasGroup.DOFade(0, 1).onComplete += () => {
|
|
countDownTxt.gameObject.SetActive(false);
|
|
canvasGroup.alpha = 1;
|
|
};
|
|
}
|
|
if (num == 1 && mainController.cyclingModel == CyclingModel.Single)
|
|
{
|
|
reviewPanel.GetComponent<CanvasGroup>().DOFade(0, 1).onComplete += () => {
|
|
reviewPanel.gameObject.SetActive(false);
|
|
};
|
|
}
|
|
countDownTxt.transform.DOPunchScale(new Vector3(1.2f, 1.2f, 1.2f), 1, 1, 1);
|
|
countDownTxt.text = num <= 0 ? App.GetLocalString("GO!") : num.ToString();
|
|
model = mainController.cyclingController as GameModel;
|
|
}
|
|
|
|
private bool FirstCompleted;
|
|
|
|
private bool Saved;
|
|
|
|
public override void SaveRide(BaseEventData baseEventData)
|
|
{
|
|
//观察者退出
|
|
if (mainController.isWatch)
|
|
{
|
|
SceneManager.LoadScene("MainScene");
|
|
return;
|
|
}
|
|
//参赛者保存并弹出赛事结果
|
|
if (!mainController.isQuit)
|
|
{
|
|
mainController.SetQuit();
|
|
playerController.Upload();
|
|
quitPanel.SetActive(false);
|
|
transform.Find("ModalPanel").gameObject.SetActive(false);
|
|
}
|
|
ShowResultList();//保存显示当前排名
|
|
}
|
|
|
|
public override void ContinueRide()
|
|
{
|
|
//mainController.SetCyclingModel(CyclingModel.GameRoom);
|
|
}
|
|
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/GameRoom/GameRoomRankingPanel"), 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/GameRoomResultPanel"), uipanel.transform);
|
|
#else
|
|
competitionResultPanel = Instantiate(Resources.Load<GameObject>("UI/Prefab/GameRoom/GameRoomResultPanel"), 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 (mainController.isWatch)
|
|
{
|
|
UIManager.ShowConfirm("Quit", "Do you want to quit?", async () =>
|
|
{
|
|
SceneManager.LoadScene("MainScene");
|
|
UIManager.CloseConfirm();
|
|
});
|
|
}
|
|
//参赛者:提醒是否退出并保存赛事结果
|
|
else
|
|
{
|
|
base.StopRide(baseEventData);
|
|
}
|
|
}
|
|
}
|
|
}
|