예제 #1
0
        public void PlacingGround()
        {
            Vector2 mousePosition = MouseControls.GetCursorWorldPosition();

            this.previewObject.transform.position = mousePosition;

            if (Input.GetButton(InputAxes.Take))
            {
                Vector3Int tilePosition = this.TerrainTilemap.WorldToCell(mousePosition);
                var        previousTile = this.TerrainTilemap.GetTile(tilePosition);
                if (previousTile != this.GroundTile)
                {
                    bool connects = false;
                    for (int x = tilePosition.x - 1; x < tilePosition.x + 2; x++)
                    {
                        for (int y = tilePosition.y - 1; y < tilePosition.y + 2; y++)
                        {
                            if (x == tilePosition.x &&
                                y == tilePosition.y)
                            {
                                continue;
                            }

                            if (this.TerrainTilemap.GetTile(new Vector3Int(x, y, 0)) == this.GroundTile)
                            {
                                connects = true;
                                break;
                            }
                        }
                    }

                    if (connects != true)
                    {
                        Debug.Log("Tile doesn't connect");
                        return;
                    }

                    // TODO: Deduct from inventory.
                    this.TerrainTilemap.SetTile(tilePosition, this.GroundTile);
                }
            }

            if (Input.GetButton(InputAxes.Care))
            {
                EndPlacement();
            }
        }
예제 #2
0
        public void PlacingSeed()
        {
            Vector2 mousePosition = MouseControls.GetCursorWorldPosition();

            this.previewObject.transform.position = mousePosition;

            if (Input.GetButton(InputAxes.Take))
            {
                Vector3Int tilePosition = this.TerrainTilemap.WorldToCell(mousePosition);
                var        previousTile = this.TerrainTilemap.GetTile(tilePosition);
                if (previousTile != this.GroundTile)
                {
                    // TODO: Deduct from inventory.
                    this.TerrainTilemap.SetTile(tilePosition, this.GroundTile);
                }
            }

            if (Input.GetButton(InputAxes.Care))
            {
                EndPlacement();
            }
        }