47 lines
2.0 KiB
C#
47 lines
2.0 KiB
C#
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;
|
||
}
|
||
}
|
||
}
|