Files
zeling_v2/Assets/_Game/Scripts/UI/BestiaryCellView.cs
2026-06-08 11:26:17 +08:00

47 lines
2.0 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using UnityEngine;
using UnityEngine.UI;
using BaseGames.Localization;
namespace BaseGames.UI
{
/// <summary>
/// 图鉴单元格视图(仿 <see cref="AbilityCellView"/>):肖像 + 名称 + 已发现/未发现视觉。
/// 未发现时:名称显示 "???"BESTIARY_LOCKED 文案)、肖像剪影化、暗罩、整格暗化。
/// 由 <see cref="BestiaryPanel"/> 据 <see cref="BestiaryDatabaseSO"/> 实例化并 Bind。
/// </summary>
[DisallowMultipleComponent]
public class BestiaryCellView : MonoBehaviour
{
[SerializeField] private Image _icon;
[SerializeField] private LocalizedText _label;
[Tooltip("未发现时显示的暗罩 / 锁图标(可空)。")]
[SerializeField] private GameObject _lockedOverlay;
[Tooltip("整格暗化用(可空)。")]
[SerializeField] private CanvasGroup _group;
[Tooltip("点击选中此格以在详情区展示(可空)。")]
[SerializeField] private Button _selectButton;
private const string LockedKey = "BESTIARY_LOCKED";
private string _nameKey;
public Button SelectButton => _selectButton;
public void Bind(string nameKey, Sprite icon, bool discovered)
{
_nameKey = nameKey;
if (_icon != null) { _icon.sprite = icon; _icon.enabled = icon != null; }
SetDiscovered(discovered);
}
/// <summary>只更新发现态(保留图标/名称。EVT_BestiaryUpdated 刷新时调用。</summary>
public void SetDiscovered(bool discovered)
{
if (_label != null) _label.SetKey(discovered ? _nameKey : LockedKey);
if (_lockedOverlay != null) _lockedOverlay.SetActive(!discovered);
// 未发现:肖像剪影化(压暗);已发现:原色
if (_icon != null) _icon.color = discovered ? Color.white : new Color(0.04f, 0.04f, 0.06f, 1f);
if (_group != null) _group.alpha = discovered ? 1f : 0.55f;
}
}
}