Files
Cielonos/Assets/Scripts/MainGame/Base/SaveData/Player/PlayerInventorySaveData.cs
SoulliesOfficial 7bc1e1722c 爆更
2026-06-05 04:21:00 -04:00

82 lines
2.6 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 System;
using System.Collections.Generic;
using Cielonos.MainGame.Inventory;
using UnityEngine;
namespace Cielonos.MainGame
{
/// <summary>
/// 玩家背包与装备数据配置包。
/// 用于记录玩家在基地Fortress中配置的全部装备和背包物品并同步至战斗关卡CityArena中。
/// </summary>
[Serializable]
public class PlayerInventorySaveData : SaveDataBase
{
public List<ItemSaveData> mainWeapons = new List<ItemSaveData>();
public List<ItemSaveData> preparedMainWeapons = new List<ItemSaveData>();
public ItemSaveData currentMainWeapon;
public List<ItemSaveData> supportEquipments = new List<ItemSaveData>() {};
public List<ItemSaveData> currentSupportEquipments = new List<ItemSaveData>();
public List<ItemSaveData> passiveEquipments = new List<ItemSaveData>();
public List<ItemSaveData> consumables = new List<ItemSaveData>();
}
[Serializable]
public class ItemSaveData
{
// 装备的类型名称(对应 Prefab 的名称,如 "Polychrome"
public string itemClass;
// 装备当前的等级Passive Attribute Submodule 的 Level
public int level = 0;
// 消耗品的堆叠数量默认为1表示单件物品大于1表示多件同类物品
public int stackAmount = 1;
public ItemSaveData()
{
}
public ItemSaveData(string itemClass)
{
this.itemClass = itemClass;
}
public ItemBase RestoreItem()
{
Type type = Type.GetType($"Cielonos.MainGame.Inventory.Collections.{itemClass}");
if (type == null)
{
Debug.LogError($"无法找到类型 {itemClass},请确保该类存在并且命名空间正确。");
return null;
}
ItemBase item = MainGameManager.Player.inventorySc.backpackSm.ObtainItem(type); // 调用我们前文扩展的非泛型方法
if (item != null)
{
// B. 注入保存的状态
// 还原等级
if (item.passiveAttributeSm != null)
{
item.passiveAttributeSm.level = level;
}
// 还原堆叠数量(仅对消耗品有效)
if (item is ConsumableBase consumable)
{
consumable.stackAmount = stackAmount;
}
}
return item;
}
}
}