public void refreshRecipes() { for (int i = 0; i < gridParent.childCount; i++) { Transform child = gridParent.GetChild(i); ReuseGameObjectHandler.putToRecycle(ReuseableGameObject.CRAFTING_ICON, child.gameObject); } List <ItemStack> items = new List <ItemStack>(); if (inventory != null) { items.AddRange(inventory.getItems()); } if (inventory2 != null) { items.AddRange(inventory2.getItems()); } foreach (CraftingRecipe recipe in GameManager.database.getCraftingRecipes(recipeType)) { GameObject o = GameManager.spawnPrefab(GameManager.UIHandler.UICraftingIcon, Vector3.zero, ReuseableGameObject.CRAFTING_ICON); o.transform.SetParent(gridParent); UICraftingIcon icon = o.GetComponent <UICraftingIcon>(); currentIcons.Add(icon); icon.setRecipe(recipe); if (CraftingHandler.canCraftRecipe(recipe, items)) { icon.setCanCraft(true); } else { icon.setCanCraft(false); } } }
public void OnPointerClick(PointerEventData eventData) { if (canCraft) { if (CraftingHandler.tryInventoryCraft(GameManager.UIHandler.uiCraftingPanel.getInventory(), recipe, inv2: GameManager.UIHandler.uiCraftingPanel.getSecondaryInventory())) { Debug.Log("crafted"); } else { Debug.Log("craft failed"); } } }
public static void onPlayerRightClickItem(Player player, Item item) { WorldSpaceUI ui = WorldSpaceUIHandler.showUI(item.getLocation().getVector3()); ui.addButton("Pick Up", () => { Debug.Log("item removed"); item.remove(); player.giveItem(item.getItemStack()); WorldSpaceUIHandler.hideUI(); }); foreach (CraftingRecipe recipe in CraftingHandler.getCraftableRecipes(CraftingRecipeType.FLOOR, item.getNearbyItemStack(3f))) { ui.addButton("Craft " + recipe.requiredItems.GetType(), () => { if (CraftingHandler.tryFloorCraft(recipe, item.getLocation().getVector3()) == null) { Debug.Log("failed!"); } WorldSpaceUIHandler.hideUI(); }); } }