2021-11-24 10:15:28 +08:00

86 lines
3.1 KiB
C#

using Assets.Scenes.Ride.Scripts.Model;
using Assets.Scenes.Ride.Scripts.Model.CyclingModels;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.UI;
namespace Assets.Scenes.Ride.Scripts
{
public class CountDownFactory : MonoBehaviour
{
Text Title { get; set; }
Text CountTimer { get; set; }
Text TimerTitle { get; set; }
Text Timer { get; set; }
CompetitionModel competitionModel { get; set; }
CyclingController cyclingController { get; set; }
private void Start()
{
cyclingController = FindObjectOfType<CyclingController>();
Title = transform.Find("Title").GetComponent<Text>();
CountTimer = transform.Find("Timer").GetComponent<Text>();
TimerTitle = transform.Find("ConpetitionTimerTitle").GetComponent<Text>();
Timer = transform.Find("ConpetitionTimer").GetComponent<Text>();
}
GameObject competitionResultPanel { get; set; }
private void Update()
{
if (competitionModel == null)
{
competitionModel = cyclingController.cyclingController as CompetitionModel;
}
if (competitionModel != null)
{
var count = competitionModel.StartCountdown();
//比赛开始前倒计时
if (count >= 0 && !competitionModel.recorderData.Saved)
{
ShowCountDown(count, "Get Ready!");//显示倒计时面板信息
Timer.gameObject.SetActive(false);
TimerTitle.gameObject.SetActive(false);
}
else
{
var s = competitionModel.EndCountDown();
var isAutoSave = s.Item1 <= 0 && !cyclingController.cyclingController.recorderData.Saved && !cyclingController.isWatch;
//显示关门时间
if (s.Item3 && !isAutoSave)
{
#if UNITY_IOS || UNITY_ANDROID
//显示倒计时面板信息
ShowCountDown(s.Item1, "Time Limit");
#else
ShowCountDown(s.Item1, "Get The First Place. Time Limit");
#endif
}
else if (s.Item1 >= 0)
{
//显示倒计时面板信息
//ShowCountDown(s.Item1, "remaining");
ShowCountDown(s.Item1, "Remaining Time");
}
//显示当前选手骑行时间
Timer.gameObject.SetActive(true);
TimerTitle.gameObject.SetActive(true);
Timer.text = Helper.FormatTicks(s.Item2);// Helper.FormatTicks(cyclingController.currentPlayer.TotalTicks);
}
}
}
private void ShowCountDown(int count, string text)
{
Title.text = text;
if (count >= 0)
{
CountTimer.text = Helper.FormatTicks(count);
}
}
}
}