powerfun-unity/Assets/Scripts/UI/Prefab/GameRoom/GameRoomDownloadTask.cs
2023-02-07 18:35:16 +08:00

83 lines
2.1 KiB
C#

using Assets.Scripts;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
using DG.Tweening;
class GameRoomDownloadTask : MonoBehaviour
{
public GameObject btn;
public Slider slider;
public GameObject icon;
public GameObject done;
public GameObject doneTxt;
public CanvasGroup canvasGroup;
private GameObject modal;
private Text fileNameText;
public int RoomId { get; set; }
public string RouteName { get; set; }
public string FileName { get; set; }
private void Start()
{
UIManager.AddEvent(btn, EventTriggerType.PointerClick, (e) =>
{
if (!modal.transform.parent.Find("MapList").gameObject.activeSelf)
{
modal.SetActive(true);
modal.GetComponent<GameRoomDownLoad>().ComeIntoStep2(FileName, RouteName);
}
else
{
modal.SetActive(false);
}
//transform.parent.parent.parent.gameObject.SetActive(false);
});
}
public void Init(int roomId,string fileName,string routeName,GameObject downloadPanel)
{
modal = downloadPanel;
fileNameText = transform.Find("Text").GetComponent<Text>();
RoomId = roomId;
RouteName = routeName;
fileNameText.text = routeName;
FileName = fileName;
}
private void Update()
{
if (Loom.DownloadStack.ContainsKey(FileName))
{
UpdateProcess(Loom.DownloadStack[FileName].Process);
}
}
public void UpdateProcess(float process)
{
slider.value = process;
if (process >= 1)
{
done.SetActive(true);
doneTxt.SetActive(true);
icon.SetActive(false);
Loom.DownloadStack.Remove(FileName);
canvasGroup.DOFade(0, 2).onComplete += () =>
{
slider.gameObject.SetActive(false);
gameObject.Destroy();
Loom.DownloadStack.Remove(FileName);
};
}
}
public void Dispose()
{
gameObject.SetActive(false);
}
}