using Assets.Scripts; using System; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.SceneManagement; using UnityEngine.UI; namespace Assets.Scenes.Ride.Scripts { public class RaceAlertController : PFUIPanel { public Text Content { get; set; } public Text Timer { get; set; } public GameObject GoBtn { get; set; } public GameObject Card { get; set; } public GameObject StayBtn { get; set; } public int ticks = 0; public int CompetitionId { get; set; } public int RouteId { get; set; } protected override void Awake() { //Card Timer = this.transform.Find("Card/Timer")?.GetComponent(); Content = this.transform.Find("Card/Content").GetComponent(); GoBtn = this.transform.Find("Card/Go").gameObject; StayBtn = this.transform.Find("Card/Stay").gameObject; Card = this.transform.Find("Card").gameObject; UIManager.AddEvent(GoBtn, UnityEngine.EventSystems.EventTriggerType.PointerClick, Go); UIManager.AddEvent(StayBtn, UnityEngine.EventSystems.EventTriggerType.PointerClick, Stay); } float t = 1f; private void Update() { t -= Time.deltaTime; while (t <= 0) { if (ticks > 0) { ticks--; if (Timer != null) { Timer.text = Helper.FormatTicks(ticks); } } t += 1f; } } public void Set(DateTime startTime, DateTime now,string title, string sceneName, int competitionId,int routeId) { ticks = (int)(startTime - now).TotalSeconds; var content = $"Your {Helper.SubStr(title,10)} race about to start"; Content.text = content; CompetitionId = competitionId; RouteId = routeId; } //切换到当前用户视角 public void Go(BaseEventData baseEventData) { App.CompetitionIdList.Add(CompetitionId); App.CompetionId = CompetitionId; App.RouteIdParam = RouteId; SceneManager.LoadScene("Ride"); } public void Stay(BaseEventData baseEventData) { App.CompetitionIdList.Add(CompetitionId); this.Close(); Utils.DestroyChildren(transform); DestroyImmediate(gameObject); } } }