Example #1
0
        /**
         * Fits this dropzone into an inventory grid
         */
        public void FitIntoGrid(int x, int y, int sortOrder, UIInventoryGrid uiGrid)
        {
            Point2 gridSize = uiGrid.inventory.gridSize;
            Graphic gridGraphic = uiGrid.gameObject.GetComponent<Graphic>();
            float slotSize = gridGraphic.rectTransform.rect.width / gridSize.x;

            this.transform.SetParent(uiGrid.transform);
            this.transform.SetSiblingIndex(sortOrder);

            this.GetImage().rectTransform.pivot = new Vector2(0, 1);
            this.GetImage().rectTransform.anchorMin = new Vector2(0, 1);
            this.GetImage().rectTransform.anchorMax = new Vector2(0, 1);
            this.GetImage().rectTransform.anchoredPosition = new Vector3(x * slotSize, -y * slotSize, 0);
            this.GetImage().rectTransform.sizeDelta = new Vector2(slotSize, slotSize);
        }
        public void Construct(Inventory.Entry entry, UIInventoryGrid uiGrid)
        {
            Point2 gridSize = uiGrid.inventory.gridSize;
            Graphic gridGraphic = uiGrid.gameObject.GetComponent<Graphic>();
            float slotSize = gridGraphic.rectTransform.rect.width / gridSize.x;

            this.entry = entry;

            this.gameObject.name = this.entry.item.title;
            this.sprite = this.entry.item.image;

            this.transform.SetParent(uiGrid.transform);

            this.rectTransform.pivot = new Vector2(0, 1);
            this.rectTransform.anchorMin = new Vector2(0, 1);
            this.rectTransform.anchorMax = new Vector2(0, 1);
            this.rectTransform.anchoredPosition = new Vector3(entry.position.x * slotSize, -entry.position.y * slotSize, 0);
            this.rectTransform.sizeDelta = new Vector2(this.entry.item.inventorySize.x * slotSize, this.entry.item.inventorySize.y * slotSize);
        }