using UnityEngine;
using System.Collections;
using System.Collections.Generic;
namespace UGUI
{
[System.Serializable]
public class InventoryItemData
{
public int slot_position;
public int item_id;
public int count;
}
[System.Serializable]
public class Inventory
{
Dictionary<int, InventoryItemData> slot_index = new Dictionary<int, InventoryItemData>();
/// <summary>
/// 通过 inventory[slot_id]的方式,去访问slot成员
/// </summary>
/// <param name="id">想要访问的格子id</param>
/// <returns>InventoryItemData,如果id不存在,则会返回空</returns>
public InventoryItemData this[int id]
{
get
{
InventoryItemData result = null;
slot_index.TryGetValue( id, out result);
return result;
}
}
}
}
C# [] 运算符
最新推荐文章于 2023-02-16 11:42:15 发布