Beispiel #1
0
    void ActivateInventory(List <PickableObject> items)
    {
        if (contentLayoutGroup == null)
        {
            Start();
        }

        gameObject.SetActive(true);
        gameActions.UI.Enable();
        Cursor.visible = true;
        EventSystem.current.SetSelectedGameObject(null);

        if (items != null)
        {
            slots = new RectTransform[items.Count];

            for (int slotIdx = 0; slotIdx < items.Count; slotIdx++)
            {
                GameObject     slot    = Instantiate(slotPrefab, contentLayoutGroup.transform);
                PickableObject slotObj = items[slotIdx];

                Texture2D inventoryImage = slotObj.GetInventorySprite();

                slot.GetComponent <Image>().sprite = Sprite.Create(inventoryImage, new Rect(0.0f, 0.0f, inventoryImage.width, inventoryImage.height), new Vector2(0.5f, 0.5f), 100.0f);
                slot.GetComponent <InventorySlotController>().SetObjectInSlot(slotObj);
                slots[slotIdx] = slot.GetComponent <RectTransform>();
            }
        }
    }