AR骑行和对战
This commit is contained in:
1 parent
341d386196
commit
3bcb3ee83e
51 files changed
+146686
-4950
No files matched your search
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 00f4c4316a3455b43bb932530608fa52
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,97 @@
|
||||
using Assets.Scenes.Ride.Scripts;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Assets.Scripts.Scenes.Scripts
|
||||
{
|
||||
class GameRoomPlayerList : MonoBehaviour
|
||||
{
|
||||
private CyclingController manager { get; set; }
|
||||
protected GameObject nearByItem;
|
||||
protected GameObject nearByMajorItem;
|
||||
public Transform parent;
|
||||
|
||||
private Text num;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
manager = FindObjectOfType<CyclingController>();
|
||||
nearByMajorItem = Resources.Load<GameObject>("UI/Prefab/Match/CompetitionRankingMajorItem");
|
||||
nearByItem = Resources.Load<GameObject>("UI/Prefab/Match/CompetitionRankingItem");
|
||||
num = transform.Find("Head/OnlineUserNum").GetComponent<Text>();
|
||||
}
|
||||
|
||||
private void InitData()
|
||||
{
|
||||
Utils.DestroyChildren(parent);
|
||||
manager = FindObjectOfType<CyclingController>();
|
||||
var list = MapUDPService.GetOnlineUsers(App.RouteIdParam, manager.roomId).OrderByDescending(c=>c.EndDistance);
|
||||
int index = 1;
|
||||
num.text = list.Count().ToString();
|
||||
foreach (var item in list)
|
||||
{
|
||||
GameObject prefabItem = item.IsSelf ? nearByMajorItem : nearByItem;
|
||||
GameObject newObj = (GameObject)Instantiate(prefabItem, parent);
|
||||
var competitionRankingItem = newObj.GetComponent<CompetitionRankingItem>();
|
||||
competitionRankingItem.setUserId(item.Id);
|
||||
#if UNITY_IOS || UNITY_ANDROID
|
||||
competitionRankingItem.SetRank(index);
|
||||
#else
|
||||
competitionRankingItem.SetRank(index);
|
||||
#endif
|
||||
competitionRankingItem.setName(item.Name);
|
||||
competitionRankingItem.setRatio(item.WeightKg.ToString("f2") + "W/KG");
|
||||
competitionRankingItem.setSpeed(item.Speed.ToString() + "KM/H");
|
||||
competitionRankingItem.setHead(item.HeadImage);
|
||||
var countryTexture = manager.GetCountryImageByName(item.Country);
|
||||
competitionRankingItem.setCountry(countryTexture);
|
||||
var near = Math.Round((item.EndDistance - manager.currentPlayer.TotalDistance) * 1000);
|
||||
competitionRankingItem.setDistance(manager.currentPlayer.UserId == item.Id ? "0M" : near.ToString() + "M");
|
||||
#if UNITY_IOS || UNITY_ANDROID
|
||||
competitionRankingItem.transform.SetSiblingIndex(index);
|
||||
#else
|
||||
competitionRankingItem.transform.SetSiblingIndex(index);
|
||||
#endif
|
||||
index++;
|
||||
}
|
||||
}
|
||||
float timer = 0f;
|
||||
private void Update()
|
||||
{
|
||||
timer -= Time.deltaTime;
|
||||
while (timer < 0)
|
||||
{
|
||||
InitData();
|
||||
//if (manager.currentPlayer == null)
|
||||
|
||||
//var totalDitance = manager.GetMapData().TotalDistance;
|
||||
//var currentDistance = manager.currentPlayer.TotalDistance;
|
||||
////var currenList = GetComponentsInChildren<ListItem>(true);
|
||||
//var list = MapUDPService.GetOnlineUsers(App.RouteIdParam, manager.cyclingController.recorderData.RoomId);
|
||||
//var currentPlayerInfo = list.Where(c => c.Id.ToString() == manager.currentPlayer.UserId.ToString()).FirstOrDefault();
|
||||
//list = list.Where(c => c.Id != App.CurrentUser.Id).ToList();
|
||||
//var currentPlayer = FindObjectOfType<AbstractPlayer>();
|
||||
|
||||
//foreach (ListItem o in currenList)
|
||||
//{
|
||||
// if (currentPlayer.UserId.ToString() == o.Id)
|
||||
// continue;
|
||||
// var needUpdate = list.Where(c => c.Id.ToString() == o.Id).FirstOrDefault();
|
||||
// if (needUpdate != null && currentPlayerInfo != null)
|
||||
// {
|
||||
// var left = Math.Round((needUpdate.EndDistance - currentPlayerInfo.EndDistance) * 1000);
|
||||
// o.UpdateItem(needUpdate.Name, left.ToString() + "M", needUpdate.Id.ToString());
|
||||
// o.gameObject.SetActive(true);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// o.gameObject.SetActive(false);
|
||||
// }
|
||||
//}
|
||||
timer += 1f;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e0c6a7cf3e8b68c48bf9e6c13a25a97a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,282 @@
|
||||
using Assets.Scenes.Ride.Scripts.Model.CyclingModels;
|
||||
using Assets.Scripts;
|
||||
using Assets.Scripts.UI.UIEffect;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UI;
|
||||
using DG.Tweening;
|
||||
using System;
|
||||
using Facebook.Unity;
|
||||
|
||||
namespace Assets.Scenes.Ride.Scripts
|
||||
{
|
||||
public class GameRoomResultScript : MonoBehaviour
|
||||
{
|
||||
CyclingController cyclingController;
|
||||
RawImage Head;
|
||||
Text Ranking;
|
||||
Text Timer;
|
||||
GameObject Mine { get; set; }
|
||||
GameObject TitleImage { get; set; }
|
||||
GameObject WatchTitle { get; set; }
|
||||
GameObject RankingPanel { get; set; }
|
||||
GameObject ShareButton { get; set; }
|
||||
GameObject ToolBarPanel { get; set; }
|
||||
GameObject WeChatButton { get; set; }
|
||||
GameObject WeChatGpButton { get; set; }
|
||||
|
||||
|
||||
RawImage TopHead { get; set; }
|
||||
RawImage SecondHead { get; set; }
|
||||
RawImage ThirdHead { get; set; }
|
||||
Image Top { get; set; }
|
||||
Sprite SpriteTop { get; set; }
|
||||
Sprite SpriteSecond { get; set; }
|
||||
Sprite SpriteThrid { get; set; }
|
||||
|
||||
Text RankingTitle { get; set; }
|
||||
Text TimerTitle { get; set; }
|
||||
Text CloseTime { get; set; }
|
||||
Text CloseTitle { get; set; }
|
||||
private void Awake()
|
||||
{
|
||||
cyclingController = FindObjectOfType<CyclingController>();
|
||||
var closeBtn = transform.Find("Close").gameObject;
|
||||
Head = transform.Find("Mine/Head").GetComponent<RawImage>();
|
||||
Ranking = transform.Find("Mine/Ranking").GetComponent<Text>();
|
||||
RankingTitle = transform.Find("Mine/RankingTitle").GetComponent<Text>();
|
||||
TimerTitle = transform.Find("Mine/TimerTitle").GetComponent<Text>();
|
||||
Timer = transform.Find("Mine/Timer").GetComponent<Text>();
|
||||
Top = transform.Find("Mine/TOP").GetComponent<Image>();
|
||||
Mine = transform.Find("Mine").gameObject;
|
||||
RankingPanel = transform.Find("Ranking").gameObject;
|
||||
TopHead = transform.Find("Ranking/TopHead").GetComponent<RawImage>();
|
||||
SecondHead = transform.Find("Ranking/SecondHead").GetComponent<RawImage>();
|
||||
ThirdHead = transform.Find("Ranking/ThirdHead").GetComponent<RawImage>();
|
||||
TitleImage = transform.Find("TitleImage").gameObject;
|
||||
WatchTitle = transform.Find("WatchTitle").gameObject;
|
||||
CloseTitle = transform.Find("CloseTitle").GetComponent<Text>();
|
||||
CloseTime = transform.Find("CloseTime").GetComponent<Text>();
|
||||
#if UNITY_IOS || UNITY_ANDROID
|
||||
ShareButton = transform.Find("ShareButton").gameObject;
|
||||
ToolBarPanel = transform.Find("ToolBarPanel").gameObject;
|
||||
WeChatButton = transform.Find("ToolBarPanel/WeChatButton").gameObject;
|
||||
WeChatGpButton = transform.Find("ToolBarPanel/GoogleButton").gameObject;
|
||||
UIManager.AddEvent(WeChatButton, UnityEngine.EventSystems.EventTriggerType.PointerClick, ShareWechat);
|
||||
UIManager.AddEvent(WeChatGpButton, UnityEngine.EventSystems.EventTriggerType.PointerClick, ShareWechatGp);
|
||||
var fbButton = transform.Find("ToolBarPanel/FaceBookButton").gameObject;
|
||||
UIManager.AddEvent(fbButton, EventTriggerType.PointerClick, shareFb);
|
||||
#endif
|
||||
SpriteTop = Resources.Load<Sprite>("Images/Ride/Match/top-1");
|
||||
SpriteSecond = Resources.Load<Sprite>("Images/Ride/Match/top-2");
|
||||
SpriteThrid = Resources.Load<Sprite>("Images/Ride/Match/top-3");
|
||||
|
||||
UIManager.AddEvent(closeBtn, UnityEngine.EventSystems.EventTriggerType.PointerClick, Close);
|
||||
}
|
||||
|
||||
|
||||
float time = 1;
|
||||
private void Update()
|
||||
{
|
||||
//var model = cyclingController.cyclingController as GameModel;
|
||||
//if (model != null)
|
||||
//{
|
||||
///var s = model.EndCountDown();
|
||||
//显示关门时间
|
||||
//var isshow = s.Item3 && s.Item1 >= 0 && !cyclingController.isWatch;
|
||||
//CloseTime.text = Helper.FormatTicks(s.Item1);
|
||||
//CloseTitle.gameObject.SetActive(isshow);
|
||||
//CloseTime.gameObject.SetActive(isshow);
|
||||
//}
|
||||
time -= Time.deltaTime;
|
||||
while (time < 0)
|
||||
{
|
||||
Refresh();
|
||||
time += 1;
|
||||
}
|
||||
}
|
||||
|
||||
private Color RED = new Color(0.9764706f, 0.1882353f, 0.5254902f);
|
||||
private Color SHALLOW_RED = new Color(1f, 0.454902f, 0.5215687f);
|
||||
|
||||
private Color PURPLE = new Color(0.1568628f, 0.4431373f, 0.8745098f);
|
||||
private Color SHALLOW_PURPLE = new Color(0.3843137f, 0.7764706f, 1f);
|
||||
|
||||
private Color BLUE = new Color(0.4352941f, 0.3333333f, 0.9372549f);
|
||||
private Color SHALLOW_BLUE = new Color(0.772549f, 0.5529412f, 1f);
|
||||
|
||||
private Color WHITE = new Color(1f, 1f, 1f);
|
||||
|
||||
|
||||
public void Refresh()
|
||||
{
|
||||
if (cyclingController.cyclingController is GameModel model)
|
||||
{
|
||||
var list = model?.mapWorkoutRecordRankings;
|
||||
if (list == null) return;
|
||||
var parent = transform.Find("ScrollView/Viewport/Content");
|
||||
|
||||
Mine.SetActive(!cyclingController.isWatch);
|
||||
RankingPanel.SetActive(cyclingController.isWatch);
|
||||
TitleImage.SetActive(!cyclingController.isWatch);
|
||||
WatchTitle.SetActive(cyclingController.isWatch);
|
||||
|
||||
if (model.FirstEndTime.HasValue)
|
||||
{
|
||||
var gap = model.FirstEndTime.Value - UIManager.Now.GetDateTime();
|
||||
var seconds = (int)Math.Floor(gap.TotalSeconds);
|
||||
CloseTime.text = Helper.FormatTicks(seconds);
|
||||
CloseTitle.gameObject.SetActive(true);
|
||||
CloseTime.gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
if (!cyclingController.isWatch)
|
||||
{
|
||||
//当前用户排名
|
||||
var currentRanking = list.Where(c => c.UserId == cyclingController.currentPlayer.UserId).FirstOrDefault();
|
||||
if (currentRanking != null)
|
||||
{
|
||||
Utils.DisplayImage(Head, currentRanking.WxHeadImg, true);
|
||||
Ranking.text = currentRanking.Rank.ToString().PadLeft(3, '0');
|
||||
Timer.text = currentRanking.TotalTime;
|
||||
var uigradient = Mine.transform.GetComponent<UIGradient>();
|
||||
if (currentRanking.Rank <= 3)
|
||||
{
|
||||
TimerTitle.color = WHITE;
|
||||
RankingTitle.color = WHITE;
|
||||
}
|
||||
if (currentRanking.Rank == 1)
|
||||
{
|
||||
uigradient.color1 = RED;
|
||||
uigradient.color2 = SHALLOW_RED;
|
||||
Top.sprite = SpriteTop;
|
||||
Top.gameObject.SetActive(true);
|
||||
}
|
||||
if (currentRanking.Rank == 2)
|
||||
{
|
||||
uigradient.color1 = PURPLE;
|
||||
uigradient.color2 = SHALLOW_PURPLE;
|
||||
Top.sprite = SpriteSecond;
|
||||
Top.gameObject.SetActive(true);
|
||||
}
|
||||
if (currentRanking.Rank == 3)
|
||||
{
|
||||
uigradient.color1 = BLUE;
|
||||
uigradient.color2 = SHALLOW_BLUE;
|
||||
Top.sprite = SpriteThrid;
|
||||
Top.gameObject.SetActive(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//观察者模式左边显示前三名
|
||||
var topList = list.OrderBy(c => c.Rank).Take(3);
|
||||
foreach (var item in topList)
|
||||
{
|
||||
if (item.Rank == 1)
|
||||
{
|
||||
Utils.DisplayImage(TopHead, item.WxHeadImg, true);
|
||||
var name = TopHead.transform.Find("Name").GetComponent<Text>();
|
||||
name.text = item.NickName;
|
||||
TopHead.gameObject.SetActive(true);
|
||||
}
|
||||
if (item.Rank == 2)
|
||||
{
|
||||
Utils.DisplayImage(SecondHead, item.WxHeadImg, true);
|
||||
var name = SecondHead.transform.Find("Name").GetComponent<Text>();
|
||||
name.text = item.NickName;
|
||||
SecondHead.gameObject.SetActive(true);
|
||||
}
|
||||
if (item.Rank == 3)
|
||||
{
|
||||
Utils.DisplayImage(ThirdHead, item.WxHeadImg, true);
|
||||
var name = ThirdHead.transform.Find("Name").GetComponent<Text>();
|
||||
name.text = item.NickName;
|
||||
ThirdHead.gameObject.SetActive(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//排名列表
|
||||
var rankingList = FindObjectsOfType<FinalRankingItemScript>();
|
||||
foreach (var item in list)
|
||||
{
|
||||
var finalRankingItemScript = rankingList.Where(c => c.UserId == item.UserId).FirstOrDefault();
|
||||
//没有就创建
|
||||
if (finalRankingItemScript == null)
|
||||
{
|
||||
#if UNITY_IOS || UNITY_ANDROID
|
||||
var finalRankingItem = Instantiate(Resources.Load<GameObject>("UI/Prefab/Match/Mobile/FinalRankingItem"), parent);
|
||||
#else
|
||||
var finalRankingItem = Instantiate(Resources.Load<GameObject>("UI/Prefab/Match/FinalRankingItem"), parent);
|
||||
#endif
|
||||
finalRankingItemScript = finalRankingItem.GetComponent<FinalRankingItemScript>();
|
||||
}
|
||||
|
||||
//有就更新
|
||||
finalRankingItemScript.setGap(item.Gap);
|
||||
//finalRankingItemScript.setSource(item.de);
|
||||
finalRankingItemScript.setUserId(item.UserId, item.WxHeadImg);
|
||||
finalRankingItemScript.setRanking(item.Rank);
|
||||
finalRankingItemScript.setHeartRate(item.HeartRate);
|
||||
finalRankingItemScript.setName(item.NickName);
|
||||
finalRankingItemScript.setPower(item.Power.ToString());
|
||||
finalRankingItemScript.setRatio(item.WeightKG);
|
||||
finalRankingItemScript.setTimer(item.TotalTime);
|
||||
finalRankingItemScript.transform.SetSiblingIndex(item.Rank);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void Close(BaseEventData baseEventData)
|
||||
{
|
||||
this.gameObject.SetActive(false);
|
||||
this.Destroy();
|
||||
SceneManager.LoadScene("MainScene");
|
||||
//App.MainSceneParam["Name"] = "RaceHomePanel";
|
||||
}
|
||||
|
||||
private void OpenShare(BaseEventData baseEventData)
|
||||
{
|
||||
((RectTransform)ToolBarPanel.transform).pivot = new Vector2(0, ((RectTransform)ToolBarPanel.transform).pivot.y);
|
||||
ShareButton.SetActive(false);
|
||||
ToolBarPanel.transform.DOScaleX(1, 1);
|
||||
}
|
||||
|
||||
private void ShareWechat(BaseEventData baseEventData)
|
||||
{
|
||||
if (!App.weChatController.IsWeChatAppInstalled())
|
||||
{
|
||||
App.weChatController.ShareWebpageToWX(0, $"{App.CurrentUser.WebHost}Mine/MatchPreview?id={cyclingController.competitionId}&Token={App.CurrentUser.cookie}", cyclingController.competition.Title, "By " + App.CurrentUser.Nickname, null);
|
||||
}
|
||||
else
|
||||
{
|
||||
Utils.showToast(null, "未安装微信");
|
||||
}
|
||||
}
|
||||
private void shareFb(BaseEventData arg0)
|
||||
{
|
||||
//cyclingController.competition.Title, "By " + App.CurrentUser.Nickname, null)
|
||||
FB.ShareLink(contentURL: new Uri($"{App.CurrentUser.WebHost}Mine/MatchPreview?id={cyclingController.competitionId}&Token={App.CurrentUser.cookie}"),
|
||||
contentTitle: cyclingController.competition.Title,
|
||||
contentDescription: "By " + App.CurrentUser.Nickname,
|
||||
photoURL: new Uri(cyclingController.competition.CoverImage));
|
||||
}
|
||||
|
||||
private void ShareWechatGp(BaseEventData baseEventData)
|
||||
{
|
||||
if (App.weChatController.IsWeChatAppInstalled())
|
||||
{
|
||||
App.weChatController.ShareWebpageToWX(1, $"{App.CurrentUser.WebHost}Mine/MatchPreview?id={cyclingController.competitionId}&Token={App.CurrentUser.cookie}", cyclingController.competition.Title, "By " + App.CurrentUser.Nickname, null);
|
||||
}
|
||||
else
|
||||
{
|
||||
Utils.showToast(null, "未安装微信");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 180198074f4b2344d8fd96e8e068324b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,260 @@
|
||||
using UnityEngine;
|
||||
using DG.Tweening;
|
||||
using Assets.Scenes.Ride.Scripts.Model;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.SceneManagement;
|
||||
using Assets.Scenes.Ride.Scripts.Model.CyclingModels;
|
||||
using System;
|
||||
|
||||
namespace Assets.Scenes.Ride.Scripts
|
||||
{
|
||||
public class GameRoomUIManager : BaseUIManager
|
||||
{
|
||||
protected override void Awake()
|
||||
{
|
||||
base.Awake();
|
||||
}
|
||||
GameObject countDownPanel { get; set; }
|
||||
Text title { get; set; }
|
||||
Text timer { get; set; }
|
||||
GameObject raceViewBtn { get; set; }
|
||||
GameObject timerIcon { get; set; }
|
||||
|
||||
GameModel model { get; set; }
|
||||
protected override void Start()
|
||||
{
|
||||
base.Start();
|
||||
|
||||
reviewPanel.SetActive(false);
|
||||
//隐藏单人骑行时间
|
||||
var spilitLineH2 = uipanel.transform.Find("ComputerPanel/SpilitLineH2").gameObject;
|
||||
raceViewBtn = uipanel.transform.Find("RaceViewButton").gameObject;
|
||||
#if UNITY_IOS || UNITY_ANDROID
|
||||
timerIcon = uipanel.transform.Find("ComputerPanel/TimerIcon").gameObject;
|
||||
timerIcon.SetActive(false);
|
||||
#else
|
||||
viewButton.gameObject.SetActive(false);
|
||||
#endif
|
||||
|
||||
UIManager.AddEvent(raceViewBtn, UnityEngine.EventSystems.EventTriggerType.PointerClick, ChangeView);
|
||||
|
||||
spilitLineH2.SetActive(false);
|
||||
//timerTxt.gameObject.SetActive(false);
|
||||
//timerTxtTitle.gameObject.SetActive(false);
|
||||
//观察者模式隐藏坡度
|
||||
if (mainController.isWatch)
|
||||
{
|
||||
nextSlopePanel.SetActive(false);
|
||||
currentSlopePanel.SetActive(false);
|
||||
}
|
||||
altitudeGraph.gameObject.SetActive(false);
|
||||
//暂停按钮禁用
|
||||
pauseButton.interactable = false;
|
||||
InitGameObject();
|
||||
}
|
||||
protected override void Update()
|
||||
{
|
||||
base.Update();
|
||||
CountDown();
|
||||
}
|
||||
|
||||
//开始游戏触发事件
|
||||
public void StartRide(BaseEventData baseEventData)
|
||||
{
|
||||
this.StartRide();
|
||||
}
|
||||
|
||||
public void StartRide(int seconds)
|
||||
{
|
||||
mainController.SetCyclingModel(CyclingModel.GameRoom);
|
||||
count = seconds;
|
||||
startPanel.SetActive(false);
|
||||
startBtn.gameObject.SetActive(false);
|
||||
countDownTxt.gameObject.SetActive(true);
|
||||
countDownTxt.text = count.ToString();
|
||||
}
|
||||
bool canStart = false;
|
||||
GameObject watchPanel { get; set; }
|
||||
//开始骑行-加个5秒钟倒计时
|
||||
public override void StartRide()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void InitGameObject()
|
||||
{
|
||||
miniMap.SetActive(false); //隐藏小地图
|
||||
#if UNITY_IOS || UNITY_ANDROID
|
||||
countDownPanel = Instantiate(Resources.Load<GameObject>("UI/Prefab/Match/Mobile/CountDownPanel"), uipanel.transform);
|
||||
title = countDownPanel.transform.Find("Title").GetComponent<Text>();
|
||||
timer = countDownPanel.transform.Find("Timer").GetComponent<Text>();
|
||||
competitionRankingList = Instantiate(Resources.Load<GameObject>("UI/Prefab/Match/Mobile/CompetitionRankingPanel"), uipanel.transform);
|
||||
topRankPanel = Instantiate(Resources.Load<GameObject>("UI/Prefab/Match/Mobile/TopRankPanel"), uipanel.transform);
|
||||
watchPanel = Instantiate(Resources.Load<GameObject>("UI/Prefab/Match/Mobile/WatcherPanel"), uipanel.transform);
|
||||
#else
|
||||
//countDownPanel = Instantiate(Resources.Load<GameObject>("UI/Prefab/Match/CountDownPanel"), uipanel.transform);
|
||||
//title = countDownPanel.transform.Find("Title").GetComponent<Text>();
|
||||
//timer = countDownPanel.transform.Find("Timer").GetComponent<Text>();
|
||||
competitionRankingList = Instantiate(Resources.Load<GameObject>("UI/Prefab/GameRoom/GameRoomRankingPanel"), uipanel.transform);
|
||||
topRankPanel = Instantiate(Resources.Load<GameObject>("UI/Prefab/Match/TopRankPanel"), uipanel.transform);
|
||||
//watchPanel = Instantiate(Resources.Load<GameObject>("UI/Prefab/Match/WatcherPanel"), uipanel.transform);
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
private void CountDown()
|
||||
{
|
||||
//倒计时开始对战
|
||||
if (count > 0)
|
||||
{
|
||||
timeRemaining -= Time.deltaTime;
|
||||
if (timeRemaining <= 0)//定时器
|
||||
{
|
||||
count--;
|
||||
if (count == 0)
|
||||
{
|
||||
mainController.SetStart();
|
||||
var canvasGroup = countDownTxt.transform.GetComponent<CanvasGroup>();
|
||||
canvasGroup.DOFade(0, 1).onComplete += () => {
|
||||
countDownTxt.gameObject.SetActive(false);
|
||||
canvasGroup.alpha = 1;
|
||||
};
|
||||
}
|
||||
if (count == 1 && mainController.cyclingModel == CyclingModel.Single)
|
||||
{
|
||||
reviewPanel.GetComponent<CanvasGroup>().DOFade(0, 1).onComplete += () => {
|
||||
reviewPanel.gameObject.SetActive(false);
|
||||
};
|
||||
}
|
||||
countDownTxt.transform.DOPunchScale(new Vector3(1.2f, 1.2f, 1.2f), 1, 1, 1);
|
||||
timeRemaining = 1.0f;
|
||||
}
|
||||
}
|
||||
countDownTxt.text = count == 0 ? App.GetLocalString("GO!") : count.ToString();
|
||||
model = mainController.cyclingController as GameModel;
|
||||
//第一名诞生开始倒计时,倒计时结束自动保存
|
||||
if (model != null && model.FirstEndTime.HasValue && !FirstCompleted && App.CurrentUser.Id != model.FirstUserId)
|
||||
{
|
||||
FirstCompleted = true;
|
||||
var gap = model.FirstEndTime.Value - UIManager.Now.GetDateTime();
|
||||
var seconds = Math.Floor(gap.TotalSeconds);
|
||||
UIManager.ShowGameRoomCountDownPanel((int)seconds, () =>
|
||||
{
|
||||
SaveRide(null);
|
||||
}, true);
|
||||
}
|
||||
if (mainController.isQuit && !Saved)
|
||||
{
|
||||
Saved = true;
|
||||
ShowResultList();
|
||||
FindObjectOfType<GameRoomCountDownController>()?.Close();
|
||||
}
|
||||
}
|
||||
|
||||
private bool FirstCompleted;
|
||||
|
||||
private bool Saved;
|
||||
|
||||
public override void SaveRide(BaseEventData baseEventData)
|
||||
{
|
||||
//观察者退出
|
||||
if (mainController.isWatch)
|
||||
{
|
||||
SceneManager.LoadScene("MainScene");
|
||||
return;
|
||||
}
|
||||
//参赛者保存并弹出赛事结果
|
||||
if (!mainController.isQuit)
|
||||
{
|
||||
mainController.SetQuit();
|
||||
playerController.Upload();
|
||||
quitPanel.SetActive(false);
|
||||
transform.Find("ModalPanel").gameObject.SetActive(false);
|
||||
}
|
||||
ShowResultList();//保存显示当前排名
|
||||
}
|
||||
|
||||
public override void ContinueRide()
|
||||
{
|
||||
//mainController.SetCyclingModel(CyclingModel.GameRoom);
|
||||
}
|
||||
public override void PauseRide(BaseEventData baseEventData)
|
||||
{
|
||||
return;
|
||||
}
|
||||
//实时显示当前比赛排名
|
||||
GameObject competitionRankingList;
|
||||
public void ShowCurrentRanking()
|
||||
{
|
||||
if (competitionRankingList == null)
|
||||
{
|
||||
#if UNITY_IOS || UNITY_ANDROID
|
||||
competitionRankingList = Instantiate(Resources.Load<GameObject>("UI/Prefab/Match/Mobile/CompetitionRankingPanel"), uipanel.transform);
|
||||
#else
|
||||
competitionRankingList = Instantiate(Resources.Load<GameObject>("UI/Prefab/GameRoom/GameRoomRankingPanel"), uipanel.transform);
|
||||
#endif
|
||||
}
|
||||
if (topRankPanel == null)
|
||||
{
|
||||
#if UNITY_IOS || UNITY_ANDROID
|
||||
topRankPanel = Instantiate(Resources.Load<GameObject>("UI/Prefab/Match/Mobile/TopRankPanel"), uipanel.transform);
|
||||
#else
|
||||
topRankPanel = Instantiate(Resources.Load<GameObject>("UI/Prefab/Match/TopRankPanel"), uipanel.transform);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
GameObject competitionResultPanel;
|
||||
GameObject topRankPanel;
|
||||
//实时刷新显示比赛结果
|
||||
public void ShowResultList()
|
||||
{
|
||||
if (competitionResultPanel == null)
|
||||
{
|
||||
#if UNITY_IOS || UNITY_ANDROID
|
||||
competitionResultPanel = Instantiate(Resources.Load<GameObject>("UI/Prefab/Match/Mobile/GameRoomResultPanel"), uipanel.transform);
|
||||
#else
|
||||
competitionResultPanel = Instantiate(Resources.Load<GameObject>("UI/Prefab/GameRoom/GameRoomResultPanel"), uipanel.transform);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
//极简模式
|
||||
public override void ClearPanel(BaseEventData baseEventData)
|
||||
{
|
||||
if (clearLock)
|
||||
{
|
||||
base.ClearPanel(baseEventData);
|
||||
//countDownPanel.transform.DOLocalMove(new Vector3(countDownPanel.transform.localPosition.x + isSimple * -430f, countDownPanel.transform.localPosition.y, countDownPanel.transform.localPosition.z), 1);
|
||||
topRankPanel.transform.DOLocalMove(new Vector3(topRankPanel.transform.localPosition.x + isSimple * -430f, topRankPanel.transform.localPosition.y, topRankPanel.transform.localPosition.z), 1);
|
||||
competitionRankingList.transform.DOLocalMove(new Vector3(competitionRankingList.transform.localPosition.x + isSimple * 430f, competitionRankingList.transform.localPosition.y, competitionRankingList.transform.localPosition.z), 1);
|
||||
//watchPanel.transform.DOLocalMove(new Vector3(watchPanel.transform.localPosition.x, watchPanel.transform.localPosition.y + isSimple * 260f, watchPanel.transform.localPosition.z), 1);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetMobileViewButton(bool enabled)
|
||||
{
|
||||
#if UNITY_IOS || UNITY_ANDROID
|
||||
//viewButton.enabled = enabled;
|
||||
viewButton.interactable = enabled;
|
||||
#endif
|
||||
}
|
||||
|
||||
protected override void StopRide(BaseEventData baseEventData)
|
||||
{
|
||||
if (mainController.isWatch)
|
||||
{
|
||||
UIManager.ShowConfirm("Quit", "Do you want to quit?", async () =>
|
||||
{
|
||||
SceneManager.LoadScene("MainScene");
|
||||
UIManager.CloseConfirm();
|
||||
});
|
||||
}
|
||||
//参赛者:提醒是否退出并保存赛事结果
|
||||
else
|
||||
{
|
||||
base.StopRide(baseEventData);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0821b0665a03be14c90fc2250e9b1d4c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -153,20 +153,27 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
//人物动画控制
|
||||
if (characterAnimator != null)
|
||||
{
|
||||
characterAnimator.SetFloat("Speed", (float)speed);
|
||||
characterAnimator.SetFloat("Slope", (float)currentSlope);
|
||||
if (currentSlope > 6)
|
||||
{
|
||||
characterAnimator.speed = 0.45f;
|
||||
}
|
||||
else
|
||||
{
|
||||
characterAnimator.speed = 0.65f;
|
||||
}
|
||||
if (speed > 40)
|
||||
//characterAnimator.SetFloat("Speed", (float)speed);
|
||||
//characterAnimator.SetFloat("Slope", (float)currentSlope);
|
||||
if (characterAnimator != null)
|
||||
{
|
||||
characterAnimator.speed = 0.75f;
|
||||
//characterAnimator.SetFloat("preSpeed", (float)preSpeed);
|
||||
characterAnimator.SetFloat("speed", (float)speed);
|
||||
characterAnimator.SetFloat("grade", (float)currentSlope);
|
||||
characterAnimator.SetFloat("power", (float)power);
|
||||
}
|
||||
//if (currentSlope > 6)
|
||||
// {
|
||||
// characterAnimator.speed = 0.45f;
|
||||
//}
|
||||
// else
|
||||
// {
|
||||
// characterAnimator.speed = 0.65f;
|
||||
//}
|
||||
//if (speed > 40)
|
||||
//{
|
||||
// characterAnimator.speed = 0.75f;
|
||||
//}
|
||||
|
||||
//if (totalDistance >= mapData.TotalDistance)
|
||||
//{
|
||||
@@ -327,7 +334,7 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
{
|
||||
if (prePos != nextPos)
|
||||
{
|
||||
Quaternion neededRotation = Quaternion.LookRotation(prePos - nextPos);
|
||||
Quaternion neededRotation = Quaternion.LookRotation(nextPos-prePos);
|
||||
|
||||
float t = 0;
|
||||
while (t < 1.0f)
|
||||
|
||||
@@ -53,7 +53,7 @@ public class CyclingController : DeviceServiceMonoBase
|
||||
public BaseCycling cyclingController { get; set; }
|
||||
private int routeId;
|
||||
public int competitionId { get; set; }
|
||||
|
||||
public int roomId { get; set; }
|
||||
private MapApi mapApi;
|
||||
public DateTime startTime { get; set; }
|
||||
public DateTime endTime;
|
||||
@@ -90,6 +90,7 @@ public class CyclingController : DeviceServiceMonoBase
|
||||
mapApi = ConfigHelper.mapApi;
|
||||
routeId = App.RouteIdParam > 0 ? App.RouteIdParam : 2633;
|
||||
competitionId = App.CompetionId;
|
||||
roomId = App.gameRoomDetail?.RoomId ??0;
|
||||
App.CompetionId = 0;//清空比赛参数
|
||||
|
||||
//处理异常中断的骑行
|
||||
@@ -104,10 +105,8 @@ public class CyclingController : DeviceServiceMonoBase
|
||||
|
||||
void OnDestroy()
|
||||
{
|
||||
//MapUDPService.Dispose();
|
||||
TouchKit.removeAllGestureRecognizers();
|
||||
Resources.UnloadUnusedAssets();
|
||||
GC.Collect();
|
||||
}
|
||||
Transform target;
|
||||
GameObject watcher;
|
||||
@@ -242,21 +241,23 @@ public class CyclingController : DeviceServiceMonoBase
|
||||
|
||||
HandleTouchAndInput();
|
||||
StartCoroutine(Ping());
|
||||
//进入对战房间
|
||||
if (App.gameRoomDetail != null)
|
||||
{
|
||||
this.cyclingModel = CyclingModel.GameRoom;
|
||||
StartCoroutine(InitGameRoom());
|
||||
}
|
||||
//进入比赛
|
||||
if (competitionId > 0)
|
||||
else if(competitionId > 0)
|
||||
{
|
||||
this.cyclingModel = CyclingModel.Competition;
|
||||
StartCoroutine(InitRace());
|
||||
return;
|
||||
}
|
||||
//进入单人骑行
|
||||
if (routeId > 0)
|
||||
else if(routeId > 0)
|
||||
{
|
||||
StartCoroutine(Init());
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
private IEnumerator Ping()
|
||||
{
|
||||
@@ -566,7 +567,7 @@ public class CyclingController : DeviceServiceMonoBase
|
||||
}
|
||||
private IEnumerator Init()
|
||||
{
|
||||
yield return null; //new WaitForSeconds(1);
|
||||
yield return null;
|
||||
mapRoute = mapApi.GetById(routeId).data;
|
||||
loadingController.Init();//初始化loading页面
|
||||
loadingController.AddProcess(10);
|
||||
@@ -575,7 +576,19 @@ public class CyclingController : DeviceServiceMonoBase
|
||||
MapUDPService.Init();//初始化TCP
|
||||
loadingController.AddProcess(10);
|
||||
}
|
||||
|
||||
|
||||
//初始对战
|
||||
private IEnumerator InitGameRoom()
|
||||
{
|
||||
yield return null;
|
||||
mapRoute = mapApi.GetById(routeId).data;
|
||||
loadingController.Init();
|
||||
loadingController.AddProcess(10);
|
||||
InitGameRoomData();
|
||||
InitGameRoomObject();
|
||||
loadingController.AddProcess(10);
|
||||
}
|
||||
|
||||
//初始比赛
|
||||
private IEnumerator InitRace()
|
||||
{
|
||||
@@ -641,6 +654,30 @@ public class CyclingController : DeviceServiceMonoBase
|
||||
}
|
||||
}
|
||||
|
||||
private void InitGameRoomData()
|
||||
{
|
||||
mapData = mapApi.GetData(routeId);//获取路书地理数据
|
||||
route = new Route(mapData, mapRoute);
|
||||
loadingController.AddProcess(10);
|
||||
#region 其他场景传参处理
|
||||
selectParamModel = new RouteResultParam
|
||||
{
|
||||
CompetitionId = 0,
|
||||
ContinueIndex = 0,
|
||||
ContinueMark = "",
|
||||
GlobalContinue = false,
|
||||
EndDistance = 0,
|
||||
RankingsId = new List<string>(),
|
||||
OnlineUserId = 0,
|
||||
RouteId = App.RouteIdParam,
|
||||
};
|
||||
|
||||
#endregion
|
||||
double endDistance = selectParamModel.EndDistance;
|
||||
//计算上次骑行距离调整地图中心点
|
||||
coordiantes = Along(endDistance);
|
||||
}
|
||||
|
||||
private void InitRaceData()
|
||||
{
|
||||
mapData = mapApi.GetData(routeId);//获取路书地理数据
|
||||
@@ -680,6 +717,27 @@ public class CyclingController : DeviceServiceMonoBase
|
||||
map.OnTileFinished += Map_OnTileFinished;
|
||||
mapPos = map.transform.position;
|
||||
}
|
||||
private void InitGameRoomObject()
|
||||
{
|
||||
#if !(UNITY_IOS || UNITY_ANDROID)
|
||||
minicamera.SetActive(true);
|
||||
map.gameObject.SetActive(true);
|
||||
player.SetActive(true);
|
||||
UIObject.SetActive(true);
|
||||
singleUIManager = UIObject.AddComponent<GameRoomUIManager>();
|
||||
map.OnTileFinished += Map_OnTileFinished;
|
||||
mapPos = map.transform.position;
|
||||
//为了解决比赛观看模式下,切换观看用户之前跨度过大导致地图海拔信息不完整的问题
|
||||
RangeAroundTransformTileProviderOptions options = new RangeAroundTransformTileProviderOptions
|
||||
{
|
||||
targetTransform = target,
|
||||
visibleBuffer = 2,
|
||||
disposeBuffer = 2
|
||||
};
|
||||
map.SetExtent(MapExtentType.RangeAroundTransform, options);
|
||||
map.SetExtentOptions(options);
|
||||
#endif
|
||||
}
|
||||
|
||||
private void InitRaceGameObject()
|
||||
{
|
||||
@@ -1207,14 +1265,13 @@ public BaseUIManager singleUIManager;
|
||||
public void Save(double totalDistance)
|
||||
{
|
||||
ClearTempFile();
|
||||
|
||||
cyclingController.recorderData.EndTime = UIManager.Now.GetDateTime();
|
||||
isQuit = true;
|
||||
isStart = false;
|
||||
//string recordId = Guid.NewGuid().ToString();
|
||||
//var path = Helper.GetDataDir("MapWorkoutRecords/"+ recordId);
|
||||
var path = PFConstants.MapWorkoutRecordFolder + "/" + recordId;
|
||||
Helper.CreateDirectoryIfNotExsit(path);
|
||||
|
||||
|
||||
string imageFileName = path +"/"+ Guid.NewGuid().ToString() + ".png";
|
||||
CaptureCamera(Camera.main, new Rect(Screen.width * 0f, Screen.height * 0f, Screen.width * 0.5f, Screen.height * 0.5f), imageFileName);
|
||||
cyclingController.recorderData.StartTime = startTime;
|
||||
@@ -1226,7 +1283,7 @@ public BaseUIManager singleUIManager;
|
||||
cyclingController.recorderData.DeviceNumber = DeviceNumber;
|
||||
RankingId =cyclingController.recorderData.SaveWithLocalRecordAysnc(cyclingModel, selectParamModel, imageFileName, recordId, path);
|
||||
//显示骑行结果(如果是比赛模式显示比赛最终排名)
|
||||
if (cyclingModel != CyclingModel.Competition)
|
||||
if (cyclingModel != CyclingModel.Competition && cyclingModel != CyclingModel.GameRoom)
|
||||
{
|
||||
resultPanel.SetActive(true);
|
||||
var rs = resultPanel.GetComponent<ResultPanelScript>();
|
||||
@@ -1267,10 +1324,7 @@ public BaseUIManager singleUIManager;
|
||||
protected void CaptureCamera(Camera camera, Rect rect,string fileName)
|
||||
{
|
||||
byte[] bytes = CaptureCameraReturnByte(camera, rect);
|
||||
//var path = Helper.GetDataDir("MapWorkoutRecords/images");
|
||||
//string filename = path + "/" + Guid.NewGuid().ToString() + ".png";
|
||||
System.IO.File.WriteAllBytes(fileName, bytes);
|
||||
//Debug.Log(string.Format("截屏了一张照片: {0}", filename));
|
||||
}
|
||||
|
||||
public Vector2d GetCenterCoordinate()
|
||||
|
||||
@@ -39,7 +39,7 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
return ((GeographicPosition)((GeoJSON.Net.Geometry.Point)pt1.Geometry).Coordinates);
|
||||
}
|
||||
|
||||
public double Bearing(double[] p1, double[] p2)
|
||||
public static double Bearing(double[] p1, double[] p2)
|
||||
{
|
||||
var pt1 = Turf.Point(p1);
|
||||
var pt2 = Turf.Point(p2);
|
||||
|
||||
@@ -159,9 +159,10 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
}
|
||||
|
||||
protected CustomRange pre { get; set; }
|
||||
protected CustomRange next { get; set; }
|
||||
public CustomRange next { get; set; }
|
||||
|
||||
protected float t { get; set; }
|
||||
protected float t { get; set; }
|
||||
protected Vector3 currentRotation;
|
||||
protected virtual void Turn()
|
||||
{
|
||||
//控制人物的转向
|
||||
@@ -179,12 +180,13 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
t = next.KeyFrame - pre.KeyFrame == 0 ? 1 : (float)(currentFrame - pre.KeyFrame) / (float)(next.KeyFrame - pre.KeyFrame);
|
||||
|
||||
var p = new Vector3(0, pre.RotationY, pre.RotationZ);
|
||||
var q = new Vector3(0, next.RotationY, next.RotationZ);
|
||||
t = next.KeyFrame - pre.KeyFrame == 0 ? 1 : (float)(currentFrame - pre.KeyFrame) / (float)(next.KeyFrame - pre.KeyFrame);
|
||||
var rt = Vector3.Lerp(p, q, t);
|
||||
transform.DORotate(rt, 0, RotateMode.Fast);
|
||||
currentRotation = Vector3.Lerp(p, q, t);
|
||||
transform.DORotate(currentRotation, 0, RotateMode.Fast);
|
||||
}
|
||||
|
||||
//计算人物当前属性
|
||||
@@ -280,7 +282,6 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
decimal right = (decimal)sumDistance;
|
||||
if (left <= right)
|
||||
{
|
||||
Debug.Log($"当前索引{i}");
|
||||
currentIndex = i;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Assets.Scenes.Ride.Scripts;
|
||||
using DG.Tweening;
|
||||
using UnityEngine;
|
||||
|
||||
@@ -10,9 +12,21 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
public Transform target;
|
||||
public double diff;
|
||||
public int frames;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
base.Start();
|
||||
ydic.Add(0, -1);
|
||||
ydic.Add(1555, 0);
|
||||
}
|
||||
protected override void Update()
|
||||
{
|
||||
base.Update();
|
||||
//如果当前用户是被观察则控制视频播放
|
||||
if (manager.CurrentPlayer.UserId == UserId)
|
||||
{
|
||||
manager.Play(manager.CurrentPlayer.totalDistance);
|
||||
}
|
||||
}
|
||||
|
||||
//计算
|
||||
@@ -24,22 +38,72 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
//var left = totalDistance % mapData.TotalDistance;
|
||||
//var right = current.totalDistance % mapData.TotalDistance;
|
||||
//diff = (left - right) * 1000;
|
||||
if (Math.Abs(diff) > 100)
|
||||
if (Math.Abs(diff*1000) > 150)
|
||||
{
|
||||
Destroy();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private const int rate = 20;// z轴与帧数的比例 1 :20
|
||||
private const int zrate = 20;// z轴与帧数的比例 1 :20 与真实距离 1:2
|
||||
private const int yrate = 3;// y轴与帧数的比例 1 :3
|
||||
private const int xrate = 20;// x轴与帧数的比例 1 :20
|
||||
|
||||
private Dictionary<int, float> ydic = new Dictionary<int, float>();
|
||||
|
||||
//人物向前超车 右边超车
|
||||
protected override void Turn()
|
||||
{
|
||||
base.Turn();
|
||||
//计算前后位移
|
||||
var current = manager.CurrentPlayer;
|
||||
var interval = this.currentFrame - manager.GetCurrentFrame();
|
||||
var z = current.transform.position.z + interval / rate;
|
||||
transform.DOMoveZ((float)z, 1f);
|
||||
var z = current.transform.position.z + interval / zrate;//diff * 500;//
|
||||
transform.DOMoveZ((float)z,1f);
|
||||
//计算上下位移
|
||||
var targetIndex = manager.CurrentPlayer.currentIndex;
|
||||
var pointList = mapData.List;
|
||||
var currentHeight = pointList[currentIndex].Elevation;//当前海拔,
|
||||
var targetHeight = pointList[targetIndex].Elevation;//目标海拔
|
||||
var heightOffset = (currentHeight - targetHeight);
|
||||
var maxEl = pointList.Max(c => c.Elevation);
|
||||
var minEl = pointList.Min(c => c.Elevation);
|
||||
var y = diff != 0 ? heightOffset / (diff * 1000) * z-1 : 0;
|
||||
var target = manager.CurrentPlayer.transform;
|
||||
if (diff > 0)
|
||||
{
|
||||
var h = heightOffset / (diff*1000);
|
||||
var height = h * (z - target.position.z) - 1;
|
||||
//if (heightOffset < 0)
|
||||
//{
|
||||
// heightOffset *= 2;
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// heightOffset /= 100;
|
||||
//}
|
||||
if (height != 0)
|
||||
{
|
||||
transform.DOMoveY((float)height, 1f);
|
||||
}
|
||||
else
|
||||
{
|
||||
transform.DOMoveY(-1, 1f);
|
||||
}
|
||||
}
|
||||
////计算左右倾斜角度
|
||||
var targetLatlon = manager.CurrentPlayer.currentlatLon; //目标gps
|
||||
var bearing = TurfHelper.Bearing(targetLatlon.ToArray(), currentlatLon.ToArray());
|
||||
//currentRotation.y += (float)bearing;
|
||||
//transform.DORotate(currentRotation, 1, RotateMode.Fast);
|
||||
//计算左右位移
|
||||
//x =(z - z1)/tanp + x1;
|
||||
|
||||
bearing = (next.RotationY + manager.CurrentPlayer.next.RotationY) * Math.PI / 180;//转化为弧度值
|
||||
var x =(z - target.position.z) * Math.Tan(bearing) + target.position.x;
|
||||
Debug.Log($"当前海拔差{heightOffset} 当前角度{bearing} 距离{(z - target.position.z)}*Tan(bearing){Math.Tanh(bearing)}+目标x{target.position.x}=当前x{x}");
|
||||
transform.DOMoveX((float)x, 1f);
|
||||
|
||||
//x轴位移
|
||||
//var x = bearing + current.bearing;
|
||||
//transform.DOMove(new Vector3(x, transform.position.y, (float)z), 1); // ((float)z, 1f);
|
||||
@@ -85,7 +149,7 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
{
|
||||
var result = manager.mockDirection.Where(c => c.Start < currentFrame && c.End > currentFrame).FirstOrDefault();
|
||||
bearing = result?.RotationY ?? 0;
|
||||
animator.SetFloat("bearing", bearing);
|
||||
//animator.SetFloat("bearing", bearing);
|
||||
}
|
||||
}
|
||||
protected override int GetCurrentFrame()
|
||||
|
||||
@@ -74,7 +74,7 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
public DateTime startTime { get; set; }
|
||||
public int FrameKM { get; private set; }//一米对应的帧数
|
||||
public CyclingModel cyclingModel;
|
||||
public BaseCycling cyclingController;
|
||||
public BaseCycling cyclingController { get; set; }
|
||||
public List<CustomRange> mockDirection = new List<CustomRange>();
|
||||
private double endDistance { get; set; }
|
||||
public List<float> slots = new List<float>();
|
||||
@@ -140,7 +140,6 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
yield return null;
|
||||
videoLoading.Init();//初始化loading页面
|
||||
}
|
||||
|
||||
public int GetFrameKm()
|
||||
{
|
||||
var s = mediaPlayer.Info.GetDurationFrames();
|
||||
@@ -158,15 +157,16 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
if (cyclingController == null)
|
||||
return;
|
||||
cyclingController.Run(null);
|
||||
var onlineRiders = cyclingController.riders;
|
||||
try
|
||||
{
|
||||
CreateOnlineUser(onlineRiders);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.Log(e.Message);
|
||||
}
|
||||
//TODO:发布单人骑行暂时注释
|
||||
//var onlineRiders = cyclingController.riders;
|
||||
//try
|
||||
//{
|
||||
// CreateOnlineUser(onlineRiders);
|
||||
//}
|
||||
//catch (Exception e)
|
||||
//{
|
||||
// Debug.Log(e.Message);
|
||||
//}
|
||||
timer += 1f;
|
||||
}
|
||||
}
|
||||
@@ -186,6 +186,8 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
//创建当前线路其他选手
|
||||
private void CreateOnlineUser(List<BaseRider> list)
|
||||
{
|
||||
if (list == null)
|
||||
return;
|
||||
//观察者模式随机选择当前骑行的人作为观察对象
|
||||
if (_aRMode == ARMode.INSPECT && CurrentPlayer == null)
|
||||
{
|
||||
@@ -243,7 +245,7 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
if (currentPlayerInfo != null)
|
||||
{
|
||||
var diff = item.EndDistance % mapData.TotalDistance - currentPlayerInfo.EndDistance % mapData.TotalDistance;
|
||||
if (Math.Abs(diff * 1000) <= 100)
|
||||
if (Math.Abs(diff * 1000) <= 150)
|
||||
{
|
||||
GameObject obj;
|
||||
if (currentPlayerInfo.Sex == 1)
|
||||
@@ -274,6 +276,10 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
InitCurrentPlayer();
|
||||
ContinueAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
SetCyclingModel(CyclingModel.Single);
|
||||
}
|
||||
}
|
||||
//初始化人物模型
|
||||
public void InitCurrentPlayer()
|
||||
@@ -365,7 +371,9 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
|
||||
private void MockDirection()
|
||||
{
|
||||
var arr = mapRoute.ARConfig.Replace("\r\n", " ").Split(' ');
|
||||
//var arr = mapRoute.ARConfig.Replace("\r\n", " ").Split(' ');
|
||||
var text = Resources.Load<TextAsset>("UI/direction");
|
||||
var arr = text.text.Replace("\r\n", " ").Split(' ');
|
||||
foreach (var item in arr)
|
||||
{
|
||||
if (string.IsNullOrEmpty(item))
|
||||
@@ -521,7 +529,8 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
{
|
||||
var mapApi = ConfigHelper.mapApi;
|
||||
int routeId = App.RouteIdParam;
|
||||
mapData = mapApi.GetData(routeId,20);//获取路书地理数据
|
||||
if(routeId > 0)
|
||||
mapData = mapApi.GetData(routeId,0);//获取路书地理数据
|
||||
}
|
||||
return mapData;
|
||||
}
|
||||
|
||||
@@ -270,12 +270,12 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
//进入观察模式
|
||||
private void WatchHandler(BaseEventData data)
|
||||
{
|
||||
manager.SetCurrentMode(VideoGameManager.ARMode.INSPECT);
|
||||
var canvasGroup = transform.GetComponent<CanvasGroup>();
|
||||
var ui = manager.GetCanvasTransform();
|
||||
canvasGroup.DOFade(0, 1).onComplete += () => {
|
||||
gameObject.SetActive(false);
|
||||
ui.Find("Panel").gameObject.SetActive(true);
|
||||
ui.gameObject.SetActive(true);
|
||||
manager.SetCurrentMode(VideoGameManager.ARMode.INSPECT);
|
||||
};
|
||||
}
|
||||
protected void Cancel(BaseEventData baseEvent)
|
||||
|
||||
@@ -72,7 +72,10 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
{
|
||||
|
||||
mapName.text = manager.GetMapRoute().Name;
|
||||
#if UNITY_EDITOR
|
||||
infoText.gameObject.SetActive(true);
|
||||
infoText.text = $"帧数:{manager.GetCurrentFrame()}";
|
||||
#endif
|
||||
if (manager.CurrentPlayer != null)
|
||||
{
|
||||
power.text = Math.Round(manager.CurrentPlayer.power).ToString();
|
||||
@@ -230,6 +233,8 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
}
|
||||
public void SaveAndShowResult()
|
||||
{
|
||||
if (manager._aRMode == VideoGameManager.ARMode.INSPECT)
|
||||
SceneManager.LoadScene("MainScene");
|
||||
videoPlayer = FindObjectOfType<VideoPlayer>();
|
||||
videoPlayer?.Upload();
|
||||
//show result
|
||||
|
||||
Reference in new issue
Block a user