Search Unity

Grids Pro: A library for hex, tri, polar and rect grids [New Dcoumentation for Grids 2]

Discussion in 'Assets and Asset Store' started by Herman-Tulleken, Jul 10, 2013.

  1. leegod

    leegod

    Joined:
    May 5, 2010
    Posts:
    2,476
    1. What is difference with Grids(100$) and Grids Binary(60$)?



    2. I bought Hex Grids(40$) and it provide same function with Grids(100$), but for only hex shape?



    3. If I need square type grid, can I refund Hex Grids and buy Grids?


    4. your email address has problem. I sent email just before and it returned back. <support@gamelogic.co.za>
     
  2. c-Row

    c-Row

    Joined:
    Nov 10, 2009
    Posts:
    853
    Unless I am mistaken you can pass the dimension of the cells as a Vector2 when creating the map.

    Code (csharp):
    1.     grid = RectGrid<MapCell>.Rectangle (rows, columns);
    2.  
    3.     map = new RectMap(cellDimensions)
    4.       .WithWindow(ExampleUtils.ScreenRect)
    5.       .AlignMiddelCenter(grid)
    6.       .AnchorCellMiddelCenter()
    7.       .To3DXY();
    This is my RectMap with using Vector2(1,1) as dimensions.



    This is the same grid with Vector2(1,2) and adjusted sizes of the background image.

     
    Last edited: Dec 1, 2014
    Herman-Tulleken likes this.
  3. Wambli

    Wambli

    Joined:
    Feb 14, 2013
    Posts:
    13
    Thanks, but I was asking about cell spacing not dimensions. I found in the doc that It's possible by calling the scale(x, y) method ;)
     
  4. Herman-Tulleken

    Herman-Tulleken

    Joined:
    Nov 20, 2009
    Posts:
    358
    You can implement your own map, and then you are free to arrange your cells any way you want. You can also affect the spacing by giving suitable cell dimensions (in code). For example, instead of giving the actual cell dimensions, you could double the y. For incremental spacing, you'd have to implement your own map. It's pretty straight forward though:

    http://gamelogic.co.za/grids/documentation-contents/quick-start-tutorial/making-your-own-maps/
     
  5. Herman-Tulleken

    Herman-Tulleken

    Joined:
    Nov 20, 2009
    Posts:
    358
    1. Grids Binary is only DLL, while Grids full you get the source code. We will stop selling Binary at some point, since almost no-one buys is.

    2. Yup, indeed.

    3. You can upgrade for the difference in price. So you only have to pay 60$ to upgrade to grids. To do this, you would just need to send us an email.

    4. I think our support email box got full. I expanded it, and it should work again. Thanks for pointing this out.
     
  6. Wambli

    Wambli

    Joined:
    Feb 14, 2013
    Posts:
    13
    Thanks, I'll take a look at custom maps creation then
     
  7. leegod

    leegod

    Joined:
    May 5, 2010
    Posts:
    2,476
    support@gamelogic.co.za this email still seems not working.


    So I run game at stresstest scene,
    it stops at 122,000 at desktop unity editor.
    So this is limit of maximum hex grids can be generated?
    Then more low number on mobile devices?
    How many it will be? I should test all devices?
     
  8. Herman-Tulleken

    Herman-Tulleken

    Joined:
    Nov 20, 2009
    Posts:
    358
    Yes, the editor cannot deal with it, but if you build and run it, it will work fine on desktop and web. For mobile devices you do need to test. There are several strategies for dealing with big grids, such as only displaying some cells, or generating a single mesh instead of separate objects. The best approach depends on the type of game, if you can give more information about what you want to do I can give you some advice.
     
    Last edited: Dec 3, 2014
  9. leegod

    leegod

    Joined:
    May 5, 2010
    Posts:
    2,476
    1. at HexWorld scene, if I increase hex numbers to 200 * 200 (total 40000), unity stops and I should quit forcibly. Is this normal?
    and even for 100 * 100 hex tiles, unity become extremely slow when play and stop editor.

    1-2. How to turn off number(like (0, 30) (5, 90)) show at editor?


    2. At this page,
    http://gamelogic.co.za/grids/examples/honeycomb/

    I followed steps, when play game, but following errors occurs.

    NullReferenceException: Object reference not set to an instance of an object
    Gamelogic.Examples.Game21.Honeycomb.Update () (at Assets/Game21/Honeycomb.cs:118)
     
  10. Wambli

    Wambli

    Joined:
    Feb 14, 2013
    Posts:
    13
    Hi, I've got a problem building the player.
    The FAQ says that I need to set .NET version of the project to .NET 4, but since I'm using UnityVS it appears that it continuously rolls back to Unity 3.5 .Net version. Is there any workaround on this?
    Thanks
     
  11. Herman-Tulleken

    Herman-Tulleken

    Joined:
    Nov 20, 2009
    Posts:
    358
    1-2. You can switch these off by opening Gizmos, and deselecting SpriteCell.
    gizmos.png

    This should already increase performance drastically in the editor.
    1. For very big grids, yes, it's normal for the editor to be slow. It's better to work with such big grids in code, or have them in segments that are easier to manage. (For example, you can create a mesh that represent a bunch of cells, similar to the technique used here: http://gamelogic.co.za/grids/featur...mesh-generation-script-with-proper-texturing/

    2. It seems the link got lost somehow; thank you for pointing this out. We wil fix it, but for now, simply do a search for HexBlock2, and link it into the Honey Comb Block Prefab field on the HoneyComb object in the scene.
     
  12. Herman-Tulleken

    Herman-Tulleken

    Joined:
    Nov 20, 2009
    Posts:
    358
    Hmmm it seems all my projects are in fact also set to .Net 3.5. It's possible that some change was introduced and we did not notice it. Do you get errors? It should work with 3.5, and it does on my side. I will investigate further, but if you are not having problems, 3.5 is probably OK.
     
  13. Wambli

    Wambli

    Joined:
    Feb 14, 2013
    Posts:
    13
    If I try to build one of the basic example (Unity 4.6, windows x86 platform using latest Grids dll), this is what I get
     
  14. leegod

    leegod

    Joined:
    May 5, 2010
    Posts:
    2,476
    Thx for reply.

    I have another questions.

    1. How can I stitch(or unite) seperate map (lets say, each map consisted by 10 * 10 hex grids) to one big map?

    2. So I want to make similar game map like Genio at your site's example games. To set various map tile textures on empty hex tiles, should I set each one by one manually? Are there tools or tips?


    Thanks.
     
    Last edited: Dec 5, 2014
  15. Herman-Tulleken

    Herman-Tulleken

    Joined:
    Nov 20, 2009
    Posts:
    358
    Oh OK, are you using the binary version of Grids? That may be the problem. Would you mind sending me a mail at herman@gamelogic.co.za so that we can sort this out for you?
     
  16. Herman-Tulleken

    Herman-Tulleken

    Joined:
    Nov 20, 2009
    Posts:
    358
    1. I have to think a bit what is the best strategy; I will get back to you. (My initial thinking is to modify the hex mesh generation script to only combine the meshes in sections. I will have to look at the code to see whether that is a good strategy).

    2. There are no tools out of the box at this stage. Depending on what you want, you may be able to provide it yourself. For example, if your textures are governed by rules, then you could implement a GridBehaviour and do the assignment in code. You should also be able to implement a wizard that allows you to change a bunch of selected cells in one go pretty easily. There are many possible workflows; if you can describe your ideal workflow, I can give some tips on how to proceed to get it or something close to it going.
     
  17. cygnusprojects

    cygnusprojects

    Joined:
    Mar 13, 2011
    Posts:
    767
    Any ETA on Unity 4.6 support using the new UI components?

    Edit: nevermind, figured it out.
     
    Last edited: Dec 9, 2014
  18. c-Row

    c-Row

    Joined:
    Nov 10, 2009
    Posts:
    853
    Hi Herman

    I am not sure if this wasn't already part of one of the 30 examples, but can I set up a grid where the tiles itself are divided into tiles, e.g. a hex map where the hex tiles consist of six individual triangles (similar to a rhombille grid)? I know I could just set up a triangle grid but I want those six triangles grouped together if that's somehow possible.
     
  19. Herman-Tulleken

    Herman-Tulleken

    Joined:
    Nov 20, 2009
    Posts:
    358
    Hey c-Row,

    Yup you can. It's easier to do it in code than with the editor, but it can even be set up in the editor.

    Remember, you can put anything as cells in a grid, including other grids. So

    Code (csharp):
    1. PointyHexGrid<FlatTriGrid<SomeCell>>  grid = ...
    is possible. There is also an example NestedGrid that ships with grids that you can check out. (Especially, check out how NestedGrid has been implemented). That example works for rects, but the same principles will apply to other grids. What makes that example nice is that the algorithms work on either the low-res or the entire high-res grids (not just single cells of the ;low-res grid). Let me know if that is enough to get you going.
     
    c-Row likes this.
  20. RDeluxe

    RDeluxe

    Joined:
    Sep 29, 2013
    Posts:
    117
    Hi Herman !

    I was wondering if your team was planning anything like a "grid painting" feature. We would like to use Unity as our level editor. Creating new objects (using our methods described before - I still need to give more details about that btw) is easy enough, but changing a tile sprite is a pain and involves multiples clicks.

    Did you start implementing anything on your side ?
     
  21. cygnusprojects

    cygnusprojects

    Joined:
    Mar 13, 2011
    Posts:
    767
    Hi Herman,

    I was wondering if there is a way to know in a behaviour which cell let's take for instance a flathexpoint is on the top, bottom, top left, bottom right, etc ...
    I checked the neighbors api/examples and can't seem to figure this one out.

    Any direction you can point me in?

    Edit: And yet again, figured it out (getting quit good in it), using the .center to check the position of the neighbors against the reference (clicked) cell. I guess this is a good way or is there even a better (faster) way?
     
    Last edited: Dec 10, 2014
  22. c-Row

    c-Row

    Joined:
    Nov 10, 2009
    Posts:
    853
    Great! I will look into the example and check out the editor as well (which I still haven't until today).
     
  23. rayfigs

    rayfigs

    Joined:
    Feb 8, 2009
    Posts:
    41
  24. Herman-Tulleken

    Herman-Tulleken

    Joined:
    Nov 20, 2009
    Posts:
    358
    Unfortunately not. Right now, we cannot give an ETA on this either (which means it won't be soon). It's definitely something we have in the back of heads, since level editing is definitely something we want to make possible.
     
  25. Herman-Tulleken

    Herman-Tulleken

    Joined:
    Nov 20, 2009
    Posts:
    358
    I am not sure I understand exactly what you mean. One thing to keep in mind is that there are constants defined such as FlatHexPoint.North which may be helpful for what you want to do. For instance, with the following

    Code (csharp):
    1. var point1 = point0 + FlatHexPoint.North
    point1 will be to the north of point0.

    You can also use this backwards. If two points are neighbors, then

    Code (csharp):
    1. if(point1 - point0 == FlatHexPoint.North)
    2. {
    3.    //then point1 is to the north of point0
    4. }
    If this is not exactly what you want, please let me know.
     
  26. Herman-Tulleken

    Herman-Tulleken

    Joined:
    Nov 20, 2009
    Posts:
    358
    Indeed. You will probably be able to program the core mechanics in an hour or two once you know the library a bit. The AI may take a bit longer (I am not sure how sophisticated it is). But Grids will definitely help you :)
     
  27. rayfigs

    rayfigs

    Joined:
    Feb 8, 2009
    Posts:
    41
    Sweet. Would Hex do the trick or would I need full on Grids?

    Many thanks ,
    Ray
     
  28. Herman-Tulleken

    Herman-Tulleken

    Joined:
    Nov 20, 2009
    Posts:
    358
    For that game, Hex Grids would be perfect :)
     
  29. wx3labs

    wx3labs

    Joined:
    Apr 5, 2014
    Posts:
    77
    I'm getting errors like:

    "Assets/Gamelogic/Plugins/Grids/Unity/EditorSupport/GridBuilders/TileGridBuilder.cs(241,34): error CS0117: `Gamelogic.Grids.__CompilerHints' does not contain a definition for `__CompilerHint__Rect'"

    It does seem that TileGridBuilder is trying to call methods on CompilerHints.cs that don't exist?
     
  30. rosskinsella0

    rosskinsella0

    Joined:
    Jun 6, 2014
    Posts:
    8
    Hey,

    I want to implement a box select on a RectTileGrid.

    - Currently I am creating a Rect in terms of screen coordinates:
    Screen Shot 2014-12-14 at 20.38.48.png

    - I would like to be able to retrieve a collection of Cells by passing GridBehavior this Rect, in a manner similar to the below, where I get a single cell based on mouse coordinates.

    public class CustomBehaviour : GridBehaviour<RectPoint> {
    public void OnClick() {
    MyCell cell = (MyCell) Grid[MousePosition];
    }
    }

    I'v spent a couple hours looking through the docs and forums and had no luck.

    Thanks,
    Ross.
     
  31. leegod

    leegod

    Joined:
    May 5, 2010
    Posts:
    2,476
    1. So if I want to make somewhat large hexagon map like minecraft (not exactly that huge map, but like 500 * 500 or 1000 * 1000 size). Are there good way to make like this big size? Because even 100 * 100 unity itself becoming too slow when play/stop game. Can't work if for 200 * 200.

    2. For mobile device like Galaxy S3, how much large size map can be loaded on it?

    Thanks.
     
  32. Herman-Tulleken

    Herman-Tulleken

    Joined:
    Nov 20, 2009
    Posts:
    358
    Which version of Grids are you using? It's possible a few lines have been omitted by mistake (and escaped our notice because of conditional compilation),
     
  33. Herman-Tulleken

    Herman-Tulleken

    Joined:
    Nov 20, 2009
    Posts:
    358
    Hi Ross,

    To get a rectangle around the MousePosition, you could simply something like this:

    Code (csharp):
    1. private readonly static List<RectPoint> SelectionRect = new List
    2. {
    3.    new RectPoint(-1, -1), new RectPoint(-1, 0), new RectPoint(-1, 1),
    4.    new RectPoint(0, -1), new RectPoint(0, 0), new RectPoint(0, 1),
    5.    new RectPoint(1, -1), new RectPoint(1, 0), new RectPoint(1, 1)
    6. }
    7.  
    8. public OnClick()
    9. {
    10.     var selectedCells = SelectionRect.Select(p => p + MousePosition).Where(Grid.Contains);
    11. }
    Let me know if this does the trick.

    It is of course easy to generate a SelectionRectangle dynamically if you needed to:

    Code (csharp):
    1. selectionRect = new List<RectPoint>();
    2.  
    3. for(int i = -radius; i <= radius; i++)
    4.    for(int j = -radius; j <= radius; j++)
    5.       selectionRect.Add(new RectPoint(i, j));
     
  34. Herman-Tulleken

    Herman-Tulleken

    Joined:
    Nov 20, 2009
    Posts:
    358
    There is not a one-fits-all solution, and you'd have to do a few experiments on your target device.

    Here are a few questions:
    • What is the nature of the camera? Are there limits on the size of the map rendered at a time? Does the camera move freely, or is it somehow constrained? (For example, orthographic, non-rotating cameras have easier solutions than free-form cameras.)
    • What is the nature of your cells? Are they textured with different textures? Or the same textured colored differently? Do they have objects? And are these 3D? How many objects are typically visible at a time? Are they static, or do they move?
    • What is the nature of your agents? How many are there (typically)? Do they move continuously, or discretely?
    • What is the nature of your simulation? Is it intense? Does everything have to run all the time, or can it be limited to what is visible or some other suitable range?
    There are a few general solutions. One is to create chunks of meshes for groups of cells. Another is to move cells that drop off from view to positions of cells coming into view (only possible under certain conditions).

    All depends on the details of what you want to do.
     
  35. wx3labs

    wx3labs

    Joined:
    Apr 5, 2014
    Posts:
    77
    I'm using Hex Grids 1.9, which I think is the latest version.
     
  36. leegod

    leegod

    Joined:
    May 5, 2010
    Posts:
    2,476
    I am testing at HexWorld scene, and questioned.

    And another problem. Texture does not change after I assign.

    It just change color, but not concrete shape of original texture.
    (If I change texture of hex mesh to some brick-filled brown texture, its color only changed, but brick shape does not show)
     
  37. Herman-Tulleken

    Herman-Tulleken

    Joined:
    Nov 20, 2009
    Posts:
    358
    OK, then it's indeed an oversight on our side; sorry for the inconvenience. The fix is simple - just remove the seven lines that give errors. (We will publish an update with the fix too). Thanks for pointing out this issue!
     
  38. Herman-Tulleken

    Herman-Tulleken

    Joined:
    Nov 20, 2009
    Posts:
    358
    If you use a SpriteCell, and if you use the grid builders (in the editor), then you can set the texture in code by making your own GridBehaviour, like the one below:

    Code (csharp):
    1. public class TestTexture : GridBehaviour<PointyHexPoint>
    2. {
    3.     public Sprite newSprite;
    4.  
    5.     override public void InitGrid()
    6.     {
    7.         foreach (var point in Grid)
    8.         {
    9.             Grid[point].GetComponentInChildren<SpriteRenderer>().sprite = newSprite;
    10.         }
    11.     }
    12. }
    If you construct your grids in code from scratch, the line that assigns the new sprite can be moved to the loop where you instantiate cells.

    Let me know if this works, or if you are perhaps using a different method for building grids.
     
  39. leegod

    leegod

    Joined:
    May 5, 2010
    Posts:
    2,476
    @Herman Tulleken
    Thx for reply.

    But at HexWorld scene (from your asset's example, 3d folder), I don't use spritecell, and just want to change haxagon tile's texture. (of course we should change its texture to our own for releasing game on market)

    So at attached file, if I assing(not via code, but drag * drop to some tile on scene screen) my custom texture, it just change color.
     

    Attached Files:

    • map3.PNG
      map3.PNG
      File size:
      943.2 KB
      Views:
      847
    Last edited: Dec 17, 2014
  40. Herman-Tulleken

    Herman-Tulleken

    Joined:
    Nov 20, 2009
    Posts:
    358
    Oh, OK, that makes more sense. So there are two situations:

    If you want all textures to be the same, change the texture on the prefab, not the instances. Also, the block that we ship's UVs are probably are not correct (the model was exported from Sketchup), so you may need to remodel it for your purposes.

    If you want different cells to have different textures, then you should assign the textures in code (otherwise, they will be overwritten every time the grid is rebuilt). If you don't ever want to adjust the grid, you can remove the grid builder script, and then change the textures. Again, the model's UVs are probably not correct, and you may need to make your own block.
     
  41. shubhank008

    shubhank008

    Joined:
    Apr 3, 2014
    Posts:
    107
  42. EchoE

    EchoE

    Joined:
    Jul 8, 2012
    Posts:
    6
    A while back I bought Grids Binary version. It seems you've discontinued this in the asset store now, so I was wondering, is it possible for me to upgrade to the full version somehow? And just pay the difference?
     
  43. leegod

    leegod

    Joined:
    May 5, 2010
    Posts:
    2,476
    So at attached image, I want to implement function of [click some tile and get info (what clicked, position, etc)].

    But it currently seems not done yet.

    You already done it?
     

    Attached Files:

    • map3.PNG
      map3.PNG
      File size:
      943.2 KB
      Views:
      840
  44. SoftwareGeezers

    SoftwareGeezers

    Joined:
    Jun 22, 2013
    Posts:
    902
    Are there any examples of realtime games? I'm interested in making a tile-based game on mobile and want features like a monster chasing after a player and a playing setting a destination to move too. All the examples are pretty much turn-based with no indicator what the AI is like for fast operation. Also, from the sounds of it there is no tile editing, so how would one piece together a dungeon from tiles? Let's say something like Dungeon Master:



    I'd look to use a top-down map editor for a level and have creatures use A* navigation to chase the player. Any games like this using Grids?
     
  45. Herman-Tulleken

    Herman-Tulleken

    Joined:
    Nov 20, 2009
    Posts:
    358
    It is indeed possible, although you may need to do some work for your special conditions. (For instance, to limit the range, and so on).

    Can you give a bit more detail exactly about what you want to do (the exact conditions for a cell to be highligted).

    The second part, is relatively easy, but again you should do a bit of work. I presume you want to move smoothly and perhaps play an animation. In this case, you would probably implement a coroutine that does the movement and drives the animation. You would use two grid points, convert those to world points using a map, and then lerp between the two positions (possibly playing the animation in the same or even different coroutine).

    (If you need more explanation I can sketcch out the code; let me know.)
     
  46. Herman-Tulleken

    Herman-Tulleken

    Joined:
    Nov 20, 2009
    Posts:
    358
    It is possible, and since we discontinued the binary you can do it for free :) I sent you an email too.
     
  47. Herman-Tulleken

    Herman-Tulleken

    Joined:
    Nov 20, 2009
    Posts:
    358
    It's not done for 3D grids, but you can easily add it in the GridBehaviour:

    Code (csharp):
    1. public void Update()
    2. {
    3.     if (Input.GetMouseButtonDown(0))
    4.     {
    5.         var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
    6.  
    7.         RaycastHit hit;
    8.  
    9.         if (Physics.Raycast(ray, out hit))
    10.         {
    11.             Vector3 worldPosition = gridRoot.transform.InverseTransformPoint(hit.point);
    12.             Debug.Log("mouse pos: " + Input.mousePosition + ", world_pos:" + worldPosition);
    13.  
    14.             var hexPoint = Map[worldPosition];
    15.  
    16.             if (Grid.Contains(hexPoint))
    17.             {
    18.                 Debug.Log("Grid hit: " + hexPoint);
    19.             }
    20.         }
    21.     }
    22. }
     
  48. Herman-Tulleken

    Herman-Tulleken

    Joined:
    Nov 20, 2009
    Posts:
    358
    From the top of my head, we do not have real-time examples that specifically uses path finding. Here is something close, although the agents do not follow A* paths.

    http://www.gamelogic.co.za/examples/30-games-in-30-days/game26/

    (In general, the path finding will of course only be called on discrete events, such as when the player changes cells or a monster spawns, or the typography changes).

    As for level editing, we do not provide support for that at this moment. We have had requests for it, and it's on our minds, but it is a big addition.

    To do it with grids, you may need to implement a cell that allows that kind of editing (by extending one of our cell types). For a specific game that may not be so much work depending on the level of sophistication you need. You would still be able to take advantage of other Grids features.

    Please let me know if I can give you more information.
     
  49. SoftwareGeezers

    SoftwareGeezers

    Joined:
    Jun 22, 2013
    Posts:
    902
    Okay, thanks. It seems Grids is more about creating grid based games rather than tile-map based, for which I want a tile editor and A* engine.
     
  50. leegod

    leegod

    Joined:
    May 5, 2010
    Posts:
    2,476
    So above code works well, I tweaked as when I click some tile, its color turn to black.

    Code (CSharp):
    1.     public void Update()
    2.     {
    3.         if (Input.GetMouseButtonDown(0))
    4.         {
    5.             var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
    6.             RaycastHit hit;
    7.  
    8.             if (Physics.Raycast(ray, out hit))
    9.             {
    10.                 Vector3 worldPosition = transform.InverseTransformPoint(hit.point);
    11.  
    12.                 Debug.Log("mouse pos: " + Input.mousePosition + ", world_pos:" + worldPosition);
    13.  
    14.                 var hexPoint = Map[worldPosition];
    15.  
    16.                 if (Grid.Contains(hexPoint))
    17.                 {
    18.                     Debug.Log("Grid hit: " + hexPoint);
    19.                     Grid.GetCell(hexPoint).Color = ExampleUtils.Colors[16];
    20.                    
    21.                 }
    22.  
    23.             }
    24.         }
    25.     }

    but when I click image like triumphal arch object, its just below tile become black. I didn't touched this tile at all, but just touch to above arch object, its below tile become clicked.

    Why? I just want to know.
     

    Attached Files:

    • map1.png
      map1.png
      File size:
      217.6 KB
      Views:
      796