using Assets.Scenes.Ride.Scripts; using Assets.Scripts; using Assets.Scripts.Apis.Models; 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; private int RoomId { get; set; } private string FileName { 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(); //新增 var obj = list.Where(c => c.RoomId == RoomId).FirstOrDefault(); if (obj == null) { var newtask = Instantiate(downLoadTask, content); newtask.GetComponent().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); }); } public void Init(int Id,string fileName,string url, GameRoomListController gameRoomListController) { RoomId = Id; FileName = fileName; FileUrl = url; manager = gameRoomListController; } private void Reset() { step2.SetActive(false); step3.SetActive(false); downloadSlider.value = 0f; } private void CancelClick(BaseEventData data) { Reset(); gameObject.SetActive(false); } private void DownloadClick(BaseEventData baseEventData) { var fileName = FileName; var path = PFConstants.VideoFolder; var filepath = path + "/" + fileName; var url = FileUrl; step2.SetActive(true); //新增 var content = downLoadList.transform.Find("Viewport/Content"); var newtask = Instantiate(downLoadTask, content); var currentTask = newtask.GetComponent(); currentTask.Init(RoomId, fileName,gameObject); Loom.Current.StartCoroutine(Utils.DownloadVideo(fileName, url , (p, req) => { downloadSlider.value = p; currentTask.UpdateProcess(p); if (Loom.DownLoadTaskList.ContainsKey(FileName)) { Loom.DownLoadTaskList[FileName] = p; } else { Loom.DownLoadTaskList.Add(FileName, p); } } , (p) => { if (string.IsNullOrEmpty(p)) { var process = 100f; if (Loom.DownLoadTaskList.ContainsKey(FileName)) { Loom.DownLoadTaskList[FileName] = process; } else { Loom.DownLoadTaskList.Add(FileName, process); } currentTask.UpdateProcess(process); downloadSlider.value = process; step3.SetActive(true); } else { Utils.showToast(gameObject, p); } } )); } }