WXGame/box1/Assets/Script/UI/WinPanel.cs
2024-11-29 21:37:01 +08:00

73 lines
1.8 KiB
C#

using System;
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
public class WinPanel : MonoBehaviour
{
[SerializeField] private Button nextButton;
[SerializeField] private Button closeButton;
[SerializeField] private List<TaskItem> _taskItems;
[SerializeField] private Slider _slider;
[SerializeField] private TextMeshProUGUI _points;
// Start is called before the first frame update
void Start()
{
}
public void SaveData(int id)
{
var data=JsonTab.Instance.tables.Level.Get(id);
_taskItems[0].InitData(id, data.Maintasks);
for (int i = 1; i < _taskItems.Count; i++)
{
_taskItems[i].gameObject.SetActive(false);
}
for (int i = 0; i < data.Additionaltasks.Count; i++)
{
_taskItems[i+1].gameObject.SetActive(true);
_taskItems[i+1].InitData(id,data.Additionaltasks[i]);
}
_points.text = DataManager.LastTimePoints(GameManager.ins.level).ToString();
_slider.value = GameManager.ins.NowLenght / data.Length;
}
private void OnEnable()
{
nextButton.onClick.AddListener(NextEvent);
closeButton.onClick.AddListener(CloseEvent);
}
// Update is called once per frame
void Update()
{
}
private void OnDisable()
{
nextButton.onClick.RemoveListener(NextEvent);
closeButton.onClick.RemoveListener(CloseEvent);
}
void NextEvent()
{
var lastPoints=DataManager.LastTimePoints(GameManager.ins.level)*2;
DataManager.SetPointsData(GameManager.ins.level, lastPoints);
MainPanel.ins.ClosePanelEvent();
}
void CloseEvent()
{
MainPanel.ins.ClosePanelEvent();
}
}