镜像 MainMenuP0 包样例
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user