130 lines
3.6 KiB
C#
130 lines
3.6 KiB
C#
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using XCharts;
|
|
using XUGL;
|
|
using System.Linq;
|
|
using System.Collections;
|
|
using Mapbox.Unity.Map;
|
|
using DG.Tweening;
|
|
|
|
namespace Assets.Scenes.Ride.Scripts
|
|
{
|
|
|
|
public class UIManager : MonoBehaviour
|
|
{
|
|
[SerializeField]
|
|
Button startBtn;
|
|
[SerializeField]
|
|
Button simpleBtn;
|
|
|
|
[SerializeField]
|
|
GameObject rightPanel;
|
|
[SerializeField]
|
|
GameObject leftPanel;
|
|
|
|
[SerializeField]
|
|
Text speedTxt;
|
|
|
|
[SerializeField]
|
|
Text powerTxt;
|
|
|
|
[SerializeField]
|
|
Text timerTxt;
|
|
|
|
[SerializeField]
|
|
Text countDownTxt;
|
|
|
|
[SerializeField]
|
|
LineChart elevationChart;
|
|
|
|
[SerializeField] Image img;
|
|
|
|
PlayerController playerController;
|
|
MainController mainController;
|
|
private float timeRemaining = 1f;
|
|
private int count = 0;
|
|
|
|
void Awake()
|
|
{
|
|
startBtn.onClick.AddListener(StartRide);
|
|
simpleBtn.onClick.AddListener(ClearPanel);
|
|
playerController = FindObjectOfType<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();
|
|
}
|
|
int isSimple = 1;
|
|
private void ClearPanel()
|
|
{
|
|
leftPanel.transform.DOMoveX(leftPanel.transform.position.x+isSimple * 286.1764f, 1);
|
|
rightPanel.transform.DOMoveX(rightPanel.transform.position.x - isSimple * 286.1764f, 1);
|
|
elevationChart.transform.DOMoveX(elevationChart.transform.position.x + isSimple * 286.1764f, 1);
|
|
}
|
|
|
|
// 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();
|
|
|
|
MoveChartMarkPoint();
|
|
}
|
|
}
|
|
|
|
void RenderChart()
|
|
{
|
|
elevationChart.ClearData();
|
|
var elevationArr = mainController.GetLineChartData();
|
|
foreach (var elevation in elevationArr)
|
|
{
|
|
elevationChart.AddData(0, elevation);
|
|
}
|
|
}
|
|
|
|
void MoveChartMarkPoint()
|
|
{
|
|
var dataPoints = elevationChart.series.list[0].dataPoints;
|
|
if (dataPoints.Count > 0)
|
|
{
|
|
var pinLoction = dataPoints[playerController.CurrentIndex];
|
|
Debug.Log(pinLoction);
|
|
Debug.Log(dataPoints[0]);
|
|
pinLoction.y += 10;
|
|
img.transform.localPosition = pinLoction;
|
|
}
|
|
}
|
|
}
|
|
}
|