82 lines
2.6 KiB
C#
82 lines
2.6 KiB
C#
|
|
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;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|