Esempio n. 1
0
        private bool StackItem(TInstance newItem)
        {
            ItemTemplate itemTemplate = newItem.Template;

            if (!itemTemplate.IsStackable)
            {
                return(false);
            }

            for (int i = 0; i < ItemSlots.Length; i++)
            {
                InventoryItemSlot <TTemplate, TInstance> slot = ItemSlots[i];
                if (slot.HasItem(newItem.Template))
                {
                    if (slot.Item.Template == itemTemplate)
                    {
                        // @todo: stack items
                        //  slot.StackItem (amount);
                        OnItemAdded(newItem);
                        return(true);
                    }
                }
            }

            return(false);
        }
Esempio n. 2
0
        public Inventory(GameObject inOwner, DataTemplateManager <TTemplate> templateManager, int slotCount)
        {
            this.owner              = inOwner;
            this.SlotCount          = slotCount;
            this.dataTempateManager = templateManager;

            // initialize item slots
            ItemSlots = new InventoryItemSlot <TTemplate, TInstance> [slotCount];
            for (int i = 0; i < slotCount; i++)
            {
                ItemSlots[i] = new InventoryItemSlot <TTemplate, TInstance>(this);
            }
        }
Esempio n. 3
0
        private void InitSlots()
        {
            Assert.IsNotNull(inventory, "can't initialize inventory ui without inventory model");

            // initialize item slots
            for (int i = 0; i < inventory.SlotCount; i++)
            {
                InventoryItemSlot <TTemplate, TInstance> slot = inventory.ItemSlots[i];

                InventoryItemSlotUI <TTemplate, TInstance> slotUI = Instantiate(slotUIPrefab, transform).GetComponent <InventoryItemSlotUI <TTemplate, TInstance> > ();
                slotUI.SetSlot(slot);
                RegisterUIEvents(slotUI);
            }
        }
Esempio n. 4
0
        private bool AddNewItem(TInstance newItem)
        {
            ItemTemplate itemTemplate = newItem.Template;

            for (int i = 0; i < ItemSlots.Length; i++)
            {
                InventoryItemSlot <TTemplate, TInstance> slot = ItemSlots[i];

                if (!slot.ContainsItem)
                {
                    slot.SetItemInstance(newItem);

                    // @todo: auto equip

                    OnItemAdded(newItem);
                    Debug.Log("item added " + newItem.Template.name);
                    return(true);
                }
            }

            return(false);
        }