示例#1
0
    public Item NewItemFromRecipe(Recipe recipe, byte slotNumber)
    {
        GameObject    itemObject    = Instantiate(itemObjectPrefab, outputSlotObject.transform.position, Quaternion.identity, outputSlotObject.transform);
        ItemDisplayer itemDisplayer = itemObject.transform.GetChild(0).GetComponent <ItemDisplayer>();
        Animator      animator      = itemDisplayer.GetComponent <Animator>();

        itemDisplayer.item = recipe.resultItems[slotNumber];
        SetOutputSlot(itemDisplayer.item);
        itemDisplayer.ActualStart();
        itemObject.GetComponent <DragHandler>().ActualStart();

        bool isItemInInventory = false;

        foreach (Item item in Inventory.inst.itemsInInventory)
        {
            if (item.name == itemDisplayer.item.name)
            {
                isItemInInventory = true;
                itemInQueuRecipe  = null;
                itemDisplayer.DisableItem();
                break;
            }
        }

        itemDisplayer.SetItemObject();

        if (!isItemInInventory)
        {
            animator.SetTrigger("NewItem");
        }

        bool isItemInDiscoveredItems = false;

        foreach (Item item in Inventory.inst.discoveredItems)
        {
            if (item.name == itemDisplayer.item.name)
            {
                isItemInDiscoveredItems = true;
                break;
            }
        }

        if (!isItemInDiscoveredItems)
        {
            DiscoveredScreen.inst.ShowItemInDiscoveredScreen(itemDisplayer);
        }

        return(itemDisplayer.item);
    }