723 lines
34 KiB
C#
723 lines
34 KiB
C#
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using System.Linq;
|
|
using Mapbox.Unity.Map;
|
|
using DG.Tweening;
|
|
using System;
|
|
using UnityEngine.SceneManagement;
|
|
using System.Collections.Generic;
|
|
using UnityEngine.EventSystems;
|
|
using ChartAndGraph;
|
|
using Assets.Scripts;
|
|
using Assets.Scripts.Apis.Models;
|
|
|
|
namespace Assets.Scenes.Ride.Scripts
|
|
{
|
|
|
|
public class BaseUIManager : MonoBehaviour
|
|
{
|
|
#region UI control
|
|
protected GameObject target;
|
|
protected GameObject nearByPanel;//附近的人列表
|
|
protected GameObject leftPanel;//伴侣骑行列表
|
|
protected GameObject nextSlopePanel;//下一个坡度面板
|
|
protected GameObject currentSlopePanel;//当前坡度面板
|
|
protected GameObject selectPanel;//骑行模式选择
|
|
protected GameObject selectPlayer;//伴侣骑行选择窗口
|
|
protected GameObject reviewPanel;
|
|
protected GameObject titlePanel;
|
|
protected GameObject quitPanel;//退出界面
|
|
protected GameObject cancelPanel;//退出(骑行里程较短不给保存)
|
|
|
|
protected Text nextSlopeText;//下一个坡度
|
|
protected Text nextSlopeDistanceText;//下一个坡度距离
|
|
protected Text currentSlopeText;//当前坡度
|
|
protected Text currentSlopeDistanceText;//当前坡度已骑行距离
|
|
protected Text currentSlopeToatalDistanceText;//当前坡度总距离
|
|
protected Text speedTxt;//当前速度
|
|
protected Text powerTxt;//功率
|
|
protected Text timerTxt { get; set; }//计时器
|
|
protected Text timerTxtTitle;//计时器标题
|
|
protected Text ditance;//当前骑行距离
|
|
protected Text totalDistance;//当前骑行距离
|
|
protected Text candance;//踏频
|
|
protected Text heartRate;//心率
|
|
protected Text countDownTxt;//倒计时5s
|
|
protected Text mapName;//路书名称
|
|
protected Text fps;//fps
|
|
protected Text totalClimb;
|
|
|
|
protected Button startBtn;//开始按钮
|
|
protected Button simpleBtn;//进入简约模式按钮
|
|
protected Button pauseButton;//暂停按钮
|
|
protected Button settingButton;//设置那妞
|
|
protected Button deviceButton;//设备按钮
|
|
protected Button viewButton;//视角按钮
|
|
protected Button exitButton;//退出按钮
|
|
protected Button singleButton;//单人骑行按钮
|
|
protected Button shadowButton;//影子选手按钮
|
|
protected Button addButton;//添加伴侣骑行
|
|
protected Button saveButton;//退出panel保存按钮
|
|
protected Button cancelQuitButton;//退出panel取消按钮
|
|
protected Button closeQuitButton;//退出panel关闭按钮
|
|
|
|
protected RawImage head;//海拔图头像
|
|
protected GameObject miniMap;//小地图
|
|
protected GameObject toolbar;//toolbar
|
|
protected RawImage altitudeGraph;//海拔图
|
|
protected Image leftImage;
|
|
protected Image rightImage;
|
|
protected Image area;
|
|
#endregion
|
|
|
|
#region 控制器
|
|
|
|
protected PlayerController playerController;//当前用户
|
|
protected CyclingController mainController;//主控制器
|
|
|
|
#endregion
|
|
|
|
protected float timeRemaining = 1f;
|
|
protected int count = 0;
|
|
protected Image arrow;
|
|
protected AbstractMap map;
|
|
protected Transform t;
|
|
protected GameObject alertPanel;
|
|
protected Button alertBtn;
|
|
protected Button alertCloseBtn;
|
|
protected Text preSlopeText;
|
|
protected GameObject startPanel;
|
|
protected GameObject headPanel;
|
|
protected GameObject settingPanel;
|
|
protected Button abandonButton;
|
|
protected GameObject singleArea;
|
|
protected Sprite downhill1;
|
|
protected Sprite uphill1;
|
|
protected Sprite straight;
|
|
|
|
protected Sprite downhill1Small;
|
|
protected Sprite uphill1Small;
|
|
protected Sprite straightSmall;
|
|
|
|
protected Image nextSlopeImage;
|
|
protected Image currentSlopeImage;
|
|
protected Image miniMapProcess;
|
|
protected Image currentSlopeProcess;
|
|
protected Text miniMapProcessText;
|
|
|
|
protected Slider cameraSlider;
|
|
|
|
protected Transform graphChart;
|
|
|
|
protected virtual void Awake()
|
|
{
|
|
|
|
}
|
|
protected virtual void Start()
|
|
{
|
|
InitData();//初始
|
|
|
|
}
|
|
Text totalDistanceCompetition { get; set; }
|
|
GameObject distanceIconCompetition { get; set; }
|
|
GameObject totalDistanceIcon { get; set; }
|
|
|
|
GameObject QuitButton;
|
|
GameObject CancelButton;
|
|
GameObject modalPanel;
|
|
private void InitGameObject()
|
|
{
|
|
#region 控件获取与事件绑定
|
|
fps = uipanel.transform.Find("FPS").GetComponent<Text>();
|
|
arrow = uipanel.transform.Find("Arrow").GetComponent<Image>();
|
|
map = transform.parent.Find("Map").GetComponent<AbstractMap>();
|
|
leftPanel = uipanel.transform.Find("ReviewPanel").gameObject;
|
|
nearByPanel = uipanel.transform.Find("NearPanel").gameObject;
|
|
startPanel = uipanel.transform.Find("StartPanel").gameObject;
|
|
startBtn = uipanel.transform.Find("StartPanel/StartButton").GetComponent<Button>();
|
|
simpleBtn = uipanel.transform.Find("SimpleButton").GetComponent<Button>();
|
|
ditance = uipanel.transform.Find("ComputerPanel/Distance").GetComponent<Text>();
|
|
titlePanel = uipanel.transform.Find("TitlePanel").gameObject;
|
|
totalDistance = uipanel.transform.Find("TitlePanel/TotalDistance").GetComponent<Text>();
|
|
totalDistanceIcon = uipanel.transform.Find("TitlePanel/DistanceIcon").gameObject;
|
|
|
|
candance = uipanel.transform.Find("PowerPanel/Cadance").GetComponent<Text>();
|
|
heartRate = uipanel.transform.Find("PowerPanel/Hrv").GetComponent<Text>();
|
|
nextSlopePanel = uipanel.transform.Find("NextSlopePanel").gameObject;
|
|
currentSlopePanel = uipanel.transform.Find("CurrentSlopePanel").gameObject;
|
|
nextSlopeText = uipanel.transform.Find("NextSlopePanel/NextSlopeText").GetComponent<Text>();
|
|
nextSlopeDistanceText = uipanel.transform.Find("NextSlopePanel/NextSlopeDistance").GetComponent<Text>();
|
|
currentSlopeText = uipanel.transform.Find("CurrentSlopePanel/CurrentSlopeText").GetComponent<Text>();
|
|
#if UNITY_IOS || UNITY_ANDROID
|
|
totalDistanceCompetition = uipanel.transform.Find("TitlePanel/TotalDistanceCompetition").GetComponent<Text>();
|
|
distanceIconCompetition = uipanel.transform.Find("TitlePanel/DistanceIconCompetition").gameObject;
|
|
nextSlopeText = uipanel.transform.Find("CurrentSlopePanel/NextSlopeText").GetComponent<Text>();
|
|
#endif
|
|
currentSlopeDistanceText = uipanel.transform.Find("CurrentSlopePanel/CurrentSlopeDistance").GetComponent<Text>();
|
|
currentSlopeToatalDistanceText = uipanel.transform.Find("CurrentSlopePanel/TotalSlopeDistance").GetComponent<Text>();
|
|
currentSlopeProcess = uipanel.transform.Find("CurrentSlopePanel/Process").GetComponent<Image>();
|
|
|
|
speedTxt = uipanel.transform.Find("ComputerPanel/Speed").GetComponent<Text>();
|
|
powerTxt = uipanel.transform.Find("PowerPanel/Power").GetComponent<Text>();
|
|
timerTxt = uipanel.transform.Find("ComputerPanel/Timer").GetComponent<Text>();
|
|
timerTxtTitle = uipanel.transform.Find("ComputerPanel/TimerTitle").GetComponent<Text>();
|
|
countDownTxt = uipanel.transform.Find("CountDown").GetComponent<Text>();
|
|
mapName = uipanel.transform.Find("TitlePanel/MapName").GetComponent<Text>();
|
|
totalClimb = uipanel.transform.Find("ComputerPanel/TotalClimb").GetComponent<Text>();
|
|
//img = uipanel.transform.Find("ElevationChart/HeadImage").GetComponent<RawImage>();
|
|
graphChart = uipanel.transform.Find("GraphChart");
|
|
head = graphChart.Find("HeadPanel/Head").GetComponent<RawImage>();
|
|
headPanel = graphChart.Find("HeadPanel").gameObject;
|
|
t = graphChart.Find("Button");
|
|
|
|
miniMap = uipanel.transform.Find("MiniMap").gameObject;
|
|
|
|
alertPanel = uipanel.transform.Find("Alert").gameObject;
|
|
|
|
selectPanel = uipanel.transform.Find("SelectPanel").gameObject;
|
|
selectPlayer = uipanel.transform.Find("SelectPlayer").gameObject;
|
|
reviewPanel = uipanel.transform.Find("ReviewPanel").gameObject;
|
|
#if UNITY_IOS || UNITY_ANDROID
|
|
modalPanel = transform.Find("ModalPanel").gameObject;
|
|
var cancelPanelPrefab = Resources.Load<GameObject>("UI/Prefab/Ride/Mobile/CancelPanel");
|
|
var quitPanelPrefab = Resources.Load<GameObject>("UI/Prefab/Ride/Mobile/QuitPanel");
|
|
quitPanel = Instantiate<GameObject>(quitPanelPrefab, modalPanel.transform);
|
|
cancelPanel = Instantiate<GameObject>(cancelPanelPrefab, modalPanel.transform);
|
|
quitPanel.SetActive(false);
|
|
cancelPanel.SetActive(false);
|
|
#else
|
|
var modalPanel = transform.Find("ModalPanel");
|
|
var cancelPanelPrefab = Resources.Load<GameObject>("UI/Prefab/Ride/CancelPanel");
|
|
var quitPanelPrefab = Resources.Load<GameObject>("UI/Prefab/Ride/QuitPanel");
|
|
quitPanel = Instantiate<GameObject>(quitPanelPrefab, modalPanel);
|
|
cancelPanel = Instantiate<GameObject>(cancelPanelPrefab, modalPanel);
|
|
quitPanel.SetActive(false);
|
|
cancelPanel.SetActive(false);
|
|
#endif
|
|
QuitButton = cancelPanel.transform.Find("QuitButton").gameObject;
|
|
CancelButton = cancelPanel.transform.Find("CancelButton").gameObject;
|
|
|
|
pauseButton = uipanel.transform.Find("ToolBarPanel/StartOrPauseButton").GetComponent<Button>();
|
|
settingButton = uipanel.transform.Find("ToolBarPanel/SettingButton").GetComponent<Button>();
|
|
deviceButton = uipanel.transform.Find("ToolBarPanel/DeviceButton").GetComponent<Button>();
|
|
exitButton = uipanel.transform.Find("ToolBarPanel/ExitButton").GetComponent<Button>();
|
|
|
|
singleButton = uipanel.transform.Find("SelectPanel/SingleButton").GetComponent<Button>();
|
|
shadowButton = uipanel.transform.Find("SelectPanel/ShadowButton").GetComponent<Button>();
|
|
|
|
singleArea = uipanel.transform.Find("ReviewPanel/SingleArea").gameObject;
|
|
addButton = uipanel.transform.Find("ReviewPanel/SingleArea/AddButton").GetComponent<Button>();
|
|
|
|
saveButton = quitPanel.transform.Find("SaveButton").GetComponent<Button>();
|
|
cancelQuitButton = quitPanel.transform.Find("CancelButton").GetComponent<Button>();
|
|
closeQuitButton = quitPanel.transform.Find("CloseButton").GetComponent<Button>();
|
|
abandonButton = quitPanel.transform.Find("AbandonButton").GetComponent<Button>();
|
|
|
|
viewButton = uipanel.transform.Find("ViewButton").GetComponent<Button>();
|
|
#if UNITY_IOS || UNITY_ANDROID
|
|
viewButton = uipanel.transform.Find("ToolBarPanel/ViewButton").GetComponent<Button>();
|
|
#endif
|
|
toolbar = uipanel.transform.Find("ToolBarPanel").gameObject;
|
|
altitudeGraph = uipanel.transform.Find("TitlePanel/AltitudeGraph").GetComponent<RawImage>();
|
|
leftImage = uipanel.transform.Find("TitlePanel/AltitudeGraph/Left").GetComponent<Image>();
|
|
rightImage = uipanel.transform.Find("TitlePanel/AltitudeGraph/Right").GetComponent<Image>();
|
|
area = uipanel.transform.Find("TitlePanel/AltitudeGraph/Area").GetComponent<Image>();
|
|
settingPanel = uipanel.transform.Find("SettingPanel").gameObject;
|
|
preSlopeText = uipanel.transform.Find("PreSlopePanel/PreSlopeText").GetComponent<Text>();
|
|
|
|
nextSlopeImage = uipanel.transform.Find("NextSlopePanel/NextSlopeImage").GetComponent<Image>();
|
|
currentSlopeImage = uipanel.transform.Find("CurrentSlopePanel/Image").GetComponent<Image>();
|
|
|
|
//加载坡度图片
|
|
downhill1 = Resources.Load<Sprite>("Images/Ride/downhill 1");
|
|
uphill1 = Resources.Load<Sprite>("Images/Ride/uphill 1");
|
|
straight = Resources.Load<Sprite>("Images/Ride/straight");
|
|
|
|
downhill1Small = Resources.Load<Sprite>("Images/Ride/downhill-small");
|
|
uphill1Small = Resources.Load<Sprite>("Images/Ride/uphill-small");
|
|
straightSmall = Resources.Load<Sprite>("Images/Ride/straight-small");
|
|
|
|
target = transform.parent.Find("Target").gameObject;
|
|
//小地图进度
|
|
miniMapProcess = uipanel.transform.Find("MiniMap/Process").GetComponent<Image>();
|
|
miniMapProcessText = uipanel.transform.Find("MiniMap/Process/Text").GetComponent<Text>();
|
|
|
|
|
|
UIManager.AddEvent(pauseButton.gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, PauseRide);
|
|
UIManager.AddEvent(exitButton.gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, StopRide);
|
|
UIManager.AddEvent(saveButton.gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, SaveRide);
|
|
|
|
UIManager.AddEvent(settingButton.gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, ShowSettingPanel);
|
|
UIManager.AddEvent(deviceButton.gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, ShowDevicePanel);
|
|
UIManager.AddEvent(simpleBtn.gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, ClearPanel);
|
|
|
|
UIManager.AddEvent(abandonButton.gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, CancelQuit);
|
|
UIManager.AddEvent(closeQuitButton.gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, CloseQuit);
|
|
UIManager.AddEvent(cancelQuitButton.gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, CloseQuit);
|
|
|
|
UIManager.AddEvent(viewButton.gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, ChangeView);
|
|
|
|
UIManager.AddEvent(singleButton.gameObject, UnityEngine.EventSystems.EventTriggerType.PointerEnter, OnPointEnter);
|
|
UIManager.AddEvent(shadowButton.gameObject, UnityEngine.EventSystems.EventTriggerType.PointerEnter, OnPointEnter);
|
|
UIManager.AddEvent(singleButton.gameObject, UnityEngine.EventSystems.EventTriggerType.PointerExit, OnPointExit);
|
|
UIManager.AddEvent(shadowButton.gameObject, UnityEngine.EventSystems.EventTriggerType.PointerExit, OnPointExit);
|
|
|
|
UIManager.AddEvent(QuitButton, UnityEngine.EventSystems.EventTriggerType.PointerClick, StopShortRide);
|
|
UIManager.AddEvent(CancelButton, UnityEngine.EventSystems.EventTriggerType.PointerClick, CancelStopShortRide);
|
|
|
|
#endregion
|
|
}
|
|
protected virtual void Update()
|
|
{
|
|
time -= Time.deltaTime;
|
|
while (time < 0)
|
|
{
|
|
MoveElevationImage();
|
|
BindDataSource();
|
|
MoveCamera();
|
|
time += 1f;
|
|
}
|
|
MoveDistance();
|
|
}
|
|
private float cameraX = 0;
|
|
private float cameraY = 0;
|
|
private float cameraZ = 0;
|
|
|
|
private Transform player;
|
|
private MapRoute routeInstance;
|
|
|
|
private float time = 1f;
|
|
private float? localY;
|
|
|
|
private Vector3 m = new Vector3(0.1f, 0.1f, 0.1f);
|
|
private Vector3 CameraVector = Vector3.zero;
|
|
|
|
public GameObject uipanel { get; set; }
|
|
public void InitData()
|
|
{
|
|
playerController = FindObjectOfType<PlayerController>();
|
|
mainController = FindObjectOfType<CyclingController>();
|
|
player = transform.parent.Find("Player");
|
|
var route = mainController.GetRoute();
|
|
uipanel = mainController.GetUIPanel();
|
|
InitGameObject();
|
|
routeInstance = route.RouteInstance;
|
|
//初始化3d视角
|
|
var camera = routeInstance.Camera;
|
|
if (!string.IsNullOrEmpty(camera))
|
|
{
|
|
var cameraArr = camera.Split(',');
|
|
cameraX = float.Parse(cameraArr[0]);
|
|
cameraY = float.Parse(cameraArr[1]);
|
|
cameraZ = float.Parse(cameraArr[2]);
|
|
}
|
|
//开发者视角调整
|
|
cameraSlider = uipanel.transform.Find("CameraSlider").GetComponent<Slider>();
|
|
Text CameraText = uipanel.transform.Find("CameraSlider/Text").GetComponent<Text>();
|
|
#if !(UNITY_IOS || UNITY_ANDROID)
|
|
//string[] phoneList = new string[] { "18120141032", "15651831367", "18120141031", "15261826280", "18662240319" };
|
|
//if (phoneList.Contains(App.CurrentUser.Phone))
|
|
//{
|
|
// cameraSlider.gameObject.SetActive(true);
|
|
// cameraSlider.value = cameraY;
|
|
// CameraText.text = cameraY.ToString("f0");
|
|
// cameraSlider.onValueChanged.AddListener((f) =>
|
|
// {
|
|
// cameraY = f;
|
|
// CameraText.text = f.ToString("f0");
|
|
// });
|
|
//}
|
|
#endif
|
|
//路书基本信息绑定
|
|
mapName.text = routeInstance.Name;
|
|
totalDistance.text = Math.Round(mainController.GetMapData().TotalDistance, 1).ToString() + "KM";//总里程
|
|
|
|
#if UNITY_IOS || UNITY_ANDROID
|
|
totalDistanceCompetition.text = Math.Round(mainController.GetMapData().TotalDistance, 1).ToString() + "KM";//总里程
|
|
#endif
|
|
|
|
Utils.DisplayImage(altitudeGraph, route.RouteInstance.AltitudeGraph);//渲染海拔图
|
|
//影子骑行按钮控制
|
|
if (mainController.mapRouteRankingList == null || mainController.mapRouteRankingList.Count == 0)
|
|
{
|
|
var lang = App.GetLocalLanguage();
|
|
shadowButton.image.sprite = lang == "zh"? Resources.Load<Sprite>("Images/Ride/Shadow Mode_PC_d") : Resources.Load<Sprite>("Images/Ride/Shadow Mode_no");
|
|
shadowButton.enabled = false;
|
|
shadowButton.interactable = false;
|
|
}
|
|
else
|
|
{
|
|
shadowButton.enabled = true;
|
|
shadowButton.interactable = true;
|
|
}
|
|
RenderChart();//渲染海拔图
|
|
//默认地图3d/2d
|
|
DefaultView(routeInstance);
|
|
}
|
|
|
|
private void DefaultView(MapRoute routeInstance)
|
|
{
|
|
if (!routeInstance.Enable3D)
|
|
{
|
|
viewButton.enabled = false;
|
|
viewButton.interactable = false;
|
|
mainController.Is3dView = false;
|
|
mainController.player.transform.localScale = new Vector3(0, 0, 0);
|
|
}
|
|
else
|
|
{
|
|
//如果是参赛选手默认进入3d视角
|
|
if (mainController.cyclingModel == Model.CyclingModel.Competition && !mainController.competition.CanWatch)
|
|
{
|
|
return;
|
|
}
|
|
mainController.Is3dView = false;
|
|
ChangeView(null);
|
|
}
|
|
}
|
|
|
|
//移动摄像头
|
|
public void MoveCamera()
|
|
{
|
|
if (target != null && mainController.Is3dView && mainController.RotateLock && mainController.currentPlayer.Speed > 0)
|
|
{
|
|
Vector3 v = Vector3.zero;
|
|
v.y += mainController.currentPlayer.currentRotation.eulerAngles.y + 160f;
|
|
if (mainController.RotateLock)
|
|
{
|
|
target.transform.DOLocalRotate(v, 1f, RotateMode.Fast);
|
|
}
|
|
}
|
|
}
|
|
//移动3d人物和箭头位置
|
|
public void MoveDistance()
|
|
{
|
|
if (target != null)
|
|
{
|
|
if (!mainController.Is3dView)
|
|
{
|
|
Vector3 v = Vector3.zero;
|
|
v.y += mainController.currentPlayer.currentRotation.eulerAngles.y + 160f; //target.transform.rotation = playerController.transform.rotation;//new Quaternion(playerController.transform.rotation.x, playerController.transform.rotation.y +1f, playerController.transform.rotation.z, playerController.transform.rotation.w);
|
|
target.transform.eulerAngles = v; //.Set(0, playerController.currentRotation.eulerAngles.y + 160f, 0);// = new Vector3(0, playerController.transform.eulerAngles.y + 160f, 0);
|
|
//mainController.player.transform.localScale.Set(0.1f, 0.1f, 0.1f);
|
|
player.transform.localScale = m;
|
|
}
|
|
target.transform.position = mainController.currentPlayer.currentPos;
|
|
//target.transform.DOLocalMove(mainController.currentPlayer.currentPos, 0.5f); //player.transform.position;// new Vector3((float)Math.Round(player.transform.position.x,1), 0, (float)Math.Round(player.transform.position.z,1));
|
|
//控制照片移动
|
|
((RectTransform)arrow.transform).position = Camera.main.WorldToScreenPoint(target.transform.position);
|
|
if (mainController.currentPlayer.Speed > 0 && mainController.isStart)
|
|
{
|
|
arrow.transform.Find("bg").gameObject.SetActive(true);
|
|
}
|
|
else
|
|
{
|
|
arrow.transform.Find("bg").gameObject.SetActive(false);
|
|
}
|
|
}
|
|
}
|
|
|
|
public void BindDataSource()
|
|
{
|
|
#if UNITY_IOS || UNITY_ANDROID
|
|
var watchList = mainController.GetWatcherList();
|
|
if (mainController.competitionId > 0)
|
|
{
|
|
var showLeft = watchList.Count > 0;
|
|
//viewButton.enabled = true;
|
|
//viewButton.interactable = true;
|
|
distanceIconCompetition.SetActive(!showLeft);
|
|
totalDistanceCompetition.gameObject.SetActive(!showLeft);
|
|
totalDistance.gameObject.SetActive(showLeft);
|
|
totalDistanceIcon.gameObject.SetActive(showLeft);
|
|
}
|
|
#endif
|
|
//获取当前选中玩家绑定当前UI
|
|
var currentPlayer = mainController.currentPlayer;
|
|
if (currentPlayer != null)
|
|
{
|
|
int ticks = 0;
|
|
if (mainController.cyclingController != null)
|
|
{
|
|
ticks = mainController.cyclingController.recorderData.RiderDatas.LastOrDefault()?.Ticks ?? 0;
|
|
}
|
|
speedTxt.text = $"{Math.Round(currentPlayer.Speed, 1)}";
|
|
powerTxt.text = $"{currentPlayer.Power}";
|
|
timerTxt.text = Helper.FormatTicks(ticks);
|
|
ditance.text = Math.Round(currentPlayer.TotalDistance, 1).ToString("f1");
|
|
heartRate.text = (currentPlayer.HeartRate ?? 0).ToString();
|
|
candance.text = $"{Math.Round(currentPlayer.Cadance, 0)}";
|
|
preSlopeText.text = $"{Math.Round(currentPlayer.PreSlope, 1)}%";
|
|
currentSlopeToatalDistanceText.text = $"{App.GetLocalString("Total")}:{Math.Round(currentPlayer.CurrentDistance, 0)}M";
|
|
//坡度相关数据
|
|
nextSlopeText.text = Math.Round(currentPlayer.NextSlope, 1).ToString() + "%";
|
|
//nextSlopeDistanceText.GetComponent<NumberDotween>().AnimateNum((float)playerController.NextSlopeDistance, 0, "-{0}M");
|
|
nextSlopeDistanceText.text = $"{Math.Round(currentPlayer.NextSlopeTotalDistance, 0)}M";
|
|
currentSlopeText.text = Math.Round(currentPlayer.CurrentSlope, 1).ToString() + "%";
|
|
if (currentSlopePanel.activeSelf)
|
|
{
|
|
currentSlopeDistanceText.GetComponent<NumberDotween>().AnimateNum((float)currentPlayer.CurrentSlopeDistance, Math.Round(currentPlayer.CurrentDistance, 0), currentPlayer.CurrentIndex, 0, "{0}M", currentSlopeProcess);
|
|
currentSlopeDistanceText.GetComponent<NumberDotween>().AnimateNumText((float)currentPlayer.CurrentDistance - (float)currentPlayer.CurrentSlopeDistance, Math.Round(currentPlayer.CurrentDistance, 0), currentPlayer.CurrentIndex, 0, "{0}M", currentSlopeProcess);
|
|
}
|
|
totalClimb.text = Math.Round(currentPlayer.TotalClimb, 0).ToString();
|
|
//小地图进度
|
|
var process = (float)(currentPlayer.TotalDistance / routeInstance.Distance);
|
|
miniMapProcess.fillAmount = process;
|
|
miniMapProcessText.text = $"{process*100:f0}%";
|
|
//动态改变坡度图片
|
|
ChangeSlopeImage(nextSlopeImage, currentPlayer.NextSlope);
|
|
ChangeSlopeImage(currentSlopeImage, currentPlayer.CurrentSlope);
|
|
}
|
|
}
|
|
//改变坡度图片
|
|
public void ChangeSlopeImage(Image image,double slope)
|
|
{
|
|
if (slope >= 1)
|
|
{
|
|
image.sprite = uphill1;
|
|
}
|
|
else if (slope > -1 && slope < 1)
|
|
{
|
|
image.sprite = straight;
|
|
}
|
|
else
|
|
{
|
|
image.sprite = downhill1;
|
|
}
|
|
}
|
|
//开始骑行
|
|
public virtual void StartRide()
|
|
{
|
|
|
|
}
|
|
//继续骑行
|
|
public virtual void ContinueRide()
|
|
{
|
|
|
|
}
|
|
//暂停游戏
|
|
public virtual void PauseRide(BaseEventData baseEventData)
|
|
{
|
|
mainController.SetPause();
|
|
count = 0;
|
|
countDownTxt.gameObject.SetActive(false);
|
|
startBtn.gameObject.SetActive(true);
|
|
startPanel.SetActive(true);
|
|
}
|
|
//保存游戏
|
|
public virtual void SaveRide(BaseEventData baseEventData)
|
|
{
|
|
mainController.ClearTempFile();
|
|
if (playerController?.TotalTicks > 0 && !mainController.isQuit)
|
|
{
|
|
mainController.SetQuit();
|
|
playerController?.Upload();
|
|
quitPanel.SetActive(false);
|
|
modalPanel.SetActive(false);
|
|
}
|
|
else
|
|
{
|
|
SceneManager.LoadScene("MainScene");
|
|
}
|
|
}
|
|
//不保存退出
|
|
public virtual void CancelQuit(BaseEventData baseEventData)
|
|
{
|
|
modalPanel.SetActive(false);
|
|
quitPanel.SetActive(false);
|
|
mainController.ClearTempFile();
|
|
SceneManager.LoadScene("MainScene");
|
|
}
|
|
//取消退出
|
|
public void CloseQuit(BaseEventData baseEventData)
|
|
{
|
|
quitPanel.SetActive(false);
|
|
modalPanel.SetActive(false);
|
|
}
|
|
//切换视角
|
|
public void ChangeView(BaseEventData baseEventData)
|
|
{
|
|
if (viewButton.interactable)
|
|
{
|
|
mainController.ChangeMapImageStyle(arrow.gameObject);
|
|
}
|
|
}
|
|
protected virtual void StopShortRide(BaseEventData baseEventData)
|
|
{
|
|
SceneManager.LoadScene("MainScene");
|
|
}
|
|
protected virtual void CancelStopShortRide(BaseEventData baseEventData)
|
|
{
|
|
cancelPanel.SetActive(false);
|
|
modalPanel.SetActive(false);
|
|
}
|
|
//结束游戏
|
|
protected virtual void StopRide(BaseEventData baseEventData)
|
|
{
|
|
if (playerController?.TotalTicks > 0 && playerController ?.TotalDistance > 0.1f)
|
|
{
|
|
modalPanel.SetActive(true);
|
|
quitPanel.SetActive(true);
|
|
quitPanel.transform.SetAsLastSibling();
|
|
}
|
|
else
|
|
{
|
|
modalPanel.SetActive(true);
|
|
cancelPanel.SetActive(true);
|
|
cancelPanel.transform.SetAsLastSibling();
|
|
}
|
|
}
|
|
//显示设备连接
|
|
public void ShowDevicePanel(BaseEventData baseEventData)
|
|
{
|
|
mainController.ShowDevice(null);
|
|
}
|
|
//显示设置
|
|
public void ShowSettingPanel(BaseEventData baseEventData)
|
|
{
|
|
settingPanel.SetActive(true);
|
|
settingPanel.transform.SetAsLastSibling();
|
|
}
|
|
//进入简约模式
|
|
protected int isSimple = 1;
|
|
public bool clearLock = true;
|
|
public virtual void ClearPanel(BaseEventData baseEventData)
|
|
{
|
|
if (clearLock)
|
|
{
|
|
clearLock = false;
|
|
leftPanel.transform.DOLocalMove(new Vector3(leftPanel.transform.localPosition.x + isSimple * 430f, leftPanel.transform.localPosition.y, leftPanel.transform.localPosition.z), 1);
|
|
titlePanel.transform.DOLocalMove(new Vector3(titlePanel.transform.localPosition.x, titlePanel.transform.localPosition.y + isSimple * 200f, titlePanel.transform.localPosition.z), 1);
|
|
miniMap.transform.DOLocalMove(new Vector3(miniMap.transform.localPosition.x, miniMap.transform.localPosition.y + isSimple * 260f, miniMap.transform.localPosition.z), 1);
|
|
var Scale = isSimple == 1 ? new Vector3(0.7f, 0.7f, 0.7f) : new Vector3(1f, 1f, 1f);
|
|
|
|
#if UNITY_IOS || UNITY_ANDROID
|
|
toolbar.transform.DOLocalMove(new Vector3(toolbar.transform.localPosition.x, toolbar.transform.localPosition.y + isSimple * 260f, toolbar.transform.localPosition.z), 1);
|
|
//中间的海拔图变长
|
|
if (isSimple == 1)
|
|
{
|
|
graphChart.DOMoveX(0, 1f);
|
|
var graphRect = ((RectTransform)graphChart);
|
|
graphRect.sizeDelta = new Vector2(App.MobileResolution.x, graphRect.rect.height);
|
|
}
|
|
else
|
|
{
|
|
graphChart.DOLocalMoveX(-250f, 1f);
|
|
var graphRect = ((RectTransform)graphChart);
|
|
graphRect.sizeDelta = new Vector2(500f, graphRect.rect.height);
|
|
}
|
|
#else
|
|
viewButton.transform.DOLocalMove(new Vector3(viewButton.transform.localPosition.x + isSimple * 200f, viewButton.transform.localPosition.y, viewButton.transform.localPosition.z), 1);
|
|
nextSlopePanel.transform.DOLocalMove(new Vector3(nextSlopePanel.transform.localPosition.x, nextSlopePanel.transform.localPosition.y + isSimple * 260f, nextSlopePanel.transform.localPosition.z), 1);
|
|
currentSlopePanel.transform.DOLocalMove(new Vector3(currentSlopePanel.transform.localPosition.x, currentSlopePanel.transform.localPosition.y + isSimple * 120f, currentSlopePanel.transform.localPosition.z), 1);
|
|
currentSlopePanel.transform.DOScale(Scale, 1);
|
|
#endif
|
|
|
|
nearByPanel.transform.DOLocalMove(new Vector3(nearByPanel.transform.localPosition.x + isSimple * -330f, nearByPanel.transform.localPosition.y, nearByPanel.transform.localPosition.z), 1).onComplete += () =>
|
|
{
|
|
clearLock = true;
|
|
isSimple *= -1;
|
|
simpleBtn.transform.GetComponent<Image>().sprite = isSimple == -1 ? Resources.Load<Sprite>("Images/Ride/full 1") : Resources.Load<Sprite>("Images/Ride/simple 1");
|
|
|
|
};
|
|
}
|
|
}
|
|
//初始化海拔图
|
|
GraphChartBase graph;
|
|
protected ChartDataSourceScript chartDataSourceScript;
|
|
public void RenderChart()
|
|
{
|
|
var mapData = mainController.GetMapData();
|
|
double x = 0;
|
|
Dictionary<double, double> dataSource = new Dictionary<double, double>();
|
|
List<double> dd = new List<double>();
|
|
var one = mapData.List.Where(c => c.Distance == 0).Count();
|
|
foreach (var item in mapData.List)
|
|
{
|
|
if (!dataSource.ContainsKey(x))
|
|
{
|
|
dataSource.Add(x, item.Elevation);
|
|
}
|
|
x += item.Distance;
|
|
dd.Add(item.Elevation);
|
|
}
|
|
chartDataSourceScript = uipanel.transform.Find("GraphChart").GetComponent<ChartDataSourceScript>();
|
|
graph = uipanel.transform.Find("GraphChart").GetComponent<GraphChartBase>();
|
|
chartDataSourceScript.SetDataSource(dd.ToArray());
|
|
#if UNITY_IOS || UNITY_ANDROID
|
|
foreach (var cat in ((IInternalGraphData)graph.DataSource).Categories)
|
|
{
|
|
cat.LineThickness = 2f;
|
|
}
|
|
#endif
|
|
if (App.CurrentUser != null)
|
|
{
|
|
Utils.DisplayImage(head, App.CurrentUser.WxHeadImg);
|
|
}
|
|
}
|
|
//移动总海拔图范围
|
|
public void MoveElevationImage()
|
|
{
|
|
if (chartDataSourceScript.mData.Count <= chartDataSourceScript.targetPoints)
|
|
{
|
|
leftImage.gameObject.SetActive(false);
|
|
rightImage.gameObject.SetActive(false);
|
|
area.gameObject.SetActive(false);
|
|
#if !(UNITY_IOS || UNITY_ANDROID)
|
|
altitudeGraph.gameObject.SetActive(false);
|
|
#endif
|
|
}
|
|
else
|
|
{
|
|
var start = chartDataSourceScript.GetRealTimeStart();
|
|
var end = chartDataSourceScript.GetRealTimeEnd();
|
|
|
|
var originWith =0D;
|
|
var with = altitudeGraph.GetComponent<RectTransform>().sizeDelta.x;
|
|
|
|
var left = start * with + originWith;
|
|
var right = end * with + originWith;
|
|
var rectTransform = area.gameObject.GetComponent<RectTransform>();
|
|
|
|
#if UNITY_IOS || UNITY_ANDROID
|
|
var width = (float)(end - start)* 120F;
|
|
rectTransform.DOSizeDelta(new Vector2((float)width+5f, 22), 1);
|
|
#else
|
|
var width = (float)(end - start)* 286F;
|
|
rectTransform.DOSizeDelta(new Vector2((float)width+5f, 40), 1);
|
|
#endif
|
|
rectTransform.DOLocalMoveX((float)(left), 1);
|
|
leftImage.GetComponent<RectTransform>().DOLocalMoveX((float)left, 1);
|
|
rightImage.GetComponent<RectTransform>().DOLocalMoveX((float)right, 1);
|
|
}
|
|
}
|
|
|
|
#region 事件行为
|
|
|
|
public void OnPointEnter(BaseEventData pointerEventData)
|
|
{
|
|
var button = ((PointerEventData)pointerEventData).pointerEnter.GetComponent<Button>();
|
|
if (button != null)
|
|
{
|
|
var enterTransform = button.transform;
|
|
if (localY == null)
|
|
{
|
|
localY = enterTransform.localPosition.y;
|
|
}
|
|
enterTransform.DOLocalMoveY(localY.Value + 5f, 0.5f);
|
|
}
|
|
}
|
|
public void OnPointExit(BaseEventData pointerEventData)
|
|
{
|
|
var button = ((PointerEventData)pointerEventData).pointerEnter.GetComponent<Button>();
|
|
if (button != null)
|
|
{
|
|
var enterTransform = button.transform;
|
|
enterTransform.DOLocalMoveY(localY.Value, 0.5f);
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|