场景加载处理一些卡顿的情况
This commit is contained in:
1 parent
e7a3214cb5
commit
65fc5b5c50
35 files changed
+8668
-2075
No files matched your search
@@ -1,4 +1,5 @@
|
||||
using Assets.Scripts.Apis.Models;
|
||||
using Assets.Scenes.Ride.Scripts.Model.CyclingModels;
|
||||
using Assets.Scripts.Apis.Models;
|
||||
using GeoJSON.Net.Geometry;
|
||||
using Mapbox.Unity.Map;
|
||||
using Mapbox.Utils;
|
||||
@@ -67,6 +68,7 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
public double CurrentSlopeDistance { get => currentSlopeDistance; }
|
||||
public double Elevation { get => elevation; }
|
||||
public double LastEndDistance { get => lastEndDistance; }
|
||||
public Vector2d Nextlatlong { get => nextlatlong; }
|
||||
#endregion
|
||||
|
||||
#region 游戏状态控制
|
||||
@@ -85,6 +87,7 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
public void SetPause()
|
||||
{
|
||||
isStart = false;
|
||||
characterAnimator.SetBool("IsRide", false);
|
||||
}
|
||||
//退出或者完成骑行
|
||||
public void SetQuit()
|
||||
@@ -101,17 +104,24 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
private void FixedUpdate()
|
||||
{
|
||||
Excute();
|
||||
}
|
||||
#region 骑行逻辑
|
||||
//初始化骑行数据
|
||||
#region 骑行逻辑
|
||||
//初始化骑行数据
|
||||
protected CyclingController mainController;
|
||||
protected BaseCycling cyclingExcutor;
|
||||
protected virtual void Init()
|
||||
{
|
||||
characterAnimator = GetComponentInChildren<Animator>();
|
||||
var mainController = transform.parent.GetComponent<CyclingController>();
|
||||
mainController = transform.parent.GetComponent<CyclingController>();
|
||||
map = FindObjectOfType<AbstractMap>();
|
||||
mapData = mainController.GetMapData();//获取路书信息
|
||||
nextlatlong = new Vector2d(mapData.List[0].Point[0], mapData.List[0].Point[1]);//初始化人物位置 TODO加上之前骑行距离
|
||||
cyclingExcutor = mainController.cyclingController;
|
||||
}
|
||||
|
||||
protected virtual void Excute()
|
||||
@@ -135,32 +145,30 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
if (totalDistance <= mapData.TotalDistance)
|
||||
{
|
||||
//数据处理
|
||||
|
||||
nextlatlong = Along(totalDistance);//下一个坐标
|
||||
nextPos = map.GeoToWorldPosition(nextlatlong);//下一个点
|
||||
nextPos.y += 0.3f;//提高y轴让人物站在地图上面
|
||||
prePos = transform.localPosition;//当前点
|
||||
thisRotation = transform.localRotation;
|
||||
//动画控制
|
||||
if (distance > 0)
|
||||
{
|
||||
characterAnimator.SetBool("IsRide", true);//开始移动动画
|
||||
StartCoroutine(LookAtNextPos());//转向
|
||||
|
||||
StartCoroutine(MoveTo());//移动
|
||||
//transform.localPosition = nextPos;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
totalDistance = mapData.TotalDistance;
|
||||
characterAnimator.SetBool("ReachEnd", true);//到达终点
|
||||
Task.Run(() => { Upload(); });//异步上传数据
|
||||
//Task.Run(() => { });//异步上传数据
|
||||
Upload();
|
||||
isStart = false;
|
||||
isQuit = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
characterAnimator.SetBool("IsRide", false);
|
||||
}
|
||||
}
|
||||
//计算功率 速度 当前骑行总里程(M)心率 踏频 等
|
||||
protected virtual void Compute()
|
||||
@@ -220,15 +228,17 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
#endregion
|
||||
|
||||
#region 人物移动与转向控制
|
||||
|
||||
Quaternion thisRotation;
|
||||
IEnumerator LookAtNextPos()
|
||||
{
|
||||
Quaternion neededRotation = Quaternion.LookRotation(transform.localPosition - nextPos);
|
||||
Quaternion thisRotation = character.transform.localRotation;
|
||||
Quaternion neededRotation = Quaternion.LookRotation(prePos - nextPos);
|
||||
//Quaternion thisRotation = character.transform.localRotation;
|
||||
|
||||
float t = 0;
|
||||
while (t < 1.0f)
|
||||
{
|
||||
t += Time.deltaTime / 0.25f;
|
||||
t += Time.deltaTime / 0.5f;
|
||||
var rotationValue = Quaternion.Slerp(thisRotation, neededRotation, t);
|
||||
character.transform.rotation = Quaternion.Euler(0, rotationValue.eulerAngles.y, 0);
|
||||
yield return null;
|
||||
@@ -238,15 +248,16 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
//人物移动控制
|
||||
IEnumerator MoveTo()
|
||||
{
|
||||
StartCoroutine(LookAtNextPos());//转向
|
||||
//让人物移动分点增加动画的流畅度
|
||||
float t = 0;
|
||||
while (t < 1)
|
||||
{
|
||||
t += Time.deltaTime;
|
||||
Vector3 v = Vector3.Lerp(prePos, nextPos, t);
|
||||
transform.localPosition = v;
|
||||
|
||||
transform.localPosition = new Vector3((float)Math.Round(v.x,4), (float)Math.Round(v.y, 4), (float)Math.Round(v.z, 4));
|
||||
//控制海拔图的位置
|
||||
|
||||
yield return null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user