Пример #1
0
    public void SetParentAndSize(InventoryItemObject item)
    {
        item.transform.SetParent(transform);

        // set size of image
        int wid = item.GetItem().GetItemSize()._width;
        int hig = item.GetItem().GetItemSize()._height;

        item.GetComponent <Image>().rectTransform.localScale = Vector3.one;
        item.SetSize(localSizeOfTile * wid, localSizeOfTile * hig);

        /*
         * item.GetImage().rectTransform.localScale = Vector3.one;
         * item.GetImage().rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, localSizeOfTile * wid);
         * item.GetImage().rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, localSizeOfTile * hig);
         */
    }
Пример #2
0
    public void AddExistingItem(InventoryItemObject itemObject)
    {
        Image img = itemObject.GetComponent <Image>();

        // add to first available
        for (int r = 0; r < _height; r++)
        {
            for (int c = 0; c < _width; c++)
            {
                Index nx = new Index(c, r);
                if (TryFit(itemObject.GetItem(), nx))
                {
                    AddToSlot(itemObject.GetItem(), nx);

                    img.transform.SetParent(transform);

                    Item item = itemObject.GetItem();
                    img.GetComponent <InventoryItemObject>().init(item, nx);

                    // set size of image
                    int wid = item.GetItemSize()._width;
                    int hig = item.GetItemSize()._height;
                    img.rectTransform.localScale = Vector3.one;
                    itemObject.SetSize(localSizeOfTile * wid, localSizeOfTile * hig);

                    /*
                     * img.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, localSizeOfTile * wid);
                     * img.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, localSizeOfTile * hig);
                     */

                    // set position of image
                    img.rectTransform.localPosition = PositionAtIndex(nx._x, nx._y) - HalfTile();

                    return;
                }
            }
        }
    }