Exemplo n.º 1
0
        /// <summary>
        /// Selects a given item in the inventory
        /// </summary>
        /// <param name="item">Item to select</param>
        /// <param name="blocked">Should the selection be rendered as blocked</param>
        /// <param name="color">The color of the selection</param>
        public void SelectItem(IInventoryItem item, bool blocked, Color color)
        {
            if (item == null)
            {
                return;
            }
            ClearSelection();

            switch (_renderMode)
            {
            case InventoryRenderMode.Single:
                _grids[0].sprite = blocked ? _cellSpriteBlocked : _cellSpriteSelected;
                _grids[0].color  = color;
                break;

            default:
                for (var x = 0; x < item.width; x++)
                {
                    for (var y = 0; y < item.height; y++)
                    {
                        if (item.IsPartOfShape(new Vector2Int(x, y)))
                        {
                            var p = item.position + new Vector2Int(x, y);
                            if (p.x >= 0 && p.x < inventory.width && p.y >= 0 && p.y < inventory.height)
                            {
                                var index = p.y * inventory.width + ((inventory.width - 1) - p.x);
                                _grids[index].sprite = blocked ? _cellSpriteBlocked : _cellSpriteSelected;
                                _grids[index].color  = color;
                            }
                        }
                    }
                }
                break;
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Returns true of this item overlaps a given item
 /// </summary>
 internal static bool Overlaps(this IInventoryItem item, IInventoryItem otherItem)
 {
     for (var iX = 0; iX < item.width; iX++)
     {
         for (var iY = 0; iY < item.height; iY++)
         {
             if (item.IsPartOfShape(new Vector2Int(iX, iY)))
             {
                 var iPoint = item.position + new Vector2Int(iX, iY);
                 for (var oX = 0; oX < otherItem.width; oX++)
                 {
                     for (var oY = 0; oY < otherItem.height; oY++)
                     {
                         if (otherItem.IsPartOfShape(new Vector2Int(oX, oY)))
                         {
                             var oPoint = otherItem.position + new Vector2Int(oX, oY);
                             if (oPoint == iPoint)
                             {
                                 return(true);
                             }                                      // Hit! Items overlap
                         }
                     }
                 }
             }
         }
     }
     return(false); // Items does not overlap
 }