2021-03-25 16:22:09 +08:00
using UnityEngine ;
using UnityEngine.UI ;
2021-03-28 18:17:15 +08:00
using System.Linq ;
2021-03-29 20:32:30 +08:00
using Mapbox.Unity.Map ;
using DG.Tweening ;
2021-03-30 17:15:16 +08:00
using System ;
using Assets.Scenes.Ride.Scripts.Model ;
2021-04-02 19:17:23 +08:00
using UnityEngine.SceneManagement ;
2021-04-07 17:22:45 +08:00
using System.Collections.Generic ;
2021-04-19 14:38:31 +08:00
using UnityEngine.EventSystems ;
2021-04-23 19:28:35 +08:00
using ChartAndGraph ;
2021-04-27 18:26:30 +08:00
using Assets.Scripts ;
2021-05-07 18:41:37 +08:00
using Assets.Scripts.Apis.Models ;
2021-03-25 16:22:09 +08:00
namespace Assets.Scenes.Ride.Scripts
{
2021-04-02 19:17:23 +08:00
public class SingleUIManager : MonoBehaviour
2021-03-25 16:22:09 +08:00
{
2021-03-30 17:15:16 +08:00
#region UI control
2021-04-15 10:13:01 +08:00
GameObject target ;
2021-04-21 14:08:45 +08:00
GameObject nearByPanel ; //附近的人列表
GameObject leftPanel ; //伴侣骑行列表
2021-03-31 20:46:57 +08:00
GameObject nextSlopePanel ; //下一个坡度面板
GameObject currentSlopePanel ; //当前坡度面板
2021-04-15 10:13:01 +08:00
GameObject selectPanel ; //骑行模式选择
GameObject selectPlayer ; //伴侣骑行选择窗口
GameObject reviewPanel ;
GameObject titlePanel ;
GameObject quitPanel ; //退出界面
2021-03-31 20:46:57 +08:00
Text nextSlopeText ; //下一个坡度
Text nextSlopeDistanceText ; //下一个坡度距离
Text currentSlopeText ; //当前坡度
2021-04-15 10:13:01 +08:00
Text currentSlopeDistanceText ; //当前坡度已骑行距离
Text currentSlopeToatalDistanceText ; //当前坡度总距离
2021-03-30 17:15:16 +08:00
Text speedTxt ; //当前速度
Text powerTxt ; //功率
Text timerTxt ; //计时器
2021-04-15 10:13:01 +08:00
Text ditance ; //当前骑行距离
Text totalDistance ; //当前骑行距离
Text candance ; //踏频
Text heartRate ; //心率
2021-03-30 17:15:16 +08:00
Text countDownTxt ; //倒计时5s
2021-04-02 19:17:23 +08:00
Text mapName ; //路书名称
2021-04-15 10:13:01 +08:00
Text fps ; //fps
Text totalClimb ;
Button startBtn ; //开始按钮
Button simpleBtn ; //进入简约模式按钮
Button pauseButton ; //暂停按钮
Button settingButton ; //设置那妞
Button deviceButton ; //设备按钮
2021-04-21 14:08:45 +08:00
Button viewButton ; //视角按钮
2021-04-15 10:13:01 +08:00
Button exitButton ; //退出按钮
Button singleButton ; //单人骑行按钮
Button shadowButton ; //影子选手按钮
Button addButton ; //添加伴侣骑行
Button saveButton ; //退出panel保存按钮
Button cancelQuitButton ; //退出panel取消按钮
Button closeQuitButton ; //退出panel关闭按钮
2021-04-28 15:37:18 +08:00
RawImage head ; //海拔图头像
2021-05-07 18:41:37 +08:00
GameObject miniMap ; //小地图
2021-04-23 19:28:35 +08:00
RawImage altitudeGraph ; //海拔图
2021-04-27 15:15:51 +08:00
Image leftImage ;
Image rightImage ;
2021-05-13 17:48:28 +08:00
Image area ;
2021-03-30 17:15:16 +08:00
#endregion
2021-03-28 18:17:15 +08:00
2021-03-30 17:15:16 +08:00
#region 控 制 器
2021-04-12 17:35:56 +08:00
public PlayerController playerController ; //当前用户
public CyclingController mainController ; //主控制器
2021-03-30 17:15:16 +08:00
#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-04-19 14:38:31 +08:00
Image arrow ;
AbstractMap map ;
2021-04-23 19:28:35 +08:00
Transform t ;
2021-04-25 13:33:43 +08:00
GameObject alertPanel ;
Button alertBtn ;
Button alertCloseBtn ;
Text preSlopeText ;
2021-04-27 20:28:03 +08:00
GameObject startPanel ;
2021-04-28 15:37:18 +08:00
GameObject headPanel ;
GameObject settingPanel ;
2021-04-28 17:23:29 +08:00
Button abandonButton ;
2021-04-29 18:07:30 +08:00
GameObject singleArea ;
2021-04-30 17:25:28 +08:00
Sprite downhill1 ;
Sprite uphill1 ;
Sprite straight ;
Sprite downhill1Small ;
Sprite uphill1Small ;
Sprite straightSmall ;
Image nextSlopeImage ;
Image currentSlopeImage ;
2021-05-07 18:41:37 +08:00
Image miniMapProcess ;
2021-05-11 18:21:32 +08:00
Image currentSlopeProcess ;
2021-05-07 18:41:37 +08:00
Text miniMapProcessText ;
2021-04-30 17:25:28 +08:00
2021-03-28 18:17:15 +08:00
void Awake ( )
{
2021-04-15 10:13:01 +08:00
#region 控 件 获 取 与 事 件 绑 定
fps = transform . Find ( "Panel/FPS" ) . GetComponent < Text > ( ) ;
2021-04-19 14:38:31 +08:00
arrow = transform . Find ( "Panel/Arrow" ) . GetComponent < Image > ( ) ;
map = transform . parent . Find ( "Map" ) . GetComponent < AbstractMap > ( ) ;
2021-04-12 17:35:56 +08:00
leftPanel = transform . Find ( "Panel/ReviewPanel" ) . gameObject ;
2021-04-21 14:08:45 +08:00
nearByPanel = transform . Find ( "Panel/NearPanel" ) . gameObject ;
2021-04-27 20:28:03 +08:00
startPanel = transform . Find ( "Panel/StartPanel" ) . gameObject ;
startBtn = transform . Find ( "Panel/StartPanel/StartButton" ) . GetComponent < Button > ( ) ;
2021-04-12 17:35:56 +08:00
simpleBtn = transform . Find ( "Panel/SimpleButton" ) . GetComponent < Button > ( ) ;
2021-04-29 18:07:30 +08:00
ditance = transform . Find ( "Panel/ComputerPanel/Distance" ) . GetComponent < Text > ( ) ;
2021-04-15 10:13:01 +08:00
titlePanel = transform . Find ( "Panel/TitlePanel" ) . gameObject ;
totalDistance = transform . Find ( "Panel/TitlePanel/TotalDistance" ) . GetComponent < Text > ( ) ;
2021-04-12 17:35:56 +08:00
candance = transform . Find ( "Panel/PowerPanel/Cadance" ) . GetComponent < Text > ( ) ;
heartRate = transform . Find ( "Panel/PowerPanel/Hrv" ) . GetComponent < Text > ( ) ;
nextSlopePanel = transform . Find ( "Panel/NextSlopePanel" ) . gameObject ;
currentSlopePanel = transform . Find ( "Panel/CurrentSlopePanel" ) . gameObject ;
2021-04-15 10:13:01 +08:00
nextSlopeText = transform . Find ( "Panel/NextSlopePanel/NextSlopeText" ) . GetComponent < Text > ( ) ;
nextSlopeDistanceText = transform . Find ( "Panel/NextSlopePanel/NextSlopeDistance" ) . GetComponent < Text > ( ) ;
currentSlopeText = transform . Find ( "Panel/CurrentSlopePanel/CurrentSlopeText" ) . GetComponent < Text > ( ) ;
currentSlopeDistanceText = transform . Find ( "Panel/CurrentSlopePanel/CurrentSlopeDistance" ) . GetComponent < Text > ( ) ;
currentSlopeToatalDistanceText = transform . Find ( "Panel/CurrentSlopePanel/TotalSlopeDistance" ) . GetComponent < Text > ( ) ;
2021-05-11 18:21:32 +08:00
currentSlopeProcess = transform . Find ( "Panel/CurrentSlopePanel/Process" ) . GetComponent < Image > ( ) ;
2021-04-29 18:07:30 +08:00
speedTxt = transform . Find ( "Panel/ComputerPanel/Speed" ) . GetComponent < Text > ( ) ;
2021-04-15 10:13:01 +08:00
powerTxt = transform . Find ( "Panel/PowerPanel/Power" ) . GetComponent < Text > ( ) ;
2021-04-21 14:08:45 +08:00
timerTxt = transform . Find ( "Panel/ComputerPanel/Timer" ) . GetComponent < Text > ( ) ;
2021-04-15 10:13:01 +08:00
countDownTxt = transform . Find ( "Panel/CountDown" ) . GetComponent < Text > ( ) ;
mapName = transform . Find ( "Panel/TitlePanel/MapName" ) . GetComponent < Text > ( ) ;
2021-04-29 18:07:30 +08:00
totalClimb = transform . Find ( "Panel/ComputerPanel/TotalClimb" ) . GetComponent < Text > ( ) ;
2021-04-23 19:28:35 +08:00
//img = transform.Find("Panel/ElevationChart/HeadImage").GetComponent<RawImage>();
2021-04-28 15:37:18 +08:00
head = transform . Find ( "Panel/GraphChart/HeadPanel/Head" ) . GetComponent < RawImage > ( ) ;
headPanel = transform . Find ( "Panel/GraphChart/HeadPanel" ) . gameObject ;
2021-04-23 19:28:35 +08:00
t = transform . Find ( "Panel/GraphChart/Button" ) ;
2021-05-07 18:41:37 +08:00
miniMap = transform . Find ( "Panel/MiniMap" ) . gameObject ;
2021-04-25 13:33:43 +08:00
alertPanel = transform . Find ( "Panel/Alert" ) . gameObject ;
2021-04-30 23:45:50 +08:00
2021-04-15 10:13:01 +08:00
selectPanel = transform . Find ( "Panel/SelectPanel" ) . gameObject ;
selectPlayer = transform . Find ( "Panel/SelectPlayer" ) . gameObject ;
reviewPanel = transform . Find ( "Panel/ReviewPanel" ) . gameObject ;
quitPanel = transform . Find ( "Panel/QuitPanel" ) . gameObject ;
pauseButton = transform . Find ( "Panel/ToolBarPanel/StartOrPauseButton" ) . GetComponent < Button > ( ) ;
settingButton = transform . Find ( "Panel/ToolBarPanel/SettingButton" ) . GetComponent < Button > ( ) ;
deviceButton = transform . Find ( "Panel/ToolBarPanel/DeviceButton" ) . GetComponent < Button > ( ) ;
exitButton = transform . Find ( "Panel/ToolBarPanel/ExitButton" ) . GetComponent < Button > ( ) ;
2021-04-29 18:07:30 +08:00
2021-04-15 10:13:01 +08:00
singleButton = transform . Find ( "Panel/SelectPanel/SingleButton" ) . GetComponent < Button > ( ) ;
shadowButton = transform . Find ( "Panel/SelectPanel/ShadowButton" ) . GetComponent < Button > ( ) ;
2021-04-29 18:07:30 +08:00
singleArea = transform . Find ( "Panel/ReviewPanel/SingleArea" ) . gameObject ;
2021-04-15 10:13:01 +08:00
addButton = transform . Find ( "Panel/ReviewPanel/SingleArea/AddButton" ) . GetComponent < Button > ( ) ;
2021-04-29 18:07:30 +08:00
2021-04-29 22:16:32 +08:00
saveButton = transform . Find ( "Panel/QuitPanel/QuitPanel/SaveButton" ) . GetComponent < Button > ( ) ;
cancelQuitButton = transform . Find ( "Panel/QuitPanel/QuitPanel/CancelButton" ) . GetComponent < Button > ( ) ;
closeQuitButton = transform . Find ( "Panel/QuitPanel/QuitPanel/CloseButton" ) . GetComponent < Button > ( ) ;
abandonButton = transform . Find ( "Panel/QuitPanel/QuitPanel/AbandonButton" ) . GetComponent < Button > ( ) ;
2021-04-29 18:07:30 +08:00
2021-04-30 23:45:50 +08:00
viewButton = transform . Find ( "Panel/ViewButton" ) . GetComponent < Button > ( ) ;
2021-04-23 19:28:35 +08:00
altitudeGraph = transform . Find ( "Panel/TitlePanel/AltitudeGraph" ) . GetComponent < RawImage > ( ) ;
2021-05-14 16:11:22 +08:00
leftImage = transform . Find ( "Panel/TitlePanel/AltitudeGraph/Left" ) . GetComponent < Image > ( ) ;
rightImage = transform . Find ( "Panel/TitlePanel/AltitudeGraph/Right" ) . GetComponent < Image > ( ) ;
area = transform . Find ( "Panel/TitlePanel/AltitudeGraph/Area" ) . GetComponent < Image > ( ) ;
2021-04-28 15:37:18 +08:00
settingPanel = transform . Find ( "Panel/SettingPanel" ) . gameObject ;
2021-04-25 13:33:43 +08:00
preSlopeText = transform . Find ( "Panel/PreSlopePanel/PreSlopeText" ) . GetComponent < Text > ( ) ;
2021-04-30 17:25:28 +08:00
nextSlopeImage = transform . Find ( "Panel/NextSlopePanel/NextSlopeImage" ) . GetComponent < Image > ( ) ;
currentSlopeImage = transform . Find ( "Panel/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" ) ;
2021-04-15 10:13:01 +08:00
target = transform . parent . Find ( "Target" ) . gameObject ;
2021-05-07 18:41:37 +08:00
//小地图进度
miniMapProcess = transform . Find ( "Panel/MiniMap/Process" ) . GetComponent < Image > ( ) ;
miniMapProcessText = transform . Find ( "Panel/MiniMap/Process/Text" ) . GetComponent < Text > ( ) ;
2021-04-12 17:35:56 +08:00
2021-04-19 14:38:31 +08:00
UIManager . AddEvent ( startBtn . gameObject , UnityEngine . EventSystems . EventTriggerType . PointerClick , StartRide ) ;
UIManager . AddEvent ( simpleBtn . gameObject , UnityEngine . EventSystems . EventTriggerType . PointerClick , ClearPanel ) ;
UIManager . AddEvent ( pauseButton . gameObject , UnityEngine . EventSystems . EventTriggerType . PointerClick , PauseRide ) ;
UIManager . AddEvent ( settingButton . gameObject , UnityEngine . EventSystems . EventTriggerType . PointerClick , ShowSettingPanel ) ;
UIManager . AddEvent ( deviceButton . gameObject , UnityEngine . EventSystems . EventTriggerType . PointerClick , ShowDevicePanel ) ;
UIManager . AddEvent ( exitButton . gameObject , UnityEngine . EventSystems . EventTriggerType . PointerClick , StopRide ) ;
UIManager . AddEvent ( singleButton . gameObject , UnityEngine . EventSystems . EventTriggerType . PointerClick , SingleRide ) ;
UIManager . AddEvent ( shadowButton . gameObject , UnityEngine . EventSystems . EventTriggerType . PointerClick , ShadowRide ) ;
UIManager . AddEvent ( addButton . gameObject , UnityEngine . EventSystems . EventTriggerType . PointerClick , ShowSelectPlayer ) ;
UIManager . AddEvent ( saveButton . gameObject , UnityEngine . EventSystems . EventTriggerType . PointerClick , SaveRide ) ;
2021-04-28 17:23:29 +08:00
UIManager . AddEvent ( abandonButton . gameObject , UnityEngine . EventSystems . EventTriggerType . PointerClick , CancelQuit ) ;
2021-04-19 14:38:31 +08:00
UIManager . AddEvent ( closeQuitButton . gameObject , UnityEngine . EventSystems . EventTriggerType . PointerClick , CloseQuit ) ;
2021-04-28 17:23:29 +08:00
UIManager . AddEvent ( cancelQuitButton . gameObject , UnityEngine . EventSystems . EventTriggerType . PointerClick , CloseQuit ) ;
2021-04-21 14:08:45 +08:00
UIManager . AddEvent ( viewButton . gameObject , UnityEngine . EventSystems . EventTriggerType . PointerClick , ChangeView ) ;
2021-04-22 19:29:59 +08:00
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 ) ;
2021-04-30 23:45:50 +08:00
2021-04-15 10:13:01 +08:00
#endregion
2021-03-28 18:17:15 +08:00
}
2021-04-15 10:13:01 +08:00
2021-04-22 19:29:59 +08:00
float? localY ;
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 ) ;
}
}
void OnPointExit ( BaseEventData pointerEventData )
{
2021-04-30 23:45:50 +08:00
var button = ( ( PointerEventData ) pointerEventData ) . pointerEnter . GetComponent < Button > ( ) ;
2021-04-22 19:29:59 +08:00
if ( button ! = null )
{
var enterTransform = button . transform ;
enterTransform . DOLocalMoveY ( localY . Value , 0.5f ) ;
}
}
2021-03-25 16:22:09 +08:00
void Start ( )
2021-04-27 15:15:51 +08:00
{
Init ( ) ;
RenderChart ( ) ;
2021-04-30 17:25:28 +08:00
//ContinueRide();//继续骑行
2021-04-27 15:15:51 +08:00
}
// Update is called once per frame
float time = 1f ;
void Update ( )
{
time - = Time . deltaTime ;
while ( time < 0 ) {
MoveChartMarkPoint ( ) ;
BindDataSource ( ) ;
fps . text = ( 1 / Time . deltaTime ) . ToString ( ) ;
time = 1 ;
}
MoveCamera ( ) ;
2021-05-07 18:41:37 +08:00
CountDown ( ) ;
2021-04-27 15:15:51 +08:00
}
2021-04-30 23:45:50 +08:00
private float cameraX = 0 ;
private float cameraY = 0 ;
private float cameraZ = 0 ;
2021-05-07 18:41:37 +08:00
Transform player ;
MapRoute routeInstance ;
2021-04-27 15:15:51 +08:00
private void Init ( )
2021-03-25 16:22:09 +08:00
{
2021-04-02 19:17:23 +08:00
playerController = FindObjectOfType < PlayerController > ( ) ;
mainController = FindObjectOfType < CyclingController > ( ) ;
2021-05-07 18:41:37 +08:00
player = transform . parent . Find ( "Player" ) ;
2021-04-02 19:17:23 +08:00
var route = mainController . GetRoute ( ) ;
2021-05-07 18:41:37 +08:00
routeInstance = route . RouteInstance ;
mapName . text = routeInstance . Name ;
var camera = routeInstance . Camera ;
2021-04-30 23:45:50 +08:00
if ( ! string . IsNullOrEmpty ( camera ) )
{
var cameraArr = camera . Split ( ',' ) ;
cameraX = float . Parse ( cameraArr [ 0 ] ) ;
cameraY = float . Parse ( cameraArr [ 1 ] ) ;
cameraZ = float . Parse ( cameraArr [ 2 ] ) ;
}
2021-04-19 18:03:04 +08:00
totalDistance . text = Math . Round ( mainController . GetMapData ( ) . TotalDistance , 1 ) . ToString ( ) + "KM" ; //总里程
2021-05-08 14:38:23 +08:00
Utils . DisplayImage ( altitudeGraph , route . RouteInstance . AltitudeGraph ) ; //渲染海拔图
2021-04-27 15:15:51 +08:00
if ( mainController . mapRouteRankingList = = null | | mainController . mapRouteRankingList . Count = = 0 )
{
2021-04-29 18:07:30 +08:00
shadowButton . image . sprite = Resources . Load < Sprite > ( "Images/Ride/Shadow Mode_no" ) ;
2021-04-27 15:15:51 +08:00
shadowButton . enabled = false ;
shadowButton . interactable = false ;
}
else
{
shadowButton . enabled = true ;
shadowButton . interactable = true ;
}
2021-04-29 18:07:30 +08:00
//标记3d的地图可以用
if ( ! route . RouteInstance . Enable3D )
{
viewButton . enabled = false ;
viewButton . interactable = false ;
2021-04-30 23:45:50 +08:00
mainController . Is3dView = false ;
mainController . player . transform . localScale = new Vector3 ( 0 , 0 , 0 ) ;
2021-04-29 18:07:30 +08:00
}
2021-04-30 17:45:21 +08:00
else
{
2021-04-30 23:45:50 +08:00
mainController . Is3dView = false ;
2021-04-30 17:45:21 +08:00
ChangeView ( null ) ;
}
2021-04-27 15:15:51 +08:00
}
//继续骑行如果有伴侣就自动进入伴侣骑行
2021-04-30 17:25:28 +08:00
public void ContinueRide ( )
2021-04-27 15:15:51 +08:00
{
2021-04-19 14:38:31 +08:00
if ( mainController . routeResult ! = null )
{
2021-05-13 17:48:28 +08:00
#region 注 释 伴 侣 骑 行 的 重 骑 和 继 续 骑 行 的 逻 辑
//if (mainController.routeResult.Mode == CyclingModel.Review.ToString())
//{
// mainController.SetCyclingModel(CyclingModel.Review);
// selectPanel.SetActive(false);
// var reviewFactory = reviewPanel.transform.GetComponent<ReviewFactory>();
// reviewFactory.Refresh();
//}
#endregion
if ( mainController . routeResult . Mode = = CyclingModel . Single . ToString ( ) )
2021-04-19 14:38:31 +08:00
{
mainController . SetCyclingModel ( CyclingModel . Single ) ;
selectPanel . SetActive ( false ) ;
}
2021-04-21 14:08:45 +08:00
//显示附近的人面板
nearByPanel . SetActive ( true ) ;
2021-04-19 14:38:31 +08:00
}
2021-03-25 16:22:09 +08:00
}
2021-05-07 18:41:37 +08:00
Vector3 m = new Vector3 ( 0.1f , 0.1f , 0.1f ) ;
2021-04-27 15:15:51 +08:00
//移动摄像头和箭头位置
private void MoveCamera ( )
2021-03-31 20:46:57 +08:00
{
2021-04-07 17:22:45 +08:00
if ( target ! = null )
{
2021-05-07 18:41:37 +08:00
target . transform . position = playerController . currentPos ; //player.transform.position;// new Vector3((float)Math.Round(player.transform.position.x,1), 0, (float)Math.Round(player.transform.position.z,1));
2021-04-21 14:08:45 +08:00
if ( ! mainController . Is3dView )
2021-05-07 18:41:37 +08:00
{
Vector3 v = Vector3 . zero ;
v . y + = playerController . 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 ;
2021-04-21 14:08:45 +08:00
}
else
{
2021-05-10 18:13:27 +08:00
target . transform . eulerAngles = new Vector3 ( cameraX , cameraY , cameraZ ) ;
2021-04-21 14:08:45 +08:00
}
2021-04-19 14:38:31 +08:00
//控制照片移动
( ( RectTransform ) arrow . transform ) . position = Camera . main . WorldToScreenPoint ( target . transform . position ) ;
2021-04-28 15:37:18 +08:00
if ( playerController . Speed > 0 & & mainController . isStart )
2021-04-25 13:33:43 +08:00
{
arrow . transform . Find ( "bg" ) . gameObject . SetActive ( true ) ;
}
else
{
arrow . transform . Find ( "bg" ) . gameObject . SetActive ( false ) ;
}
2021-04-07 17:22:45 +08:00
}
2021-03-31 20:46:57 +08:00
}
2021-04-27 15:15:51 +08:00
//倒计时
private void CountDown ( )
{
if ( count > 0 )
{
timeRemaining - = Time . deltaTime ;
if ( timeRemaining < = 0 ) //定时器
{
count - - ;
if ( count = = 0 )
{
mainController . SetStart ( ) ;
countDownTxt . gameObject . SetActive ( false ) ;
}
2021-04-29 18:07:30 +08:00
if ( count = = 1 & & mainController . cyclingModel = = CyclingModel . Single )
{
reviewPanel . GetComponent < CanvasGroup > ( ) . DOFade ( 0 , 1 ) ;
2021-04-30 17:25:28 +08:00
//附近的人
2021-04-30 23:45:50 +08:00
// nearByPanel.GetComponent<CanvasGroup>().DOFade(0, 1);
2021-04-29 18:07:30 +08:00
}
2021-04-27 15:15:51 +08:00
timeRemaining = 1.0f ;
}
}
countDownTxt . text = count . ToString ( ) ;
}
private void BindDataSource ( )
{
//获取当前选中玩家绑定当前UI
if ( playerController ! = null )
{
speedTxt . text = $"{Math.Round(playerController.Speed, 1)}" ;
powerTxt . text = $"{playerController.Power}" ;
timerTxt . text = Helper . FormatTicks ( playerController . TotalTicks ) ;
ditance . text = Math . Round ( playerController . TotalDistance , 1 ) . ToString ( "f1" ) ;
heartRate . text = $"{Math.Round(playerController.HeartRate, 0)}" ;
candance . text = $"{Math.Round(playerController.Cadance, 0)}" ;
preSlopeText . text = $"{Math.Round(playerController.PreSlope, 1)}%" ;
currentSlopeToatalDistanceText . text = $"Total:{Math.Round(playerController.CurrentDistance, 0)}M" ;
//坡度相关数据
nextSlopeText . text = Math . Round ( playerController . NextSlope , 1 ) . ToString ( ) + "%" ;
//nextSlopeDistanceText.GetComponent<NumberDotween>().AnimateNum((float)playerController.NextSlopeDistance, 0, "-{0}M");
2021-04-30 23:45:50 +08:00
nextSlopeDistanceText . text = $"{Math.Round(playerController.NextSlopeTotalDistance, 0)}M" ;
2021-04-27 15:15:51 +08:00
currentSlopeText . text = Math . Round ( playerController . CurrentSlope , 1 ) . ToString ( ) + "%" ;
2021-05-13 17:48:28 +08:00
currentSlopeDistanceText . GetComponent < NumberDotween > ( ) . AnimateNum ( ( float ) playerController . CurrentSlopeDistance , Math . Round ( playerController . CurrentDistance , 0 ) , playerController . CurrentIndex , 0 , "{0}M" , currentSlopeProcess ) ;
2021-05-19 18:39:47 +08:00
currentSlopeDistanceText . GetComponent < NumberDotween > ( ) . AnimateNumText ( ( float ) playerController . CurrentDistance - ( float ) playerController . CurrentSlopeDistance , Math . Round ( playerController . CurrentDistance , 0 ) , playerController . CurrentIndex , 0 , "{0}M" , currentSlopeProcess ) ;
2021-04-27 15:15:51 +08:00
totalClimb . text = Math . Round ( playerController . TotalClimb , 0 ) . ToString ( ) ;
2021-05-07 18:41:37 +08:00
//小地图进度
var process = ( float ) ( playerController . TotalDistance / routeInstance . Distance ) ;
miniMapProcess . fillAmount = process ;
miniMapProcessText . text = $"{process*100:f0}%" ;
2021-04-30 17:25:28 +08:00
//动态改变坡度图片
2021-05-19 18:39:47 +08:00
ChangeSlopeImage ( nextSlopeImage , playerController . NextSlope ) ;
ChangeSlopeImage ( currentSlopeImage , playerController . CurrentSlope ) ;
2021-05-11 18:21:32 +08:00
}
}
2021-04-30 17:25:28 +08:00
2021-05-19 18:39:47 +08:00
private void ChangeSlopeImage ( Image image , double slope )
2021-05-11 18:21:32 +08:00
{
2021-05-19 18:39:47 +08:00
if ( slope > = 1 )
2021-05-11 18:21:32 +08:00
{
2021-05-19 18:39:47 +08:00
image . sprite = uphill1 ;
2021-05-11 18:21:32 +08:00
}
2021-05-19 18:39:47 +08:00
else if ( slope > - 1 & & slope < 1 )
2021-05-11 18:21:32 +08:00
{
2021-05-19 18:39:47 +08:00
image . sprite = straight ;
2021-05-11 18:21:32 +08:00
}
else
{
2021-05-19 18:39:47 +08:00
image . sprite = downhill1 ;
2021-04-27 15:15:51 +08:00
}
}
2021-04-29 18:07:30 +08:00
//重置游戏
public void Reset ( )
{
mainController . isStart = false ;
mainController . isPause = false ;
mainController . isQuit = false ;
count = 0 ;
countDownTxt . gameObject . SetActive ( false ) ;
}
2021-04-19 14:38:31 +08:00
private void SingleRide ( BaseEventData baseEventData )
2021-04-15 10:13:01 +08:00
{
selectPanel . SetActive ( false ) ;
2021-04-19 14:38:31 +08:00
mainController . SetCyclingModel ( CyclingModel . Single ) ;
2021-04-15 10:13:01 +08:00
//显示单人骑行列表
reviewPanel . SetActive ( true ) ;
2021-04-21 14:08:45 +08:00
//显示附近的人列表
nearByPanel . SetActive ( true ) ;
2021-04-15 10:13:01 +08:00
}
2021-04-19 14:38:31 +08:00
private void ShadowRide ( BaseEventData baseEventData )
2021-04-15 10:13:01 +08:00
{
2021-04-25 19:41:35 +08:00
//mainController.SetCyclingModel(CyclingModel.Review);
2021-04-15 10:13:01 +08:00
selectPanel . SetActive ( false ) ;
//显示影子选手骑行列表
selectPlayer . SetActive ( true ) ;
2021-04-21 14:08:45 +08:00
//显示附近的人列表
nearByPanel . SetActive ( true ) ;
2021-04-15 10:13:01 +08:00
}
2021-04-19 14:38:31 +08:00
private void ShowSelectPlayer ( BaseEventData baseEventData )
2021-04-15 10:13:01 +08:00
{
2021-04-29 18:07:30 +08:00
Reset ( ) ;
2021-04-15 10:13:01 +08:00
selectPlayer . SetActive ( true ) ;
}
2021-04-30 23:45:50 +08:00
2021-04-25 13:33:43 +08:00
public void StartRide ( BaseEventData baseEventData )
2021-03-25 16:22:09 +08:00
{
2021-05-20 15:55:27 +08:00
// var antConnected = mainController.CheckAnt();//初始化ant+设备
//#if UNITY_EDITOR
// antConnected = true;
//#endif
// if (!antConnected)
// {
// alertPanel.SetActive(true);
// }
// else
2021-04-25 13:33:43 +08:00
{
2021-04-27 20:28:03 +08:00
//加个5秒钟倒计时
count = 5 ;
startPanel . SetActive ( false ) ;
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
//暂停游戏
2021-04-19 14:38:31 +08:00
private void PauseRide ( BaseEventData baseEventData )
2021-03-30 17:15:16 +08:00
{
2021-04-19 18:03:04 +08:00
mainController . SetPause ( ) ;
2021-04-29 18:07:30 +08:00
count = 0 ;
countDownTxt . gameObject . SetActive ( false ) ;
2021-03-30 17:15:16 +08:00
startBtn . gameObject . SetActive ( true ) ;
2021-04-27 20:28:03 +08:00
startPanel . SetActive ( true ) ;
2021-03-30 17:15:16 +08:00
}
2021-04-19 14:38:31 +08:00
private void SaveRide ( BaseEventData baseEventData )
2021-04-15 10:13:01 +08:00
{
2021-04-30 23:45:50 +08:00
if ( playerController . TotalTicks > 0 & & ! mainController . isQuit )
2021-04-15 17:09:35 +08:00
{
2021-04-22 19:29:59 +08:00
mainController . SetQuit ( ) ;
2021-04-15 17:09:35 +08:00
playerController . Upload ( ) ;
quitPanel . SetActive ( false ) ;
}
2021-04-22 19:29:59 +08:00
else
{
SceneManager . LoadScene ( "MainScene" ) ;
}
2021-04-15 10:13:01 +08:00
}
2021-04-19 14:38:31 +08:00
private void CancelQuit ( BaseEventData baseEventData )
2021-04-15 10:13:01 +08:00
{
quitPanel . SetActive ( false ) ;
SceneManager . LoadScene ( "MainScene" ) ;
}
2021-04-19 14:38:31 +08:00
private void CloseQuit ( BaseEventData baseEventData )
2021-04-15 10:13:01 +08:00
{
quitPanel . SetActive ( false ) ;
}
2021-04-21 14:08:45 +08:00
//切换到3d视角
private void ChangeView ( BaseEventData baseEventData )
{
mainController . ChangeMapImageStyle ( arrow . gameObject ) ;
}
2021-03-30 17:15:16 +08:00
//结束游戏
2021-04-19 14:38:31 +08:00
private void StopRide ( BaseEventData baseEventData )
2021-03-30 17:15:16 +08:00
{
2021-04-15 17:09:35 +08:00
if ( playerController . TotalTicks > 0 )
{
quitPanel . SetActive ( true ) ;
}
else
{
SceneManager . LoadScene ( "MainScene" ) ;
}
2021-03-30 17:15:16 +08:00
}
//显示设备连接
2021-04-19 14:38:31 +08:00
private void ShowDevicePanel ( BaseEventData baseEventData )
2021-03-30 17:15:16 +08:00
{
2021-04-15 17:09:35 +08:00
UIManager . Show ( UIManager . Instance . DevicePanel , transform . Find ( "Panel" ) . GetComponent < PFUIPanel > ( ) ) ;
2021-03-30 17:15:16 +08:00
}
//显示设置
2021-04-19 14:38:31 +08:00
private void ShowSettingPanel ( BaseEventData baseEventData )
2021-03-30 17:15:16 +08:00
{
2021-04-28 15:37:18 +08:00
settingPanel . SetActive ( true ) ;
2021-03-30 17:15:16 +08:00
}
2021-03-29 20:32:30 +08:00
int isSimple = 1 ;
2021-04-15 10:13:01 +08:00
private bool clearLock = true ;
2021-04-27 15:15:51 +08:00
private void ClearPanel ( BaseEventData baseEventData )
2021-03-29 20:32:30 +08:00
{
2021-04-15 10:13:01 +08:00
if ( clearLock )
{
clearLock = false ;
2021-04-30 17:25:28 +08:00
leftPanel . transform . DOLocalMove ( new Vector3 ( leftPanel . transform . localPosition . x + isSimple * 430f , leftPanel . transform . localPosition . y , leftPanel . transform . localPosition . z ) , 1 ) ;
2021-04-27 15:15:51 +08:00
titlePanel . transform . DOLocalMove ( new Vector3 ( titlePanel . transform . localPosition . x , titlePanel . transform . localPosition . y + isSimple * 200f , titlePanel . transform . localPosition . z ) , 1 ) ;
2021-04-30 23:45:50 +08:00
miniMap . transform . DOLocalMove ( new Vector3 ( miniMap . transform . localPosition . x , miniMap . transform . localPosition . y + isSimple * 260f , miniMap . transform . localPosition . z ) , 1 ) ;
2021-04-29 22:16:32 +08:00
nextSlopePanel . transform . DOLocalMove ( new Vector3 ( nextSlopePanel . transform . localPosition . x , nextSlopePanel . transform . localPosition . y + isSimple * 260f , nextSlopePanel . transform . localPosition . z ) , 1 ) ;
2021-05-11 18:21:32 +08:00
currentSlopePanel . transform . DOLocalMove ( new Vector3 ( currentSlopePanel . transform . localPosition . x , currentSlopePanel . transform . localPosition . y + isSimple * 120f , currentSlopePanel . transform . localPosition . z ) , 1 ) ;
var Scale = isSimple = = 1 ? new Vector3 ( 0.7f , 0.7f , 0.7f ) : new Vector3 ( 1f , 1f , 1f ) ;
currentSlopePanel . transform . DOScale ( Scale , 1 ) ;
viewButton . transform . DOLocalMove ( new Vector3 ( viewButton . transform . localPosition . x + isSimple * 200f , viewButton . transform . localPosition . y , viewButton . transform . localPosition . z ) , 1 ) ;
2021-04-29 22:16:32 +08:00
2021-04-30 17:25:28 +08:00
nearByPanel . transform . DOLocalMove ( new Vector3 ( nearByPanel . transform . localPosition . x + isSimple * - 330f , nearByPanel . transform . localPosition . y , nearByPanel . transform . localPosition . z ) , 1 ) . onComplete + = ( ) = >
2021-04-15 10:13:01 +08:00
{
clearLock = true ;
isSimple * = - 1 ;
2021-05-20 15:55:27 +08:00
simpleBtn . transform . GetComponent < Image > ( ) . sprite = isSimple = = - 1 ? Resources . Load < Sprite > ( "Images/Ride/full 1" ) : Resources . Load < Sprite > ( "Images/Ride/simple 1" ) ;
2021-04-25 19:41:35 +08:00
2021-04-15 10:13:01 +08:00
} ;
}
2021-03-25 16:22:09 +08:00
}
2021-04-23 19:28:35 +08:00
GraphChartBase graph ;
2021-04-27 15:15:51 +08:00
ChartDataSourceScript chartDataSourceScript ;
2021-03-30 17:15:16 +08:00
//初始化海拔图
2021-03-28 18:17:15 +08:00
void RenderChart ( )
{
2021-04-22 19:29:59 +08:00
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 )
2021-03-28 18:17:15 +08:00
{
2021-04-22 19:29:59 +08:00
x + = item . Distance ;
if ( ! dataSource . ContainsKey ( x ) )
{
dataSource . Add ( x , item . Elevation ) ;
}
dd . Add ( item . Elevation ) ;
2021-03-28 18:17:15 +08:00
}
2021-04-27 15:15:51 +08:00
chartDataSourceScript = transform . Find ( "Panel/GraphChart" ) . GetComponent < ChartDataSourceScript > ( ) ;
2021-04-23 19:28:35 +08:00
graph = transform . Find ( "Panel/GraphChart" ) . GetComponent < GraphChartBase > ( ) ;
2021-04-27 15:15:51 +08:00
chartDataSourceScript . SetDataSource ( dd . ToArray ( ) ) ;
2021-04-30 23:45:50 +08:00
2021-04-12 17:35:56 +08:00
if ( App . CurrentUser ! = null )
{
2021-05-08 14:38:23 +08:00
Utils . DisplayImage ( head , App . CurrentUser . WxHeadImg ) ;
2021-04-12 17:35:56 +08:00
}
2021-04-07 17:22:45 +08:00
}
2021-04-30 23:45:50 +08:00
2021-04-27 15:15:51 +08:00
void MoveChartMarkPoint ( )
2021-04-07 17:22:45 +08:00
{
2021-04-27 15:15:51 +08:00
//if (mainController.isStart)
2021-04-07 17:22:45 +08:00
{
2021-04-27 15:15:51 +08:00
MoverCurrentUserHead ( ) ;
MoveOtherHeads ( ) ;
MoveElevationImage ( ) ;
2021-04-07 17:22:45 +08:00
}
}
2021-04-27 15:15:51 +08:00
//移动当前用户头像
private void MoverCurrentUserHead ( )
2021-03-28 18:17:15 +08:00
{
2021-04-28 15:37:18 +08:00
Vector3 prePos = headPanel . transform . position ;
2021-04-30 23:45:50 +08:00
int nextIndex = playerController . CurrentIndex + 1 ;
2021-04-27 15:15:51 +08:00
var viewIndex = chartDataSourceScript . GetViewIndex ( nextIndex ) ;
2021-05-01 01:02:54 +08:00
if ( ! mainController . isStart & & ! mainController . isPause & & ! mainController . isQuit | | ( mainController . isStart & & playerController . TotalDistance = = 0 ) ) //未开始未暂停未结束
2021-04-27 15:15:51 +08:00
{
viewIndex = 0 ;
}
2021-04-30 17:25:28 +08:00
2021-04-27 15:15:51 +08:00
var n = graph . DataSource . GetPoint ( "Player 2" , viewIndex ) ;
graph . PointToWorldSpace ( out Vector3 nextPosition , n . x , n . y , "Player 2" ) ;
nextPosition . x - = 14f ;
nextPosition . y + = 5f ;
//人物移动 停止条件 到中间且线未加载完
if ( chartDataSourceScript . ReachMid ( viewIndex ) & & ! chartDataSourceScript . ReachEnd ( ) )
2021-03-29 20:32:30 +08:00
{
2021-04-27 15:15:51 +08:00
var currentDistance = playerController . CurrentDistance ;
var distance = playerController . Distance ;
var offset = currentDistance > 0 ? distance * 1000 / currentDistance : 1 ;
graph . HorizontalScrolling + = offset ;
2021-04-28 15:37:18 +08:00
headPanel . transform . DOMove ( new Vector3 ( prePos . x , nextPosition . y , 0 ) , 1 ) ;
2021-03-29 20:32:30 +08:00
}
2021-04-27 15:15:51 +08:00
else
{
2021-04-28 15:37:18 +08:00
headPanel . transform . DOMove ( new Vector3 ( nextPosition . x , nextPosition . y , 0 ) , 1 ) ;
2021-04-27 15:15:51 +08:00
}
2021-04-28 15:37:18 +08:00
headPanel . transform . SetSiblingIndex ( 999 ) ;
2021-03-28 18:17:15 +08:00
}
2021-04-27 15:15:51 +08:00
//移动其他骑手头像
private void MoveOtherHeads ( )
2021-04-19 14:38:31 +08:00
{
2021-04-27 15:15:51 +08:00
var others = FindObjectsOfType < OtherPlayerController > ( ) ;
foreach ( var item in others )
2021-04-25 19:41:35 +08:00
{
2021-04-28 15:37:18 +08:00
var itemIndex = chartDataSourceScript . GetViewIndex ( item . CurrentIndex ) + 1 ;
2021-05-01 01:02:54 +08:00
if ( ! mainController . isStart & & ! mainController . isPause & & ! mainController . isQuit | | ( mainController . isStart & & item . TotalDistance = = 0 ) ) //未开始未暂停未结束
2021-04-25 19:41:35 +08:00
{
2021-04-27 15:15:51 +08:00
itemIndex = 0 ;
2021-04-25 19:41:35 +08:00
}
2021-04-27 15:15:51 +08:00
var m = graph . DataSource . GetPoint ( "Player 2" , itemIndex ) ;
graph . PointToWorldSpace ( out Vector3 itemPosition , m . x , m . y , "Player 2" ) ;
itemPosition . x - = 12f ;
itemPosition . y + = 5f ;
2021-05-08 18:36:59 +08:00
item . MoveHead ( graph . transform , itemPosition ) ;
}
2021-05-11 18:21:32 +08:00
2021-04-27 15:15:51 +08:00
}
//移动总海拔图范围
private void MoveElevationImage ( )
{
if ( chartDataSourceScript . mData . Count < = chartDataSourceScript . targetPoints )
{
leftImage . gameObject . SetActive ( false ) ;
rightImage . gameObject . SetActive ( false ) ;
altitudeGraph . gameObject . SetActive ( false ) ;
2021-05-13 17:48:28 +08:00
area . gameObject . SetActive ( false ) ;
2021-04-27 15:15:51 +08:00
}
else
{
2021-05-14 16:11:22 +08:00
//var m = Screen.width / 1600D;
2021-04-27 15:15:51 +08:00
var start = chartDataSourceScript . GetRealTimeStart ( ) ;
var end = chartDataSourceScript . GetRealTimeEnd ( ) ;
2021-04-19 14:38:31 +08:00
2021-05-14 16:11:22 +08:00
var originWith = 0D ;
var with = altitudeGraph . GetComponent < RectTransform > ( ) . sizeDelta . x ;
2021-04-23 19:28:35 +08:00
2021-04-27 15:15:51 +08:00
var left = start * with + originWith ;
var right = end * with + originWith ;
2021-05-13 17:48:28 +08:00
var rectTransform = area . gameObject . GetComponent < RectTransform > ( ) ;
2021-05-14 16:11:22 +08:00
var width = ( float ) ( end - start ) * 286F ;
rectTransform . DOSizeDelta ( new Vector2 ( ( float ) width + 5f , 40 ) , 1 ) ;
rectTransform . DOLocalMoveX ( ( float ) ( left ) , 1 ) ;
leftImage . GetComponent < RectTransform > ( ) . DOLocalMoveX ( ( float ) left , 1 ) ;
rightImage . GetComponent < RectTransform > ( ) . DOLocalMoveX ( ( float ) right , 1 ) ;
2021-04-27 15:15:51 +08:00
}
2021-04-19 14:38:31 +08:00
}
2021-03-25 16:22:09 +08:00
}
}