Пример #1
0
    // Draw the item textures, fitted to the background tiles
    private void DrawItems()
    {
        if (isGridEnabled)
        {
            // Draw all items in inventory
            List <Equipment> equipments = inventoryGrid.GetItems();
            foreach (Equipment equipment in equipments)
            {
                // If item is currently being moved, draw it at partial opacity
                float alpha = GUI.color.a;
                if (itemMoving && equipment == itemMoving)
                {
                    SetAlpha(0.4f);
                }
                GUI.DrawTexture(RectFromGridItem(equipment.inventoryGridItem), equipment.inventoryGridItem.texture);
                SetAlpha(alpha);
            }

            // Draw dummy item if an item is being moved
            if (itemMoving)
            {
                // If the item is dragged onto a hotkey tile, draw it on the hotkey tile
                int hotKeyIndex = MousePosToHotkey();
                if (hotKeyIndex >= 0)
                {
                    GUI.DrawTexture(hotkeyTileRects[hotKeyIndex], itemMoving.inventoryGridItem.textureHotkey);
                }
                // Otherwise, draw the item being moved around
                else
                {
                    // If the item is in outside bounds of the grid, let it follow the mouse freely
                    Rect posRect;
                    if (itemMovingDummy.x < 0 || itemMovingDummy.y < 0 || itemMovingDummy.x > numTilesX - itemMovingDummy.width || itemMovingDummy.y > numTilesY - itemMovingDummy.height)
                    {
                        float tileWidth  = tileRects[0, 0].width;
                        float tileHeight = tileRects[0, 0].height;
                        posRect = new Rect(
                            (Input.mousePosition - dummyOffsetPixels).x - (tileRects[0, 0].width / 2),
                            Screen.height - (Input.mousePosition - dummyOffsetPixels).y - (tileRects[0, 0].height / 2),
                            (tileWidth * itemMovingDummy.width) + (tilePadding * (itemMovingDummy.width - 1)),
                            (tileHeight * itemMovingDummy.height) + (tilePadding * (itemMovingDummy.height - 1))
                            );
                    }
                    // Otherwise, if the item is within the grid, snap it to the grid tiles
                    else
                    {
                        posRect = RectFromGridItem(itemMovingDummy);
                    }

                    // Tint red if it is in a spot where it doesn't fit, and will not be successfully moved
                    Color color = GUI.color;
                    if (!inventoryGrid.CanItemFit(itemMovingDummy, itemMovingDummy.x, itemMovingDummy.y))
                    {
                        GUI.color = Color.red;
                    }
                    SetAlpha(0.75f);
                    GUI.DrawTexture(posRect, itemMovingDummy.texture);
                    GUI.color = color;
                }
            }
        }

        // Draw all hotkey items
        // Exception: in the special case where an item is being moved onto the hotkey in question
        for (int i = 0; i < numHotkeys; i++)
        {
            Equipment item = inventoryGrid.GetHotkeyItem(i);
            if (item && !(itemMoving && MousePosToHotkey() == i))
            {
                GUI.DrawTexture(hotkeyTileRects[i], item.inventoryGridItem.textureHotkey);
            }
        }
    }