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

83 lines
2.1 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; }
2023-02-07 18:35:16 +08:00
public string RouteName { get; set; }
2022-05-13 09:28:58 +08:00
public string FileName { get; set; }
private void Start()
{
UIManager.AddEvent(btn, EventTriggerType.PointerClick, (e) =>
{
2023-02-07 18:35:16 +08:00
if (!modal.transform.parent.Find("MapList").gameObject.activeSelf)
{
modal.SetActive(true);
modal.GetComponent<GameRoomDownLoad>().ComeIntoStep2(FileName, RouteName);
}
else
{
modal.SetActive(false);
}
2023-01-31 18:22:15 +08:00
//transform.parent.parent.parent.gameObject.SetActive(false);
});
}
2023-02-07 18:35:16 +08:00
public void Init(int roomId,string fileName,string routeName,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;
2023-02-07 18:35:16 +08:00
RouteName = routeName;
fileNameText.text = routeName;
2022-05-13 09:28:58 +08:00
FileName = fileName;
}
private void Update()
{
2023-02-07 18:35:16 +08:00
if (Loom.DownloadStack.ContainsKey(FileName))
2022-05-13 09:28:58 +08:00
{
2023-02-07 18:35:16 +08:00
UpdateProcess(Loom.DownloadStack[FileName].Process);
2022-05-13 09:28:58 +08:00
}
}
public void UpdateProcess(float process)
{
slider.value = process;
2022-12-08 19:17:34 +08:00
if (process >= 1)
{
done.SetActive(true);
doneTxt.SetActive(true);
icon.SetActive(false);
2023-02-07 18:35:16 +08:00
Loom.DownloadStack.Remove(FileName);
2022-05-13 09:28:58 +08:00
canvasGroup.DOFade(0, 2).onComplete += () =>
{
slider.gameObject.SetActive(false);
gameObject.Destroy();
2023-02-07 18:35:16 +08:00
Loom.DownloadStack.Remove(FileName);
2022-05-13 09:28:58 +08:00
};
}
}
public void Dispose()
{
gameObject.SetActive(false);
}
}