powerfun-unity/Assets/Scenes/Ride/Scripts/PlayerController.cs

72 lines
2.0 KiB
C#
Raw Normal View History

2021-04-01 11:01:29 +08:00
using UnityEngine;
2021-03-23 16:07:31 +08:00
using Assets.Scripts.Apis.Models;
using System;
using Assets.Scripts.Apis;
using System.Linq;
using System.Collections.Generic;
2021-03-28 18:17:15 +08:00
using System.Globalization;
using Assets.Scenes.Ride.Scripts.Model;
using System.IO;
2021-03-22 19:20:51 +08:00
2021-03-23 16:07:31 +08:00
namespace Assets.Scenes.Ride.Scripts
2021-03-22 19:20:51 +08:00
{
2021-04-01 11:01:29 +08:00
public class PlayerController : AbstractPlayer
2021-03-22 19:20:51 +08:00
{
#region
2021-04-01 11:01:29 +08:00
protected override void Init()
{
base.Init();
}
2021-04-12 17:35:56 +08:00
TargetData targetData;
/// <summary>
/// 计算数据,父类会在此方法后处理动画
/// </summary>
2021-04-12 17:35:56 +08:00
protected override void Compute()
2021-04-01 11:01:29 +08:00
{
//计算数据
//speed = mainController.UpDateSpeed();
heartRate = mainController.UpDateHeart()??0;
power = mainController.UpdatePower();
cadance = mainController.UpdateCadence();
2021-04-12 17:35:56 +08:00
#if UNITY_EDITOR
power = 2000;//测试功率
2021-04-12 17:35:56 +08:00
#endif
2021-04-01 11:01:29 +08:00
speed = Helper.CalculateSpeed(elevation, currentSlope, power, weight, bicycleWeight);
distance = mainController.UpdateDistance(speed);
2021-04-01 11:01:29 +08:00
totalDistance += distance;
//记录骑行数据
#if UNITY_EDITOR
var recorderData = cyclingExcutor.recorderData;
2021-04-12 17:35:56 +08:00
targetData = new TargetData
{
Ticks = ticks,
_Power = power,
_Speed = speed,
2021-04-12 17:35:56 +08:00
_Distance = totalDistance > mapData.TotalDistance ? mapData.TotalDistance : totalDistance,
_Cadence = cadance,
_HeartRate = heartRate,
_Lat = nextlatlong.x,
_Lon = nextlatlong.y
2021-04-12 17:35:56 +08:00
};
recorderData.RiderDatas.Add(targetData);
#endif
2021-04-12 17:35:56 +08:00
}
protected override void SendTcp()
{
mainController.cyclingController.Run(null);
}
//上传数据
protected override void Upload()
2021-04-01 11:01:29 +08:00
{
#if UNITY_EDITOR
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);
#endif
}
#endregion
}
}