Example #1
0
        public void UpdatePage(Recipe recipe)
        {
            selectedRecipe           = recipe;
            resultItemSlot.ItemStack = recipe.Result;

            foreach (ItemStackSlot slot in ingredientsItemSlots)
            {
                Destroy(slot.gameObject);
            }
            ingredientsItemSlots.Clear();

            Dictionary <ItemStack, bool> ingredients =
                CraftingManager.GetMissingIngredients(playerInventory.ItemInventory, recipe);

            foreach (KeyValuePair <ItemStack, bool> kvPair in ingredients)
            {
                GameObject obj = Instantiate(ingredientItemSlotPreFab, ingredientsContent.transform);
                obj.SetActive(true);
                if (!obj.TryGetComponent(out IngredientItemStack slot))
                {
                    continue;
                }

                slot.ItemStack    = kvPair.Key;
                slot.HasItemStack = kvPair.Value;

                ingredientsItemSlots.Add(slot);
            }

            craftButton.interactable = CraftingManager.CanCraft(playerInventory.ItemInventory, recipe);
        }
Example #2
0
        public void Craft()
        {
            if (selectedRecipe == null)
            {
                return;
            }

            if (!CraftingManager.CanCraft(playerInventory.ItemInventory, selectedRecipe))
            {
                return;
            }

            CraftingManager.Craft(playerInventory.ItemInventory, selectedRecipe);
            UpdatePage(selectedRecipe);
        }