部分代码重构,AR起步冲的问题和停车动画调整
This commit is contained in:
1 parent
71b6155946
commit
fb4da81ce2
18 files changed
+3520
-4391
No files matched your search
@@ -7,6 +7,7 @@ using Assets.Scripts.Apis.Models;
|
||||
using DG.Tweening;
|
||||
using Mapbox.Utils;
|
||||
using Assets.Scenes.Ride.Scripts;
|
||||
using UnityEngine.Assertions;
|
||||
|
||||
namespace Assets.Scripts.Scenes.VideoRide
|
||||
{
|
||||
@@ -58,6 +59,10 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
|
||||
public double mockpower { get; set; }
|
||||
protected float ratio = 1;
|
||||
private static readonly int PreSpeed = Animator.StringToHash("preSpeed");
|
||||
private static readonly int AnimatorSpeed = Animator.StringToHash("speed");
|
||||
private static readonly int Grade = Animator.StringToHash("grade");
|
||||
private static readonly int Power = Animator.StringToHash("power");
|
||||
|
||||
protected virtual void Start()
|
||||
{
|
||||
@@ -112,10 +117,10 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
{
|
||||
if (animator != null)
|
||||
{
|
||||
animator.SetFloat("preSpeed", (float)preSpeed);
|
||||
animator.SetFloat("speed", (float)Speed);
|
||||
animator.SetFloat("grade", (float)currentSlope);
|
||||
animator.SetFloat("power", (float)power);
|
||||
animator.SetFloat(PreSpeed, (float)preSpeed);
|
||||
animator.SetFloat(AnimatorSpeed, (float)speed);
|
||||
animator.SetFloat(Grade, (float)currentSlope);
|
||||
animator.SetFloat(Power, (float)power);
|
||||
}
|
||||
}
|
||||
//计算人物当前属性
|
||||
@@ -148,21 +153,22 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
}
|
||||
public virtual void ComputeAnimatorSpeed()
|
||||
{
|
||||
if (manager == null)
|
||||
return;
|
||||
Assert.IsNotNull(manager);
|
||||
|
||||
mapData = manager.GetMapData();
|
||||
int safeIndex = currentIndex + 1 < mapData.List.Count ? currentIndex + 1 : currentIndex;
|
||||
float num = speed == 0 ? 1f : (float)(speed / mapData.List[safeIndex].Distance);
|
||||
|
||||
var safeIndex = currentIndex + 1 < mapData.List.Count ? currentIndex + 1 : currentIndex;
|
||||
var num = speed == 0 ? 1f : (float)(speed / mapData.List[safeIndex].Distance);
|
||||
|
||||
ratio = Mathf.Clamp(num, 0.3f, 1.2f);
|
||||
|
||||
var info = animator.GetCurrentAnimatorClipInfo(0);
|
||||
if (info != null)
|
||||
if (info == null) return;
|
||||
|
||||
var currentClip = info.FirstOrDefault();
|
||||
if (currentClip.clip != null)
|
||||
{
|
||||
var currentClip = info.FirstOrDefault();
|
||||
if (currentClip.clip != null)
|
||||
{
|
||||
animator.speed = ratio;
|
||||
}
|
||||
animator.speed = ratio;
|
||||
}
|
||||
}
|
||||
public virtual void ComputeRecord() { }
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
using UnityEngine.UI;
|
||||
using DG.Tweening;
|
||||
using UnityEngine.SceneManagement;
|
||||
@@ -14,58 +13,56 @@ 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, IProgress<float>
|
||||
{
|
||||
UnityWebRequest request { get; set; }
|
||||
VideoGameManager manager { get; set; }
|
||||
|
||||
protected Text mapName;
|
||||
protected RawImage mapRouteImage;
|
||||
protected CanvasGroup canvasGroup;
|
||||
protected Slider slider;
|
||||
protected Text processText;
|
||||
protected Text rideNowText;
|
||||
protected Button rideNow;
|
||||
protected Button cancel;
|
||||
protected Text mapDescText;
|
||||
protected Text distance;
|
||||
protected Text elevaction;
|
||||
protected Text slope;
|
||||
protected GameObject panel;
|
||||
protected GameObject download;
|
||||
protected GameObject watch;
|
||||
private Text mapName;
|
||||
private RawImage mapRouteImage;
|
||||
private CanvasGroup canvasGroup;
|
||||
private Slider slider;
|
||||
private Text processText;
|
||||
private Text rideNowText;
|
||||
private Button rideNow;
|
||||
private Button cancel;
|
||||
private Text mapDescText;
|
||||
private Text distance;
|
||||
private Text elevaction;
|
||||
private Text slope;
|
||||
private GameObject panel;
|
||||
private GameObject download;
|
||||
private GameObject watch;
|
||||
|
||||
protected GameObject loadingPanel { get; set; }
|
||||
|
||||
protected Text level;
|
||||
protected Text rideNum;
|
||||
protected Text uploadByUserName;
|
||||
protected RawImage head;
|
||||
protected RawImage country;
|
||||
protected RawImage mapCountry;
|
||||
protected RawImage altitudeGraph { get; set; }
|
||||
protected Transform mapRanking;
|
||||
protected Text mapId;
|
||||
|
||||
private Text level;
|
||||
private Text rideNum;
|
||||
private Text uploadByUserName;
|
||||
private RawImage head;
|
||||
private RawImage country;
|
||||
private RawImage mapCountry;
|
||||
private RawImage altitudeGraph { get; set; }
|
||||
private Transform mapRanking;
|
||||
private Text mapId;
|
||||
private Text downloadText { get; set; }
|
||||
private Transform ui;
|
||||
private MapRoute route;
|
||||
|
||||
protected float process = 0;//0-100 %
|
||||
public float targetAlpha = 0f;
|
||||
public float alphaSpeed = 2.0f;
|
||||
|
||||
protected Transform ui;
|
||||
|
||||
protected MapRoute route;
|
||||
|
||||
|
||||
private bool startBtnLock = false;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if(App.gameRoomDetail != null)
|
||||
ShowGameRoomLoading();
|
||||
}
|
||||
void Start()
|
||||
|
||||
private void Start()
|
||||
{
|
||||
manager = FindObjectOfType<VideoGameManager>();
|
||||
ui = manager.GetCanvasTransform();
|
||||
@@ -184,19 +181,18 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
|
||||
downloadText = rideNow.GetComponentInChildren<Text>();//视频下载进度text
|
||||
}
|
||||
Text downloadText { get; set; }
|
||||
|
||||
protected void InitGameObjectData()
|
||||
{
|
||||
var route = manager.mapRoute;
|
||||
#region 绑定路书基本信息
|
||||
mapName.text = GetMaxString(route.Name, 40);
|
||||
mapName.text = route.Name.ToEllipsisString(40);
|
||||
level.text = route.Hard;
|
||||
elevaction.text = Math.Round(route.TotalClimb.GetValueOrDefault(0), 2).ToString() + "M";
|
||||
slope.text = Math.Round(route.AverageGrade, 2).ToString() + "%";
|
||||
elevaction.text = Math.Round(route.TotalClimb.GetValueOrDefault(0), 2) + "M";
|
||||
slope.text = Math.Round(route.AverageGrade, 2) + "%";
|
||||
rideNum.text = route.TheHeat.ToString();
|
||||
distance.text = route.Distance.ToString("f1") + "KM";
|
||||
mapDescText.text = GetMaxString(route.Dec, 255);
|
||||
mapDescText.text = route.Dec.ToEllipsisString(255);
|
||||
mapId.text = $"#{route.Id.ToString()}";
|
||||
var userList = ConfigHelper.mapApi.GetOnlineUserInfo(new int[] { route.UserId }).data;
|
||||
if (userList.Count > 0)
|
||||
@@ -218,15 +214,18 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
CreateRankingList(list.data.list);
|
||||
}
|
||||
}
|
||||
bool startBtnLock = false;
|
||||
public void StartRide(BaseEventData baseEvent)
|
||||
|
||||
private void StartRide(BaseEventData baseEvent)
|
||||
{
|
||||
if (startBtnLock)
|
||||
return;
|
||||
if (startBtnLock) return;
|
||||
|
||||
startBtnLock = true;
|
||||
var ui = manager.GetCanvasTransform();
|
||||
|
||||
InitClientState(false);
|
||||
|
||||
InitAR();
|
||||
|
||||
canvasGroup.DOFade(0, 1).onComplete += () => {
|
||||
InitAR();
|
||||
gameObject.SetActive(false);
|
||||
manager.StartGame();
|
||||
manager.SetCyclingModel(Assets.Scenes.Ride.Scripts.Model.CyclingModel.Single);
|
||||
@@ -234,9 +233,9 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
};
|
||||
}
|
||||
|
||||
public async void InitAR()
|
||||
private async void InitAR()
|
||||
{
|
||||
var route = manager.mapRoute;
|
||||
route = manager.mapRoute;
|
||||
var arDataPath = $"{PFConstants.ARFolder}/{route.Id}/{route.Id}.json";
|
||||
var videoRoute = $"{PFConstants.ARFolder}/{route.Id}/route-{route.Id}.json";
|
||||
|
||||
@@ -245,13 +244,15 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
public void StartRide(int seconds)
|
||||
{
|
||||
InitClientState(false);
|
||||
|
||||
var ui = manager.GetCanvasTransform();
|
||||
canvasGroup.DOFade(0, 0).onComplete += () => {
|
||||
InitAR();
|
||||
@@ -260,6 +261,7 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
manager.SetCurrentMode(VideoGameManager.ARMode.RIDE);
|
||||
ui.Find("Panel").gameObject.SetActive(true);
|
||||
};
|
||||
|
||||
UIManager.ShowGameRoomCountDownPanel(seconds,()=> {
|
||||
manager.StartGame();
|
||||
},false,true);
|
||||
@@ -267,7 +269,7 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
|
||||
private bool downloading = false;
|
||||
private CancellationTokenSource cancelToken;
|
||||
protected async void DownloadAsync(BaseEventData baseEvent)
|
||||
private async void DownloadAsync(BaseEventData baseEvent)
|
||||
{
|
||||
if (downloading)
|
||||
return;
|
||||
@@ -322,24 +324,35 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
return;
|
||||
|
||||
slider.value = value < 1 ? (float)Math.Round(value * 100, 0) : 100;
|
||||
downloadText.text = slider.value.ToString() + "%";
|
||||
downloadText.text = slider.value.ToString(CultureInfo.InvariantCulture) + "%";
|
||||
}
|
||||
//进入观察模式
|
||||
private void WatchHandler(BaseEventData data)
|
||||
{
|
||||
var canvasGroup = transform.GetComponent<CanvasGroup>();
|
||||
var ui = manager.GetCanvasTransform();
|
||||
InitAR();
|
||||
MapUDPService.IsWatch = true;
|
||||
MapUDPService.SendGizpModel();
|
||||
canvasGroup.DOFade(0, 1).onComplete += () => {
|
||||
InitClientState(true);
|
||||
|
||||
var canvas = transform.GetComponent<CanvasGroup>();
|
||||
var canvasTransform = manager.GetCanvasTransform();
|
||||
canvas.DOFade(0, 1).onComplete += () => {
|
||||
gameObject.SetActive(false);
|
||||
ui.gameObject.SetActive(true);
|
||||
canvasTransform.gameObject.SetActive(true);
|
||||
manager.SetCurrentMode(VideoGameManager.ARMode.INSPECT);
|
||||
manager.StartGame();
|
||||
};
|
||||
}
|
||||
protected void Cancel(BaseEventData baseEvent)
|
||||
|
||||
/// <summary>
|
||||
/// 告诉服务器是观察模式还是骑行模式
|
||||
/// </summary>
|
||||
/// <param name="isWatch"></param>
|
||||
private static void InitClientState(bool isWatch)
|
||||
{
|
||||
MapUDPService.IsWatch = isWatch;
|
||||
MapUDPService.SendGizpModel();
|
||||
}
|
||||
|
||||
private void Cancel(BaseEventData baseEvent)
|
||||
{
|
||||
if (cancelToken == null)
|
||||
{
|
||||
@@ -361,7 +374,7 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
UIManager.CloseConfirm();
|
||||
});
|
||||
}
|
||||
protected async void DrawMapRouteAsync(int routeId, int type = 0)
|
||||
private async void DrawMapRouteAsync(int routeId, int type = 0)
|
||||
{
|
||||
var result = await ConfigHelper.mapApi.GetMapLoadingCoverageUrl(routeId, type);
|
||||
if (!result.result)
|
||||
@@ -378,7 +391,7 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
Utils.DisplayImageAysnc(StartCoroutine, mapRouteImage, url, DowloadCallBack);
|
||||
}
|
||||
}
|
||||
protected void DowloadCallBack(string url, RawImage rawImage)
|
||||
private void DowloadCallBack(string url, RawImage rawImage)
|
||||
{
|
||||
if (!App.TextureCache.ContainsKey(url))
|
||||
{
|
||||
@@ -449,11 +462,5 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
protected string GetMaxString(string value, int length)
|
||||
{
|
||||
var s = Helper.SubStr(value, length);
|
||||
return s;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
using System.Text;
|
||||
|
||||
public static class ObjectExtension
|
||||
{
|
||||
public static string ToEllipsisString(this string message, int length)
|
||||
{
|
||||
var index = 0;
|
||||
var sb = new StringBuilder();
|
||||
foreach (var item in message)
|
||||
{
|
||||
if (IsChineseCharacter(item))
|
||||
{
|
||||
index += 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
index += 1;
|
||||
}
|
||||
|
||||
sb.Append(item);
|
||||
if (length <= index)
|
||||
{
|
||||
return sb.Append("...").ToString();
|
||||
}
|
||||
}
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
private static bool IsChineseCharacter(char c)
|
||||
{
|
||||
return (19968 <= (int)c) && ((int)c <= 171941);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6474a1d1e1c3429dba1abc390b5e67e9
|
||||
timeCreated: 1678262635
|
||||
Reference in new issue
Block a user