镜像 MainMenuP0 包样例

This commit is contained in:
JSD\13999
2026-06-04 20:16:28 +08:00
parent 3b3957fb74
commit ac8fcc3c24
29 changed files with 1548 additions and 2 deletions

View File

@@ -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();
}
}
}
}