89 lines
1.9 KiB
C#
Raw Normal View History

2024-11-08 18:21:41 +08:00
using System;
using System.Collections;
using System.Collections.Generic;
using cfg;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
public class LevelButton : MonoBehaviour
{
private BLevel data;
2024-11-21 09:35:48 +08:00
private int levelID=0;
public LevelPanel _panel;
2024-11-08 18:21:41 +08:00
[SerializeField] private TextMeshProUGUI name;
[SerializeField] private Button _button;
[SerializeField] private GameObject back;
[SerializeField] private GameObject lockObj;
2024-11-21 09:35:48 +08:00
[SerializeField] private GameObject selectObj;
2024-11-08 18:21:41 +08:00
private void Awake()
{
}
public void Reset()
{
if (data == null)
{
back.SetActive(true);
_button.gameObject.SetActive(false);
}
}
public void SetLevelData(int id)
{
if (id != 0)
{
data = JsonTab.Instance.tables.Level.Get(id);
2024-11-26 15:44:50 +08:00
name.text = JsonTab.Instance.tables.DisplayTxt.Get(data.Name).Text;
2024-11-08 18:21:41 +08:00
back.SetActive(false);
_button.gameObject.SetActive(true);
2024-11-26 15:44:50 +08:00
var levelOpen = DataManager.LevelOpen(data.Front);
lockObj.GetComponent<Image>().color = levelOpen ? Color.white : Color.gray;
_button.enabled = levelOpen;
2024-11-21 09:35:48 +08:00
levelID = id;
2024-11-08 18:21:41 +08:00
}
else
{
data = null;
back.SetActive(true);
_button.gameObject.SetActive(false);
}
}
2024-11-26 15:44:50 +08:00
public void SelelObj()
{
selectObj.SetActive(_panel.LevelID==levelID);
}
2024-11-08 18:21:41 +08:00
private void ButtonEvent()
{
2024-11-26 15:44:50 +08:00
if (DataManager.LevelOpen(data.Front))
{
_panel.SaveLevelID(levelID);
}
2024-11-08 18:21:41 +08:00
}
// Start is called before the first frame update
void Start()
{
}
private void OnEnable()
{
_button.onClick.AddListener(ButtonEvent);
}
// Update is called once per frame
void Update()
{
}
private void OnDisable()
{
_button.onClick.RemoveListener(ButtonEvent);
}
}