powerfun-unity/Assets/Scripts/UI/Prefab/Panel/RaceAlertController.cs

96 lines
3.2 KiB
C#

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 BandContent { get; set; }
public Text Timer { get; set; }
public GameObject GoBtn { get; set; }
public GameObject Card { get; set; }
public GameObject Band { get; set; }
public GameObject BandGoBtn { get; set; }
public GameObject StayBtn { get; set; }
public GameObject BandStayBtn { 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<Text>();
Content = this.transform.Find("Card/Content").GetComponent<Text>();
GoBtn = this.transform.Find("Card/Go").gameObject;
StayBtn = this.transform.Find("Card/Stay").gameObject;
Card = this.transform.Find("Card").gameObject;
//band
BandContent = this.transform.Find("Band/Content").GetComponent<Text>();
BandGoBtn = this.transform.Find("Band/Go").gameObject;
BandStayBtn = this.transform.Find("Band/Stay").gameObject;
Band = this.transform.Find("Band").gameObject;
UIManager.AddEvent(GoBtn, UnityEngine.EventSystems.EventTriggerType.PointerClick, Go);
UIManager.AddEvent(StayBtn, UnityEngine.EventSystems.EventTriggerType.PointerClick, Stay);
UIManager.AddEvent(BandGoBtn, UnityEngine.EventSystems.EventTriggerType.PointerClick, Go);
UIManager.AddEvent(BandStayBtn, UnityEngine.EventSystems.EventTriggerType.PointerClick, Stay);
}
float t = 1f;
private void Update()
{
t -= Time.deltaTime;
while (t <= 0)
{
if (ticks > 0)
{
ticks--;
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 <color='#F93086'>{title}</color> race about to start";
Content.text = content;
BandContent.text = content;
CompetitionId = competitionId;
RouteId = routeId;
var ride = sceneName.Equals("Ride");
Card.SetActive(ride);
Band.SetActive(!ride);
}
//切换到当前用户视角
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();
}
}
}