117 lines
3.4 KiB
C#
117 lines
3.4 KiB
C#
using Cysharp.Threading.Tasks;
|
|
using Assets.AR;
|
|
using Assets.Core;
|
|
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
using UnityEngine.UI;
|
|
|
|
class GameRoomDownLoad : MonoBehaviour
|
|
{
|
|
public GameObject step1;
|
|
public GameObject step2;
|
|
public GameObject step3;
|
|
|
|
public GameObject downloadBtn;
|
|
public GameObject backBtn;
|
|
|
|
public Slider downloadSlider;
|
|
public GameObject runInbackBtn;
|
|
|
|
public GameObject enterBtn;
|
|
public GameObject cancelBtn;
|
|
|
|
public GameObject downLoadList;
|
|
public GameObject downLoadTask;
|
|
|
|
private GameRoomListController manager;
|
|
public int RoomId { get; set; }
|
|
public string FileName { get; set; }
|
|
public string RouteName { get; set; }
|
|
private string FileUrl { get; set; }
|
|
|
|
private void Start()
|
|
{
|
|
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);
|
|
});
|
|
|
|
UIManager.AddEvent(enterBtn, EventTriggerType.PointerClick, (ee) =>
|
|
{
|
|
manager.GetInRoom();
|
|
Reset();
|
|
gameObject.SetActive(false);
|
|
});
|
|
UIManager.AddEvent(cancelBtn, EventTriggerType.PointerClick, (ee) =>
|
|
{
|
|
Reset();
|
|
gameObject.SetActive(false);
|
|
});
|
|
}
|
|
|
|
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;
|
|
RouteName = routeName;
|
|
step2.SetActive(true);
|
|
step2.transform.Find("RouteName").GetComponent<Text>().text = routeName;
|
|
step3.transform.Find("RouteName").GetComponent<Text>().text = routeName;
|
|
step3.SetActive(false);
|
|
}
|
|
|
|
private void Reset()
|
|
{
|
|
step2.SetActive(false);
|
|
step3.SetActive(false);
|
|
downloadSlider.value = 0f;
|
|
}
|
|
|
|
private void CancelClick(BaseEventData data)
|
|
{
|
|
Reset();
|
|
gameObject.SetActive(false);
|
|
}
|
|
|
|
private async void Download_Click(BaseEventData baseEventData)
|
|
{
|
|
step2.SetActive(true);
|
|
step2.transform.Find("RouteName").GetComponent<Text>().text = RouteName;
|
|
|
|
await _downloader.DownLoadDefault(ReportProgress);
|
|
}
|
|
|
|
private void ReportProgress(float progress)
|
|
{
|
|
downloadSlider.value = progress;
|
|
|
|
if (!Loom.DownloadStack.ContainsKey(FileName) )
|
|
{
|
|
Loom.DownloadStack.Add(FileName, new DownloadInfo(FileName, RouteName,progress));
|
|
}
|
|
Loom.DownloadStack[FileName].Process = progress;
|
|
|
|
LayoutRebuilder.ForceRebuildLayoutImmediate((RectTransform)this.downloadSlider.transform);
|
|
if (progress == 1f)
|
|
{
|
|
Loom.DownloadStack.Remove(FileName);
|
|
step3.SetActive(true);
|
|
step3.transform.Find("RouteName").GetComponent<Text>().text = RouteName;
|
|
}
|
|
}
|
|
}
|