Gamelogic
  • Home
  • Blog
  • Tools
    • Grids 2 (for Unity)
      • Features
      • Documentation
    • Grids 1 (Legacy, for Unity)
      • 30 games in 30 days
      • Features
      • Tutorials, Documentation, and FAQ
      • Games made with Grids for Unity
      • Examples
      • What is new?
      • Grid Prototypes and Previews
      • Buy
    • Extensions
    • Colors
      • Features
      • Documentation and tutorials
      • Buy
    • Words
      • Features
      • Documentation
      • Buy
    • Abstract Strategy
      • Features
      • Documentation and tutorials
      • Examples
      • Buy
    • Match
      • Features
    • Grids (for GameMaker)
      • 30 games in 30 days
      • Features
      • Documentation
      • Buy
  • Buy
  • Articles
  • Support
    • Knowledge Base
    • Email Support
  • About
    • Meet our team

Making your own grid shapes

CustomEditorShapes
To make your own grid shape:

  1. Extend a new class from CustomGridBuilder.
  2. Override the MakeGrid method, and return the grid of the required shape from this method.
  3. Attach this component to the same game object as the builder you are using, and set the shape to Custom on the grid builder in the inspector.

You can use all the ways of creating new shapes in code available:

  • Static functions
  • Shape builder functions
  • Custom containment function

See Constructing Grids for more information on how to build grids in code.

It’s a good idea to test that the point type is of the right type, and print an error message if the test fails. This will prevent someone from trying to use your grid builder with the wrong type of grid.

Also note the cast before returning the grid. The cast is necessary because the point type of the grid created in code is more specific than the one required, and C# cannot do the conversion automatically.

Here is an example that makes a hexagon ring:

C#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
public class RingGridBuilder : CustomGridBuilder
{
public int size;
 
public override IGrid<TCell, TPoint> MakeGrid<TCell, TPoint>()
{
if (typeof(TPoint) != typeof(PointyHexPoint))
{
Debug.LogError("You can only use this GridBuilder with pointy hex grids", this);
}
 
return (IGrid<TCell, TPoint>)PointyHexGrid<TCell>
   .BeginShape()
  .Hexagon(size)
  .Translate(size - 2, size - 2)
  .Difference()
  .Hexagon(size - 1)
   .EndShape();
}
}

Here is an example that shows how to set it up:

(Import Grids, import the package, and open the CustomShapesInTheEditor scene.)

CustomShapesInTheEditor.unitypackage

Share this:

  • Click to share on Facebook (Opens in new window)
  • Click to share on Twitter (Opens in new window)
  • Click to share on LinkedIn (Opens in new window)
  • Click to share on Reddit (Opens in new window)
  • Click to share on Pinterest (Opens in new window)

Related

  1. Making your own maps  Editor grids support 2D maps that are converted to 3D...
  2. Working with GridBehaviours  GridBehaviours* are what you use to add more behavior to...
  3. Making your own cells  Grids come with a few minimal cells, but for your...
  4. Example with 2D Toolkit  This is a simple example that shows how to use...

  • Grid Index
  • Introduction and Terminology
  • Working with grids in the editor
  • Working with GridBehaviours
  • Making your own grid shapes
  • Making your own maps
  • Quick-Start Tutorial
  • Working with Maps
  • Constructing Grids
Follow us on Twitter
My Tweets
Meta
  • Log in
  • Entries RSS
  • Comments RSS
  • WordPress.org
  • Home
  • Features
  • Blog
  • About
  • 14 Eglin Road, Sunninghill, Johannesburg, South Africa
  • support@gamelogic.co.za
Stay Connected
  • Facebook
  • Google
  • Linkedin
  • Rss
  • Twitter
  • Gamelogic © 2013