2021-03-25 16:22:09 +08:00
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
using UnityEngine.UI;
|
2021-03-28 18:17:15 +08:00
|
|
|
|
using XCharts;
|
|
|
|
|
|
using XUGL;
|
|
|
|
|
|
using System.Linq;
|
2021-03-29 20:32:30 +08:00
|
|
|
|
using System.Collections;
|
|
|
|
|
|
using Mapbox.Unity.Map;
|
|
|
|
|
|
using DG.Tweening;
|
2021-03-30 17:15:16 +08:00
|
|
|
|
using System;
|
|
|
|
|
|
using Assets.Scenes.Ride.Scripts.Model;
|
2021-03-25 16:22:09 +08:00
|
|
|
|
|
|
|
|
|
|
namespace Assets.Scenes.Ride.Scripts
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
public class UIManager : MonoBehaviour
|
|
|
|
|
|
{
|
2021-03-30 17:15:16 +08:00
|
|
|
|
#region UI control
|
2021-03-25 16:22:09 +08:00
|
|
|
|
[SerializeField]
|
2021-03-30 17:15:16 +08:00
|
|
|
|
Button startBtn;//开始按钮
|
2021-03-29 20:32:30 +08:00
|
|
|
|
[SerializeField]
|
2021-03-30 17:15:16 +08:00
|
|
|
|
Button simpleBtn;//进入简约模式按钮
|
2021-03-29 20:32:30 +08:00
|
|
|
|
[SerializeField]
|
2021-03-30 17:15:16 +08:00
|
|
|
|
Text ditance;//当前骑行距离
|
2021-03-29 20:32:30 +08:00
|
|
|
|
[SerializeField]
|
2021-03-30 17:15:16 +08:00
|
|
|
|
Text candance;//踏频
|
2021-03-25 16:22:09 +08:00
|
|
|
|
[SerializeField]
|
2021-03-30 17:15:16 +08:00
|
|
|
|
Text heartRate;//心率
|
2021-03-25 16:22:09 +08:00
|
|
|
|
[SerializeField]
|
2021-03-30 17:15:16 +08:00
|
|
|
|
GameObject rightPanel;//右边列表
|
2021-03-25 16:22:09 +08:00
|
|
|
|
[SerializeField]
|
2021-03-30 17:15:16 +08:00
|
|
|
|
GameObject leftPanel;//左边列表
|
2021-03-25 16:22:09 +08:00
|
|
|
|
[SerializeField]
|
2021-03-30 17:15:16 +08:00
|
|
|
|
Text speedTxt;//当前速度
|
|
|
|
|
|
[SerializeField]
|
|
|
|
|
|
Text powerTxt;//功率
|
|
|
|
|
|
[SerializeField]
|
|
|
|
|
|
Text timerTxt;//计时器
|
2021-03-28 18:17:15 +08:00
|
|
|
|
[SerializeField]
|
2021-03-30 17:15:16 +08:00
|
|
|
|
Text countDownTxt;//倒计时5s
|
|
|
|
|
|
[SerializeField] LineChart elevationChart;//海拔图
|
|
|
|
|
|
[SerializeField] Image img;//当前用户头像
|
|
|
|
|
|
[SerializeField]
|
|
|
|
|
|
Button StartOrPauseButton;//暂停按钮
|
|
|
|
|
|
[SerializeField]
|
|
|
|
|
|
Button SettingButton;//设置那妞
|
|
|
|
|
|
[SerializeField]
|
|
|
|
|
|
Button DeviceButton;//设备按钮
|
|
|
|
|
|
[SerializeField]
|
|
|
|
|
|
Button ExitButton;//退出按钮
|
|
|
|
|
|
#endregion
|
2021-03-28 18:17:15 +08:00
|
|
|
|
|
2021-03-30 17:15:16 +08:00
|
|
|
|
#region 控制器
|
|
|
|
|
|
|
|
|
|
|
|
PlayerController playerController;//当前用户
|
|
|
|
|
|
CyclingController mainController;//主控制器
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
2021-03-29 20:32:30 +08:00
|
|
|
|
|
2021-03-25 16:22:09 +08:00
|
|
|
|
private float timeRemaining = 1f;
|
|
|
|
|
|
private int count = 0;
|
2021-03-28 18:17:15 +08:00
|
|
|
|
|
|
|
|
|
|
void Awake()
|
|
|
|
|
|
{
|
|
|
|
|
|
startBtn.onClick.AddListener(StartRide);
|
2021-03-29 20:32:30 +08:00
|
|
|
|
simpleBtn.onClick.AddListener(ClearPanel);
|
2021-03-30 17:15:16 +08:00
|
|
|
|
StartOrPauseButton.onClick.AddListener(PauseRide);
|
|
|
|
|
|
SettingButton.onClick.AddListener(ShowSettingPanel);
|
|
|
|
|
|
DeviceButton.onClick.AddListener(ShowDevicePanel);
|
|
|
|
|
|
ExitButton.onClick.AddListener(StopRide);
|
|
|
|
|
|
|
2021-03-29 20:32:30 +08:00
|
|
|
|
playerController = FindObjectOfType<PlayerController>();
|
2021-03-30 17:15:16 +08:00
|
|
|
|
mainController = FindObjectOfType<CyclingController>();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//根据不同的骑行模式渲染不同的UI界面
|
|
|
|
|
|
void InitUI(CyclingModel cyclingModel)
|
|
|
|
|
|
{
|
|
|
|
|
|
|
2021-03-28 18:17:15 +08:00
|
|
|
|
}
|
2021-03-29 20:32:30 +08:00
|
|
|
|
|
2021-03-25 16:22:09 +08:00
|
|
|
|
void Start()
|
|
|
|
|
|
{
|
2021-03-28 18:17:15 +08:00
|
|
|
|
RenderChart();
|
2021-03-25 16:22:09 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void StartRide()
|
|
|
|
|
|
{
|
|
|
|
|
|
//加个5秒钟倒计时
|
|
|
|
|
|
count = 5;
|
|
|
|
|
|
startBtn.gameObject.SetActive(false);
|
|
|
|
|
|
countDownTxt.gameObject.SetActive(true);
|
|
|
|
|
|
countDownTxt.text = count.ToString();
|
2021-03-29 20:32:30 +08:00
|
|
|
|
}
|
2021-03-30 17:15:16 +08:00
|
|
|
|
//暂停游戏
|
|
|
|
|
|
private void PauseRide()
|
|
|
|
|
|
{
|
|
|
|
|
|
playerController.SetPause();
|
|
|
|
|
|
startBtn.gameObject.SetActive(true);
|
|
|
|
|
|
}
|
|
|
|
|
|
//结束游戏
|
|
|
|
|
|
private void StopRide()
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
//显示设备连接
|
|
|
|
|
|
private void ShowDevicePanel()
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
//显示设置
|
|
|
|
|
|
private void ShowSettingPanel()
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
2021-03-29 20:32:30 +08:00
|
|
|
|
int isSimple = 1;
|
2021-03-30 17:15:16 +08:00
|
|
|
|
//TODO:简约模式
|
2021-03-29 20:32:30 +08:00
|
|
|
|
private void ClearPanel()
|
|
|
|
|
|
{
|
2021-03-30 17:15:16 +08:00
|
|
|
|
leftPanel.transform.DOLocalMove(new Vector3(leftPanel.transform.localPosition.x + isSimple * -430f, leftPanel.transform.localPosition.y, leftPanel.transform.localPosition.z), 1);
|
|
|
|
|
|
rightPanel.transform.DOLocalMove(new Vector3(rightPanel.transform.localPosition.x+ isSimple* 330f, rightPanel.transform.localPosition.y, rightPanel.transform.localPosition.z), 1);
|
|
|
|
|
|
//elevationChart.transform.DOMoveX(elevationChart.transform.position.x + isSimple * 286.1764f, 1);
|
|
|
|
|
|
isSimple *= -1;
|
2021-03-25 16:22:09 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Update is called once per frame
|
|
|
|
|
|
void Update()
|
|
|
|
|
|
{
|
2021-03-30 17:15:16 +08:00
|
|
|
|
//获取当前选中玩家绑定当前UI
|
2021-03-25 16:22:09 +08:00
|
|
|
|
if (playerController != null)
|
|
|
|
|
|
{
|
2021-03-30 17:15:16 +08:00
|
|
|
|
//绑定UI
|
2021-03-25 16:22:09 +08:00
|
|
|
|
speedTxt.text = $"{playerController.Speed}";
|
|
|
|
|
|
powerTxt.text = $"{playerController.Power}";
|
|
|
|
|
|
timerTxt.text = Helper.FormatTicks(playerController.TotalTicks);
|
2021-03-30 17:15:16 +08:00
|
|
|
|
ditance.text = $"{Math.Round(playerController.TotalDistance,2)}KM";
|
|
|
|
|
|
heartRate.text = $"{Math.Round(playerController.HeartRate, 0)}";
|
|
|
|
|
|
candance.text = $"{Math.Round(playerController.Cadance, 0)}";
|
|
|
|
|
|
//倒计时
|
2021-03-25 16:22:09 +08:00
|
|
|
|
if (count > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
timeRemaining -= Time.deltaTime;
|
|
|
|
|
|
if (timeRemaining <= 0)//定时器
|
|
|
|
|
|
{
|
|
|
|
|
|
count--;
|
|
|
|
|
|
if (count == 0)
|
|
|
|
|
|
{
|
2021-03-28 18:17:15 +08:00
|
|
|
|
playerController.SetStart();
|
2021-03-25 16:22:09 +08:00
|
|
|
|
countDownTxt.gameObject.SetActive(false);
|
|
|
|
|
|
}
|
|
|
|
|
|
timeRemaining = 1.0f;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
countDownTxt.text = count.ToString();
|
2021-03-30 17:15:16 +08:00
|
|
|
|
//移动海拔图头像 TODO:移动所有人的头像
|
2021-03-29 20:32:30 +08:00
|
|
|
|
MoveChartMarkPoint();
|
2021-03-25 16:22:09 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2021-03-30 17:15:16 +08:00
|
|
|
|
//初始化海拔图
|
2021-03-28 18:17:15 +08:00
|
|
|
|
void RenderChart()
|
|
|
|
|
|
{
|
|
|
|
|
|
elevationChart.ClearData();
|
|
|
|
|
|
var elevationArr = mainController.GetLineChartData();
|
|
|
|
|
|
foreach (var elevation in elevationArr)
|
|
|
|
|
|
{
|
|
|
|
|
|
elevationChart.AddData(0, elevation);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2021-03-29 20:32:30 +08:00
|
|
|
|
|
|
|
|
|
|
void MoveChartMarkPoint()
|
2021-03-28 18:17:15 +08:00
|
|
|
|
{
|
2021-03-30 17:15:16 +08:00
|
|
|
|
var dataPoints = elevationChart.series.list[0].dataPoints.OrderBy(c=>c.x).ToList();
|
2021-03-29 20:32:30 +08:00
|
|
|
|
if (dataPoints.Count > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
var pinLoction = dataPoints[playerController.CurrentIndex];
|
|
|
|
|
|
pinLoction.y += 10;
|
|
|
|
|
|
img.transform.localPosition = pinLoction;
|
|
|
|
|
|
}
|
2021-03-28 18:17:15 +08:00
|
|
|
|
}
|
2021-03-25 16:22:09 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|