2021-06-24 18:19:28 +08:00
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 Text nextSlopeText ; //下一个坡度
protected Text nextSlopeDistanceText ; //下一个坡度距离
protected Text currentSlopeText ; //当前坡度
protected Text currentSlopeDistanceText ; //当前坡度已骑行距离
protected Text currentSlopeToatalDistanceText ; //当前坡度总距离
protected Text speedTxt ; //当前速度
protected Text powerTxt ; //功率
2021-08-12 18:57:30 +08:00
protected Text timerTxt { get ; set ; } //计时器
2021-07-23 09:04:56 +08:00
protected Text timerTxtTitle ; //计时器标题
2021-06-24 18:19:28 +08:00
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 ; //小地图
2021-09-02 10:08:46 +08:00
protected GameObject toolbar ; //toolbar
2021-06-24 18:19:28 +08:00
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 virtual void Awake ()
2021-09-02 10:08:46 +08:00
{
}
protected virtual void Start ()
{
InitData (); //初始
RenderChart (); //渲染海拔图
}
2021-09-07 16:11:15 +08:00
Text totalDistanceCompetition { get ; set ; }
GameObject distanceIconCompetition { get ; set ; }
GameObject totalDistanceIcon { get ; set ; }
2021-09-02 10:08:46 +08:00
private void InitGameObject ()
2021-06-24 18:19:28 +08:00
{
#region 控件获取与事件绑定
2021-09-02 10:08:46 +08:00
fps = uipanel . transform . Find ( "FPS" ). GetComponent < Text >();
arrow = uipanel . transform . Find ( "Arrow" ). GetComponent < Image >();
2021-06-24 18:19:28 +08:00
map = transform . parent . Find ( "Map" ). GetComponent < AbstractMap >();
2021-09-02 10:08:46 +08:00
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 >();
2021-09-07 16:11:15 +08:00
totalDistanceIcon = uipanel . transform . Find ( "TitlePanel/DistanceIcon" ). gameObject ;
2021-09-02 10:08:46 +08:00
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 >();
2021-09-07 16:11:15 +08:00
#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
2021-09-02 10:08:46 +08:00
currentSlopeDistanceText = uipanel . transform . Find ( "CurrentSlopePanel/CurrentSlopeDistance" ). GetComponent < Text >();
currentSlopeToatalDistanceText = uipanel . transform . Find ( "CurrentSlopePanel/TotalSlopeDistance" ). GetComponent < Text >();
currentSlopeProcess = uipanel . transform . Find ( "CurrentSlopePanel/Process" ). GetComponent < Image >();
2021-06-24 18:19:28 +08:00
2021-09-02 10:08:46 +08:00
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>();
head = uipanel . transform . Find ( "GraphChart/HeadPanel/Head" ). GetComponent < RawImage >();
headPanel = uipanel . transform . Find ( "GraphChart/HeadPanel" ). gameObject ;
t = uipanel . transform . Find ( "GraphChart/Button" );
miniMap = uipanel . transform . Find ( "MiniMap" ). gameObject ;
2021-06-24 18:19:28 +08:00
2021-09-02 10:08:46 +08:00
alertPanel = uipanel . transform . Find ( "Alert" ). gameObject ;
2021-06-24 18:19:28 +08:00
2021-09-02 10:08:46 +08:00
selectPanel = uipanel . transform . Find ( "SelectPanel" ). gameObject ;
selectPlayer = uipanel . transform . Find ( "SelectPlayer" ). gameObject ;
reviewPanel = uipanel . transform . Find ( "ReviewPanel" ). gameObject ;
quitPanel = uipanel . transform . Find ( "QuitPanel" ). gameObject ;
2021-06-24 18:19:28 +08:00
2021-09-02 10:08:46 +08:00
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 >();
2021-06-24 18:19:28 +08:00
2021-09-02 10:08:46 +08:00
singleButton = uipanel . transform . Find ( "SelectPanel/SingleButton" ). GetComponent < Button >();
shadowButton = uipanel . transform . Find ( "SelectPanel/ShadowButton" ). GetComponent < Button >();
2021-06-24 18:19:28 +08:00
2021-09-02 10:08:46 +08:00
singleArea = uipanel . transform . Find ( "ReviewPanel/SingleArea" ). gameObject ;
addButton = uipanel . transform . Find ( "ReviewPanel/SingleArea/AddButton" ). GetComponent < Button >();
2021-06-24 18:19:28 +08:00
2021-09-02 10:08:46 +08:00
saveButton = uipanel . transform . Find ( "QuitPanel/SaveButton" ). GetComponent < Button >();
cancelQuitButton = uipanel . transform . Find ( "QuitPanel/CancelButton" ). GetComponent < Button >();
closeQuitButton = uipanel . transform . Find ( "QuitPanel/CloseButton" ). GetComponent < Button >();
abandonButton = uipanel . transform . Find ( "QuitPanel/AbandonButton" ). GetComponent < Button >();
2021-06-24 18:19:28 +08:00
2021-09-02 10:08:46 +08:00
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 >();
2021-06-24 18:19:28 +08:00
//加载坡度图片
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 ;
//小地图进度
2021-09-02 10:08:46 +08:00
miniMapProcess = uipanel . transform . Find ( "MiniMap/Process" ). GetComponent < Image >();
miniMapProcessText = uipanel . transform . Find ( "MiniMap/Process/Text" ). GetComponent < Text >();
2021-06-24 18:19:28 +08:00
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 );
2021-09-02 10:08:46 +08:00
2021-06-24 18:19:28 +08:00
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 );
2021-09-02 10:08:46 +08:00
2021-09-07 16:11:15 +08:00
#endregion
2021-06-24 18:19:28 +08:00
}
protected virtual void Update ()
{
time -= Time . deltaTime ;
2021-09-27 18:43:41 +08:00
while ( time < 0 )
{
2021-06-24 18:19:28 +08:00
MoveElevationImage ();
BindDataSource ();
2021-09-27 18:43:41 +08:00
time += 1f ;
2021-06-24 18:19:28 +08:00
}
MoveCamera ();
}
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 ;
2021-09-03 13:06:26 +08:00
public GameObject uipanel { get ; set ; }
2021-09-02 10:08:46 +08:00
public void InitData ()
2021-06-24 18:19:28 +08:00
{
playerController = FindObjectOfType < PlayerController >();
mainController = FindObjectOfType < CyclingController >();
player = transform . parent . Find ( "Player" );
var route = mainController . GetRoute ();
2021-09-02 10:08:46 +08:00
uipanel = mainController . GetUIPanel ();
InitGameObject ();
2021-06-24 18:19:28 +08:00
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 ]);
}
//开发者视角调整
2021-09-02 10:08:46 +08:00
cameraSlider = uipanel . transform . Find ( "CameraSlider" ). GetComponent < Slider >();
Text CameraText = uipanel . transform . Find ( "CameraSlider/Text" ). GetComponent < Text >();
2021-09-07 16:11:15 +08:00
#if !( UNITY_IOS || UNITY_ANDROID )
2021-06-24 18:19:28 +08:00
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" );
});
}
2021-09-07 16:11:15 +08:00
#endif
2021-06-24 18:19:28 +08:00
//路书基本信息绑定
mapName . text = routeInstance . Name ;
totalDistance . text = Math . Round ( mainController . GetMapData (). TotalDistance , 1 ). ToString () + "KM" ; //总里程
2021-09-07 16:11:15 +08:00
#if UNITY_IOS || UNITY_ANDROID
totalDistanceCompetition . text = Math . Round ( mainController . GetMapData (). TotalDistance , 1 ). ToString () + "KM" ; //总里程
#endif
2021-06-24 18:19:28 +08:00
Utils . DisplayImage ( altitudeGraph , route . RouteInstance . AltitudeGraph ); //渲染海拔图
//影子骑行按钮控制
if ( mainController . mapRouteRankingList == null || mainController . mapRouteRankingList . Count == 0 )
{
shadowButton . image . sprite = Resources . Load < Sprite >( "Images/Ride/Shadow Mode_no" );
shadowButton . enabled = false ;
shadowButton . interactable = false ;
}
else
{
shadowButton . enabled = true ;
shadowButton . interactable = true ;
}
2021-07-29 16:13:23 +08:00
//默认地图3d/2d
DefaultView ( routeInstance );
}
private void DefaultView ( MapRoute routeInstance )
{
if (! routeInstance . Enable3D )
2021-06-24 18:19:28 +08:00
{
viewButton . enabled = false ;
viewButton . interactable = false ;
mainController . Is3dView = false ;
mainController . player . transform . localScale = new Vector3 ( 0 , 0 , 0 );
}
else
{
2021-07-28 18:56:23 +08:00
//如果是参赛选手默认进入3d视角
2021-07-29 09:26:19 +08:00
if ( mainController . cyclingModel == Model . CyclingModel . Competition && ! mainController . competition . CanWatch )
2021-07-28 18:56:23 +08:00
{
return ;
}
2021-06-24 18:19:28 +08:00
mainController . Is3dView = false ;
ChangeView ( null );
}
}
2021-06-29 18:03:20 +08:00
2021-06-24 18:19:28 +08:00
//移动摄像头和箭头位置
public void MoveCamera ()
{
if ( target != null )
{
2021-07-01 18:41:35 +08:00
target . transform . position = mainController . currentPlayer . currentPos ; //player.transform.position;// new Vector3((float)Math.Round(player.transform.position.x,1), 0, (float)Math.Round(player.transform.position.z,1));
2021-06-24 18:19:28 +08:00
if (! mainController . Is3dView )
{
Vector3 v = Vector3 . zero ;
2021-07-01 18:41:35 +08:00
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);
2021-06-24 18:19:28 +08:00
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 ;
}
else
{
CameraVector . x = cameraX ;
CameraVector . y = cameraY ;
CameraVector . z = cameraZ ;
target . transform . eulerAngles = CameraVector ;
}
//控制照片移动
(( RectTransform ) arrow . transform ). position = Camera . main . WorldToScreenPoint ( target . transform . position );
2021-07-01 18:41:35 +08:00
if ( mainController . currentPlayer . Speed > 0 && mainController . isStart )
2021-06-24 18:19:28 +08:00
{
arrow . transform . Find ( "bg" ). gameObject . SetActive ( true );
}
else
{
arrow . transform . Find ( "bg" ). gameObject . SetActive ( false );
}
}
}
//绑定数据源
public void BindDataSource ()
{
2021-09-09 16:29:22 +08:00
#if UNITY_IOS || UNITY_ANDROID
var watchList = mainController . GetWatcherList ();
if ( mainController . competitionId > 0 )
{
var showLeft = watchList . Count > 0 ;
2021-09-13 18:21:43 +08:00
//viewButton.enabled = true;
//viewButton.interactable = true;
2021-09-09 16:29:22 +08:00
distanceIconCompetition . SetActive (! showLeft );
totalDistanceCompetition . gameObject . SetActive (! showLeft );
totalDistance . gameObject . SetActive ( showLeft );
totalDistanceIcon . gameObject . SetActive ( showLeft );
}
#endif
2021-06-24 18:19:28 +08:00
//获取当前选中玩家绑定当前UI
2021-07-01 18:41:35 +08:00
var currentPlayer = mainController . currentPlayer ;
if ( currentPlayer != null )
2021-06-24 18:19:28 +08:00
{
2021-08-12 18:57:30 +08:00
int ticks = 0 ;
if ( mainController . cyclingController != null )
{
ticks = mainController . cyclingController . recorderData . RiderDatas . LastOrDefault ()?. Ticks ?? 0 ;
}
2021-07-01 18:41:35 +08:00
speedTxt . text = $"{Math.Round(currentPlayer.Speed, 1)}" ;
powerTxt . text = $"{currentPlayer.Power}" ;
2021-08-12 18:57:30 +08:00
timerTxt . text = Helper . FormatTicks ( ticks );
2021-07-01 18:41:35 +08:00
ditance . text = Math . Round ( currentPlayer . TotalDistance , 1 ). ToString ( "f1" );
2021-08-10 16:36:13 +08:00
heartRate . text = ( currentPlayer . HeartRate ?? 0 ). ToString ();
2021-07-01 18:41:35 +08:00
candance . text = $"{Math.Round(currentPlayer.Cadance, 0)}" ;
preSlopeText . text = $"{Math.Round(currentPlayer.PreSlope, 1)}%" ;
2021-11-10 18:13:38 +08:00
currentSlopeToatalDistanceText . text = $"{App.GetLocalString(" Total ")}:{Math.Round(currentPlayer.CurrentDistance, 0)}M" ;
2021-06-24 18:19:28 +08:00
//坡度相关数据
2021-07-01 18:41:35 +08:00
nextSlopeText . text = Math . Round ( currentPlayer . NextSlope , 1 ). ToString () + "%" ;
2021-06-24 18:19:28 +08:00
//nextSlopeDistanceText.GetComponent<NumberDotween>().AnimateNum((float)playerController.NextSlopeDistance, 0, "-{0}M");
2021-07-01 18:41:35 +08:00
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 ();
2021-06-24 18:19:28 +08:00
//小地图进度
2021-07-01 18:41:35 +08:00
var process = ( float )( currentPlayer . TotalDistance / routeInstance . Distance );
2021-06-24 18:19:28 +08:00
miniMapProcess . fillAmount = process ;
miniMapProcessText . text = $"{process*100:f0}%" ;
//动态改变坡度图片
2021-07-01 18:41:35 +08:00
ChangeSlopeImage ( nextSlopeImage , currentPlayer . NextSlope );
ChangeSlopeImage ( currentSlopeImage , currentPlayer . CurrentSlope );
2021-06-24 18:19:28 +08:00
}
}
//改变坡度图片
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 ()
{
}
//暂停游戏
2021-06-29 18:03:20 +08:00
public virtual void PauseRide ( BaseEventData baseEventData )
2021-06-24 18:19:28 +08:00
{
mainController . SetPause ();
count = 0 ;
countDownTxt . gameObject . SetActive ( false );
startBtn . gameObject . SetActive ( true );
startPanel . SetActive ( true );
}
//保存游戏
2021-06-29 18:03:20 +08:00
public virtual void SaveRide ( BaseEventData baseEventData )
2021-06-24 18:19:28 +08:00
{
2021-07-06 18:24:15 +08:00
if ( playerController ?. TotalTicks > 0 && ! mainController . isQuit )
2021-06-24 18:19:28 +08:00
{
mainController . SetQuit ();
2021-07-06 18:24:15 +08:00
playerController ?. Upload ();
2021-06-24 18:19:28 +08:00
quitPanel . SetActive ( false );
}
else
{
SceneManager . LoadScene ( "MainScene" );
}
}
//不保存退出
2021-06-29 18:03:20 +08:00
public virtual void CancelQuit ( BaseEventData baseEventData )
2021-06-24 18:19:28 +08:00
{
quitPanel . SetActive ( false );
SceneManager . LoadScene ( "MainScene" );
}
//取消退出
public void CloseQuit ( BaseEventData baseEventData )
{
quitPanel . SetActive ( false );
}
//切换视角
public void ChangeView ( BaseEventData baseEventData )
{
2021-09-16 15:59:08 +08:00
if ( viewButton . interactable )
{
mainController . ChangeMapImageStyle ( arrow . gameObject );
}
2021-06-24 18:19:28 +08:00
}
//结束游戏
2021-07-23 09:04:56 +08:00
protected virtual void StopRide ( BaseEventData baseEventData )
2021-06-24 18:19:28 +08:00
{
2021-07-06 18:24:15 +08:00
if ( playerController ?. TotalTicks > 0 )
2021-06-24 18:19:28 +08:00
{
quitPanel . SetActive ( true );
2021-09-09 16:29:22 +08:00
quitPanel . transform . SetAsLastSibling ();
2021-06-24 18:19:28 +08:00
}
else
{
SceneManager . LoadScene ( "MainScene" );
}
}
//显示设备连接
public void ShowDevicePanel ( BaseEventData baseEventData )
{
2021-11-02 17:55:49 +08:00
mainController . ShowDevice ( null );
2021-06-24 18:19:28 +08:00
}
//显示设置
public void ShowSettingPanel ( BaseEventData baseEventData )
{
settingPanel . SetActive ( true );
2021-09-09 16:29:22 +08:00
settingPanel . transform . SetAsLastSibling ();
2021-06-24 18:19:28 +08:00
}
//进入简约模式
2021-07-23 09:04:56 +08:00
protected int isSimple = 1 ;
2021-09-03 13:06:26 +08:00
public bool clearLock = true ;
2021-09-02 10:08:46 +08:00
public virtual void ClearPanel ( BaseEventData baseEventData )
2021-06-24 18:19:28 +08:00
{
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 );
2021-09-02 10:08:46 +08:00
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 );
#else
viewButton . transform . DOLocalMove ( new Vector3 ( viewButton . transform . localPosition . x + isSimple * 200f , viewButton . transform . localPosition . y , viewButton . transform . localPosition . z ), 1 );
2021-06-24 18:19:28 +08:00
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 );
2021-09-02 10:08:46 +08:00
#endif
2021-06-24 18:19:28 +08:00
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 ;
2021-07-23 09:04:56 +08:00
protected ChartDataSourceScript chartDataSourceScript ;
2021-06-24 18:19:28 +08:00
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 );
}
2021-09-02 10:08:46 +08:00
chartDataSourceScript = uipanel . transform . Find ( "GraphChart" ). GetComponent < ChartDataSourceScript >();
graph = uipanel . transform . Find ( "GraphChart" ). GetComponent < GraphChartBase >();
2021-06-24 18:19:28 +08:00
chartDataSourceScript . SetDataSource ( dd . ToArray ());
2021-09-02 10:08:46 +08:00
#if UNITY_IOS || UNITY_ANDROID
foreach ( var cat in (( IInternalGraphData ) graph . DataSource ). Categories )
{
cat . LineThickness = 2f ;
}
#endif
2021-06-24 18:19:28 +08:00
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 );
2021-09-02 10:08:46 +08:00
#if !( UNITY_IOS || UNITY_ANDROID )
altitudeGraph . gameObject . SetActive ( false );
#endif
2021-06-24 18:19:28 +08:00
}
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 >();
2021-09-02 10:08:46 +08:00
#if UNITY_IOS || UNITY_ANDROID
var width = ( float )( end - start )* 120F ;
rectTransform . DOSizeDelta ( new Vector2 (( float ) width + 5f , 22 ), 1 );
#else
2021-06-24 18:19:28 +08:00
var width = ( float )( end - start )* 286F ;
rectTransform . DOSizeDelta ( new Vector2 (( float ) width + 5f , 40 ), 1 );
2021-09-02 10:08:46 +08:00
#endif
2021-06-24 18:19:28 +08:00
rectTransform . DOLocalMoveX (( float )( left ), 1 );
leftImage . GetComponent < RectTransform >(). DOLocalMoveX (( float ) left , 1 );
rightImage . GetComponent < RectTransform >(). DOLocalMoveX (( float ) right , 1 );
}
}
2021-09-02 10:08:46 +08:00
#region 事件行为
2021-06-24 18:19:28 +08:00
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 );
}
}
2021-09-02 10:08:46 +08:00
#endregion
2021-06-24 18:19:28 +08:00
}
}