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; private int levelID=0; public LevelPanel _panel; [SerializeField] private TextMeshProUGUI name; [SerializeField] private Button _button; [SerializeField] private GameObject back; [SerializeField] private GameObject lockObj; [SerializeField] private GameObject selectObj; 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); name.text = JsonTab.Instance.tables.DisplayTxt.Get(data.Name).Text; back.SetActive(false); _button.gameObject.SetActive(true); var levelOpen = DataManager.LevelOpen(data.Front); lockObj.GetComponent().color = levelOpen ? Color.white : Color.gray; _button.enabled = levelOpen; levelID = id; } else { data = null; back.SetActive(true); _button.gameObject.SetActive(false); } } public void SelelObj() { selectObj.SetActive(_panel.LevelID==levelID); } private void ButtonEvent() { if (DataManager.LevelOpen(data.Front)) { _panel.SaveLevelID(levelID); } } // 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); } }