AR文件更新流程&AR网络延时问题
This commit is contained in:
1 parent
16cd2fd26b
commit
74ba5790f9
18 files changed
+867
-508
No files matched your search
@@ -1,14 +1,6 @@
|
||||
using Assets.Scenes.Ride.Scripts;
|
||||
using Assets.Scripts;
|
||||
using Assets.Scripts.Apis.Models;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using PolyAndCode.UI;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using Assets.AR;
|
||||
using Assets.Core;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
@@ -36,24 +28,49 @@ class GameRoomDownLoad : MonoBehaviour
|
||||
public string FileName { get; set; }
|
||||
public string RouteName { get; set; }
|
||||
private string FileUrl { get; set; }
|
||||
|
||||
private float _videoProgress;
|
||||
|
||||
public float VideoProgress
|
||||
{
|
||||
get => _videoProgress;
|
||||
set
|
||||
{
|
||||
_videoProgress = value;
|
||||
ComputeProgress();
|
||||
}
|
||||
}
|
||||
|
||||
private float _dataProgress = 0f;
|
||||
public float DataProgress
|
||||
{
|
||||
get => _dataProgress;
|
||||
set
|
||||
{
|
||||
_dataProgress = value;
|
||||
ComputeProgress();
|
||||
}
|
||||
}
|
||||
|
||||
private float _routeProgress = 0f;
|
||||
public float RouteProgress
|
||||
{
|
||||
get => _routeProgress;
|
||||
set
|
||||
{
|
||||
_routeProgress = value;
|
||||
ComputeProgress();
|
||||
}
|
||||
}
|
||||
private void Start()
|
||||
{
|
||||
UIManager.AddEvent(downloadBtn, EventTriggerType.PointerClick, DownloadClick);
|
||||
UIManager.AddEvent(downloadBtn, EventTriggerType.PointerClick, Download_Click);
|
||||
UIManager.AddEvent(backBtn, EventTriggerType.PointerClick, CancelClick);
|
||||
|
||||
UIManager.AddEvent(runInbackBtn, EventTriggerType.PointerClick, (d) =>
|
||||
{
|
||||
gameObject.SetActive(false);
|
||||
downLoadList.SetActive(true);
|
||||
//var content = downLoadList.transform.Find("Viewport/Content");
|
||||
//var list = FindObjectsOfType<GameRoomDownloadTask>();
|
||||
////新增
|
||||
//var obj = list.Where(c => c.RoomId == RoomId).FirstOrDefault();
|
||||
//if (obj == null)
|
||||
//{
|
||||
// var newtask = Instantiate(downLoadTask, content);
|
||||
// newtask.GetComponent<GameRoomDownloadTask>().Init(RoomId, FileName,gameObject);
|
||||
//}
|
||||
});
|
||||
|
||||
UIManager.AddEvent(enterBtn, EventTriggerType.PointerClick, (ee) =>
|
||||
@@ -69,22 +86,17 @@ class GameRoomDownLoad : MonoBehaviour
|
||||
});
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
//if (!string.IsNullOrEmpty(FileName) && Loom.DownloadStack.ContainsKey(FileName))
|
||||
//{
|
||||
// processing(Loom.DownloadStack[FileName]);
|
||||
//}
|
||||
}
|
||||
|
||||
public void Init(int Id, string fileName, string url, GameRoomListController gameRoomListController, string routeName)
|
||||
private ARDownloader _downloader;
|
||||
public void Init(int Id, string fileName, string url, GameRoomListController gameRoomListController, string routeName,ARDownloader downloader)
|
||||
{
|
||||
RoomId = Id;
|
||||
FileName = fileName;
|
||||
RouteName = routeName;
|
||||
FileUrl = url;
|
||||
manager = gameRoomListController;
|
||||
_downloader = downloader;
|
||||
}
|
||||
|
||||
public void ComeIntoStep2(string fileName, string routeName)
|
||||
{
|
||||
FileName = fileName;
|
||||
@@ -101,42 +113,47 @@ class GameRoomDownLoad : MonoBehaviour
|
||||
step3.SetActive(false);
|
||||
downloadSlider.value = 0f;
|
||||
}
|
||||
|
||||
private void CancelClick(BaseEventData data)
|
||||
{
|
||||
Reset();
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
private void processing(float p)
|
||||
{
|
||||
downloadSlider.value = p;
|
||||
|
||||
if (!Loom.DownloadStack.ContainsKey(FileName) )
|
||||
{
|
||||
Loom.DownloadStack.Add(FileName, new Assets.Core.DownloadInfo(FileName, RouteName, p));
|
||||
}
|
||||
|
||||
Loom.DownloadStack[FileName].Process = p;
|
||||
|
||||
if (p >= 1)
|
||||
{
|
||||
Loom.DownloadStack.Remove(FileName);
|
||||
}
|
||||
}
|
||||
|
||||
private async void DownloadClick(BaseEventData baseEventData)
|
||||
|
||||
private async void Download_Click(BaseEventData baseEventData)
|
||||
{
|
||||
step2.SetActive(true);
|
||||
step2.transform.Find("RouteName").GetComponent<Text>().text = RouteName;
|
||||
|
||||
var filepath = PFConstants.VideoFolder + "/" + FileName;
|
||||
await Loom.DownloadToFileAsync(FileUrl, filepath, Progress.Create<float>(x => {
|
||||
processing(x);
|
||||
if (x >= 1)
|
||||
{
|
||||
downloadSlider.value = 100;
|
||||
step3.SetActive(true);
|
||||
step3.transform.Find("RouteName").GetComponent<Text>().text = RouteName;
|
||||
}
|
||||
}));
|
||||
|
||||
downloadSlider.maxValue = _downloader.Total * 100;
|
||||
|
||||
if(_downloader.IsVideoDownloaded)
|
||||
await _downloader.DownLoadVideoAsync(Progress.Create<float>(x => VideoProgress = x));
|
||||
if(_downloader.IsARRouteDownloaded)
|
||||
await _downloader.DownLoadARRouteAsync(Progress.Create<float>(x=> RouteProgress = x));
|
||||
if(_downloader.IsARDataDownloaded)
|
||||
await _downloader.DownLoadARDataAsync(Progress.Create<float>(x=> DataProgress = x));
|
||||
}
|
||||
|
||||
private void ComputeProgress()
|
||||
{
|
||||
//update progress
|
||||
var progress = (_videoProgress + _routeProgress + _dataProgress) / _downloader.Total;
|
||||
downloadSlider.value = progress * 100;
|
||||
|
||||
//update download info
|
||||
if (!Loom.DownloadStack.ContainsKey(FileName) )
|
||||
{
|
||||
Loom.DownloadStack.Add(FileName, new DownloadInfo(FileName, RouteName,progress));
|
||||
}
|
||||
Loom.DownloadStack[FileName].Process = progress;
|
||||
|
||||
if (progress >= 1)
|
||||
{
|
||||
Loom.DownloadStack.Remove(FileName);
|
||||
downloadSlider.value = 100;
|
||||
step3.SetActive(true);
|
||||
step3.transform.Find("RouteName").GetComponent<Text>().text = RouteName;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,25 +1,25 @@
|
||||
using Assets.AR;
|
||||
using Assets.Scenes.Ride.Scripts;
|
||||
using System;
|
||||
using Assets.Scripts;
|
||||
using Assets.Scripts.Apis;
|
||||
using Assets.Scripts.Apis.Models;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using DG.Tweening;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Assets.AR;
|
||||
using Assets.Core;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.Networking;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UI;
|
||||
|
||||
|
||||
public class GameRoomMapItem : MonoBehaviour, IPointerExitHandler, IPointerEnterHandler, IPointerUpHandler
|
||||
{
|
||||
private GameObject downloadBtn;
|
||||
private GameObject downloading;
|
||||
private GameObject downloadTxt;
|
||||
|
||||
public class PropNames
|
||||
{
|
||||
public static List<string> icons = new List<string> { "icon1", "icon2", "icon3" };
|
||||
@@ -29,27 +29,66 @@ public class GameRoomMapItem : MonoBehaviour, IPointerExitHandler, IPointerEnter
|
||||
{ true,"#ffffff"},{false,"#5c5c6e" }
|
||||
};
|
||||
}
|
||||
|
||||
public bool isModal = false;
|
||||
float width;
|
||||
float height;
|
||||
GameRoomListController listController;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
width = this.GetComponent<RectTransform>().rect.width;
|
||||
height = this.GetComponent<RectTransform>().rect.height;
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
listController = FindObjectOfType<GameRoomListController>();
|
||||
}
|
||||
|
||||
float? localY = null;
|
||||
MapRoute map;
|
||||
Dictionary<string, Texture> caches;
|
||||
private MapRouteAreaItem area = null;
|
||||
Slider slider;
|
||||
GameRoomListController listController;
|
||||
NearRouteModel model { get; set; }
|
||||
|
||||
private ARDownloader downloader { get; set; }
|
||||
|
||||
|
||||
private float _videoProgress;
|
||||
|
||||
public float VideoProgress
|
||||
{
|
||||
get => _videoProgress;
|
||||
set
|
||||
{
|
||||
_videoProgress = value;
|
||||
ComputeProgress();
|
||||
}
|
||||
}
|
||||
|
||||
private float _dataProgress = 0f;
|
||||
public float DataProgress
|
||||
{
|
||||
get => _dataProgress;
|
||||
set
|
||||
{
|
||||
_dataProgress = value;
|
||||
ComputeProgress();
|
||||
}
|
||||
}
|
||||
|
||||
private float _routeProgress = 0f;
|
||||
public float RouteProgress
|
||||
{
|
||||
get => _routeProgress;
|
||||
set
|
||||
{
|
||||
_routeProgress = value;
|
||||
ComputeProgress();
|
||||
}
|
||||
}
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
width = this.GetComponent<RectTransform>().rect.width;
|
||||
height = this.GetComponent<RectTransform>().rect.height;
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
listController = FindObjectOfType<GameRoomListController>();
|
||||
}
|
||||
|
||||
public void Initial(MapRoute myMap, Dictionary<string, Texture> caches, MapRouteAreaItem area = null)
|
||||
{
|
||||
if (caches != null)
|
||||
@@ -63,30 +102,14 @@ public class GameRoomMapItem : MonoBehaviour, IPointerExitHandler, IPointerEnter
|
||||
transform.GetComponent<Button>().onClick.RemoveAllListeners();
|
||||
transform.GetComponent<Button>().onClick.AddListener(Ride);
|
||||
}
|
||||
var downloadBtn = transform.Find("DownLoadModal/DownLoad").gameObject;
|
||||
var downloading = transform.Find("DownLoadModal/Downloading").gameObject;
|
||||
var downloadTxt = transform.Find("DownLoadModal/Text").gameObject;
|
||||
downloadBtn = transform.Find("DownLoadModal/DownLoad").gameObject;
|
||||
downloading = transform.Find("DownLoadModal/Downloading").gameObject;
|
||||
downloadTxt = transform.Find("DownLoadModal/Text").gameObject;
|
||||
slider = transform.Find("DownLoadModal/Slider").GetComponent<Slider>();
|
||||
|
||||
var fileName = map.FileName;
|
||||
var path = PFConstants.VideoFolder;
|
||||
var filepath = path + "/" + fileName;
|
||||
transform.Find("DownLoadModal").gameObject.SetActive(map.EnableAR && !File.Exists(filepath));
|
||||
UIManager.AddEvent(downloadBtn, EventTriggerType.PointerClick, async (e) =>
|
||||
{
|
||||
downloadBtn.SetActive(false);
|
||||
downloading.SetActive(true);
|
||||
downloadTxt.SetActive(false);
|
||||
slider.gameObject.SetActive(true);
|
||||
var progress = Progress.Create<float>(x =>
|
||||
{
|
||||
Loom.DownloadStack[map.FileName].Process = x;
|
||||
slider.value = x;
|
||||
LayoutRebuilder.ForceRebuildLayoutImmediate((RectTransform)this.slider.transform);
|
||||
transform.Find("DownLoadModal").gameObject.SetActive(x!=1);
|
||||
});
|
||||
await Loom.DownloadLoadARDataAndVideo(map, progress);
|
||||
});
|
||||
ShowDownloadModal();
|
||||
|
||||
UIManager.AddEvent(downloadBtn, EventTriggerType.PointerClick,Download_Click);
|
||||
|
||||
transform.Find("Name").GetComponent<Text>().text = myMap.Name;
|
||||
transform.Find("IdContainer/Text").GetComponent<Text>().text = $"#{myMap.Id}";
|
||||
@@ -104,16 +127,7 @@ public class GameRoomMapItem : MonoBehaviour, IPointerExitHandler, IPointerEnter
|
||||
tabContainer.Find("3d").gameObject.SetActive(myMap.Enable3D && !myMap.EnableAR);
|
||||
tabContainer.Find("AR").gameObject?.SetActive(myMap.EnableAR);
|
||||
tabContainer.Find("Country").GetComponent<RawImage>().texture = UIManager.Instance.loginRegOptions.GetCountryImage(myMap.CountryCode);
|
||||
//if (!isModal)
|
||||
//{
|
||||
// transform.Find("CollectImg").GetComponent<Button>().onClick.RemoveAllListeners();
|
||||
// transform.Find("CollectImg").GetComponent<Button>().onClick.AddListener(Collect);
|
||||
//}
|
||||
//transform.Find("CollectImg").Find("Image").GetComponent<Image>().sprite =
|
||||
// UIManager.Instance.collectDict[myMap.IsFavorite];
|
||||
#if !(UNITY_ANDROID || UNITY_IOS)
|
||||
//transform.Find("CollectImg").gameObject.SetActive(false);
|
||||
#endif
|
||||
|
||||
transform.Find("BtnInfo").GetComponent<Button>().onClick.AddListener(Info);
|
||||
transform.Find("BtnRide").GetComponent<Button>().onClick.AddListener(Ride);
|
||||
|
||||
@@ -126,7 +140,45 @@ public class GameRoomMapItem : MonoBehaviour, IPointerExitHandler, IPointerEnter
|
||||
transform.Find("BtnContinue").gameObject.SetActive(isRecent);
|
||||
transform.Find("BtnReride").gameObject.SetActive(isRecent);
|
||||
transform.Find("MapHBImg").gameObject.SetActive(!isRecent);
|
||||
}
|
||||
|
||||
private async void Download_Click(BaseEventData data)
|
||||
{
|
||||
downloadBtn.SetActive(false);
|
||||
downloading.SetActive(true);
|
||||
downloadTxt.SetActive(false);
|
||||
slider.gameObject.SetActive(true);
|
||||
|
||||
slider.maxValue = downloader.Total * 100;
|
||||
if(downloader.IsVideoDownloaded)
|
||||
await downloader.DownLoadVideoAsync(Progress.Create<float>(x => VideoProgress = x));
|
||||
if(downloader.IsARRouteDownloaded)
|
||||
await downloader.DownLoadARRouteAsync(Progress.Create<float>(x=> RouteProgress = x));
|
||||
if(downloader.IsARDataDownloaded)
|
||||
await downloader.DownLoadARDataAsync(Progress.Create<float>(x=> DataProgress = x));
|
||||
}
|
||||
|
||||
private void ComputeProgress()
|
||||
{
|
||||
//update progress
|
||||
var progress = (_videoProgress + _routeProgress + _dataProgress) / downloader.Total;
|
||||
slider.value = progress * 100;
|
||||
//update download info
|
||||
if(!Loom.DownloadStack.ContainsKey(map.FileName))
|
||||
Loom.DownloadStack.Add(map.FileName, new DownloadInfo(map.FileName,map.Name,0, map.Url));
|
||||
Loom.DownloadStack[map.FileName].Process = progress;
|
||||
//refresh slider
|
||||
LayoutRebuilder.ForceRebuildLayoutImmediate((RectTransform)this.slider.transform);
|
||||
transform.Find("DownLoadModal").gameObject.SetActive(progress != 1);
|
||||
}
|
||||
|
||||
//显示下载面板
|
||||
private async void ShowDownloadModal()
|
||||
{
|
||||
if(!map.EnableAR) return;
|
||||
downloader = new ARDownloader(map);
|
||||
var showDownload = await downloader.CheckAllAsync();
|
||||
transform.Find("DownLoadModal").gameObject.SetActive(showDownload);
|
||||
}
|
||||
|
||||
private void Ride()
|
||||
@@ -206,7 +258,7 @@ public class GameRoomMapItem : MonoBehaviour, IPointerExitHandler, IPointerEnter
|
||||
transform.Find("Shadow").GetComponent<Image>().DOFade(1, 0.3f);
|
||||
#endif
|
||||
}
|
||||
void SetActive4Button(bool b)
|
||||
private void SetActive4Button(bool b)
|
||||
{
|
||||
transform.Find("MapHBImg").gameObject.SetActive(!b);
|
||||
transform.Find("BtnInfo").gameObject.SetActive(b);
|
||||
@@ -228,7 +280,7 @@ public class GameRoomMapItem : MonoBehaviour, IPointerExitHandler, IPointerEnter
|
||||
transform.Find("MapHBImg").GetComponent<RawImage>().color = Utils.HexToColorHtml(
|
||||
PropNames.colorDict[isFav]);
|
||||
}
|
||||
async void Collect()
|
||||
private async void Collect()
|
||||
{
|
||||
JsonResult<object> r;
|
||||
//transform.Find("CollectImg").GetComponent<Button>().enabled = false;
|
||||
@@ -256,7 +308,6 @@ public class GameRoomMapItem : MonoBehaviour, IPointerExitHandler, IPointerEnter
|
||||
UIManager.ShowAlert("WARNING", r.errMsg);
|
||||
}
|
||||
}
|
||||
NearRouteModel model { get; set; }
|
||||
|
||||
public void Show(Vector3 position, NearRouteModel model)
|
||||
{
|
||||
|
||||
@@ -9,8 +9,9 @@ using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UI;
|
||||
using Assets.Scenes.Ride.Scripts.Model;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
public class GameRoomDetailController : PFUIPanel
|
||||
public class GameRoomDetailController : PFUIPanel,IProgress<float>
|
||||
{
|
||||
public Text versionText;
|
||||
public RawImage Avatar;
|
||||
@@ -27,12 +28,10 @@ public class GameRoomDetailController : PFUIPanel
|
||||
public Text bestTabName;
|
||||
public Text bestTabTimer;
|
||||
public RawImage bestTabHead;
|
||||
|
||||
public GameObject readyBtn;
|
||||
public GameObject startBtn;
|
||||
public GameObject quitBtn;
|
||||
public GameObject cancelBtn;
|
||||
|
||||
public GameObject d2;
|
||||
public GameObject d3;
|
||||
public GameObject ar;
|
||||
@@ -40,68 +39,80 @@ public class GameRoomDetailController : PFUIPanel
|
||||
public GameRoomModel GameRoom { get; set; }
|
||||
public DateTime? StartTime { get; set; }
|
||||
public int Status { get; set; }
|
||||
|
||||
private bool isQuit = false;
|
||||
private bool DataSourceChanged { get; set; }
|
||||
float timer = 0f;
|
||||
private bool isOwner { get; set; } = true;
|
||||
private MapRoute route { get; set; }
|
||||
|
||||
protected override void Start()
|
||||
{
|
||||
base.Start();
|
||||
UIManager.AddBackHandler((e) =>
|
||||
{
|
||||
MapUDPService.SendGameRoomKick(GameRoom.RoomId,App.CurrentUser.Id,App.CurrentUser.Id);
|
||||
App.gameRoomDetail = null;
|
||||
});
|
||||
UIManager.AddBackHandler(QuitGameRoom);
|
||||
transform.Find("MainNav").GetComponent<MainNav>().ShowBack();
|
||||
Utils.DisplayHead(Avatar, App.CurrentUser.WxHeadImg);
|
||||
UIManager.AddEvent(startBtn, UnityEngine.EventSystems.EventTriggerType.PointerClick, (e) =>
|
||||
|
||||
UIManager.AddEvent(startBtn, UnityEngine.EventSystems.EventTriggerType.PointerClick,StartRide);
|
||||
UIManager.AddEvent(readyBtn, UnityEngine.EventSystems.EventTriggerType.PointerClick,Ready);
|
||||
UIManager.AddEvent(cancelBtn, UnityEngine.EventSystems.EventTriggerType.PointerClick,CancelReady);
|
||||
UIManager.AddEvent(quitBtn, UnityEngine.EventSystems.EventTriggerType.PointerClick,LeaveGameRoom);
|
||||
}
|
||||
|
||||
private void LeaveGameRoom(BaseEventData data)
|
||||
{
|
||||
if (Status == 1)
|
||||
{
|
||||
var list = GameRoom.RoomPlayerList;
|
||||
var notReady = list.Where(c => c.Status == 0 && c.IsOwner == false).Any();
|
||||
if (notReady)
|
||||
{
|
||||
Utils.showToast(gameObject, App.GetLocalString("have to wait for all ready!"));
|
||||
}
|
||||
else
|
||||
{
|
||||
MapUDPService.SendGameRoomStartTime(App.gameRoomDetail.RoomId, App.CurrentUser.Id);
|
||||
}
|
||||
});
|
||||
//准备
|
||||
UIManager.AddEvent(readyBtn, UnityEngine.EventSystems.EventTriggerType.PointerClick, (e) =>
|
||||
Utils.showToast(gameObject, App.GetLocalString("CancelReadyToQuit"));
|
||||
return;
|
||||
}
|
||||
App.gameRoomDetail = null;
|
||||
isQuit = true;
|
||||
MapUDPService.SendGameRoomKick(GameRoom.RoomId, App.CurrentUser.Id, App.CurrentUser.Id);
|
||||
UIManager.ShowGameRoomListPanel();
|
||||
}
|
||||
|
||||
private void CancelReady(BaseEventData data)
|
||||
{
|
||||
Status = 0;
|
||||
readyBtn.SetActive(true);
|
||||
cancelBtn.SetActive(false);
|
||||
MapUDPService.SendGameRoomReadyStatus(App.gameRoomDetail.RoomId, App.CurrentUser.Id, Status);
|
||||
}
|
||||
|
||||
private void Ready(BaseEventData data)
|
||||
{
|
||||
Status = 1;
|
||||
readyBtn.SetActive(false);
|
||||
cancelBtn.SetActive(true);
|
||||
MapUDPService.SendGameRoomReadyStatus(App.gameRoomDetail.RoomId, App.CurrentUser.Id, Status);
|
||||
}
|
||||
|
||||
private void StartRide(BaseEventData data)
|
||||
{
|
||||
var list = GameRoom.RoomPlayerList;
|
||||
var notReady = list.Any(c => c.Status == 0 && c.IsOwner == false);
|
||||
if (notReady)
|
||||
{
|
||||
Status = 1;
|
||||
readyBtn.SetActive(false);
|
||||
cancelBtn.SetActive(true);
|
||||
MapUDPService.SendGameRoomReadyStatus(App.gameRoomDetail.RoomId, App.CurrentUser.Id, Status);
|
||||
});
|
||||
//取消准备
|
||||
UIManager.AddEvent(cancelBtn, UnityEngine.EventSystems.EventTriggerType.PointerClick, (e) =>
|
||||
Utils.showToast(gameObject, App.GetLocalString("have to wait for all ready!"));
|
||||
}
|
||||
else
|
||||
{
|
||||
Status = 0;
|
||||
readyBtn.SetActive(true);
|
||||
cancelBtn.SetActive(false);
|
||||
MapUDPService.SendGameRoomReadyStatus(App.gameRoomDetail.RoomId, App.CurrentUser.Id, Status);
|
||||
});
|
||||
//退出
|
||||
UIManager.AddEvent(quitBtn, UnityEngine.EventSystems.EventTriggerType.PointerClick, (e) =>
|
||||
{
|
||||
if (Status == 1)
|
||||
{
|
||||
Utils.showToast(gameObject, App.GetLocalString("CancelReadyToQuit"));
|
||||
return;
|
||||
}
|
||||
App.gameRoomDetail = null;
|
||||
isQuit = true;
|
||||
MapUDPService.SendGameRoomKick(GameRoom.RoomId, App.CurrentUser.Id, App.CurrentUser.Id);
|
||||
UIManager.ShowGameRoomListPanel();
|
||||
});
|
||||
MapUDPService.SendGameRoomStartTime(App.gameRoomDetail.RoomId, App.CurrentUser.Id);
|
||||
}
|
||||
}
|
||||
|
||||
private void QuitGameRoom(string e)
|
||||
{
|
||||
MapUDPService.SendGameRoomKick(GameRoom.RoomId,App.CurrentUser.Id,App.CurrentUser.Id);
|
||||
App.gameRoomDetail = null;
|
||||
}
|
||||
|
||||
public override void Show()
|
||||
{
|
||||
base.Show();
|
||||
Init();
|
||||
Initialize();
|
||||
}
|
||||
private bool DataSourceChanged { get; set; }
|
||||
|
||||
private void ListenerHandler(List<ReceiveMsgModel> message)
|
||||
{
|
||||
var detail = message.FirstOrDefault();
|
||||
@@ -113,22 +124,24 @@ public class GameRoomDetailController : PFUIPanel
|
||||
GameRoom = null;
|
||||
return;
|
||||
}
|
||||
GameRoom = detail.RoomList.Where(c => c.RoomId == GameRoom.RoomId).FirstOrDefault();
|
||||
|
||||
GameRoom = detail.RoomList.FirstOrDefault(c => c.RoomId == GameRoom.RoomId);
|
||||
if (GameRoom != null)
|
||||
{
|
||||
DataSourceChanged = true;
|
||||
}
|
||||
}
|
||||
float timer = 0f;
|
||||
|
||||
private void Update()
|
||||
{
|
||||
TcpHandler();
|
||||
}
|
||||
private void Init()
|
||||
|
||||
private void Initialize()
|
||||
{
|
||||
DataSourceChanged = false;
|
||||
App.Model = "GameRoom";
|
||||
versionText.text = "V"+App.AppVersion.ToString();
|
||||
versionText.text = "V"+App.AppVersion;
|
||||
MapUDPService.MessageListener = ListenerHandler;
|
||||
GameRoom = App.gameRoomDetail;
|
||||
|
||||
@@ -150,17 +163,13 @@ public class GameRoomDetailController : PFUIPanel
|
||||
distanceText.text = $"{Math.Round(GameRoom.Distance, 1)}KM";
|
||||
eleText.text = $"{Math.Round(GameRoom.TotalClimb, 0)}M";
|
||||
slopeText.text = $"{Math.Round(GameRoom.AverageGrade, 1)}%";
|
||||
//查询某线路最佳
|
||||
var result = ConfigHelper.mapApi.GetMapBestInfo(GameRoom.MapRouteId);
|
||||
if (result.result && !string.IsNullOrEmpty(result.data.BestNickName))
|
||||
{
|
||||
bestTab.SetActive(true);
|
||||
bestTabName.text = result.data.BestNickName;
|
||||
bestTabTimer.text = result.data.BestTotalTime;
|
||||
Utils.DisplayHead(bestTabHead, result.data.BestWxHeadImg);
|
||||
}
|
||||
Utils.DisplayHead(altitudeGraph, GameRoom.AltitudeGraph);
|
||||
|
||||
RenderBestPlayer();
|
||||
|
||||
GetMapRoute();
|
||||
|
||||
Utils.DisplayHead(altitudeGraph, GameRoom.AltitudeGraph);
|
||||
|
||||
var playerList = FindObjectsOfType<GameRoomPlayerPanel>();
|
||||
foreach (var item in playerList)
|
||||
{
|
||||
@@ -174,94 +183,126 @@ public class GameRoomDetailController : PFUIPanel
|
||||
}
|
||||
}
|
||||
}
|
||||
private bool isOwner { get; set; } = true;
|
||||
private void TcpHandler()
|
||||
|
||||
private void GetMapRoute()
|
||||
{
|
||||
if (DataSourceChanged)
|
||||
var result = ConfigHelper.mapApi.GetById(GameRoom.MapRouteId);
|
||||
if (result != null && result.result)
|
||||
{
|
||||
//房间被销毁了返回房间列表
|
||||
if (GameRoom == null)
|
||||
{
|
||||
Debug.Log("GameRoom == null");
|
||||
UIManager.ShowGameRoomListPanel();
|
||||
return;
|
||||
}
|
||||
var playerList = FindObjectsOfType<GameRoomPlayerPanel>();
|
||||
var list = GameRoom.RoomPlayerList;
|
||||
//自己是否是房主
|
||||
var mine = list.Where(c => c.UserId == App.CurrentUser.Id).FirstOrDefault();
|
||||
if (mine != null && isOwner != mine.IsOwner)
|
||||
{
|
||||
isOwner = mine.IsOwner;
|
||||
readyBtn.SetActive(!isOwner);
|
||||
startBtn.SetActive(isOwner);
|
||||
cancelBtn.SetActive(!isOwner);
|
||||
}
|
||||
//新增/更新
|
||||
foreach (var item in list)
|
||||
{
|
||||
var userName =item.Name;
|
||||
var headurl = item.WxHeadImage;
|
||||
var ftp = item.FTP;
|
||||
var weight = item.Weight;
|
||||
var sex = item.Sex;
|
||||
var current = playerList.Where(c => c.UserId == item.UserId).FirstOrDefault();
|
||||
if (current == null)
|
||||
{
|
||||
var s = playerList.Where(c => c.UserId == 0 && c.NotUse == false).OrderBy(c => c.sort).FirstOrDefault();
|
||||
if (s != null)
|
||||
{
|
||||
s.Init(item.UserId, userName, headurl, weight, ftp, item.IsOwner, item.Status,sex);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
current.UpdatePlayer(item.UserId, userName, headurl, weight, ftp, item.IsOwner, item.Status,sex);
|
||||
}
|
||||
}
|
||||
//删除
|
||||
foreach (var item in playerList)
|
||||
{
|
||||
if (item.UserId != 0)
|
||||
{
|
||||
var current = list.Where(c => c.UserId == item.UserId).FirstOrDefault();
|
||||
if (current == null)
|
||||
{
|
||||
item.ShowInviteModal();
|
||||
}
|
||||
var myself = list.Where(c => c.UserId == App.CurrentUser.Id).FirstOrDefault();
|
||||
//被移除房间/掉线
|
||||
if (myself == null)
|
||||
{
|
||||
if (!isQuit)
|
||||
{
|
||||
Utils.showToast(gameObject, App.GetLocalString("you have been kicked out of the room"));
|
||||
UIManager.ShowGameRoomListPanel();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//收到服务器开始命令进入 loading页面
|
||||
if (GameRoom.Status == 1)
|
||||
{
|
||||
//路线
|
||||
App.RouteIdParam = GameRoom.MapRouteId;
|
||||
App.MainSceneParam["Name"] = "GameRoomList";
|
||||
if (GameRoom.EnableAR)
|
||||
{
|
||||
SceneManager.LoadScene("VideoPlay");
|
||||
}
|
||||
else
|
||||
{
|
||||
SceneManager.LoadScene("Ride");
|
||||
}
|
||||
}
|
||||
DataSourceChanged = false;
|
||||
this.route = result.data;
|
||||
}
|
||||
}
|
||||
|
||||
//查询某线路最佳
|
||||
private void RenderBestPlayer()
|
||||
{
|
||||
var result = ConfigHelper.mapApi.GetMapBestInfo(GameRoom.MapRouteId);
|
||||
if (result.result && !string.IsNullOrEmpty(result.data.BestNickName))
|
||||
{
|
||||
bestTab.SetActive(true);
|
||||
bestTabName.text = result.data.BestNickName;
|
||||
bestTabTimer.text = result.data.BestTotalTime;
|
||||
Utils.DisplayHead(bestTabHead, result.data.BestWxHeadImg);
|
||||
}
|
||||
}
|
||||
|
||||
private void TcpHandler()
|
||||
{
|
||||
if (!DataSourceChanged) return;
|
||||
|
||||
//房间被销毁了返回房间列表
|
||||
if (GameRoom == null)
|
||||
{
|
||||
UIManager.ShowGameRoomListPanel();
|
||||
return;
|
||||
}
|
||||
|
||||
var playerList = FindObjectsOfType<GameRoomPlayerPanel>();
|
||||
SetRoomOwner();
|
||||
CreatePlayers(playerList);
|
||||
RemovePlayers(playerList);
|
||||
LoadScene();
|
||||
DataSourceChanged = false;
|
||||
}
|
||||
|
||||
//自己是否是房主
|
||||
private void SetRoomOwner()
|
||||
{
|
||||
var mine = GameRoom.RoomPlayerList.FirstOrDefault(c => c.UserId == App.CurrentUser.Id);
|
||||
if (mine != null && isOwner != mine.IsOwner)
|
||||
{
|
||||
isOwner = mine.IsOwner;
|
||||
readyBtn.SetActive(!isOwner);
|
||||
startBtn.SetActive(isOwner);
|
||||
cancelBtn.SetActive(!isOwner);
|
||||
}
|
||||
}
|
||||
|
||||
//收到服务器开始命令进入 loading页面
|
||||
private void LoadScene()
|
||||
{
|
||||
if (GameRoom.Status != 1) return;
|
||||
|
||||
App.RouteIdParam = GameRoom.MapRouteId;
|
||||
App.MainSceneParam["Name"] = "GameRoomList";
|
||||
|
||||
SceneManager.LoadScene(GameRoom.EnableAR?"VideoPlay":"Ride");
|
||||
}
|
||||
|
||||
private void CreatePlayers(GameRoomPlayerPanel[] playerList)
|
||||
{
|
||||
foreach (var item in GameRoom.RoomPlayerList)
|
||||
{
|
||||
var userName = item.Name;
|
||||
var headurl = item.WxHeadImage;
|
||||
var ftp = item.FTP;
|
||||
var weight = item.Weight;
|
||||
var sex = item.Sex;
|
||||
var current = playerList.Where(c => c.UserId == item.UserId).FirstOrDefault();
|
||||
if (current == null)
|
||||
{
|
||||
var s = playerList.Where(c => c.UserId == 0 && c.NotUse == false).OrderBy(c => c.sort).FirstOrDefault();
|
||||
if (s != null)
|
||||
{
|
||||
s.Init(item.UserId, userName, headurl, weight, ftp, item.IsOwner, item.Status,sex);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
current.UpdatePlayer(item.UserId, userName, headurl, weight, ftp, item.IsOwner, item.Status,sex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void RemovePlayers(GameRoomPlayerPanel[] playerList)
|
||||
{
|
||||
foreach (var item in playerList)
|
||||
{
|
||||
if (item.UserId == 0) continue;
|
||||
|
||||
var current = GameRoom.RoomPlayerList.FirstOrDefault(c => c.UserId == item.UserId);
|
||||
if (current == null)
|
||||
{
|
||||
item.ShowInviteModal();
|
||||
}
|
||||
|
||||
//被移除房间/掉线
|
||||
var myself = GameRoom.RoomPlayerList.FirstOrDefault(c => c.UserId == App.CurrentUser.Id);
|
||||
if (myself == null && !isQuit )
|
||||
{
|
||||
Utils.showToast(gameObject, App.GetLocalString("you have been kicked out of the room"));
|
||||
UIManager.ShowGameRoomListPanel();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnDisable()
|
||||
{
|
||||
App.Model = "";
|
||||
}
|
||||
|
||||
public void Report(float value)
|
||||
{
|
||||
Debug.Log(value);
|
||||
}
|
||||
}
|
||||
@@ -7,10 +7,9 @@ using Assets.Scripts.UI.Control;
|
||||
using Assets.Scripts.UI.Prefab.MapList;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using Assets.AR;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
@@ -54,7 +53,6 @@ public class GameRoomListController : PFUIPanel
|
||||
private GameObject right;
|
||||
private GameObject right2;
|
||||
|
||||
|
||||
private GameObject btn30;
|
||||
private GameObject btn40;
|
||||
private GameObject btn50;
|
||||
@@ -70,7 +68,6 @@ public class GameRoomListController : PFUIPanel
|
||||
private Transform enterRoomModal;
|
||||
private Transform cycingRoomModal;
|
||||
private Transform resultRoomModal;
|
||||
|
||||
private GameObject RoomRankItem;
|
||||
|
||||
private string RoomName;
|
||||
@@ -100,10 +97,8 @@ public class GameRoomListController : PFUIPanel
|
||||
GameObject _avatar;
|
||||
|
||||
private GameObject RoomCell { get; set; }
|
||||
|
||||
//Dummy data List
|
||||
private List<GameRoomModel> _list = new List<GameRoomModel>();
|
||||
|
||||
private string seachName = "";
|
||||
private bool ListChanged = false;
|
||||
private bool CreateRoomSuccessed = false;
|
||||
@@ -162,7 +157,6 @@ public class GameRoomListController : PFUIPanel
|
||||
var g = Instantiate(RoomCell, _rectTransform);
|
||||
g.GetComponent<GameRoomCell>().ConfigureCell(item, index);
|
||||
}
|
||||
|
||||
}
|
||||
List<GameRoomModel> list;
|
||||
private int Total { get; set; }
|
||||
@@ -268,7 +262,13 @@ public class GameRoomListController : PFUIPanel
|
||||
CreateClicked = false;
|
||||
UIManager.ShowGameRoomDetailPanel();
|
||||
}
|
||||
//LOOM中取数据渲染下载当前下载进度
|
||||
|
||||
RenderDownloadTask();
|
||||
}
|
||||
|
||||
//LOOM中取数据渲染下载当前下载进度
|
||||
private void RenderDownloadTask()
|
||||
{
|
||||
var downLoadList = transform.Find("DownLoadList").gameObject;
|
||||
var list = Loom.DownloadStack.Where(c => c.Value.Process < 1);
|
||||
if (list.Count() > 0)
|
||||
@@ -736,24 +736,30 @@ public class GameRoomListController : PFUIPanel
|
||||
enterRoomModal.gameObject.SetActive(true);
|
||||
}
|
||||
//如果本地没有视频文件则弹窗下载否则直接进入房间
|
||||
public void ShowDownLoadConfirm()
|
||||
public async void ShowDownLoadConfirm()
|
||||
{
|
||||
var fileName = GameRoom.FileName;
|
||||
var path = PFConstants.VideoFolder;
|
||||
var filepath = path + "/" + fileName;
|
||||
if(!GameRoom.EnableAR) return ;
|
||||
var result = ConfigHelper.mapApi.GetById(GameRoom.MapRouteId);
|
||||
if (!result.result) return;
|
||||
var route = result.data;
|
||||
|
||||
var download = transform.Find("DownloadPanel").gameObject;
|
||||
if (GameRoom.EnableAR && !File.Exists(filepath))
|
||||
downloader = new ARDownloader(route);
|
||||
var showDownload = await downloader.CheckAllAsync();
|
||||
if (showDownload)
|
||||
{
|
||||
//查询fileUrl
|
||||
GameRoom.FileUrl = ConfigHelper.GameRoomApi.GetMapVideoURL(GameRoom.MapRouteId).data;
|
||||
GameRoom.FileUrl = route.Url;
|
||||
download.SetActive(true);
|
||||
download.GetComponent<GameRoomDownLoad>().Init(RoomId, GameRoom.FileName, GameRoom.FileUrl, this, GameRoom.MapRouteName);
|
||||
download.GetComponent<GameRoomDownLoad>().Init(RoomId, GameRoom.FileName, GameRoom.FileUrl, this, GameRoom.MapRouteName,downloader);
|
||||
}
|
||||
else
|
||||
{
|
||||
GetInRoom();
|
||||
}
|
||||
}
|
||||
|
||||
private ARDownloader downloader;
|
||||
|
||||
private GameRoomModel modelGameRoom { get; set; }
|
||||
//private GameRoomModel modelGameRoom { get; set; }
|
||||
private Text CyclingTimer { get; set; }
|
||||
@@ -788,7 +794,6 @@ public class GameRoomListController : PFUIPanel
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ShowStatusModal(Transform tr,GameRoomModel data)
|
||||
{
|
||||
tr.Find("Modal/Id").GetComponent<Text>().text = data.RoomId.ToString().PadLeft(7, '0');
|
||||
@@ -818,8 +823,6 @@ public class GameRoomListController : PFUIPanel
|
||||
UIManager.AddEvent(quit, EventTriggerType.PointerClick, (e) => { tr.gameObject.SetActive(false); });
|
||||
tr.gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
|
||||
public void GetInRoom()
|
||||
{
|
||||
//1.房间人数已经满了
|
||||
@@ -841,13 +844,11 @@ public class GameRoomListController : PFUIPanel
|
||||
MapUDPService.SendJoinGameRoom(App.gameRoomDetail.RoomId,App.CurrentUser.Id,UIManager.Now.GetDateTime().ToUniversalTime());
|
||||
UIManager.ShowGameRoomDetailPanel();
|
||||
}
|
||||
|
||||
public void SelectRoom(GameRoomModel room)
|
||||
{
|
||||
GameRoom = room;
|
||||
RoomId = GameRoom.RoomId;
|
||||
}
|
||||
|
||||
public int GetRoomId()
|
||||
{
|
||||
return RoomId;
|
||||
@@ -886,7 +887,6 @@ public class GameRoomListController : PFUIPanel
|
||||
tabContainer.Find("Country").GetComponent<RawImage>().texture = UIManager.Instance.loginRegOptions.GetCountryImage(map.CountryCode);
|
||||
|
||||
}
|
||||
|
||||
public void Refresh()
|
||||
{
|
||||
content.transform.DestroyChildren();
|
||||
@@ -894,14 +894,12 @@ public class GameRoomListController : PFUIPanel
|
||||
isEnd = false;
|
||||
GetList();
|
||||
}
|
||||
|
||||
private void onEndEdit()
|
||||
{
|
||||
var t = searchInput.GetComponent<InputField>().text;
|
||||
ftname = t;
|
||||
Refresh();
|
||||
}
|
||||
|
||||
private void DisplayMaps(List<MapRoute> list)
|
||||
{
|
||||
if (map != null)
|
||||
|
||||
Reference in new issue
Block a user