调整多人开始骑行状态&动画控制&AR loading页面
This commit is contained in:
1 parent
995aef63f8
commit
8150b99411
11 files changed
+13367
-1895
No files matched your search
@@ -39,7 +39,7 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
public double totalClimb;
|
||||
public Vector2d currentlatLon { get; set; }
|
||||
public int currentIndex;
|
||||
protected float bearing = 0f;
|
||||
public float bearing = 0f;
|
||||
protected MapDataModel mapData;
|
||||
protected bool isHit = false;
|
||||
protected RaycastHit hit;
|
||||
@@ -74,16 +74,17 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
protected virtual void Update()
|
||||
{
|
||||
timer -= Time.deltaTime;
|
||||
ComputeAnimator();//控制动画
|
||||
|
||||
CreateHeadImage();
|
||||
|
||||
|
||||
while (timer <= 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
ComputeAnimator();//控制动画
|
||||
ComputeNextSlope();//计算下一个坡度
|
||||
ComputePlayer();//计算人物属性
|
||||
if (manager.IsStart())
|
||||
if (GetStart())
|
||||
{
|
||||
ticks++;
|
||||
Forward();
|
||||
@@ -118,16 +119,21 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
isHit = Physics.Raycast(ray, out hit, 1f, 1 << 0, QueryTriggerInteraction.Collide);
|
||||
}
|
||||
|
||||
protected virtual bool GetStart()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
//动画状态机
|
||||
protected virtual void ComputeAnimator()
|
||||
{
|
||||
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("bearing", bearing);
|
||||
}
|
||||
}
|
||||
protected virtual int GetCurrentFrame()
|
||||
|
||||
@@ -10,7 +10,7 @@ using UnityEngine.UI;
|
||||
|
||||
namespace Assets.Scripts.Scenes.VideoRide
|
||||
{
|
||||
public struct ContactInfo
|
||||
public class ContactInfo
|
||||
{
|
||||
public string Name;
|
||||
public string Gender;
|
||||
@@ -69,7 +69,8 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
var totalDitance = manager.GetMapData().TotalDistance;
|
||||
var currentDistance = manager.CurrentPlayer.totalDistance;
|
||||
|
||||
var currenList = FindObjectsOfType<ListItem>();//当前列表
|
||||
//var currenList = FindObjectsOfType<ListItem>();//当前列表
|
||||
var currenList = GetComponentsInChildren<ListItem>(true);
|
||||
var list = MapUDPService.GetOnlineUsers(App.RouteIdParam);//最新列表
|
||||
list = list.Where(c => c.Id != App.CurrentUser.Id).ToList();
|
||||
if (currenList.Count() == 0 && list.Count() > 0)
|
||||
@@ -83,6 +84,8 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
//var currenList = FindObjectsOfType<ListItem>();//当前列表
|
||||
//var list = MapUDPService.GetOnlineUsers(App.RouteIdParam);//最新列表
|
||||
var currentPlayer = FindObjectOfType<VideoPlayer>();
|
||||
|
||||
|
||||
foreach (ListItem o in currenList)
|
||||
{
|
||||
if (currentPlayer.UserId.ToString() == o.Id)
|
||||
@@ -91,14 +94,26 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
if (needUpdate != null)
|
||||
{
|
||||
var left = Math.Round((needUpdate.EndDistance - manager.CurrentPlayer.totalDistance) * 1000);
|
||||
//var right = (needUpdate.EndDistance % totalDitance - totalDitance - currentDistance) * 1000;
|
||||
//var diff = Math.Abs(left) > Math.Abs(right) ? right : left;
|
||||
o.UpdateItem(needUpdate.Name, left.ToString() + "M", needUpdate.Id.ToString());
|
||||
//o.gameObject.SetActive(true);
|
||||
o.gameObject.SetActive(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
//o.gameObject.SetActive(false);
|
||||
o.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var item in list)
|
||||
{
|
||||
var newOne = _contactList.Where(c => c.id == item.Id.ToString()).FirstOrDefault();
|
||||
if (newOne == null)
|
||||
{
|
||||
var one = new ContactInfo();
|
||||
one.Name = item.Name;
|
||||
one.Gender = "";
|
||||
one.id = item.Id.ToString();
|
||||
_contactList.Add(one);
|
||||
_recyclableScrollRect.ReloadData();
|
||||
}
|
||||
}
|
||||
timer +=1f;
|
||||
|
||||
@@ -18,6 +18,7 @@ using Assets.Scenes.Ride.Scripts.Model.RiderModels;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.Events;
|
||||
using Helper = Assets.Scenes.Ride.Scripts.Helper;
|
||||
using System.Collections;
|
||||
|
||||
namespace Assets.Scripts.Scenes.VideoRide
|
||||
{
|
||||
@@ -78,6 +79,7 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
MockDirection();
|
||||
infoPanel = Resources.Load<GameObject>("UI/Prefab/AR/VideoPlayerHead");
|
||||
OnlinePlayer = Resources.Load<GameObject>("UI/Prefab/OnlineVideoPlayer");
|
||||
StartCoroutine(Init());
|
||||
}
|
||||
void Start()
|
||||
{
|
||||
@@ -108,8 +110,16 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
endDistance = 0;
|
||||
//倒计时5s开始
|
||||
SetCyclingModel(CyclingModel.Single);
|
||||
videoLoading = FindObjectOfType<VideoLoading>();
|
||||
|
||||
|
||||
}
|
||||
private IEnumerator Init()
|
||||
{
|
||||
yield return null;
|
||||
videoLoading.Init();//初始化loading页面
|
||||
}
|
||||
VideoLoading videoLoading { get; set; }
|
||||
// Update is called once per frame
|
||||
float timer = 1f;
|
||||
void Update()
|
||||
@@ -474,6 +484,10 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
{
|
||||
return UIManager.Instance.loginRegOptions.GetCountryImage(code);
|
||||
}
|
||||
public Texture GetCountryImageByName(string name)
|
||||
{
|
||||
return UIManager.Instance.loginRegOptions.GetCountryImageByName(name);
|
||||
}
|
||||
//截图
|
||||
protected void CaptureCamera(Camera camera, Rect rect, string fileName)
|
||||
{
|
||||
|
||||
@@ -8,6 +8,9 @@ using UnityEngine.UI;
|
||||
using DG.Tweening;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.EventSystems;
|
||||
using Assets.Scenes.Ride.Scripts;
|
||||
using Assets.Scripts.Apis.Models;
|
||||
using System.Linq;
|
||||
|
||||
namespace Assets.Scripts.Scenes.VideoRide
|
||||
{
|
||||
@@ -17,6 +20,42 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
UnityWebRequest request { get; set; }
|
||||
VideoGameManager manager { get; set; }
|
||||
// Start is called before the first frame update
|
||||
|
||||
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 loadingPanel { get; set; }
|
||||
|
||||
protected Text level;
|
||||
protected Text rideNum;
|
||||
protected Text uploadByUserName;
|
||||
protected RawImage head;
|
||||
protected RawImage country;
|
||||
protected RawImage mapCountry;
|
||||
protected RawImage altitudeGraph;
|
||||
protected Transform mapRanking;
|
||||
protected Text mapId;
|
||||
|
||||
protected float process = 0;//0-100 %
|
||||
public float targetAlpha = 0f;
|
||||
public float alphaSpeed = 2.0f;
|
||||
private bool depressFlag = false;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
|
||||
}
|
||||
void Start()
|
||||
{
|
||||
manager = FindObjectOfType<VideoGameManager>();
|
||||
@@ -77,6 +116,12 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
SceneManager.LoadScene("MainScene");
|
||||
});
|
||||
}
|
||||
|
||||
public void Init()
|
||||
{
|
||||
InitGameObject();
|
||||
InitGameObjectData();
|
||||
}
|
||||
//进入观察模式
|
||||
private void InspectHandler(BaseEventData data)
|
||||
{
|
||||
@@ -89,10 +134,154 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
};
|
||||
}
|
||||
|
||||
private void InitGameObject()
|
||||
{
|
||||
panel = transform.Find("Panel").gameObject;
|
||||
mapName = panel.transform.Find("MapName").GetComponent<Text>();
|
||||
distance = panel.transform.Find("Distance").GetComponent<Text>();
|
||||
elevaction = panel.transform.Find("Elevaction").GetComponent<Text>();
|
||||
slope = panel.transform.Find("Slope").GetComponent<Text>();
|
||||
mapRouteImage = panel.transform.Find("MapRouteImage").GetComponent<RawImage>();
|
||||
slider = panel.transform.Find("Process").GetComponent<Slider>();
|
||||
slider.gameObject.SetActive(false);
|
||||
processText = panel.transform.Find("ProcessText").GetComponent<Text>();
|
||||
processText.gameObject.SetActive(false);
|
||||
mapDescText = panel.transform.Find("MapDesc").GetComponent<Text>();
|
||||
rideNow = panel.transform.Find("RideNow").GetComponent<Button>();
|
||||
rideNowText = rideNow.transform.Find("Text").GetComponent<Text>();
|
||||
cancel = panel.transform.Find("Cancel").GetComponent<Button>();
|
||||
UIManager.AddEvent(rideNow.gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, StartRide);
|
||||
UIManager.AddEvent(cancel.gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, Cancel);
|
||||
slider.onValueChanged.AddListener((f) =>
|
||||
{
|
||||
processText.text = $"{(f).ToString("#0")}%";
|
||||
});
|
||||
|
||||
level = panel.transform.Find("level/Text").GetComponent<Text>();
|
||||
rideNum = panel.transform.Find("RideNum").GetComponent<Text>();
|
||||
uploadByUserName = panel.transform.Find("UploadByUserName").GetComponent<Text>();
|
||||
country = panel.transform.Find("UploadByCountry").GetComponent<RawImage>();
|
||||
mapCountry = panel.transform.Find("Country").GetComponent<RawImage>();
|
||||
head = panel.transform.Find("UploadByHead").GetComponent<RawImage>();
|
||||
altitudeGraph = panel.transform.Find("AltitudeGraph").GetComponent<RawImage>();
|
||||
mapRanking = panel.transform.Find("MapRanking");
|
||||
mapId = panel.transform.Find("MapId").GetComponent<Text>();
|
||||
}
|
||||
protected void InitGameObjectData()
|
||||
{
|
||||
var route = manager.mapRoute;
|
||||
#region 绑定路书基本信息
|
||||
//mapName.text = route.Name;
|
||||
#if UNITY_IOS || UNITY_ANDROID
|
||||
enable3D = panel.transform.Find("Enable3D").gameObject;
|
||||
enable3D.SetActive(route.Enable3D);
|
||||
#endif
|
||||
mapName.text = GetMaxString(route.Name, 40);
|
||||
level.text = route.Hard;
|
||||
elevaction.text = Math.Round(route.TotalClimb.GetValueOrDefault(0), 2).ToString() + "M";
|
||||
slope.text = Math.Round(route.AverageGrade, 2).ToString() + "%";
|
||||
rideNum.text = route.TheHeat.ToString();
|
||||
distance.text = route.Distance.ToString("f1") + "KM";
|
||||
mapDescText.text = GetMaxString(route.Dec, 255);
|
||||
mapId.text = $"#{route.Id.ToString()}";
|
||||
var userList = ConfigHelper.mapApi.GetOnlineUserInfo(new int[] { route.UserId }).data;
|
||||
if (userList.Count > 0)
|
||||
{
|
||||
uploadByUserName.text = userList[0].Name;
|
||||
var countryUrl = App.Host + $"User/GetCountryImg?userid={userList[0].Id}";
|
||||
Utils.DisplayImage(head, userList[0].HeadImage);//头像
|
||||
country.texture = manager.GetCountryImageByName(userList[0].Country);//上传者国家
|
||||
mapCountry.texture = manager.GetCountryImageByCode(route.CountryCode);//路书国家
|
||||
}
|
||||
#endregion
|
||||
|
||||
//查询排行榜
|
||||
var list = ConfigHelper.mapApi.GetRouteRanking(route.Id, "1", 0, 10000, "");
|
||||
if (list.result)
|
||||
{
|
||||
CreateRankingList(list.data.list);
|
||||
}
|
||||
}
|
||||
protected void StartRide(BaseEventData baseEvent)
|
||||
{
|
||||
}
|
||||
protected void Cancel(BaseEventData baseEvent)
|
||||
{
|
||||
SceneManager.LoadScene("MainScene");
|
||||
}
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
private int RankingPageSize = 10;
|
||||
//创建排行榜
|
||||
public void CreateRankingList(List<MapRouteRanking> list)
|
||||
{
|
||||
#if UNITY_IOS || UNITY_ANDROID
|
||||
var prefab = Resources.Load<GameObject>("UI/Prefab/Ride/Mobile/RankingItem");
|
||||
var myprefab = Resources.Load<GameObject>("UI/Prefab/Ride/Mobile/MySelfRankingItem");
|
||||
var viewAllbtn = Resources.Load<GameObject>("UI/Prefab/Ride/Mobile/ViewAll");
|
||||
#else
|
||||
var prefab = Resources.Load<GameObject>("UI/Prefab/Ride/RankingItem");
|
||||
var myprefab = Resources.Load<GameObject>("UI/Prefab/Ride/MySelfRankingItem");
|
||||
var viewAllbtn = Resources.Load<GameObject>("UI/Prefab/Ride/ViewAll");
|
||||
#endif
|
||||
var parent = panel.transform.Find("MapRanking");
|
||||
var title = panel.transform.Find("RankingTitle").gameObject;
|
||||
title.SetActive(list.Count != 0);
|
||||
int index = 0;
|
||||
foreach (var item in list)
|
||||
{
|
||||
index++;
|
||||
if (index > RankingPageSize)
|
||||
break;
|
||||
GameObject newObj = (GameObject)Instantiate(prefab, parent);
|
||||
var selectPlayerItemScript = newObj.GetComponent<Assets.Scenes.Ride.Scripts.RankingItemScript>();
|
||||
selectPlayerItemScript.SetRanking(item.RowNumber.ToString());
|
||||
selectPlayerItemScript.SetName(item.NickName);
|
||||
selectPlayerItemScript.SetTimer(item.IsDNF ? "DNF" : item.TotalTime);
|
||||
selectPlayerItemScript.SetHead(item.WxHeadImg);
|
||||
var texture = manager.GetCountryImageByCode(item.CountryCode);
|
||||
selectPlayerItemScript.SetCountry(texture);
|
||||
}
|
||||
//如果有自己的记录显示自己的排名
|
||||
var myself = list.Where(c => c.MySelf).FirstOrDefault();
|
||||
GameObject myselfObj = (GameObject)Instantiate(myprefab, parent);
|
||||
var myselfItemScript = myselfObj.GetComponent<Assets.Scenes.Ride.Scripts.RankingItemScript>();
|
||||
if (myself == null)
|
||||
{
|
||||
myselfItemScript.SetRanking("--");
|
||||
myselfItemScript.SetName(App.CurrentUser.Nickname);
|
||||
myselfItemScript.SetTimer("--:--:--");
|
||||
myselfItemScript.SetHead(App.CurrentUser.WxHeadImg);
|
||||
var texture = manager.GetCountryImageByName(App.CurrentUser.Country);
|
||||
myselfItemScript.SetCountry(texture);
|
||||
}
|
||||
else
|
||||
{
|
||||
myselfItemScript.SetRanking(myself.RowNumber.ToString());
|
||||
myselfItemScript.SetName(myself.NickName);
|
||||
myselfItemScript.SetTimer(myself.IsDNF ? "DNF" : myself.TotalTime);
|
||||
myselfItemScript.SetHead(myself.WxHeadImg);
|
||||
var texture = manager.GetCountryImageByCode(myself.CountryCode);
|
||||
myselfItemScript.SetCountry(texture);
|
||||
}
|
||||
//显示查询全部按钮
|
||||
if (list.Count > 0)
|
||||
{
|
||||
GameObject ViewAll = (GameObject)Instantiate(viewAllbtn, parent);
|
||||
UIManager.AddEvent(ViewAll, UnityEngine.EventSystems.EventTriggerType.PointerClick, b =>
|
||||
{
|
||||
Application.OpenURL($"{App.CurrentUser.WebHost}Routes/{manager.mapRoute.Id}?Token={App.CurrentUser.cookie}");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
protected string GetMaxString(string value, int length)
|
||||
{
|
||||
var s = Helper.SubStr(value, length);
|
||||
return s;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,11 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
UserName = App.CurrentUser.Nickname;
|
||||
}
|
||||
|
||||
protected override bool GetStart()
|
||||
{
|
||||
return manager.IsStart();
|
||||
}
|
||||
|
||||
protected override void Update()
|
||||
{
|
||||
base.Update();
|
||||
@@ -38,25 +43,23 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
protected override void ComputeAnimator()
|
||||
{
|
||||
base.ComputeAnimator();
|
||||
|
||||
var mainFrame = manager.GetCurrentFrame();
|
||||
var result = manager.mockDirection.Where(c => c.Start < mainFrame && c.End > mainFrame).FirstOrDefault();
|
||||
bearing = result?.Value ?? 0;
|
||||
animator.SetFloat("bearing", bearing);
|
||||
}
|
||||
protected override void ComputePlayer()
|
||||
{
|
||||
heartRate = manager.UpDateHeart();
|
||||
power = manager.UpdatePower();
|
||||
cadance = manager.UpdateCadence();
|
||||
#if UNITY_EDITOR
|
||||
power = 0;
|
||||
//#if UNITY_EDITOR
|
||||
power = 150;
|
||||
cadance = 150;
|
||||
heartRate = 160;
|
||||
#endif
|
||||
//#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?.Value ?? 0;
|
||||
//发送阻力
|
||||
manager.TrackResistance(currentSlope);
|
||||
base.ComputePlayer();
|
||||
|
||||
Reference in new issue
Block a user