Exemple #1
0
    /// <summary>
    /// Adds the inventory slots.
    /// </summary>
    private void AddSlots()
    {
        int numSlots = rows * columns;

        _slots = new Slot[numSlots];
        int itemCount = _inventory.Count();

        for (int index = 0; index < numSlots; index++)
        {
            // Add Slot Panel
            GameObject slotPanel = Instantiate(slotPanelPrefab);
            slotPanel.transform.SetParent(slotsPanel.transform, false);
            slotPanel.name = string.Format("Slot {0}", index);

            Slot slotPanelClass = slotPanel.GetComponent <Slot> ();
            slotPanelClass.Index = index;

            _slots [index] = slotPanelClass;

            // Set slot image for all inventory items
            if (itemCount > 0 && _inventory.Get(index) != null)
            {
                Item item = _inventory.Get(index);
                SlotImageCanvas.InstantiateInstance(slotImageCanvasPrefab, item, slotPanel, toolTipPanel, toolTipPanelSecondary, slotResolution, slotResolution);
                itemCount--;
            }
            else
            {
                // Add null values to inventory
                _inventory.Add(null);
            }
        }
    }
    /// <summary>
    /// Sets the equipped items.
    /// </summary>
    /// <param name="unit">Unit.</param>
    public void SetEquippedItems(Unit unit)
    {
        _inventorySlots = unit.GetInventorySlots();

        // Delete existing slot image (if exists) before adding new one.
        // TODO: Clearly, this is terrible. Come up with better solution.
        ClearAllSlotImages();
        ClearAttributeText();

        // Iterate over weapons/armor and add
        foreach (Item item in _inventorySlots.GetInventorySlots().Values)
        {
            SetAllAttributesText(item);

            GameObject slotPanel = GetPanelBySlot(item.SlotType).transform.Find("Slot").gameObject;

            RectTransform rectTransform = (RectTransform)slotPanel.transform;
            float         height        = rectTransform.rect.height;
            float         width         = rectTransform.rect.width;

            // Create slot images
            SlotImageCanvas.InstantiateInstance(
                slotImageCanvasPrefab,
                item,
                slotPanel,
                toolTipPanel,
                toolTipPanelSecondary,
                width,
                height
                );
        }
    }