コード例 #1
0
ファイル: Backpack.cs プロジェクト: stamen9/Junkyard-BC
    public void AddItem(int id)
    {
        Item itemToAdd = itemDB.FetchByID(id);

        if (itemToAdd.stackable && CheckIfinInv(itemToAdd))
        {
            for (int i = 0; i < items.Count; i++)
            {
                SlotData data = slots[i].transform.GetChild(0).GetComponent <SlotData>();
                data.amount++;
                //Debug.Log (data.transform);
                data.transform.GetChild(0).GetComponent <Text>().text = data.amount.ToString();
                break;
            }
        }
        else
        {
            for (int i = 0; i < items.Count; i++)
            {
                if (items[i].ID == -1)
                {
                    items[i] = itemToAdd;
                    GameObject itemObj = Instantiate(inventoryItem);
                    itemObj.GetComponent <SlotData>().item   = itemToAdd;
                    itemObj.GetComponent <SlotData>().sloti  = i;
                    itemObj.GetComponent <SlotData>().amount = 1;
                    itemObj.transform.SetParent(slots[i].transform);
                    itemObj.transform.position   = slots[i].transform.position;
                    itemObj.transform.rotation   = slots[i].transform.rotation;
                    itemObj.transform.localScale = slots[i].transform.localScale;

                    itemObj.GetComponent <Image>().sprite = itemToAdd.Sprite;
                    break;
                }
            }
        }
    }