63 lines
1.9 KiB
C#
63 lines
1.9 KiB
C#
using UnityEngine;
|
||
using UnityEngine.UI;
|
||
|
||
/// <summary>
|
||
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> interactable <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
/// </summary>
|
||
public class MainMenuButtonsUpdater : MonoBehaviour
|
||
{
|
||
[SerializeField] private int playerId;
|
||
[SerializeField] private Button playVsBotButton;
|
||
[SerializeField] private Button playVsPlayerButton;
|
||
|
||
private bool eventsSubscribed;
|
||
|
||
private void OnEnable()
|
||
{
|
||
CreditSystem.OnInitialize += Subscribe;
|
||
|
||
if (!eventsSubscribed && (CreditSystem.onCoinAdded != null || CreditSystem.onCoinRemoved != null))
|
||
Subscribe();
|
||
}
|
||
|
||
private void OnDisable()
|
||
{
|
||
if (eventsSubscribed)
|
||
{
|
||
if (CreditSystem.onCoinAdded != null) CreditSystem.onCoinAdded.RemoveListener(OnCoinsChanged);
|
||
if (CreditSystem.onCoinRemoved != null) CreditSystem.onCoinRemoved.RemoveListener(OnCoinsChanged);
|
||
eventsSubscribed = false;
|
||
}
|
||
|
||
CreditSystem.OnInitialize -= Subscribe;
|
||
}
|
||
|
||
private void Subscribe()
|
||
{
|
||
if (eventsSubscribed) return;
|
||
|
||
if (CreditSystem.onCoinAdded != null) CreditSystem.onCoinAdded.AddListener(OnCoinsChanged);
|
||
if (CreditSystem.onCoinRemoved != null) CreditSystem.onCoinRemoved.AddListener(OnCoinsChanged);
|
||
|
||
eventsSubscribed = true;
|
||
UpdateButtons();
|
||
}
|
||
|
||
private void Start()
|
||
{
|
||
UpdateButtons();
|
||
}
|
||
|
||
private void OnCoinsChanged(int playerID, int newAmount)
|
||
{
|
||
UpdateButtons();
|
||
}
|
||
|
||
public void UpdateButtons()
|
||
{
|
||
// Визуальное состояние кнопок не меняется.
|
||
// При нехватке денег GameManager покажет панель "Пополните баланс".
|
||
}
|
||
}
|
||
|