新版loading逻辑
This commit is contained in:
1 parent
3c64109090
commit
ae58f4d461
367 files changed
+74232
-220035
No files matched your search
@@ -1,25 +1,24 @@
|
||||
using Assets.Scenes.Ride.Scripts;
|
||||
using Assets.Scripts.Apis.Models;
|
||||
using Assets.Scenes.Ride.Scripts.Model;
|
||||
using DG.Tweening;
|
||||
using Mapbox.Utils;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using Assets.Core;
|
||||
|
||||
namespace Assets.Scripts.Scenes.VideoRide
|
||||
{
|
||||
public abstract class AbstractVideoPlayer : MonoBehaviour
|
||||
public abstract class AbstractVideoPlayer : MonoBehaviour, IRider
|
||||
{
|
||||
protected Animator animator;
|
||||
public GameObject head { get; set; }
|
||||
protected Image ftpImage { get; set; }
|
||||
protected Text headName { get; set; }
|
||||
protected Text headWkg { get; set; }
|
||||
public int UserId;
|
||||
public string UserName;
|
||||
public int userId { get; set; }
|
||||
public string userName { get; set; }
|
||||
public double weight;//体重
|
||||
protected double bicycleWeight;//车重
|
||||
protected double preSpeed;
|
||||
@@ -42,20 +41,34 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
public int currentIndex;
|
||||
public float bearing = 0f;
|
||||
protected MapDataModel mapData;
|
||||
|
||||
protected RaycastHit hit;
|
||||
float timer = 1f;
|
||||
private float timer = 1f;
|
||||
protected bool start = true;
|
||||
|
||||
protected Sequence sequence;
|
||||
protected VideoGameManager manager { get; set; }
|
||||
Camera camera { get; set; }
|
||||
private Camera camera { get; set; }
|
||||
float currenPlayerHeight;
|
||||
Transform bone_bottle_2 { get; set; }
|
||||
//切换视角
|
||||
public double offsetX = 0d;
|
||||
public double offsetY = 0d;
|
||||
public double offsetZ = 0d;
|
||||
Vector3 current { get; set; }
|
||||
Vector3 forward { get; set; }
|
||||
public double Weight { get => this.weight; }
|
||||
public double BicycleWeight { get => this.bicycleWeight; }
|
||||
public double Speed { get => this.speed; }
|
||||
public double Power { get => this.power; }
|
||||
public double Elevation { get => this.elevation; }
|
||||
public double Cadance { get => this.cadance; }
|
||||
public double Wkg { get => this.wkg; }
|
||||
public int? HeartRate { get => this.heartRate; }
|
||||
public double TotalDistance { get => this.totalDistance; }
|
||||
public double CurrentSlope { get => this.currentSlope; }
|
||||
public double CurrentSlopeDistance { get => this.currentSlopeDistance; }
|
||||
public double NextSlope { get => this.nextSlope; }
|
||||
public double NextSlopeDistance { get => this.nextSlopeDistance; }
|
||||
public double Distance { get => this.distance; }
|
||||
public double TotalClimb => this.totalClimb;
|
||||
|
||||
public int UserId => this.userId;
|
||||
|
||||
public string UserName => this.userName;
|
||||
|
||||
protected virtual void Start()
|
||||
{
|
||||
@@ -78,18 +91,6 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
//pre = config[0];
|
||||
//next = config[0];
|
||||
}
|
||||
|
||||
//人物状态
|
||||
public const int HERO_UP = 0;
|
||||
public const int HERO_RIGHT = 1;
|
||||
public const int HERO_DOWN = 2;
|
||||
public const int HERO_LEFT = 3;
|
||||
|
||||
//人物当前行走的方向状态
|
||||
public int state = 0;
|
||||
//人物移动速度
|
||||
public int moveSpeed = 2;
|
||||
|
||||
protected virtual void Update()
|
||||
{
|
||||
|
||||
@@ -111,7 +112,6 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
Forward();
|
||||
ComputeRecord();
|
||||
ComputeVideo();
|
||||
RayCastHit();
|
||||
}
|
||||
ComputeAnimator();//控制动画
|
||||
timer += 1f;
|
||||
@@ -124,61 +124,10 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
}
|
||||
}
|
||||
}
|
||||
private void OnTriggerEnter(Collider other)
|
||||
{
|
||||
Debug.Log("触发");
|
||||
}
|
||||
|
||||
void RayCastHit()
|
||||
{
|
||||
//更新物理位置
|
||||
Physics.SyncTransforms();
|
||||
var target = transform;
|
||||
|
||||
//前方检测
|
||||
Vector3 pos = new Vector3(target.position.x, 1, target.position.z);
|
||||
Vector3 fwd = target.TransformDirection(Vector3.forward);
|
||||
Ray ray = new Ray(new Vector3(pos.x, 1, pos.z), fwd);
|
||||
var fHit = Physics.Raycast(ray, out hit,1f, 1 << 0, QueryTriggerInteraction.Collide);
|
||||
Debug.DrawLine(pos, pos + 15* fwd, Color.red);
|
||||
|
||||
//左边检测
|
||||
Vector3 lft = target.TransformDirection(Vector3.left);
|
||||
Ray lray = new Ray(new Vector3(pos.x, 1, pos.z), lft);
|
||||
var lHit = Physics.Raycast(lray, out hit, 1f, 1 << 0, QueryTriggerInteraction.Collide);
|
||||
Debug.DrawLine(pos, pos + lft, Color.red);
|
||||
|
||||
//右边检测
|
||||
Vector3 rft = target.TransformDirection(Vector3.right);
|
||||
Ray rray = new Ray(new Vector3(pos.x, 1, pos.z), rft);
|
||||
var rHit = Physics.Raycast(rray, out hit, 1f, 1 << 0, QueryTriggerInteraction.Collide);
|
||||
|
||||
//如果检测到前方有人坐标就往两边移动
|
||||
if (fHit)
|
||||
{
|
||||
if (!lHit)
|
||||
{
|
||||
var newx = transform.localPosition.x - 1;
|
||||
transform.DOLocalMoveX(newx, 1f);
|
||||
}
|
||||
else if (!rHit)
|
||||
{
|
||||
var newx = transform.localPosition.x + 1;
|
||||
transform.DOLocalMoveX(newx, 1f);
|
||||
}
|
||||
}
|
||||
//骑行过程尽可能向中间位置靠拢
|
||||
if (speed > 0 && !fHit && !lHit && !rHit && ticks % 15 == 0)
|
||||
{
|
||||
transform.DOLocalMoveX(0, 1f);
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual bool GetStart()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
//动画状态机
|
||||
protected virtual void ComputeAnimator()
|
||||
{
|
||||
@@ -209,39 +158,8 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
{
|
||||
return manager.GetCurrentFrame();
|
||||
}
|
||||
|
||||
protected CustomRange pre { get; set; }
|
||||
public CustomRange next { get; set; }
|
||||
|
||||
protected float t { get; set; }
|
||||
protected Vector3 currentRotation;
|
||||
protected virtual void Turn()
|
||||
{
|
||||
//控制人物的转向
|
||||
var currentFrame = GetCurrentFrame();
|
||||
var config = manager.mockDirection;
|
||||
if (config.Count == 0)
|
||||
return;
|
||||
|
||||
for (int i = 0; i < config.Count; i++)
|
||||
{
|
||||
if (config[i].KeyFrame >= currentFrame)
|
||||
{
|
||||
pre = i > 0 ? config[i - 1] : config[i];
|
||||
next = config[i];
|
||||
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);
|
||||
currentRotation = Vector3.Lerp(p, q, t);
|
||||
transform.localEulerAngles = currentRotation;
|
||||
//transform.DORotate(currentRotation, 0, RotateMode.Fast);
|
||||
}
|
||||
|
||||
//计算人物当前属性
|
||||
protected virtual void ComputePlayer()
|
||||
{
|
||||
@@ -264,8 +182,6 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
// }
|
||||
//}
|
||||
}
|
||||
Vector3 current { get; set; }
|
||||
Vector3 forward { get; set; }
|
||||
//计算当前人物的经纬度
|
||||
protected virtual void Forward()
|
||||
{
|
||||
@@ -281,7 +197,6 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
}
|
||||
}
|
||||
protected float ratio = 1;//视频播放速率
|
||||
|
||||
protected virtual void ComputeVideo()
|
||||
{
|
||||
mapData = manager.GetMapData();
|
||||
@@ -296,8 +211,6 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
}
|
||||
if (manager.CurrentPlayer != null && manager.CurrentPlayer.UserId != UserId)
|
||||
return;
|
||||
//ratio = (float)Math.Round(ratio, 1);
|
||||
manager.Play(currentIndex,currentSlopeDistance);
|
||||
|
||||
if (ratio > 1)
|
||||
{
|
||||
@@ -318,9 +231,7 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
animator.speed = ratio;
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void ComputeRecord() { }
|
||||
|
||||
//计算当前区段属性下一个区段属性
|
||||
void ComputeNextSlope()
|
||||
{
|
||||
@@ -394,7 +305,6 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
headWkg.text = $"{wkg}W/KG";
|
||||
}
|
||||
}
|
||||
|
||||
public void Destroy()
|
||||
{
|
||||
if (manager.CurrentPlayer != null && manager.CurrentPlayer.UserId == UserId)
|
||||
|
||||
@@ -1,172 +1,37 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Assets.Scenes.Ride.Scripts;
|
||||
using DG.Tweening;
|
||||
using FluffyUnderware.Curvy.Controllers;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Assets.Scripts.Scenes.VideoRide
|
||||
{
|
||||
public class OnlineVideoPlayer : AbstractVideoPlayer
|
||||
{
|
||||
public Transform target;
|
||||
public double diff;
|
||||
public int frames;
|
||||
public float xOffset;
|
||||
|
||||
private void Start()
|
||||
protected override 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);
|
||||
//}
|
||||
}
|
||||
|
||||
//计算
|
||||
protected override void ComputePlayer()
|
||||
{
|
||||
var current = manager.CurrentPlayer;
|
||||
if (current != null && current.UserId != UserId)
|
||||
{
|
||||
//var left = totalDistance % mapData.TotalDistance;
|
||||
//var right = current.totalDistance % mapData.TotalDistance;
|
||||
//diff = (left - right) * 1000;
|
||||
//if (Math.Abs(diff*1000) > 150)
|
||||
//{
|
||||
// //销毁父容器
|
||||
// transform.parent.Destroy();
|
||||
// Destroy();
|
||||
//}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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();
|
||||
//if (splineController != null && manager != null && manager.splineController != null)
|
||||
//{
|
||||
// var ratio = this.diff / manager.GetMapData().TotalDistance;
|
||||
// splineController.Position = (float)(ratio + manager.splineController.Position);
|
||||
//}
|
||||
//if (manager.CurrentPlayer.UserId == UserId)
|
||||
// return;
|
||||
////计算前后位移
|
||||
//var current = manager.CurrentPlayer;
|
||||
//var interval = this.currentFrame - manager.GetCurrentFrame();
|
||||
//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);
|
||||
//人物转向
|
||||
//transform.Rotate(new Vector3(0,1,0), bearing);
|
||||
//z轴位移
|
||||
|
||||
//try
|
||||
//{
|
||||
// var offsetX = 1f;
|
||||
// var current = manager.CurrentPlayer;
|
||||
// var z = current.transform.position.z + diff * 0.5f;
|
||||
// //前方有人
|
||||
// if (isHit)
|
||||
// {
|
||||
// var onlinePlayer = hit.collider.transform.GetComponent<AbstractVideoPlayer>();
|
||||
// if (distance - onlinePlayer.distance > 20)
|
||||
// {
|
||||
// var prePos = onlinePlayer.transform.position;
|
||||
// var disx = prePos.x + offsetX;
|
||||
// var disz = prePos.z + diff;
|
||||
// var disy = prePos.y;
|
||||
// var end = new Vector3(disx, (float)disz, disy);
|
||||
// animator.Play("turnRight");
|
||||
// transform.DOMove(end, 1f);
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// transform.DOMoveZ((float)z, 1f);
|
||||
// }
|
||||
//}
|
||||
//catch (Exception e) {
|
||||
// print(e.Message);
|
||||
//}
|
||||
}
|
||||
|
||||
private int currentFrame { get; set; }
|
||||
protected override void ComputeAnimator()
|
||||
{
|
||||
base.ComputeAnimator();
|
||||
if (manager.CurrentPlayer == null || manager.CurrentPlayer.UserId != UserId)
|
||||
{
|
||||
var result = manager.mockDirection.Where(c => c.Start < currentFrame && c.End > currentFrame).FirstOrDefault();
|
||||
bearing = result?.RotationY ?? 0;
|
||||
//animator.SetFloat("bearing", bearing);
|
||||
}
|
||||
}
|
||||
protected override int GetCurrentFrame()
|
||||
{
|
||||
return this.currentFrame;//(int)(diff * 10) + manager.GetCurrentFrame();
|
||||
return this.currentFrame;
|
||||
}
|
||||
protected override void ComputeVideo()
|
||||
{
|
||||
@@ -178,13 +43,7 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
if (diff < 0)
|
||||
((RectTransform)head.transform).anchoredPosition = new Vector2(((RectTransform)head.transform).anchoredPosition.x, -800f);
|
||||
}
|
||||
//人物碰撞
|
||||
void OnCollisionEnter(Collision collision)
|
||||
{
|
||||
transform.DOMoveX(transform.position.x - 1,1);
|
||||
}
|
||||
|
||||
private SplineController splineController;
|
||||
private double preTime;
|
||||
//设置当前玩家属性
|
||||
public void SetPlayer(string name, double distance, double totalDistance, double cadance,double heartRate, double wkg, int userId,double power,double currentPlayerDistance,int frame)
|
||||
@@ -193,43 +52,18 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
{
|
||||
manager = FindObjectOfType<VideoGameManager>();
|
||||
}
|
||||
|
||||
var f = totalDistance;
|
||||
StartCoroutine(DoAnimation(this.preTime, f - this.preTime));
|
||||
preTime = f;
|
||||
|
||||
this.wkg = wkg;
|
||||
this.UserName = name;
|
||||
this.userName = name;
|
||||
this.cadance = cadance;
|
||||
this.totalDistance = totalDistance;
|
||||
this.heartRate = (int?)heartRate;
|
||||
this.UserId = userId;
|
||||
this.userId = userId;
|
||||
this.power = power;
|
||||
this.speed = distance * 3600;
|
||||
this.diff = totalDistance - currentPlayerDistance;
|
||||
this.currentFrame = frame;
|
||||
splineController = transform.parent.GetComponent<SplineController>();
|
||||
}
|
||||
|
||||
private IEnumerator DoAnimation(double preFrame,double offset)
|
||||
{
|
||||
float t = 0;
|
||||
while (t < 1)
|
||||
{
|
||||
t += Time.deltaTime;
|
||||
double result = preFrame + offset * t;
|
||||
|
||||
//var s1 = manager.frameList.OrderBy(c => c.Second).Where(c => c.Second > result).FirstOrDefault();
|
||||
//var s2 = manager.frameList.OrderByDescending(c => c.Second).Where(c => c.Second < result).FirstOrDefault();
|
||||
if (splineController != null)
|
||||
{
|
||||
splineController.Position = manager.startOffset + (float)(result * manager.ratio);//(float)(s2.Distance + (result - s2.Second) / (s1.Second - s2.Second) * (s1.Distance - s2.Distance)); //(float)(result / (double)s1.Key * s1.Value);
|
||||
}
|
||||
|
||||
//if (splineController != null)
|
||||
// splineController.Position = (float)(result / manager.GetMapData().TotalDistance * splineController.Length);
|
||||
yield return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -12,10 +12,14 @@ using Assets.Scenes.Ride.Scripts;
|
||||
using Assets.Scripts.Apis.Models;
|
||||
using System.Linq;
|
||||
using Assets.Scenes.Ride.Scripts.Model;
|
||||
using Assets.AR;
|
||||
using System.Threading.Tasks;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using System.Threading;
|
||||
|
||||
namespace Assets.Scripts.Scenes.VideoRide
|
||||
{
|
||||
public class VideoLoading : MonoBehaviour
|
||||
public class VideoLoading : MonoBehaviour, IProgress<float>
|
||||
{
|
||||
UnityWebRequest request { get; set; }
|
||||
VideoGameManager manager { get; set; }
|
||||
@@ -47,7 +51,7 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
protected RawImage altitudeGraph;
|
||||
protected Transform mapRanking;
|
||||
protected Text mapId;
|
||||
|
||||
|
||||
protected float process = 0;//0-100 %
|
||||
public float targetAlpha = 0f;
|
||||
public float alphaSpeed = 2.0f;
|
||||
@@ -126,7 +130,7 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
{
|
||||
watch.SetActive(false);
|
||||
//检查本地文件是否存在 如果存在直接设置mediaPlayer 否则显示下载按钮
|
||||
UIManager.AddEvent(download.gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, Download);
|
||||
UIManager.AddEvent(download.gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, DownloadAsync);
|
||||
}
|
||||
#region
|
||||
level = panel.transform.Find("level/Text").GetComponent<Text>();
|
||||
@@ -177,7 +181,11 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
panel.transform.Find("RideTip").GetComponent<CanvasGroup>().DOFade(0, 0.5f);
|
||||
});
|
||||
#endregion
|
||||
|
||||
downloadText = rideNow.GetComponentInChildren<Text>();//视频下载进度text
|
||||
}
|
||||
Text downloadText { get; set; }
|
||||
|
||||
protected void InitGameObjectData()
|
||||
{
|
||||
var route = manager.mapRoute;
|
||||
@@ -200,6 +208,7 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
mapCountry.texture = manager.GetCountryImageByCode(route.CountryCode);//路书国家
|
||||
}
|
||||
#endregion
|
||||
|
||||
//显示线路背景图
|
||||
DrawMapRouteAsync(route.Id);
|
||||
//查询排行榜 TODO优化
|
||||
@@ -210,21 +219,35 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
}
|
||||
}
|
||||
bool startBtnLock = false;
|
||||
public void StartRide(BaseEventData baseEvent)
|
||||
public async void StartRide(BaseEventData baseEvent)
|
||||
{
|
||||
if (startBtnLock)
|
||||
return;
|
||||
startBtnLock = true;
|
||||
var ui = manager.GetCanvasTransform();
|
||||
|
||||
//加载本地文件
|
||||
var route = manager.mapRoute;
|
||||
var arDataPath = $"{PFConstants.ARFolder}/{route.Id}/{route.Id}.json";
|
||||
var videoRoute = $"{PFConstants.ARFolder}/{route.Id}/route-{route.Id}.json";
|
||||
|
||||
ARData aRData = null;
|
||||
RouteDetailData routeDetailData = null;
|
||||
|
||||
await Task.Run<ARData>((Func<ARData>)(() => aRData = ARData.LoadFromFile(arDataPath)));
|
||||
await Task.Run<RouteDetailData>((Func<RouteDetailData>)(() => routeDetailData = RouteDetailData.LoadFromFile(videoRoute)));
|
||||
var arController = FindObjectOfType<ARTrainingController>();
|
||||
arController.Initialize(aRData, routeDetailData);
|
||||
|
||||
canvasGroup.DOFade(0, 1).onComplete += () => {
|
||||
gameObject.SetActive(false);
|
||||
manager.StartGame();
|
||||
manager.SetCyclingModel(Assets.Scenes.Ride.Scripts.Model.CyclingModel.Single);
|
||||
manager.SetCurrentMode(VideoGameManager.ARMode.RIDE);
|
||||
//ui.Find("Panel").gameObject.SetActive(true);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public void StartRide(int seconds)
|
||||
{
|
||||
var ui = manager.GetCanvasTransform();
|
||||
@@ -239,37 +262,49 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
});
|
||||
}
|
||||
|
||||
protected void Download(BaseEventData baseEvent)
|
||||
protected async void DownloadAsync(BaseEventData baseEvent)
|
||||
{
|
||||
var route = manager.mapRoute;
|
||||
var path = PFConstants.VideoFolder;
|
||||
var filepath = path + $"/{route.FileName}";
|
||||
var text = rideNow.GetComponentInChildren<Text>();
|
||||
StartCoroutine(Utils.DownloadVideo(route.FileName, route.Url
|
||||
, (p, req) =>
|
||||
var localPath = PFConstants.ARFolder;
|
||||
var arDataPath = route.ARConfig;
|
||||
var videoRoute = route.VideoRoute;
|
||||
|
||||
var cancelToken = new CancellationTokenSource();
|
||||
var res1 = await UnityWebRequest.Get(arDataPath).SendWebRequest().WithCancellation(cancelToken.Token);//下载AR数据
|
||||
var res2 = await UnityWebRequest.Get(videoRoute).SendWebRequest().WithCancellation(cancelToken.Token);//下载video视频数据
|
||||
var res3 = await UnityWebRequest.Get(route.Url).SendWebRequest().ToUniTask(progress: this);//下载视频
|
||||
//持久化到磁盘
|
||||
var dataPath = $"{localPath}/{route.Id}";
|
||||
Helper.CreateDirectoryIfNotExsit(dataPath);
|
||||
Helper.CreateDirectoryIfNotExsit(dataPath);
|
||||
File.WriteAllBytes($"{dataPath}/{route.Id}.json", res1.downloadHandler.data);
|
||||
File.WriteAllBytes($"{dataPath}/route-{route.Id}.json", res2.downloadHandler.data);
|
||||
File.WriteAllBytes($"{path}/{route.FileName}", res3.downloadHandler.data);
|
||||
}
|
||||
|
||||
public void Report(float value)
|
||||
{
|
||||
if (value < 1)
|
||||
{
|
||||
rideNow.enabled = false;
|
||||
rideNow.interactable = false;
|
||||
slider.value = (float)Math.Round(p * 100, 2);
|
||||
text.text = slider.value.ToString()+"%";
|
||||
request = req;
|
||||
slider.value = (float)Math.Round(value * 100, 0);
|
||||
downloadText.text = slider.value.ToString() + "%";
|
||||
download.SetActive(false);
|
||||
}
|
||||
, (p) =>
|
||||
else
|
||||
{
|
||||
if (!string.IsNullOrEmpty(p)) {
|
||||
Debug.LogError(p);
|
||||
}
|
||||
else
|
||||
{
|
||||
rideNow.enabled = true;
|
||||
rideNow.interactable = true;
|
||||
text.text = App.GetLocalString("Ride Now");
|
||||
watch.SetActive(true);
|
||||
slider.value = 100;
|
||||
manager.SetMedia(filepath);
|
||||
}
|
||||
var route = manager.mapRoute;
|
||||
var path = PFConstants.VideoFolder;
|
||||
rideNow.enabled = true;
|
||||
rideNow.interactable = true;
|
||||
downloadText.text = App.GetLocalString("Ride Now");
|
||||
//watch.SetActive(true);
|
||||
slider.value = 100;
|
||||
var filepath = $"{path}/{route.FileName}";
|
||||
manager.SetMedia(filepath);
|
||||
}
|
||||
));
|
||||
}
|
||||
//进入观察模式
|
||||
private void WatchHandler(BaseEventData data)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Assets.Scenes.Ride.Scripts;
|
||||
using Assets.AR;
|
||||
using Assets.Scenes.Ride.Scripts;
|
||||
using Assets.Scenes.Ride.Scripts.Model;
|
||||
using Assets.Scenes.Ride.Scripts.Model.CyclingModels;
|
||||
using DG.Tweening;
|
||||
@@ -15,19 +16,13 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
public class VideoPlayer : AbstractVideoPlayer
|
||||
{
|
||||
public double EndDistance => totalDistance;
|
||||
protected Transform LightTrans { get; set; }
|
||||
private bool isSingle = true;
|
||||
protected override void Start()
|
||||
{
|
||||
base.Start();
|
||||
animator.Play("idle");
|
||||
UserId = App.CurrentUser.Id;
|
||||
UserName = App.CurrentUser.Nickname;
|
||||
var light = FindObjectOfType<Light>();
|
||||
LightTrans = light.transform;
|
||||
#if UNITY_EDITOR
|
||||
InitConfig();
|
||||
#endif
|
||||
userId = App.CurrentUser.Id;
|
||||
userName = App.CurrentUser.Nickname;
|
||||
}
|
||||
|
||||
protected override bool GetStart()
|
||||
@@ -39,14 +34,17 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
{
|
||||
base.Update();
|
||||
}
|
||||
|
||||
public void SetPower(double power)
|
||||
{
|
||||
this.power = power;
|
||||
}
|
||||
|
||||
public void SetEndDistance(double distance)
|
||||
{
|
||||
this.totalDistance = distance;
|
||||
}
|
||||
|
||||
public void Complete()
|
||||
{
|
||||
start = false;
|
||||
@@ -56,43 +54,26 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
uimanager.SaveAndShowResult();
|
||||
}
|
||||
}
|
||||
|
||||
protected override void ComputeAnimator()
|
||||
{
|
||||
base.ComputeAnimator();
|
||||
}
|
||||
protected override void Turn()
|
||||
{
|
||||
base.Turn();
|
||||
////控制人物的前后左右
|
||||
//if (manager._viewMode != VideoGameManager.ViewMode.FIRST)
|
||||
//{
|
||||
// var l = new Vector3(pre.PositionX, pre.PositionY, pre.PositionZ);
|
||||
// var s = new Vector3(next.PositionX, next.PositionY, next.PositionZ);
|
||||
// var pos = Vector3.Lerp(l, s, t);
|
||||
// transform.DOMove(pos, 0);
|
||||
//}
|
||||
////控制光线
|
||||
//var z = new Vector3(50, pre.LightY, 0);
|
||||
//var c = new Vector3(50, next.LightY, 0);
|
||||
//var zc = Vector3.Lerp(z, c, t);
|
||||
//LightTrans.DORotate(zc, 0);
|
||||
}
|
||||
|
||||
protected override void ComputePlayer()
|
||||
{
|
||||
heartRate = manager.UpDateHeart();
|
||||
power = manager.UpdatePower();
|
||||
cadance = manager.UpdateCadence();
|
||||
//#if UNITY_EDITOR
|
||||
power = 220;
|
||||
power = 230;
|
||||
cadance = 50;
|
||||
heartRate = 120;
|
||||
//#endif
|
||||
weight = App.CurrentUser.Weight;
|
||||
bicycleWeight = App.CurrentUser.BicycleWeight;
|
||||
wkg = Math.Round(power / weight, 2);
|
||||
var mainFrame = manager.GetCurrentFrame();
|
||||
var result = manager.mockDirection.Where(c => c.Start < mainFrame && c.End > mainFrame).FirstOrDefault();
|
||||
bearing = result?.RotationY ?? 0;
|
||||
|
||||
//发送阻力
|
||||
manager.TrackResistance(currentSlope * App.RideSetting.Sensitivity / 100);
|
||||
base.ComputePlayer();
|
||||
@@ -126,8 +107,6 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
protected override void ComputeRecord()
|
||||
{
|
||||
var mapData = manager.GetMapData();
|
||||
//Debug.Log($"ticks:{manager.GetCurrentFrame()}:{manager.GetMapData().List[currentIndex].Elevation}");
|
||||
//Debug.Log($"ticks:{ticks}-{manager.GetCurrentFrame()}-endistance:{totalDistance}-totalDistance:{mapData.TotalDistance}-index:{currentIndex}-speed:{speed}-currentSlope:{currentSlope}-GetCurrentFrame:{manager.GetCurrentFrame()}-currentlatLon:{bearing}");
|
||||
//记录骑行数据
|
||||
var recorderData = manager.cyclingController.recorderData;
|
||||
var targetData = new TargetData
|
||||
@@ -155,6 +134,7 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
//默认启用多圈
|
||||
if (isSingle && totalDistance >= mapData.TotalDistance)
|
||||
{
|
||||
Debug.Log($"{totalDistance}-{mapData.TotalDistance}");
|
||||
Complete();
|
||||
}
|
||||
}
|
||||
@@ -173,98 +153,5 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
manager.Save(totalDistance);
|
||||
}
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
//人物状态
|
||||
public const int HERO_UP = 0;
|
||||
public const int HERO_RIGHT = 1;
|
||||
public const int HERO_DOWN = 2;
|
||||
public const int HERO_LEFT = 3;
|
||||
public const int UP = 4;
|
||||
public const int DOWN = 5;
|
||||
private Vector3 rotation = Vector3.zero;
|
||||
private void LateUpdate()
|
||||
{
|
||||
var zdelta = 0.1f;
|
||||
var delta = 0.2f;
|
||||
//控制人物方向
|
||||
if (Input.GetKey(KeyCode.Q))
|
||||
{
|
||||
rotation.y -= delta;
|
||||
transform.DORotate(rotation, 0);
|
||||
}
|
||||
if (Input.GetKey(KeyCode.E))
|
||||
{
|
||||
rotation.y += delta;
|
||||
transform.DORotate(rotation, 0);
|
||||
}
|
||||
//控制人物左右倾斜
|
||||
if (Input.GetKey(KeyCode.J))
|
||||
{
|
||||
rotation.z += zdelta;
|
||||
transform.DORotate(rotation, 0);
|
||||
}
|
||||
if (Input.GetKey(KeyCode.K))
|
||||
{
|
||||
rotation.z -= zdelta;
|
||||
transform.DORotate(rotation, 0);
|
||||
}
|
||||
if (Input.GetKey(KeyCode.Space))
|
||||
Save();
|
||||
}
|
||||
private string ConfigPath = Application.streamingAssetsPath + "/newdirection.txt";
|
||||
//初始化配置
|
||||
private void InitConfig()
|
||||
{
|
||||
var text = File.ReadAllText(ConfigPath);
|
||||
var arr = text.Replace("\r\n", " ").Split(' ');
|
||||
foreach (var item in arr)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(item))
|
||||
{
|
||||
int key = Convert.ToInt32(item.Split(':')[0]);
|
||||
list.Add(key, item);
|
||||
}
|
||||
}
|
||||
}
|
||||
private Dictionary<int, string> list = new Dictionary<int, string>();
|
||||
private void Save()
|
||||
{
|
||||
var key = GetCurrentFrame();
|
||||
//获取人物inpector面板的rotation值
|
||||
Vector3 vect3 = Vector3.zero;
|
||||
Vector3 vect = Vector3.zero;
|
||||
MethodInfo mth = typeof(Transform).GetMethod("GetLocalEulerAngles", BindingFlags.Instance | BindingFlags.NonPublic);
|
||||
PropertyInfo pi = typeof(Transform).GetProperty("rotationOrder", BindingFlags.Instance | BindingFlags.NonPublic);
|
||||
object rotationOrder = null;
|
||||
if (pi != null)
|
||||
{
|
||||
rotationOrder = pi.GetValue(transform, null);
|
||||
}
|
||||
if (mth != null)
|
||||
{
|
||||
object retVector3 = mth.Invoke(transform, new object[] { rotationOrder });
|
||||
vect3 = (Vector3)retVector3;
|
||||
}
|
||||
//保存记录
|
||||
var s = $"{key}:{ Math.Round(vect3.y, 3)},{ Math.Round(vect3.z, 3)},{Math.Round(transform.position.x, 3)},{Math.Round(transform.position.y, 3)},{Math.Round(transform.position.z, 3)},{Math.Round(vect.y, 3)}";
|
||||
Debug.Log(s);
|
||||
if (list.ContainsKey(key))
|
||||
{
|
||||
list[key] = s;
|
||||
}
|
||||
else
|
||||
{
|
||||
list.Add(key, s);
|
||||
}
|
||||
var coll = list.OrderBy(c => c.Key);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
foreach (var item in coll)
|
||||
{
|
||||
sb.AppendLine(item.Value);
|
||||
}
|
||||
File.WriteAllText(ConfigPath, sb.ToString());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -67,8 +67,8 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
|
||||
mapName.text = manager.GetMapRoute().Name;
|
||||
//#if UNITY_EDITOR
|
||||
infoText.gameObject.SetActive(true);
|
||||
infoText.text = $"帧数:{manager.GetCurrentFrame()}";
|
||||
//infoText.gameObject.SetActive(true);
|
||||
//infoText.text = $"帧数:{manager.GetCurrentFrame()}";
|
||||
//#endif
|
||||
if (manager.CurrentPlayer != null)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user