Files
zeling_v2/Assets/Scripts/World/Shop/ShopItemSO.cs
2026-05-13 09:19:54 +08:00

96 lines
3.3 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 BaseGames.Equipment;
namespace BaseGames.World.Shop
{
// ─── 商品效果基类及子类 ──────────────────────────────────────────────────
// 使用 [SerializeReference] 多态序列化Inspector 中右键可选择具体效果类型,
// 只显示该类型所需字段,消除原平铺字段方案中大量空字段的噪音。
[System.Serializable]
public abstract class ShopItemEffect
{
public abstract ShopItemType Type { get; }
}
[System.Serializable]
public class HealthRestorationEffect : ShopItemEffect
{
public override ShopItemType Type => ShopItemType.HealthRestoration;
/// <summary>恢复的 HP 量。</summary>
public int Amount;
}
[System.Serializable]
public class CharmItemEffect : ShopItemEffect
{
public override ShopItemType Type => ShopItemType.CharmItem;
/// <summary>购买后解锁/获得的护符。</summary>
public CharmSO CharmReference;
}
[System.Serializable]
public class KeyItemEffect : ShopItemEffect
{
public override ShopItemType Type => ShopItemType.KeyItem;
/// <summary>授予玩家的关键道具 ID对应 GameIds.Collectible。</summary>
public string KeyItemId;
}
[System.Serializable]
public class ConsumableBuffEffect : ShopItemEffect
{
public override ShopItemType Type => ShopItemType.ConsumableBuff;
// 可按需在此扩展 BuffId、Duration、Magnitude 等字段
}
[System.Serializable]
public class MapFragmentEffect : ShopItemEffect
{
public override ShopItemType Type => ShopItemType.MapFragment;
/// <summary>购买后揭示的房间 ID对应 MapManager.SetMapped。</summary>
public string RoomId;
}
// ─── 商品 SO ──────────────────────────────────────────────────────────────
/// <summary>
/// 商店单品 SO架构 15_MapShopModule §2.1)。
/// 资产路径: Assets/ScriptableObjects/Shop/Item_{ItemId}.asset
/// </summary>
[CreateAssetMenu(menuName = "World/Shop/ShopItem")]
public class ShopItemSO : ScriptableObject
{
[Header("标识")]
public string ItemId;
public string DisplayName;
[TextArea(2, 5)]
public string Description;
public Sprite Icon;
[Header("价格")]
public int BasePrice;
public bool IsUnique; // 购买一次后永久从库存移除
public int MaxPurchaseCount = -1; // -1 = 无限次
[Header("商品效果")]
[SerializeReference]
public ShopItemEffect Effect;
/// <summary>
/// 便捷属性:从 Effect 类型推导商品分类,供 ShopPanel/UI 按类型渲染图标或提示文字。
/// Effect 为 null 时回退到 HealthRestorationInspector 未配置的保护值)。
/// </summary>
public ShopItemType ItemType => Effect?.Type ?? ShopItemType.HealthRestoration;
}
public enum ShopItemType
{
HealthRestoration,
CharmItem,
KeyItem,
ConsumableBuff,
MapFragment,
}
}