コード例 #1
0
    /// <summary>
    /// Gets the specified slot from the specified storage. Null if this item storage does not have
    /// a slot with the given identifier.
    /// </summary>
    /// <param name="itemStorage"></param>
    /// <param name="slotIdentifier"></param>
    /// <returns></returns>
    public static ItemSlot Get(ItemStorage itemStorage, SlotIdentifier slotIdentifier)
    {
        if (!itemStorage.HasSlot(slotIdentifier))
        {
            return(null);
        }

        var instanceID = itemStorage.GetInstanceID();

        slots.TryGetValue(instanceID, out var dict);
        if (dict == null)
        {
            dict = new Dictionary <SlotIdentifier, ItemSlot>();
            slots.Add(instanceID, dict);
        }

        dict.TryGetValue(slotIdentifier, out var slot);
        if (slot == null)
        {
            slot = new ItemSlot(itemStorage, slotIdentifier);
            dict.Add(slotIdentifier, slot);
        }

        return(slot);
    }
コード例 #2
0
 private ItemSlot(ItemStorage itemStorage, SlotIdentifier slotIdentifier)
 {
     this.itemStorage      = itemStorage;
     this.itemStorageNetId = itemStorage.GetInstanceID();
     this.slotIdentifier   = slotIdentifier;
 }