public override void Awake()
        {
            base.Awake();

            // Fill the container on startup, can add / remove later on
            for (uint i = 0; i < initialCollectionSize; i++)
            {
                ((InventoryUIItemWrapperKeyTrigger)items[i]).keyCombination = keys[i].name;
                items[i].Repaint(); // First time
            }

            foreach (var i in InventoryManager.GetLootToCollections())
            {
                // Item added to inventory
                i.OnAddedItem += (InventoryItemBase item, uint slot, uint amount) =>
                {
                    RepaintOfID(item.ID);
                };
                i.OnRemovedItem += (uint itemID, uint slot, uint amount) =>
                {
                    RepaintOfID(itemID);
                };
                i.OnUsedItem += (uint itemID, uint slot, uint amount) =>
                {
                    RepaintOfID(itemID);
                };
            }
        }
        public virtual void Awake()
        {
            if (blueprintCategoryPrefab != null)
            {
                categoryPool = new InventoryPool <InventoryCraftingCategoryUI>(blueprintCategoryPrefab, 16);
            }

#if UNITY_EDITOR
            if (blueprintButtonPrefab == null)
            {
                Debug.LogWarning("Blueprint button prefab is empty in CraftingWindowStandardUI", gameObject);
            }

            if (blueprintRequiredItemPrefab == null)
            {
                Debug.LogWarning("Blueprint required item prefab is empty in CraftingWindowStandardUI", gameObject);
            }
#endif

            blueprintPool = new InventoryPool <InventoryCraftingBlueprintUI>(blueprintButtonPrefab, 128);
            blueprintRequiredItemsPool = new InventoryPool <InventoryUIItemWrapper>(blueprintRequiredItemPrefab, 8);

            if (defaultCategoryID >= 0 && defaultCategoryID <= ItemManager.instance.craftingCategories.Length - 1)
            {
                currentCategory = defaultCategory;
            }

            if (blueprintMinCraftButton != null)
            {
                blueprintMinCraftButton.onClick.AddListener(() =>
                {
                    if (Input.GetKey(KeyCode.LeftShift))
                    {
                        blueprintCraftAmountInput.text = (GetCraftInputFieldAmount() - 10).ToString();
                    }
                    else
                    {
                        blueprintCraftAmountInput.text = (GetCraftInputFieldAmount() - 1).ToString();
                    }

                    ValidateCraftInputFieldAmount();
                });
            }
            if (blueprintPlusCraftButton != null)
            {
                blueprintPlusCraftButton.onClick.AddListener(() =>
                {
                    if (Input.GetKey(KeyCode.LeftShift))
                    {
                        blueprintCraftAmountInput.text = (GetCraftInputFieldAmount() + 10).ToString();
                    }
                    else
                    {
                        blueprintCraftAmountInput.text = (GetCraftInputFieldAmount() + 1).ToString();
                    }

                    ValidateCraftInputFieldAmount();
                });
            }

            blueprintCraftButton.onClick.AddListener(() => CraftItem(currentCategory, currentBlueprint, GetCraftInputFieldAmount()));

            window.OnShow += () =>
            {
                if (currentCategory != null)
                {
                    SetCraftingCategory(currentCategory);
                }

                if (currentBlueprint != null)
                {
                    SetBlueprint(currentBlueprint);
                }
            };

            window.OnHide += CancelActiveCraft;

            foreach (var col in InventoryManager.GetLootToCollections())
            {
                col.OnAddedItem += (InventoryItemBase item, uint slot, uint amount) =>
                {
                    if (currentBlueprint != null)
                    {
                        SetBlueprint(currentBlueprint);
                    }
                };
                col.OnRemovedItem += (uint itemID, uint slot, uint amount) =>
                {
                    if (currentBlueprint != null)
                    {
                        SetBlueprint(currentBlueprint);
                    }
                };
                col.OnDroppedItem += (InventoryItemBase item, uint slot, GameObject droppedObj) =>
                {
                    CancelActiveCraft(); // If the user drops something.

                    if (currentBlueprint != null)
                    {
                        SetBlueprint(currentBlueprint);
                    }
                };
            }

            InventoryManager.instance.inventory.OnGoldChanged += (float added) =>
            {
                if (currentBlueprint != null)
                {
                    SetBlueprint(currentBlueprint);
                }
            };
        }
Exemple #3
0
        public override void Awake()
        {
            base.Awake();
            currentBlueprintItemsDict = new Dictionary <uint, uint>(9);
            SetCraftingCategory(craftingCategory);

            window.OnHide += () =>
            {
                CancelActiveCraft();
            };

            window.OnShow += () =>
            {
                foreach (var i in items)
                {
                    i.Repaint();
                }

                ValidateReferences();
                ValidateBlueprint();
            };

            foreach (var col in InventoryManager.GetLootToCollections())
            {
                col.OnRemovedItem += (uint itemID, uint slot, uint amount) =>
                {
                    if (window.isVisible == false)
                    {
                        return;
                    }

                    foreach (var i in items)
                    {
                        i.Repaint();
                    }

                    ValidateReferences();
                    ValidateBlueprint();
                };
                col.OnAddedItem += (InventoryItemBase item, uint slot, uint amount) =>
                {
                    if (window.isVisible == false)
                    {
                        return;
                    }

                    foreach (var i in items)
                    {
                        i.Repaint();
                    }

                    ValidateBlueprint();
                };
                col.OnUsedItem += (uint itemID, uint slot, uint amount) =>
                {
                    if (window.isVisible == false)
                    {
                        return;
                    }

                    foreach (var item in items)
                    {
                        if (item.item != null && item.item.ID == itemID)
                        {
                            item.Repaint();
                        }
                    }

                    if (currentBlueprintItemsDict.ContainsKey(itemID))
                    {
                        CancelActiveCraft(); // Used an item that we're using in crafting.
                        ValidateBlueprint();
                    }
                };
            }

            blueprintCraftButton.onClick.AddListener(() =>
            {
                if (currentBlueprint != null)
                {
                    CraftItem(currentCategory, currentBlueprint, 1);
                }
            });
        }