Creating your own pieces

OwnPieces

This tutorial will show you how to create your own pieces. We will use the following board,

OwnPieces1

with these rules:

  • One turn per player.
  • Al blue ones moves first, then red.
  • You can move anywhere.
  • You can’t capture enemy pieces.
  • You can’t win or lose.

[dropcap style=”dark”]1[/dropcap]Make a new empty GameObject. Add a SpriteRenderer, and set the sprite to whatever image you want. Add a GridGamePiece component. Finally, you make this GameObject a prefab.

OwnPieces2

 

[dropcap style=”dark”]2[/dropcap]Create another empty GameObject, and give it the same name as the piece created in the previous step with  _Logic or _Setting added so that you know they are related.  Add a Grid Game Piece Setting component, and fill in the settings. For these examples all pieces have an Id of “piece” (they will have the same rules), and there is one player for each color and shape. Set the piece prefab to the prefab you made in the previous step.

Add a Open Space Move Rule component so that players can move pieces to any open position on the board.

OwnPieces3

Make this GameObject a Prefab too.

You can also add more piece rules. The default ones can be found by clicking on Add Component and then Gamelogic|Stragegy|Piece Rules. You can also create your own piece rules.

[dropcap style=”dark”]3[/dropcap]To add the piece to the board, you need to configure two components on the GameBoard. On the Grid Game Rules component, add all the logical piece prefabs to the Pieces field in any order you want.

OwnPieces4

On the GridGameManager, add the pieces as you want to position them on the grid in the initial configuration.

OwnPieces5

Remember that the Piece ID and the Player ID are set on the *_Logical prefab of the piece.

To check out this example:

  1. Import Abstract Strategy in a new project.
  2. Import the package below into the same project.
  3. Open the YourOwnPieces scene.

YourOwnPieces.unitypackage

Scroll to Top