powerfun-unity/Assets/Scenes/Ride/Scripts/PlayerController.cs
2021-04-12 17:35:56 +08:00

72 lines
2.0 KiB
C#

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;
/// <summary>
/// 计算数据,父类会在此方法后处理动画
/// </summary>
protected override void Compute()
{
//计算数据
//speed = mainController.UpDateSpeed();
heartRate = mainController.UpDateHeart()??0;
power = mainController.UpdatePower();
cadance = mainController.UpdateCadence();
#if UNITY_EDITOR
power = 2000;//测试功率
#endif
speed = Helper.CalculateSpeed(elevation, currentSlope, power, weight, bicycleWeight);
distance = mainController.UpdateDistance(speed);
totalDistance += distance;
//记录骑行数据
#if UNITY_EDITOR
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);
#endif
}
protected override void SendTcp()
{
mainController.cyclingController.Run(null);
}
//上传数据
protected override void Upload()
{
#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
}
}