powerfun-unity/Assets/Scripts/UI/Prefab/GameRoom/GameRoomDownloadTask.cs

73 lines
1.8 KiB
C#
Raw Normal View History

using Assets.Scripts;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
2022-05-13 09:28:58 +08:00
using DG.Tweening;
class GameRoomDownloadTask : MonoBehaviour
{
public GameObject btn;
public Slider slider;
public GameObject icon;
public GameObject done;
public GameObject doneTxt;
2022-05-13 09:28:58 +08:00
public CanvasGroup canvasGroup;
private GameObject modal;
private Text fileNameText;
public int RoomId { get; set; }
2022-05-13 09:28:58 +08:00
public string FileName { get; set; }
private void Start()
{
UIManager.AddEvent(btn, EventTriggerType.PointerClick, (e) =>
{
modal.SetActive(true);
2022-08-05 15:10:09 +08:00
modal.GetComponent<GameRoomDownLoad>().ComeIntoStep2(FileName);
2022-05-13 09:28:58 +08:00
transform.parent.parent.parent.gameObject.SetActive(false);
});
}
2022-05-13 11:10:37 +08:00
public void Init(int roomId,string fileName,GameObject downloadPanel)
{
2022-05-13 11:10:37 +08:00
modal = downloadPanel;
2022-05-13 09:28:58 +08:00
fileNameText = transform.Find("Text").GetComponent<Text>();
RoomId = roomId;
2022-05-13 09:28:58 +08:00
fileNameText.text = fileName;
FileName = fileName;
}
private void Update()
{
if (Loom.DownLoadTaskList.ContainsKey(FileName))
{
UpdateProcess(Loom.DownLoadTaskList[FileName]);
}
}
public void UpdateProcess(float process)
{
slider.value = process;
if (process >= 100)
{
done.SetActive(true);
doneTxt.SetActive(true);
icon.SetActive(false);
2022-05-13 09:28:58 +08:00
canvasGroup.DOFade(0, 2).onComplete += () =>
{
slider.gameObject.SetActive(false);
gameObject.Destroy();
2022-05-25 18:40:47 +08:00
Loom.DownLoadTaskList.Remove(FileName);
2022-05-13 09:28:58 +08:00
};
}
}
public void Dispose()
{
gameObject.SetActive(false);
}
}