public void AddInventory(Transform targetTransform, WarehouseItem droppedObject) { var id = droppedObject.GetInstanceID(); var index = targetTransform.GetSiblingIndex(); var r = index / _spaces.Cols; var c = index % _spaces.Cols; _spaces[r, c] = id; RepopulateGrid(); }
public bool IsValidDrop(Transform targetTx, WarehouseItem item) { var index = targetTx.GetSiblingIndex(); var row = index / _spaces.Cols; var col = index % _spaces.Cols; var itemId = item.GetInstanceID(); var id = _spaces[row, col]; return(id == 0 || id == itemId); }
public void RemoveInventory(WarehouseItem removedObject) { var id = removedObject.GetInstanceID(); for (int r = 0; r < _spaces.Rows; r++) { for (int c = 0; c < _spaces.Cols; c++) { if (_spaces[r, c] == id) { _spaces[r, c] = 0; } } } RepopulateGrid(); }
public void AddInventory(Transform targetTransform, WarehouseItem droppedObject) { var id = droppedObject.GetInstanceID(); var index = targetTransform.GetSiblingIndex(); var row = index / _spaces.Cols; var col = index % _spaces.Cols; for (int i = 0; i < droppedObject.BlockSpaces.Length; i++) { var offset = droppedObject.BlockSpaces[i]; var r = row + offset.y; var c = col + offset.x; if (r < 0 || r >= _spaces.Rows || c < 0 || c >= _spaces.Cols) { Debug.LogFormat(droppedObject, "Index out of range r{0},c{1})", r, c); return; } _spaces[r, c] = id; } RepopulateGrid(); }
public bool IsValidDrop(Transform targetTx, WarehouseItem item) { var index = targetTx.GetSiblingIndex(); var row = index / _spaces.Cols; var col = index % _spaces.Cols; var itemId = item.GetInstanceID(); for (int i = 0; i < item.BlockSpaces.Length; i++) { var offset = item.BlockSpaces[i]; var r = row + offset.y; var c = col + offset.x; if (r < 0 || r >= _spaces.Rows || c < 0 || c >= _spaces.Cols) { return(false); } var id = _spaces[r, c]; if (id != 0 && id != itemId) { return(false); } } return(true); }