2023-05-15 15:11:50 +08:00

86 lines
3.2 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, App.GetLocalString("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, App.GetLocalString("Close Gate"));
#else
ShowCountDown(s.Item1, App.GetLocalString("GetCloseGate"));
#endif
}
else if (s.Item1 >= 0)
{
//显示倒计时面板信息
//ShowCountDown(s.Item1, "remaining");
ShowCountDown(s.Item1, App.GetLocalString("Remaining"));
}
//显示当前选手骑行时间
//CountTimer.gameObject.SetActive(true);
//TimerTitle.gameObject.SetActive(true);
CountTimer.text = Helper.FormatTicks(s.Item2);// Helper.FormatTicks(cyclingController.currentPlayer.TotalTicks);
}
}
}
private void ShowCountDown(int count, string text)
{
TimerTitle.text = text;
if (count >= 0)
{
Timer.text = Helper.FormatTicks(count);
}
}
}
}