143 lines
4.2 KiB
C#
143 lines
4.2 KiB
C#
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 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, DownloadClick);
|
|
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) =>
|
|
{
|
|
manager.GetInRoom();
|
|
Reset();
|
|
gameObject.SetActive(false);
|
|
});
|
|
UIManager.AddEvent(cancelBtn, EventTriggerType.PointerClick, (ee) =>
|
|
{
|
|
Reset();
|
|
gameObject.SetActive(false);
|
|
});
|
|
}
|
|
|
|
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)
|
|
{
|
|
RoomId = Id;
|
|
FileName = fileName;
|
|
RouteName = routeName;
|
|
FileUrl = url;
|
|
manager = gameRoomListController;
|
|
}
|
|
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 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)
|
|
{
|
|
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;
|
|
}
|
|
}));
|
|
}
|
|
}
|