105 lines
2.8 KiB
C#
105 lines
2.8 KiB
C#
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using XCharts;
|
|
using XUGL;
|
|
using System.Linq;
|
|
|
|
namespace Assets.Scenes.Ride.Scripts
|
|
{
|
|
|
|
public class UIManager : MonoBehaviour
|
|
{
|
|
[SerializeField]
|
|
Button startBtn;
|
|
|
|
[SerializeField]
|
|
Text speedTxt;
|
|
|
|
[SerializeField]
|
|
Text powerTxt;
|
|
|
|
[SerializeField]
|
|
Text timerTxt;
|
|
|
|
[SerializeField]
|
|
Text countDownTxt;
|
|
|
|
[SerializeField]
|
|
LineChart elevationChart;
|
|
|
|
PlayerController playerController;
|
|
MainController mainController;
|
|
private float timeRemaining = 1f;
|
|
private int count = 0;
|
|
|
|
void Awake()
|
|
{
|
|
startBtn.onClick.AddListener(StartRide);
|
|
playerController = transform.parent.Find("Player").GetComponent<PlayerController>();
|
|
mainController = FindObjectOfType<MainController>();
|
|
}
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
RenderChart();
|
|
}
|
|
|
|
private void StartRide()
|
|
{
|
|
//加个5秒钟倒计时
|
|
count = 5;
|
|
startBtn.gameObject.SetActive(false);
|
|
countDownTxt.gameObject.SetActive(true);
|
|
countDownTxt.text = count.ToString();
|
|
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
if (playerController != null)
|
|
{
|
|
speedTxt.text = $"{playerController.Speed}";
|
|
powerTxt.text = $"{playerController.Power}";
|
|
timerTxt.text = Helper.FormatTicks(playerController.TotalTicks);
|
|
|
|
if (count > 0)
|
|
{
|
|
timeRemaining -= Time.deltaTime;
|
|
if (timeRemaining <= 0)//定时器
|
|
{
|
|
count--;
|
|
if (count == 0)
|
|
{
|
|
playerController.SetStart();
|
|
countDownTxt.gameObject.SetActive(false);
|
|
}
|
|
timeRemaining = 1.0f;
|
|
}
|
|
}
|
|
countDownTxt.text = count.ToString();
|
|
|
|
UpdateChartMarkPoint();
|
|
}
|
|
}
|
|
|
|
void RenderChart()
|
|
{
|
|
elevationChart.ClearData();
|
|
var elevationArr = mainController.GetLineChartData();
|
|
foreach (var elevation in elevationArr)
|
|
{
|
|
elevationChart.AddData(0, elevation);
|
|
}
|
|
}
|
|
VertexHelper Vh;
|
|
[SerializeField] Image img;
|
|
void UpdateChartMarkPoint()
|
|
{
|
|
var dataPoints = elevationChart.series.list[0].dataPoints;
|
|
var pinLoction = dataPoints[playerController.CurrentIndex];
|
|
img.transform.localPosition = pinLoction;
|
|
}
|
|
}
|
|
}
|