using UnityEngine; namespace Cielonos.MainGame.Inventory.Collections { /// /// 预制件 / Prefabricated Component /// 获得时自动使用,用于随机对玩家背包中的某一件可升级装备进行升级(升级次数等于堆叠数量)。 /// public class PrefabricatedComponent : ConsumableBase { /// 被选定的目标升级装备。 public ItemBase targetEquipment; public override void OnObtained() { base.OnObtained(); // 升级的次数由当前获得的堆叠数决定,至少为 1 次 int amountToUpgrade = stackAmount > 0 ? stackAmount : 1; if (targetEquipment != null) { // 根据数量循环多次执行升级 for (int i = 0; i < amountToUpgrade; i++) { targetEquipment.Upgrade(); } Debug.Log($"[PrefabricatedComponent] 自动使用:成功升级了装备 '{targetEquipment.name}' {amountToUpgrade} 次 (新等级: {targetEquipment.passiveAttributeSm.level})。"); } else { Debug.LogWarning("[PrefabricatedComponent] 自动使用失败:未指定目标升级装备。"); } // 立即标记为已使用并自毁 Use(amountToUpgrade); Destroy(gameObject); } } }