Demo entry 6552838

c++

   

Submitted by anonymous on Jun 02, 2017 at 08:55
Language: C++. Code size: 1.2 kB.

public bool StoreItem(int id)
    {
        Item item = InventoryManager.Instance.GetItemById(id);
        return StoreItem(item);
    }
    public bool StoreItem(Item item)
    {
        if (item == null)
        {
            Debug.LogWarning("要储存的物品的ID无存在");
            return false;
        }
        if (item.Capacity == 1)
        {
            Slot slot = FindSlotEmpty();
            if (slot == null)
            {
                Debug.LogWarning("没有空的物品槽");
                return false;
            }
            else
            {
                slot.StoreItem(item);//将物品储存在空的物品槽中
            }
        }
        else
        {
            Slot slot = FindSameIdSlot(item);
            if (slot != null)
            {
                slot.StoreItem(item);
            }
            else
            {
                Slot slotEmpty = FindSlotEmpty();
                if (slotEmpty != null)
                {
                    slotEmpty.StoreItem(item);
                }
                else
                {
                    Debug.LogWarning("没有空的物品槽");
                    return false;
                }
            }
        }
        return true;
}	

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).