Esempio n. 1
0
        /// <inheritdoc />
        public bool CanAddAt(IInventoryItem item, Vector2Int point)
        {
            if (!_provider.CanAddInventoryItem(item) || _provider.isInventoryFull)
            {
                return(false);
            }

            if (_provider.inventoryRenderMode == InventoryRenderMode.Single)
            {
                return(true);
            }

            var previousPoint = item.position;

            item.position = point;
            var padding = Vector2.one * 0.01f;

            // Check if item is outside of inventory
            if (!_fullRect.Contains(item.GetMinPoint() + padding) || !_fullRect.Contains(item.GetMaxPoint() - padding))
            {
                item.position = previousPoint;
                return(false);
            }

            // Check if item overlaps another item already in the inventory
            if (!allItems.Any(otherItem => item.Overlaps(otherItem)))
            {
                return(true);                                                      // Item can be added
            }
            item.position = previousPoint;
            return(false);
        }