/// <summary> /// Called when the craft button is clicked. /// </summary> public void callback_craftButtonClick() { Recipe r = this.selectedRecipe.getRecipe(); ContainerContents <IItemBase> inventory = this.getPlayer().inventory; // Remove the items from the players inventory. foreach (ItemData item in r.getIngredients()) { int i; inventory.containsItem(item, out i); if (i != -1) { ItemManager.destroyItem(this.getPlayer(), i); } } // Add the new item to the players inventory. if (r.getResult() != null) { IItemBase item = ItemManager.create <IItemBase>(r.getResult()); item.setInWorld(false, Vector3.zero, Quaternion.identity); inventory.addItem(item); } // Set the selected recipe to be null. this.selectedRecipe.setOutlined(false); this.setSelectedRecipe(null); }
public static T create <T>(ItemData itemData, ContainerContents <IItemBase> container) where T : IItemBase { T item = ItemManager.create <T>(itemData); item.setInWorld(false, Vector3.zero, Quaternion.identity); // TODO where should they be stored? container.addItem(item); return(item); }