2022-03-24 09:36:59 +08:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
using UnityEngine.Networking;
|
|
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
|
using DG.Tweening;
|
|
|
|
|
|
using UnityEngine.SceneManagement;
|
2022-03-25 09:57:30 +08:00
|
|
|
|
using UnityEngine.EventSystems;
|
2022-04-18 19:13:16 +08:00
|
|
|
|
using Assets.Scenes.Ride.Scripts;
|
|
|
|
|
|
using Assets.Scripts.Apis.Models;
|
|
|
|
|
|
using System.Linq;
|
2022-03-24 09:36:59 +08:00
|
|
|
|
|
|
|
|
|
|
namespace Assets.Scripts.Scenes.VideoRide
|
|
|
|
|
|
{
|
|
|
|
|
|
public class VideoLoading : MonoBehaviour
|
|
|
|
|
|
{
|
|
|
|
|
|
Button download { get; set; }
|
|
|
|
|
|
UnityWebRequest request { get; set; }
|
|
|
|
|
|
VideoGameManager manager { get; set; }
|
|
|
|
|
|
// Start is called before the first frame update
|
2022-04-18 19:13:16 +08:00
|
|
|
|
|
|
|
|
|
|
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()
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2022-03-24 09:36:59 +08:00
|
|
|
|
void Start()
|
|
|
|
|
|
{
|
|
|
|
|
|
manager = FindObjectOfType<VideoGameManager>();
|
2022-03-31 18:40:19 +08:00
|
|
|
|
|
2022-03-24 09:36:59 +08:00
|
|
|
|
var button = transform.Find("Panel/Button").GetComponent<Button>();
|
|
|
|
|
|
var Start = transform.Find("Panel/Start").GetComponent<Button>();
|
|
|
|
|
|
var Back = transform.Find("Panel/Back").GetComponent<Button>();
|
2022-03-25 09:57:30 +08:00
|
|
|
|
var Inspect = transform.Find("Panel/Inspect").gameObject;
|
|
|
|
|
|
UIManager.AddEvent(Inspect, UnityEngine.EventSystems.EventTriggerType.PointerClick, InspectHandler);
|
2022-03-24 09:36:59 +08:00
|
|
|
|
var canvasGroup = transform.GetComponent<CanvasGroup>();
|
|
|
|
|
|
var ui = manager.GetCanvasTransform();
|
2022-03-25 09:57:30 +08:00
|
|
|
|
var route = manager.GetMapRoute();
|
2022-03-24 09:36:59 +08:00
|
|
|
|
var text = transform.GetComponentInChildren<Text>();
|
2022-03-25 09:57:30 +08:00
|
|
|
|
var fileName = route.FileName;// "12067924_720p.mp4";
|
|
|
|
|
|
var url = route.Url; //@"http://192.168.0.97:6031/12067924_720p.mp4";
|
2022-03-24 09:36:59 +08:00
|
|
|
|
var currentPath = "";
|
|
|
|
|
|
var path = PFConstants.VideoFolder;
|
|
|
|
|
|
var filepath = path + "/" + fileName;
|
|
|
|
|
|
|
|
|
|
|
|
if (File.Exists(filepath))
|
|
|
|
|
|
{
|
|
|
|
|
|
button.gameObject.SetActive(false);
|
|
|
|
|
|
Start.gameObject.SetActive(true);
|
|
|
|
|
|
manager.SetMedia(filepath);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
//检查本地文件是否存在 如果存在直接设置mediaPlayer 否则显示下载按钮
|
|
|
|
|
|
button.onClick.AddListener(() =>
|
|
|
|
|
|
{
|
|
|
|
|
|
StartCoroutine(Utils.DownloadVideo(fileName, url
|
|
|
|
|
|
, (p, req) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
text.text = Math.Round(p * 100, 2).ToString() + "%";
|
|
|
|
|
|
request = req;
|
|
|
|
|
|
}
|
|
|
|
|
|
, (p) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
text.text = "100%";
|
|
|
|
|
|
currentPath = p;
|
|
|
|
|
|
Start.gameObject.SetActive(true);
|
|
|
|
|
|
manager.SetMedia(p);
|
|
|
|
|
|
}
|
|
|
|
|
|
));
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
var g = gameObject;
|
|
|
|
|
|
Start.onClick.AddListener(() =>
|
|
|
|
|
|
{
|
|
|
|
|
|
canvasGroup.DOFade(0, 1).onComplete+=()=> {
|
|
|
|
|
|
g.SetActive(false);
|
2022-03-29 18:41:32 +08:00
|
|
|
|
manager.SetCurrentMode(VideoGameManager.ARMode.RIDE);
|
2022-03-24 09:36:59 +08:00
|
|
|
|
ui.Find("Panel").gameObject.SetActive(true);
|
|
|
|
|
|
};
|
|
|
|
|
|
});
|
|
|
|
|
|
Back.onClick.AddListener(() =>
|
|
|
|
|
|
{
|
|
|
|
|
|
SceneManager.LoadScene("MainScene");
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
2022-04-18 19:13:16 +08:00
|
|
|
|
|
|
|
|
|
|
public void Init()
|
|
|
|
|
|
{
|
|
|
|
|
|
InitGameObject();
|
|
|
|
|
|
InitGameObjectData();
|
|
|
|
|
|
}
|
2022-03-25 09:57:30 +08:00
|
|
|
|
//进入观察模式
|
|
|
|
|
|
private void InspectHandler(BaseEventData data)
|
|
|
|
|
|
{
|
|
|
|
|
|
manager.SetCurrentMode(VideoGameManager.ARMode.INSPECT);
|
|
|
|
|
|
var canvasGroup = transform.GetComponent<CanvasGroup>();
|
2022-03-31 18:40:19 +08:00
|
|
|
|
var ui = manager.GetCanvasTransform();
|
|
|
|
|
|
canvasGroup.DOFade(0, 1).onComplete += () => {
|
|
|
|
|
|
gameObject.SetActive(false);
|
|
|
|
|
|
ui.Find("Panel").gameObject.SetActive(true);
|
|
|
|
|
|
};
|
2022-03-25 09:57:30 +08:00
|
|
|
|
}
|
2022-03-24 09:36:59 +08:00
|
|
|
|
|
2022-04-18 19:13:16 +08:00
|
|
|
|
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");
|
|
|
|
|
|
}
|
2022-03-24 09:36:59 +08:00
|
|
|
|
// Update is called once per frame
|
|
|
|
|
|
void Update()
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2022-04-18 19:13:16 +08:00
|
|
|
|
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;
|
|
|
|
|
|
}
|
2022-03-24 09:36:59 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|