using UnityEngine; using Assets.Scripts.Apis.Models; using System; using Assets.Scripts.Apis; using System.Linq; using System.Collections.Generic; using System.Globalization; using Assets.Scenes.Ride.Scripts.Model; using System.IO; namespace Assets.Scenes.Ride.Scripts { public class PlayerController : AbstractPlayer { #region 骑行逻辑 protected override void Init() { base.Init(); } TargetData targetData; /// /// 计算数据,父类会在此方法后处理动画 /// protected override void Compute() { //计算数据 //speed = mainController.UpDateSpeed(); heartRate = mainController.UpDateHeart()??0; power = mainController.UpdatePower(); cadance = mainController.UpdateCadence(); weight = App.CurrentUser.Weight; bicycleWeight = App.CurrentUser.BicycleWeight; Debug.Log(power); //#if UNITY_EDITOR // power = 2000;//测试功率 //#endif speed = Helper.CalculateSpeed(elevation, currentSlope, power, weight, bicycleWeight); distance = mainController.UpdateDistance(speed); totalDistance += distance; //记录骑行数据 var recorderData = cyclingExcutor.recorderData; targetData = new TargetData { Ticks = ticks, _Power = power, _Speed = speed, _Distance = totalDistance > mapData.TotalDistance ? mapData.TotalDistance : totalDistance, _Cadence = cadance, _HeartRate = heartRate, _Lat = nextlatlong.x, _Lon = nextlatlong.y }; recorderData.RiderDatas.Add(targetData); } protected override void SendTcp() { mainController.cyclingController.Run(null); } //上传数据 public override void Upload() { mainController.isStart = false; string imageFileName = base.CaptureCamera(Camera.main, new Rect(Screen.width * 0f, Screen.height * 0f, Screen.width * 0.5f, Screen.height * 0.5f)); cyclingExcutor.recorderData.IsCompleted = totalDistance == mapData.TotalDistance; cyclingExcutor.recorderData.EndDistance = totalDistance; cyclingExcutor.recorderData.SaveData(cyclingExcutor.Mode,null, imageFileName); } #endregion } }