63 lines
1.6 KiB
C#
63 lines
1.6 KiB
C#
using FlowScope.UI;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace FlowScope.Samples.MainMenuP0
|
|
{
|
|
[UIPanel("hud", "FlowScope/Samples/MainMenuP0/MainMenuPanel")]
|
|
public sealed class MainMenuPanel : UIPanelBase<MainMenuViewModel>
|
|
{
|
|
[SerializeField] private Text goldText;
|
|
[SerializeField] private Button incrementButton;
|
|
|
|
public void Configure(Text goldLabel, Button incrementGoldButton)
|
|
{
|
|
goldText = goldLabel;
|
|
incrementButton = incrementGoldButton;
|
|
}
|
|
|
|
protected override void OnBind(MainMenuViewModel viewModel)
|
|
{
|
|
if (goldText == null)
|
|
{
|
|
goldText = GetComponentInChildren<Text>(true);
|
|
}
|
|
|
|
if (incrementButton == null)
|
|
{
|
|
incrementButton = GetComponentInChildren<Button>(true);
|
|
}
|
|
|
|
UpdateGold(viewModel.Gold.Value);
|
|
viewModel.GoldChanged += UpdateGold;
|
|
if (incrementButton != null)
|
|
{
|
|
incrementButton.onClick.AddListener(viewModel.IncrementGold);
|
|
}
|
|
}
|
|
|
|
public override void Unbind()
|
|
{
|
|
if (ViewModel != null)
|
|
{
|
|
ViewModel.GoldChanged -= UpdateGold;
|
|
}
|
|
|
|
if (incrementButton != null)
|
|
{
|
|
incrementButton.onClick.RemoveAllListeners();
|
|
}
|
|
|
|
base.Unbind();
|
|
}
|
|
|
|
private void UpdateGold(int value)
|
|
{
|
|
if (goldText != null)
|
|
{
|
|
goldText.text = value.ToString();
|
|
}
|
|
}
|
|
}
|
|
}
|