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 ( ) ; //渲染海拔图
}
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 > ( ) ;
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 > ( ) ;
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>();
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 ;
alertPanel = uipanel . transform . Find ( "Alert" ) . gameObject ;
selectPanel = uipanel . transform . Find ( "SelectPanel" ) . gameObject ;
selectPlayer = uipanel . transform . Find ( "SelectPlayer" ) . gameObject ;
reviewPanel = uipanel . transform . Find ( "ReviewPanel" ) . gameObject ;
quitPanel = uipanel . transform . Find ( "QuitPanel" ) . 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 = 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 > ( ) ;
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-06-24 18:19:28 +08:00
#endregion
}
protected virtual void Update ( )
{
time - = Time . deltaTime ;
while ( time < 0 ) {
MoveElevationImage ( ) ;
BindDataSource ( ) ;
time = 1 ;
}
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-02 10:08:46 +08:00
GameObject uipanel { get ; set ; }
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-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" ) ;
} ) ;
}
//路书基本信息绑定
mapName . text = routeInstance . Name ;
totalDistance . text = Math . Round ( mainController . GetMapData ( ) . TotalDistance , 1 ) . ToString ( ) + "KM" ; //总里程
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 ( )
{
//获取当前选中玩家绑定当前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)}%" ;
currentSlopeToatalDistanceText . text = $"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 )
{
mainController . ChangeMapImageStyle ( arrow . gameObject ) ;
}
//结束游戏
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 ) ;
}
else
{
SceneManager . LoadScene ( "MainScene" ) ;
}
}
//显示设备连接
public void ShowDevicePanel ( BaseEventData baseEventData )
{
2021-09-02 11:04:50 +08:00
#if UNITY_IOS | | UNITY_ANDROID
UIManager . ShowDevicePanel ( ) ;
#else
2021-09-02 10:08:46 +08:00
UIManager . Show ( UIManager . Instance . DevicePanel , uipanel . GetComponent < PFUIPanel > ( ) ) ;
2021-09-02 11:04:50 +08:00
#endif
2021-06-24 18:19:28 +08:00
}
//显示设置
public void ShowSettingPanel ( BaseEventData baseEventData )
{
settingPanel . SetActive ( true ) ;
}
//进入简约模式
2021-07-23 09:04:56 +08:00
protected int isSimple = 1 ;
protected 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
}
}