public GridObjectBase SpawnObject(GridObjectBase newObjectPrefab, Vector2Int position, Color colorNormal, Color colorLinked) { bool canSpawn = IsFree(position, newObjectPrefab.size); if (canSpawn) { GridObjectBase newObject = Instantiate(newObjectPrefab, transform); newObject.UpdatePosition(position); if (newObject is Piece) { (newObject as Piece).Init(colorNormal, colorLinked); activePieces.Add((Piece)newObject); } ForGridRectDo(position, newObject.size, (x, y) => { grid[x, y] = newObject; }); return(newObject); } else { return(null); } }
public void MoveObject(GridObjectBase movedObject, Vector2Int newPosition) { //Remove piece from prev location ForGridRectDo(movedObject.Position, movedObject.size, (x, y) => { if (grid[x, y] == movedObject) { grid[x, y] = null; } }); //Move piece to new position movedObject.UpdatePosition(newPosition); ForGridRectDo(movedObject.Position, movedObject.size, (x, y) => { grid[x, y] = movedObject; }); }