轨迹插件引入

This commit is contained in:
lishuo committed 2022-09-06 13:47:45 +08:00
1 parent 89b5275efd
commit 195893a1b0
1023 files changed
+378944 -18404

No files matched your search

+64 -6
View File
@@ -25,8 +25,6 @@ public class MainController : BaseScene
{
base.Awake();
Debug.Log("执行25");
MapUDPService.MessageListener = ListenerHandler;
Version = this.transform.Find("GameObject").Find("Version").GetComponent<Text>();
Version.text = "V" + App.AppVersion;
DeviceCache.Init(PFConstants.DeviceCacheFolder);
@@ -61,6 +59,7 @@ public class MainController : BaseScene
EventQueueSystem.AddListener<LinkedMessageEvent>(LinkedMessageHandler);
App.isHomeChanged -= OnIsHomeChanged;
App.isHomeChanged += OnIsHomeChanged;
MapUDPService.MessageListener = ListenerHandler;
}
#region 显示消息有关
//切换页面后
@@ -71,15 +70,45 @@ public class MainController : BaseScene
homePlayer?.SetActive(App.currentPageIsHome);
}
private bool DataSorceChanged { get; set; }
private int outRoom = 0;
private void ListenerHandler(List<ReceiveMsgModel> message)
{
//创建房间并加入房间
var msg = message.Where(c => c.RoomList != null && c.RoomList.Count > 0).FirstOrDefault();
if (msg != null)
{
App.gameRoomDetail = msg.RoomList.FirstOrDefault();
DataSorceChanged = true;
}
//重新连接
var msg1 = message.Where(c => c.MemberId == App.CurrentUser.Id && c.RoomList != null).FirstOrDefault();
if (msg1 == null && isSendJoinGame)
{
outRoom++;
if (outRoom >= 2)
{
gameRoomClosed = true;
isSendJoinGame = false;
}
}
if(msg1 != null && isSendJoinGame)
{
var room = msg.RoomList.FirstOrDefault();
isSendJoinGame = false;
if (room.Status == 2)
{
gameRoomDone = true;
}
else
{
App.gameRoomDetail = room;
gameRoomProcessing = true;
}
}
}
private bool gameRoomClosed = false;
private bool gameRoomDone = false;
private bool gameRoomProcessing = false;
List<CanvasGroup> msgs;
Vector3 msgLocation;
@@ -407,6 +436,25 @@ public class MainController : BaseScene
UIManager.ShowGameRoomDetailPanel();
return;
}
if (gameRoomClosed)
{
gameRoomClosed = false;
App.tempRecordData = null;
Utils.showToast(gameObject, "房间已经关闭!");
Helper.DelectDir(PFConstants.MapWorkoutRecordTempFolder);
}
if (gameRoomDone)
{
gameRoomDone = false;
App.tempRecordData = null;
Utils.showToast(gameObject, "房间已经结束!");
Helper.DelectDir(PFConstants.MapWorkoutRecordTempFolder);
}
if (gameRoomProcessing)
{
gameRoomProcessing = false;
SceneManager.LoadScene("Ride");
}
clearcachet -= Time.deltaTime;
if (clearcachet <= 0)
{
@@ -515,7 +563,7 @@ public class MainController : BaseScene
App.CurrentUser = result.data;
}
private bool isSendJoinGame;
/// <summary>
/// 检查上次异常中断的骑行
/// </summary>
@@ -529,14 +577,24 @@ public class MainController : BaseScene
if (!string.IsNullOrEmpty(content))
{
var tempRecordData = Newtonsoft.Json.JsonConvert.DeserializeObject<TempRecordData>(content);
App.tempRecordData = tempRecordData;
if (App.tempRecordData.UserId == App.CurrentUser.Id)
if (tempRecordData.UserId == App.CurrentUser.Id)
{
App.tempRecordData = tempRecordData;
UIManager.ShowConfirm(App.GetLocalString("Reconnect"), App.GetLocalString("Did you want to reconnect the trip that was interrupted abnormally?"), () =>
{
App.RouteIdParam = App.tempRecordData.RouteId;
App.CompetionId = App.tempRecordData.CompetitionId;
SceneManager.LoadScene("Ride");
//是否区分
if (App.tempRecordData.RoomId > 0)
{
isSendJoinGame = true;
MapUDPService.SendJoinGameRoom(App.tempRecordData.RoomId,App.CurrentUser.Id, UIManager.Now.GetDateTime().ToUniversalTime());
}
else
{
SceneManager.LoadScene("Ride");
}
UIManager.CloseConfirm();
}, 2, () =>
{
Helper.DelectDir(PFConstants.MapWorkoutRecordTempFolder);
@@ -30,6 +30,7 @@ namespace Assets.Scripts.Scenes.Scripts
var list = MapUDPService.GetOnlineUsers(App.RouteIdParam, manager.roomId).OrderByDescending(c=>c.EndDistance);
int index = 1;
num.text = list.Count().ToString();
var current = list.Where(c => c.Id == manager.currentPlayer.UserId).FirstOrDefault();
foreach (var item in list)
{
GameObject prefabItem = item.IsSelf ? nearByMajorItem : nearByItem;
@@ -47,7 +48,7 @@ namespace Assets.Scripts.Scenes.Scripts
competitionRankingItem.setHead(item.HeadImage);
var countryTexture = manager.GetCountryImageByName(item.Country);
competitionRankingItem.setCountry(countryTexture);
var near = Math.Round((item.EndDistance - manager.currentPlayer.TotalDistance) * 1000);
var near = Math.Round((item.EndDistance - current.EndDistance)*1000,0);
competitionRankingItem.setDistance(manager.currentPlayer.UserId == item.Id ? "0M" : near.ToString() + "M");
#if UNITY_IOS || UNITY_ANDROID
competitionRankingItem.transform.SetSiblingIndex(index);
@@ -64,33 +65,7 @@ namespace Assets.Scripts.Scenes.Scripts
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;
timer += 1f;
}
}
}
@@ -22,6 +22,7 @@ namespace Assets.Scenes.Ride.Scripts
GameObject timerIcon { get; set; }
GameModel model { get; set; }
Text gameTimerText { get; set; }
protected override void Start()
{
base.Start();
@@ -40,7 +41,9 @@ namespace Assets.Scenes.Ride.Scripts
UIManager.AddEvent(raceViewBtn, UnityEngine.EventSystems.EventTriggerType.PointerClick, ChangeView);
spilitLineH2.SetActive(false);
//timerTxt.gameObject.SetActive(false);
timerTxt.gameObject.SetActive(false);
gameTimerText = uipanel.transform.Find("ComputerPanel/GameTimer").GetComponent<Text>();
gameTimerText.gameObject.SetActive(true);
//timerTxtTitle.gameObject.SetActive(false);
//观察者模式隐藏坡度
if (mainController.isWatch)
@@ -68,11 +71,23 @@ namespace Assets.Scenes.Ride.Scripts
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();
//如果是重新连接的话就不需要倒计时
var ss = mainController.cyclingController.recorderData.RiderDatas;
if (ss.Count > 0)
{
count = 0;
startUI(0);
countDownTxt.gameObject.SetActive(true);
countDownTxt.text = count.ToString();
}
else
{
count = seconds;
countDownTxt.gameObject.SetActive(true);
countDownTxt.text = count.ToString();
}
}
bool canStart = false;
GameObject watchPanel { get; set; }
@@ -112,26 +127,16 @@ namespace Assets.Scenes.Ride.Scripts
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;
startUI(count);
timeRemaining += 1.0f;
}
}
countDownTxt.text = count == 0 ? App.GetLocalString("GO!") : count.ToString();
if (mainController.isStart)
{
var ticks = playerController.TotalTicks;
gameTimerText.text = Helper.FormatTicks(ticks);
}
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)
@@ -152,6 +157,28 @@ namespace Assets.Scenes.Ride.Scripts
}
}
private void startUI(int num)
{
if (num <= 0)
{
mainController.SetStart();
var canvasGroup = countDownTxt.transform.GetComponent<CanvasGroup>();
canvasGroup.DOFade(0, 1).onComplete += () => {
countDownTxt.gameObject.SetActive(false);
canvasGroup.alpha = 1;
};
}
if (num == 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);
countDownTxt.text = num <= 0 ? App.GetLocalString("GO!") : num.ToString();
model = mainController.cyclingController as GameModel;
}
private bool FirstCompleted;
private bool Saved;
@@ -279,6 +279,7 @@ namespace Assets.Scenes.Ride.Scripts.Model
public class TempRecordData
{
public int RoomId { get; set; }
public int CompetitionId { get; set; }
public int UserId { get; set; }
public int RouteId { get; set; }
@@ -52,7 +52,7 @@ namespace Assets.Scenes.Ride.Scripts
protected double elevation;
protected double cadance;
protected int? heartRate { get; set; }
public int ticks;
public int ticks { get; set; }
protected double totalDistance;
protected double currentSlope;
protected double nextSlope;
@@ -106,6 +106,8 @@ public class CyclingController : DeviceServiceMonoBase
void OnDestroy()
{
App.RouteIdParam = 0;
App.tempRecordData = null;
TouchKit.removeAllGestureRecognizers();
Resources.UnloadUnusedAssets();
}
@@ -882,6 +884,11 @@ public class CyclingController : DeviceServiceMonoBase
{
tick = recorderData.RiderDatas.Last().Ticks;
}
//对战模式重连秒数按照现在的日期减去对战开始的日期
if (recorderData.RoomId > 0 && recorderData.RiderDatas.Count > 0)
{
tick = (int)(UIManager.Now.GetDateTime() - startTime).TotalSeconds;
}
playerController.Init(index, recorderData.EndDistance, tick);
}
public void InitGraph(int index)
@@ -1268,6 +1275,7 @@ public BaseUIManager singleUIManager;
tempRecordData.ManufacturerName = recorderData.ManufacturerName;
tempRecordData.Mode = cyclingModel.ToString();
tempRecordData.EndDistance = recorderData.EndDistance;
tempRecordData.RoomId = roomId;
var guid = recorderData.ContinueMark;
var filePath = PFConstants.MapWorkoutRecordTempFolder + "/" + guid.ToString()+".txt";
@@ -56,10 +56,10 @@ namespace Assets.Scenes.Ride.Scripts
cadance = mainController.UpdateCadence();
weight = App.CurrentUser.Weight;
bicycleWeight = App.CurrentUser.BicycleWeight;
//#if !UNITY_EDITOR
power = 100;
//#endif
mainController.TrackResistance(currentSlope * App.RideSetting.Sensitivity / 100);
#if UNITY_EDITOR
power = 100;
#endif
mainController.TrackResistance(currentSlope * App.RideSetting.Sensitivity / 100);
}
catch (Exception ex)
{
@@ -113,7 +113,7 @@ namespace Assets.Scenes.Ride.Scripts
//实时计算MaxAp
//mainController.ComputeMaxAP(Power, ticks);
//实时保存骑行记录
if (ticks % 60 == 0 && !(mainController.cyclingController is GameModel))
if (ticks % 60 == 0)
{
mainController.SaveRealTime();
}
@@ -149,7 +149,7 @@ namespace Assets.Scripts.Scenes.VideoRide
if (manager._viewMode == VideoGameManager.ViewMode.FIRST &&manager.CurrentPlayer.UserId == App.CurrentUser.Id)
{
animator.SetFloat("preSpeed", (float)preSpeed);
animator.SetFloat("speed", (float)Math.Min(speed,30));
animator.SetFloat("speed", (float)Math.Min(speed,25));
animator.SetFloat("grade", (float)currentSlope);
animator.SetFloat("power", (float)power);
}
@@ -75,11 +75,11 @@ namespace Assets.Scripts.Scenes.VideoRide
heartRate = manager.UpDateHeart();
power = manager.UpdatePower();
cadance = manager.UpdateCadence();
//#if !UNITY_EDITOR
#if UNITY_EDITOR
power = 280;
cadance = 70;
heartRate = 160;
//#endif
#endif
weight = App.CurrentUser.Weight;
bicycleWeight = App.CurrentUser.BicycleWeight;
wkg = Math.Round(power / weight, 2);