Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

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. Herman-Tulleken

    Herman-Tulleken

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

    We are doing some tests on our side; we will get back to you shortly to let you know what's up.
     
    Last edited: Nov 21, 2013
  2. The Bag

    The Bag

    Joined:
    May 28, 2012
    Posts:
    24
    Thanks, I think it's to do with generic value types and AOT compilation.
    http://docs.xamarin.com/guides/ios/advanced_topics/limitations/

    http://docs.unity3d.com/Documentation/Manual/TroubleShooting.html

     
  3. Herman-Tulleken

    Herman-Tulleken

    Joined:
    Nov 20, 2009
    Posts:
    358
    Update:

    With appropriate hinting, we managed to get our examples to run on iOS. I'm still looking into a few things, and making sure the algorithms work, then I'll give some more information on exactly how to do this, but so far, the workaround is not too hectic.
     
  4. Herman-Tulleken

    Herman-Tulleken

    Joined:
    Nov 20, 2009
    Posts:
    358
    OK, here is a set of hints that can be used. You have to call the appropriate method anywhere in your program for each grid that you use, and change the type Cell to whatever type you have in your grid. (We tried using dummy methods that really do nothing, but struggle to have them not strip away. The following works with default options.)

    This is not the most elegant solution; we will see if there is a better way to do it. It may also not be complete; we are systemtaically working our way through the entire library to see what else may be needed.

    Code (csharp):
    1.  
    2. /** Call this method if you use a RectGrid
    3.    
    4.     Typically like this:
    5.     if(!__CompilerHint__Rect()) return;
    6. */
    7. public static bool __CompilerHint__Rect()
    8. {
    9.     var grid = new RectGrid<Cell[]>(1, 1);
    10.  
    11.     foreach(var point in grid)
    12.     {
    13.         grid[point] = new Cell[1];
    14.     }
    15.  
    16.     var shapeStorageInfo = new ShapeStorageInfo<RectPoint>(new IntRect(), p => true);
    17.     var shapeInfo = new RectShapeInfo<Cell>(shapeStorageInfo);
    18.  
    19.     return grid[grid.First()][0] == null || shapeInfo.Translate(RectPoint.Zero) != null;
    20. }
    21.  
    22.  
    23. /** Call this method if you use a DiamondGrid
    24.    
    25.     Typically like this:
    26.     if(!__CompilerHint__Diamond()) return;
    27. */
    28. public static bool __CompilerHint__Diamond()
    29. {
    30.     var grid = new DiamondGrid<Cell[]>(1, 1);
    31.  
    32.     foreach(var point in grid)
    33.     {
    34.         grid[point] = new Cell[1];
    35.     }
    36.  
    37.     var shapeStorageInfo = new ShapeStorageInfo<DiamondPoint>(new IntRect(), p => true);
    38.     var shapeInfo = new DiamondShapeInfo<Cell>(shapeStorageInfo);
    39.  
    40.     return grid[grid.First()][0] == null || shapeInfo.Translate(DiamondPoint.Zero) != null;
    41. }
    42.  
    43.  
    44. /** Call this method if you use a PointyHexGrid
    45.    
    46.     Typically like this:
    47.     if(!__CompilerHint__PointyHex()) return;
    48. */
    49. public static bool __CompilerHint__PointyHex()
    50. {
    51.     var grid = new PointyHexGrid<Cell[]>(1, 1);
    52.  
    53.     foreach(var point in grid)
    54.     {
    55.         grid[point] = new Cell[1];
    56.     }
    57.  
    58.     var shapeStorageInfo = new ShapeStorageInfo<PointyHexPoint>(new IntRect(), p => true);
    59.     var shapeInfo = new PointyHexShapeInfo<Cell>(shapeStorageInfo);
    60.  
    61.     return grid[grid.First()][0] == null || shapeInfo.Translate(PointyHexPoint.Zero) != null;
    62. }
    63.  
    64.  
    65. /** Call this method if you use a FlatHexGrid
    66.    
    67.     Typically like this:
    68.     if(!__CompilerHint__FlatHex()) return;
    69. */
    70. public static bool __CompilerHint__FlatHex()
    71. {
    72.     var grid = new FlatHexGrid<Cell[]>(1, 1);
    73.  
    74.     foreach(var point in grid)
    75.     {
    76.         grid[point] = new Cell[1];
    77.     }
    78.  
    79.     var shapeStorageInfo = new ShapeStorageInfo<FlatHexPoint>(new IntRect(), p => true);
    80.     var shapeInfo = new FlatHexShapeInfo<Cell>(shapeStorageInfo);
    81.  
    82.     return grid[grid.First()][0] == null || shapeInfo.Translate(FlatHexPoint.Zero) != null;
    83. }
    84.  
    85.  
    86. /** Call this method if you use a PointyTriGrid
    87.    
    88.     Typically like this:
    89.     if(!__CompilerHint__PointyTri()) return;
    90. */
    91. public static bool __CompilerHint__PointyTri()
    92. {
    93.     var grid = new FlatHexGrid<Cell[]>(1, 1);
    94.  
    95.     foreach(var point in grid)
    96.     {
    97.         grid[point] = new Cell[1];
    98.     }
    99.  
    100.     var shapeStorageInfo = new ShapeStorageInfo<PointyTriPoint>(new IntRect(), p => true);
    101.     var shapeInfo = new PointyTriShapeInfo<Cell>(shapeStorageInfo);
    102.  
    103.     return grid[grid.First()][0] == null || shapeInfo.Translate(FlatHexPoint.Zero) != null;
    104. }
    105.  
    106.  
    107. /** Call this method if you use a FlatTriGrid
    108.    
    109.     Typically like this:
    110.     if(!__CompilerHint__FlatTri()) return;
    111. */
    112. public static bool __CompilerHint__FlatTri()
    113. {
    114.     var grid = new PointyHexGrid<Cell[]>(1, 1);
    115.  
    116.     foreach(var point in grid)
    117.     {
    118.         grid[point] = new Cell[1];
    119.     }
    120.  
    121.     var shapeStorageInfo = new ShapeStorageInfo<FlatTriPoint>(new IntRect(), p => true);
    122.     var shapeInfo = new FlatTriShapeInfo<Cell>(shapeStorageInfo);
    123.  
    124.     return grid[grid.First()][0] == null || shapeInfo.Translate(PointyHexPoint.Zero) != null;
    125. }
    126.  
    127.  
    128. /** Call this method if you use a PointyRhombGrid
    129.    
    130.     Typically like this:
    131.     if(!__CompilerHint__PointyRhomb()) return;
    132. */
    133. public static bool __CompilerHint__PointyRhomb()
    134. {
    135.     var grid = new PointyHexGrid<Cell[]>(1, 1);
    136.  
    137.     foreach(var point in grid)
    138.     {
    139.         grid[point] = new Cell[1];
    140.     }
    141.  
    142.     var shapeStorageInfo = new ShapeStorageInfo<PointyRhombPoint>(new IntRect(), p => true);
    143.     var shapeInfo = new PointyRhombShapeInfo<Cell>(shapeStorageInfo);
    144.  
    145.     return grid[grid.First()][0] == null || shapeInfo.Translate(PointyHexPoint.Zero) != null;
    146. }
    147.  
    148.  
    149. /** Call this method if you use a FlatRhombGrid
    150.    
    151.     Typically like this:
    152.     if(!__CompilerHint__FlatRhomb()) return;
    153. */
    154. public static bool __CompilerHint__FlatRhomb()
    155. {
    156.     var grid = new FlatHexGrid<Cell[]>(1, 1);
    157.  
    158.     foreach(var point in grid)
    159.     {
    160.         grid[point] = new Cell[1];
    161.     }
    162.  
    163.     var shapeStorageInfo = new ShapeStorageInfo<FlatRhombPoint>(new IntRect(), p => true);
    164.     var shapeInfo = new FlatRhombShapeInfo<Cell>(shapeStorageInfo);
    165.  
    166.     return grid[grid.First()][0] == null || shapeInfo.Translate(FlatHexPoint.Zero) != null;
    167. }
    168.  
    169.  
    170. /** Call this method if you use a CairoGrid
    171.    
    172.     Typically like this:
    173.     if(!__CompilerHint__Cairo()) return;
    174. */
    175. public static bool __CompilerHint__Cairo()
    176. {
    177.     var grid = new PointyHexGrid<Cell[]>(1, 1);
    178.  
    179.     foreach(var point in grid)
    180.     {
    181.         grid[point] = new Cell[1];
    182.     }
    183.  
    184.     var shapeStorageInfo = new ShapeStorageInfo<CairoPoint>(new IntRect(), p => true);
    185.     var shapeInfo = new CairoShapeInfo<Cell>(shapeStorageInfo);
    186.  
    187.     return grid[grid.First()][0] == null || shapeInfo.Translate(PointyHexPoint.Zero) != null;
    188. }
    189.  
     
  5. MikeTon

    MikeTon

    Joined:
    Jan 10, 2013
    Posts:
    57
    Hey I just bought this and are liking the examples. However I'm more familiar with javascript.

    Any examples on how to use Grids with Javascript?

    I'm struggling with compilation order when trying to extend with javascript.

    Let me know your thoughts. Thanks for your attention.

    -Mike
     
  6. Herman-Tulleken

    Herman-Tulleken

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

    I am not so familiar with the syntax necessary to call all the C# constructs from JavaScript.

    However, I did manage to get the compilation order sorted (but then run into issues with generics and such - maybe you already know how to solve those). Notice I also had to restructure the NGUI stuff a bit to get it to compile. The highlighted folder is where your Javascript scripts can go.

    $FolderStructure.png

    I will play around some more and post a Javascript example later today.

    Edit 1: For some reason the forum does not want to include my picture.

    Here is a link to it:
    http://www.gamelogic.co.za/images/FolderStructure.png

    Edit 2:

    Here is a JavaScript example that works. It's a simplified version of the PointyHexTest example that comes with the library (you can just replace PointyHexTest with this script on the PointyHexTest game object in the PointyHexTest scene). The one construct that I could not get to compile was specifying the type of the map. I am sure there is just something small in the syntax I don't get, but while I figure it out, the following can maybe help you get going. (It's for this reason that I removed #pragma strict.)

    Code (csharp):
    1. //#pragma strict
    2. //Not using strict to remove the need for specifying a type for map
    3.  
    4. import Gamelogic.Grids;
    5.  
    6. var HexDimensions: Vector2 = new Vector2(74, 84);  
    7.  
    8.     public var cellPrefab : Cell;
    9.     public var testTexture : Texture2D ;
    10.     public var root : GameObject;
    11.    
    12.     var grid : PointyHexGrid.<Cell>;
    13.     var map; //Giving map the type IMap3D.<PointyHexPoint> gives compiler error - not sure why
    14.  
    15. function Start ()
    16. {
    17.     BuildGrid();
    18. }
    19.  
    20. function Update ()
    21. {
    22.     if(Input.GetMouseButtonDown(0))
    23.     {          
    24.         var worldPosition = ExampleUtils.ScreenToWorld_NGUI(root, Input.mousePosition);
    25.         var hexPoint = map[worldPosition];
    26.            
    27.         if(grid.Contains(hexPoint))
    28.         {
    29.             grid[hexPoint].HighlightOn = !grid[hexPoint].HighlightOn;
    30.         }
    31.     }          
    32. }
    33.  
    34. function BuildGrid()
    35. {
    36.     var width:int = 3;
    37.     var height:int = 5;
    38.  
    39.     Debug.Log(HexDimensions);
    40.  
    41.     grid = PointyHexGrid.<Cell>.Rectangle(width, height);
    42.  
    43.     map = new PointyHexMap(HexDimensions)
    44.         .AnchorCellMiddleCenter()
    45.         .WithWindow(ExampleUtils.ScreenRect)
    46.         .AlignMiddleCenter(grid)
    47.         .To3DXY();     
    48.  
    49.     for(var point:PointyHexPoint in grid)
    50.     {
    51.         var cell = Instantiate(cellPrefab);
    52.         var worldPoint = map[point];
    53.  
    54.         cell.transform.parent = root.transform;
    55.         cell.transform.localScale = Vector3.one;
    56.         cell.transform.localPosition = worldPoint;
    57.  
    58.         cell.SetColor(ExampleUtils.colors[point.GetColor3_7()]);
    59.         cell.SetText(point.ToString());
    60.         grid[point] = cell;
    61.     }
    62. }
     
    Last edited: Nov 25, 2013
  7. The Bag

    The Bag

    Joined:
    May 28, 2012
    Posts:
    24
    Thanks, I shall give this a try
     
  8. MikeTon

    MikeTon

    Joined:
    Jan 10, 2013
    Posts:
    57
    Thanks Herman. That got things working.

    It was tricky however, it looks like putting the entirety of GameLogicGrids in the Plugin folder, got things to match Unity's compile order.

    Any thoughts on support for Javascript users in the future?

    ToolKit2D I recall has a function that actually re-ordered the directory for Javascript users. That might be a possible approach?

    Anyhows really liking the framework so far. And I really appreciate the quick support and turnaround.

    -Mike

     
  9. Herman-Tulleken

    Herman-Tulleken

    Joined:
    Nov 20, 2009
    Posts:
    358
    Glad to hear you have it working.

    We did not realise that JavaScript might pose issues :eek: But we are definitely thinking about it now!

    The one thing is that we separate the examples from the actual library code; I think it's actually Cell and the like (that's part of an example script, not the library proper) that would not compile initially. Reordering the folders automatically is a good idea. We will definitely look into it!

    An alternative would be to supply separate JavaScript classes (and then JavaScript versions of classes like Cell. (We actually did not expect so many people to use the example components directly. Now that we know they do, it's worth considering how to make them as usable as possible).
     
    Last edited: Nov 25, 2013
  10. The Bag

    The Bag

    Joined:
    May 28, 2012
    Posts:
    24
    Hi this works great with generating the grids, however the algorithms are still an issue as they seem to rely heavily on reflection. I'm using A* and I get this output in xcode:

    Code (csharp):
    1.  
    2. ExecutionEngineException: Attempting to JIT compile method 'System.Collections.Generic.GenericEqualityComparer`1<Gamelogic.Grids.PointyHexPoint>:.ctor ()' while running with --aot-only.
    3.  
    4.   at System.Reflection.MonoCMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0
    5. Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.
    6.   at System.Reflection.MonoCMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0
    7.   at System.Reflection.MonoCMethod.Invoke (BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0
    8.   at System.Reflection.ConstructorInfo.Invoke (System.Object[] parameters) [0x00000] in <filename unknown>:0
    9.   at System.Activator.CreateInstance (System.Type type, Boolean nonPublic) [0x00000] in <filename unknown>:0
    10.   at System.Activator.CreateInstance (System.Type type) [0x00000] in <filename unknown>:0
    11.   at System.Collections.Generic.EqualityComparer`1[Gamelogic.Grids.PointyHexPoint]..cctor () [0x0001e] in /Users/builduser/buildslave/monoAndRuntimeClassLibs/build/mcs/class/corlib/System.Collections.Generic/EqualityComparer.cs:41
    12. Rethrow as TypeInitializationException: An exception was thrown by the type initializer for System.Collections.Generic.EqualityComparer`1
    13.   at System.Collections.Generic.Dictionary`2[Gamelogic.Grids.PointyHexPoint,Gamelogic.Grids.PointyHexPoint].Init (Int32 capacity, IEqualityComparer`1 hcp) [0x00012] in /Users/builduser/buildslave/monoAndRuntimeClassLibs/build/mcs/class/corlib/System.Collections.Generic/Dictionary.cs:266
    14.   at System.Collections.Generic.Dictionary`2[Gamelogic.Grids.PointyHexPoint,Gamelogic.Grids.PointyHexPoint]..ctor () [0x00006] in /Users/builduser/buildslave/monoAndRuntimeClassLibs/build/mcs/class/corlib/System.Collections.Generic/Dictionary.cs:224
    15.   at Gamelogic.Grids.Algorithms.AStar[TBHexCell,PointyHexPoint] (IGrid`2 grid, PointyHexPoint start, PointyHexPoint goal, System.Func`3 heuristicCostEstimate, System.Func`2 isAccessible) [0x00030] in /Users/[...]/GamelogicGrids/Plugins/Gamelogic/Grids/Util/Algorithms.cs:174
    16.   at TurnBasedGameManager.OnTap (.TapGesture tap_gesture) [0x00212] in /Users/[...]/Scripts/TurnBasedGameManager.cs:589
    I'm trying to workout what I should be hinting for this one.

    Edit: I'm really getting nowhere fast with this, so any help would be appreciated.

    Edit 2: I've hacked together a non-generic version, it's not pretty but it does what I need
     
    Last edited: Nov 26, 2013
  11. Herman-Tulleken

    Herman-Tulleken

    Joined:
    Nov 20, 2009
    Posts:
    358
    This is indeed a very sticky problem.

    I have managed to solve the very specific issue you mentioned by giving the dictionary a custom IEqualityComparer, as explained here:

    (From http://docs.xamarin.com/guides/ios/advanced_topics/limitations/)

    However, this exposes a new issue, and that is that the equality method used for Contains and Remove on List is not working. We have not been able to overcome this.

    So far, it looks like there may be two solutions:
    • One is to provide non-generic algorithms (we can do this fairly easily; a lot of our code is already generated from text templates).
    • The second is to make points reference types (another customer had success following this approach). This is obviously not ideal in terms of garbage collection, so we need to investigate this.

    Either way, we are working towards a complete solution, and will keep you posted.
     
  12. Herman-Tulleken

    Herman-Tulleken

    Joined:
    Nov 20, 2009
    Posts:
    358
    Good news :)

    We found a solution to the problem (suggested to us by a client) that is better than the two methods I initially thought of. The basic idea is to use alternative methods for Contains, Remove, and IndexOf for Lists of points. So far, it seems to work really well. We are still thinking whether these should be extension methods, or whether we should roll out our own list type, or inherit from the base type, but should send an update to the Asset Store soon. If you have any feedback on the method we choose, please let us know. [It won't affect the library interface, but it will affect how you call the three culprit methods in your own lists].

    (Anyone that needs an urgent patch can send me an email herman@gamelogic.co.za ).
     
  13. Jonathan-Bailey

    Jonathan-Bailey

    Joined:
    Aug 12, 2013
    Posts:
    79
    Hi Everyone,

    Based on some feedback we got about Grids, we have developed a prototype for a new system in which you can see and edit grids in the Unity editor.

    We made a page for it here:
    http://gamelogic.co.za/custom-editors-for-grids-and-cells/

    We’ll be updating it as we figure out how it should work and we’d love any feedback.

    This version now updates the grid dynamically when you edit the properties, and we implemented the Lights Out game as an example. (So "levels" are puzzles).

    To give you an idea of how terse the code is using the visual editor, here is all the code for the entire game:

    Code (csharp):
    1. using System.Linq;
    2. using Gamelogic.Grids;
    3. using UnityEngine;
    4.  
    5. public class LightsOut : GLMonoBehaviour
    6. {
    7.     public Grid grid;
    8.     private bool gameOver;
    9.  
    10.     public void OnCellClicked(PointyHexPoint point)
    11.     {
    12.         if(gameOver) return;
    13.  
    14.         var gridData = grid.GridData;
    15.         foreach (var neighbor in gridData.GetNeighbors(point))
    16.         {
    17.             gridData[neighbor].ToggleHighlight();
    18.         }
    19.  
    20.         CheckGameEnd();
    21.     }
    22.  
    23.     private void CheckGameEnd()
    24.     {
    25.         var gridData = grid.GridData;
    26.         if (gridData.All(x => !gridData[x].HighlightOn))
    27.         {
    28.             Debug.Log("You win!");
    29.             gameOver = true;
    30.         }
    31.     }
    32. }
    33.  
    $GridEditor.png
     
  14. c-Row

    c-Row

    Joined:
    Nov 10, 2009
    Posts:
    847
    Whoa, sexy. :cool: That should come in handy next time.
     
  15. robertwahler

    robertwahler

    Joined:
    Mar 6, 2013
    Posts:
    43
    Very interesting! Thanks for posting a preview of visual grid editing. I've been following your product's release closely. Building grids programmatically is a must have feature but the lack of visual editing was holding me back from purchasing your product. I could make immediate use of the visual editing and will be delighted to become a customer when you have a release ready. Best of luck.
     
  16. RedVonix

    RedVonix

    Joined:
    Dec 13, 2011
    Posts:
    421
    This looks wonderful! I wish it had been available when we were developing Out on a Limb... would have made the hex grid logic a breeze to assemble!
     
  17. Herman-Tulleken

    Herman-Tulleken

    Joined:
    Nov 20, 2009
    Posts:
    358
    Thanks c-Row , robertwahler, DCalabrese. We are looking forward to get it out; so far we are having fun using it. (Not to mention how much time it will save us making new examples!)

    Right now, we are still figuring out how to properly design it: what to expose, how you should interact with it (should you be able to access grid coordinates on the component straight, or only on a property, as the code example above? - things like that), whether to have the same component for all grids, and so on. We also wonder bout the role Maps should play in this system. Maps are really what sets our Grids apart from other systems, making things such as spiral grids possible...but most people will probably use the default maps, so it is important that they don't get into the way.

    Anyways, keep an eye on the thread :)
     
  18. Jonathan-Bailey

    Jonathan-Bailey

    Joined:
    Aug 12, 2013
    Posts:
    79
    Grids Version 1.7

    $Grids1.7.png

    Grids 1.7 is out. It’s the biggest update yet, incorporating a lot of the tech we built for our 30 Games in 30 Days campaign, as well as a lot of the feedback we received from users.

    Highlights
    • We added wrapped grids for rectangular, diamond, and hexagonal grids.
    • We added four types of polar grids.
    $PolarGrids.png

    $Colouring.png

    • We added more math functions to points (Div, Mod, Mul, Dot, PerpDot).
    • We added some LINQ-like methods for grids, and added methods to make writing LINQ expressions clearer.
    • We added a few shapes for Cairo grids.
    • We simplified underlying storage mechanism, making it easier to define your own grid shapes.
    • We improved speed and garbage generation of the AStar algorithm. We also added a version of the function that lets you specify the actual cost (not just the estimated cost).
    • We fixed many bugs, and also made a few optimizations.
    • We restructured the examples so that it is easier to know where to start, and go through them in a sequence.
    $Examples.png


    You can find a full list of changes on the What is new? page.
     
  19. cupsster

    cupsster

    Joined:
    Apr 14, 2009
    Posts:
    363
    Hello,
    for couple of days I'm fighting with this small problem. Let me describe it. I'm creating game with laser and mirrors that use pointy hex grid as an base to place blocks.
    I solved all logic stuff with ease but I have problem with mapping results back to grid.

    Color explanation as in image:
    magenta = points
    yellow = mirror normal
    blue = mirror
    red = laser

    To do point reflection I'm using Unity3D Vector3.Reflect (which works as double side mirror) to get point where my beam should go from mirror. Problem is I can't get correct results by mapping reflected point back to grid to obtain correct PointyHexPoint for next cell iteration search. I'm curious if there are some methods that can help me with this already built-in.
    I'm using NGUI for visual representation and grid blocks are parented to NGUI root anchor (may be the source of all trouble??). Cells have theirs anchors in their centres.

    My code is as follows:
    - get Vector3 of pointyhexpoint [2,0] (this can be problem as well cause grid is child of NGUI objects, do I need to do additional inverse transform point to get real top level world position? )
    - get Vector3 of mirror normal (yellow in image)
    - calculate Vector3.reflection from this
    - map back this Vector3 to grid representation to get proper cell after reflection for next iteration of search (this is where it broke for me) result should be [3,1]

    If my explanation was clear, please can you provide some example working code so I can either test it or understand my mistake. I read something about compensation when mapping to world position but do not understand in full when or what to do.

    Are there some functions that I can use to get around of converting from one coordinate system to another?

    Thank you and very nice framework!
     

    Attached Files:

  20. Herman-Tulleken

    Herman-Tulleken

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

    I notice that the image you post is not the coordinate system supported by default by Grids. That may already be the source of your problem. The coordinate system in that image uses offset coordinates, while Grids uses axial coordinates. You can see how coordinates are normally laid out here: http://gamelogic.co.za/grids/quick-start-tutorial/grid-index/

    NGUI may cause additional problems with its parenting system :/

    Fortunately, there is a way you can do reflections without having to convert between coordinate systems.

    Code (csharp):
    1. private static PointyHexPoint ReflectNormalX(PointyHexPoint point, PointyHexPoint mirrorPoint)
    2. {
    3.    var translated = point - mirrorPoint; //move problem to origin
    4.    var reflected = new PointyHexPoint(-translated.X - translated.Y, translated.Y); //reflect
    5.    var result = reflected + mirrorPoint; //move problem back
    6.  
    7.    return result;
    8. }
    9.  
    10. private static PointyHexPoint ReflectNormalY(PointyHexPoint point, PointyHexPoint mirrorPoint)
    11. {
    12.    var translated = point - mirrorPoint; //move problem to origin
    13.    var reflected = new PointyHexPoint(-translated.X, translated.X + translated.Y); //reflect
    14.    var result = reflected + mirrorPoint; //move problem back
    15.  
    16.    return result;
    17. }
    18.  
    19. private static PointyHexPoint ReflectNormalZ(PointyHexPoint point, PointyHexPoint mirrorPoint)
    20. {
    21.    var translated = point - mirrorPoint; //move problem to origin
    22.    var reflected = new PointyHexPoint(-translated.Y, -translated.X); //reflect
    23.    var result = reflected + mirrorPoint; //move problem back
    24.  
    25.    return result;
    26. }
    I also made an interactive example with full source code that you can check out:
    http://gamelogic.co.za/reflections-on-a-hex-grid/

    $screen_2.png

    You can also check out this article for more information on hex coordinates used by Grids (it covers reflections, but not the ones you are interested in):

    http://devmag.org.za/2013/08/31/geometry-with-hex-coordinates/

    Let me know if this helps you :)
     
  21. cupsster

    cupsster

    Joined:
    Apr 14, 2009
    Posts:
    363
    Hello, thank you for quick reply.
    I'm aware that I used not the best image :) I understand how coordinates works in this framework, this image was random find from internet. Thank you for examples, I'll examine them and reply after that.
     
  22. EmeralLotus

    EmeralLotus

    Joined:
    Aug 10, 2012
    Posts:
    1,459
    Really nice and very complete package. Awesome work.

    A few questions:

    1. Does it work in all unity platform?
    2. Are the 30 days/30 games examples included with the package.

    Cheers.
     
  23. Parallel_

    Parallel_

    Joined:
    Dec 9, 2012
    Posts:
    90
    Any chance of playmaker actions in the near future?
     
  24. TokyoDan

    TokyoDan

    Joined:
    Jun 16, 2012
    Posts:
    1,080
    Can grids be used to make 2.5D Isometric games?
     
  25. Herman-Tulleken

    Herman-Tulleken

    Joined:
    Nov 20, 2009
    Posts:
    358
    @rocki It does work on all platforms. Because C# has some limitations on iOS, you need to add a line or two to make it work on iOS (you can see some details here: http://gamelogic.co.za/how-to-make-sure-the-aot-compiler-generates-code-to-instantiate-grids-on-ios/)

    The 30 games are not included, but we are happy to share the code (the main reason is we did not have a chance to clean it up yet, we have been moving to get the features developed during that tine into the main library, and getting visual grid editing in for version 1.8.

    @O'parallel It's something we have been thinking about. We do not have plans for Play Maker support in the short term, but if there are lot's of interest we will definitely do it.

    @TokyoDan Yup, indeed it can. And there are many ways to do it too. Most games use diamond shape tiles (we used this scheme in our zombie game). For variable heights, you need to figure out a bit of a system - for instance, will you use a single shape tile, or multiple shape tiles? But Grids could make many things much easier. If you describe your system, I could give you more info.
     
    Last edited: Jan 30, 2014
  26. TokyoDan

    TokyoDan

    Joined:
    Jun 16, 2012
    Posts:
    1,080
    Thanks Herman. I just like 2.5d isometric turn-based tactics games so I wanted to know if those types of games were possible with your tool.

    Where can I see your Zombie game?
     
  27. Herman-Tulleken

    Herman-Tulleken

    Joined:
    Nov 20, 2009
    Posts:
    358
  28. Braza

    Braza

    Joined:
    Oct 11, 2013
    Posts:
    136
    Hi,
    I like your grids. Looks great. I`ve already implemented my own by this moment, not as multi-purpose as yours, jsut for my own game. But I was interested if it still worth for me to purchase it with the todays deal. Could you pelase tell if anything from the list is possible with your lib:
    - Hex core logic translated to Java, as the Model part is going to be calculated on the SFS2X server side. That`s not likely, I know(
    - Pathfinding
    - (De)Serialization of the grid
     
    Last edited: Jan 30, 2014
  29. TokyoDan

    TokyoDan

    Joined:
    Jun 16, 2012
    Posts:
    1,080
    BTW. When I click on your 30-day trial link I get this Phishing warning... $phis.png
     
  30. TokyoDan

    TokyoDan

    Joined:
    Jun 16, 2012
    Posts:
    1,080
    Anyway, I don't need the demo. This sale and Grids is just too good to pass up. I bought it. I'll use it in my next game.
     
  31. Silly_Rollo

    Silly_Rollo

    Joined:
    Dec 21, 2012
    Posts:
    501
    Does this include anything to help laying out objects in the editor to stay on the grid? Does your A* contain anything like Astar Project's Constant Path? (checking all possible paths from a central point that can be reached under X value)
     
  32. Herman-Tulleken

    Herman-Tulleken

    Joined:
    Nov 20, 2009
    Posts:
    358
    @Braza

    I am not sure how easy it would be to translate the core logic to Java. Grids uses some advanced C# features, and furthermore, the hex code relies quite a bit on the generic components (not only the base classes for grids, but also the logic that makes shape building possible).

    The library includes AStar for path finding.

    Grids cannot be serialized directly. We are looking into this for the feature, though. Once we have the visual editor components in, level building becomes much more prominent.

    However, it is very easy to serialise grid data and reconstruct the grid from that. Assuming your grid is fixed, you can just convert the data to an array like this:

    Code (csharp):
    1. grid.Values.ToArray();
    and serialise the result. To fill in data from an array (say gridData), you could do the following:

    Code (csharp):
    1. int i = 0;
    2.  
    3. foreach(point in grid)
    4. {
    5.    grid[point] = gridData[i];
    6.    i++;
    7. }
    @TokyoDan
    Thanks for the purchase!

    I have no idea why your software reports the link as a phishing site (it's a direct download link to a unity package). But thanks for letting us know - this may prevent other users from downloading it as well; we will definitely look into it.

    @Fuzzy_Slippers We will start adding some editor capabilities with version 1.8.

    Below is a Work in Progress screenshot:

    $GridsEditor.png

    This opens up a lot of exciting possibilities, and we look forward to get some feedback in where we could take it once it is out.

    Our AStar algorithm is quite vanilla, it does not have the feature you speak of. But of course, we always keep our eyes open for new features to add, and if it is generally useful we will.
     
    Last edited: Jan 30, 2014
  33. Devilbox-Games

    Devilbox-Games

    Joined:
    Jul 3, 2012
    Posts:
    205
    I'd just like to say Grids is awesome, it was exactly what I was looking for for some of my projects and it was very coincidental timing discovering it on the day it was on 24 hours sale. I had not actually bought anything off the asset store before as I tend to be a bit anal about creating everything myself, but this was just too good an asset at too good a price to pass up :) Seriously great work on this one!
     
  34. Spungo

    Spungo

    Joined:
    Apr 10, 2013
    Posts:
    3
    Oh, this looks good. I've been toying with a couple of grid-based ideas but this looks like it might save me a bit of work. Could I ask an idiot question?

    Lets assume I want a play area that's basically a grid on the inside of an octagonal tube, like this...

    $OctGrids.png

    A couple of days ago, I nailed together a (very) rough test where
    • The player movement is turn-based, with the player (represented by the imaginatively designed pink thing) moving from square to square
    • Each square is a Quad GameObject
    • A '2D' X/Y grid array stores which quad gameobject corresponds to each particular 2D coordinate
    • As the player moves from square to square inside the tube, the grid array looks up which quad gameobject corresponds to that 2d coordinate, and the player's position/rotation is set to match that in 3d space.

    After a quick skim of your web docs, am I right in thinking that with your Grids system the same sort of thing would be a case of setting up a grid and providing a fairly simple 3D Map for it to work with?

    Is your system set up to handle grids that 'wrap' btw (i.e - if the player in the above pic kept going right, after 33 moves it would have wrapped back to it's original point) in terms of, say, it's pathfinding and so on?
     
  35. EmeralLotus

    EmeralLotus

    Joined:
    Aug 10, 2012
    Posts:
    1,459
    Very Cool,

    Just bought.

    I understand that you guys are working on 1.8 and do not have time to clean up the examples. If you get some spare time, would love to have a link to whatever you have. It will at least give me some place to start.

    Cheers.
     
  36. EmeralLotus

    EmeralLotus

    Joined:
    Aug 10, 2012
    Posts:
    1,459
    Forgot to ask.

    Is there documentation or examples of integrating NGUI or DaikonForge with the Grid?
     
  37. MrAdventure

    MrAdventure

    Joined:
    Aug 22, 2012
    Posts:
    28
    Hi there,

    I'm going to buy this during your sale just to have around for when I want to make quick 2d games. I'm wondering if it will be useful for what I am currently doing, though. I'm making a simulation that tracks the properties of terrain at different areas. I'm using the terrain engine.

    So can grids be used in conjunction with the terrain engine to handle the tracking of properties?

    Thanks,

    Victor
     
  38. jmatthews

    jmatthews

    Joined:
    Jul 27, 2011
    Posts:
    199
    Purchased, and the timing on the sale is perfect for me. I'll be using this for my February 1 Game a Month entry.
     
  39. Herman-Tulleken

    Herman-Tulleken

    Joined:
    Nov 20, 2009
    Posts:
    358
    @Spungo
    Yes, you would indeed be able to use your own 3DMap to accomplish what you need. We did something very similar; I dont know if you have seen this example:


    http://gamelogic.co.za/how-to-use-a-rectangular-grid-on-the-inside-of-a-torus/


    This uses a custom map to use a rect grid on a torus; it should be a good starting point for your own case.


    Grids do support wrapped versions. Rectangular grids can be wrapped horizontally, vertically, or both. Pathfiding also works on these grids.


    (It's great tto see some other ideas for non-flat grids!)


    @rocki
    Yes, we get a lot of requests for the games. There are 7 simple games included in the examples with Grids, but we will see if we can make a plan with the 30 other games (and a few others in our basement) too.


    Almost all the examples in 1.7 uses NGUI. (It's very simple to replace with any other sprite technology!) From 1.8 we will mostly be using Unity native sprites, whcih are much nicer :)


    I see no reason why Grids should not work with Daikon too (you literally only have to replace the sprites, and perhaps update the dimensions if they work different).


    @MrAdventure
    Indeed you can. Grids work well with all kinds of data.


    For example, say you had a cell like this: (one you define yourself)


    Code (csharp):
    1. class TerrainCell
    2. {
    3.     water: false;
    4.     gold: 10;
    5.     silver: 0;
    6.     poison: 5;
    7. }
    8.  
    9.  
    10.  
    Then you can construct a grid like this:


    Code (csharp):
    1. var grid = RectGrid<TerrainCell>.Rectangle(40, 40);
    2.  
    3.  
    4. foreach(var point in grid)
    5. {
    6.    grid[point] = InitCellSomehow(...)
    7. }
    8.  
    9.  
    10. ....
    11.  
    Now you can run queries like this:


    Code (csharp):
    1. var poisonousCells = grid.Where(p => grid[p].poisson > 2);
    2.  
    or cause a flood:


    Code (csharp):
    1. var waterNeighboringCells = grid.Where(p => grid[p].water).SelectMany(p => grid.GetNeighbors(p));
    2.  
    3.  
    4. foreach(var point in waterNeighboringCells) grid[point].water = true;
    5.  
    and so on.


    Of course you will have to keep your visual and data states in synch, but that should be straightforward too.
     
  40. MrAdventure

    MrAdventure

    Joined:
    Aug 22, 2012
    Posts:
    28
    Thanks, I just bought it!
     
  41. krissebesta

    krissebesta

    Joined:
    Oct 20, 2010
    Posts:
    16
    Hi Herman, I just bought Grids and am really excited by what I saw in the library. I have a question: Can Grids support "layered" grids? Like 3D Tic-Tac-Toe with three layers of 9 cells? I'm planning a game with three layers (much more complex than 3D Tic-Tac-Toe however! ;-) Do you have an example of such a design? If not do you have some advice on how to create such a design?

    Thanks and keep up the awesome work!!!! - Cheers! - Kris
     
  42. c-Row

    c-Row

    Joined:
    Nov 10, 2009
    Posts:
    847
    This probably won't help much, but I can confirm that switching from NGUI to 2DToolkit was as easy as you would expect. :)
     
  43. Herman-Tulleken

    Herman-Tulleken

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

    Not out of the box, no. But the good news is it should be quite straightforward to implement.

    There are two ways I would suggest.

    The "quick" way would be to implement a special point, that has a point and layer as components. Make a map to work with this point (simply delegate to the RectMaps). You then simply use this point to access the right grid, which you can put as an array of grids, and implement all your algorithms in terms of these points.

    The longer but more powerful method would be to do the following:


    • Define your own RectPoint3 (a 3D point) (I would let it implement IVectorPoint, so that you can do basic arithmetic, which simplifies many algorithms).
    • Define your own grid, let it implement IGrid<TCell, RectPoint3>. Internally this grid would contain an array of ordinary RectGrids.
    • Define a map to work with these (most of the work can be delegated to a RectMap)

    This method allows you to use grid algorithms (such as GetConnectedLines and GetConnectedShapes, AStar, etc.)

    If you need more help with this, let me know!

    Edit: It is something we might include in the future. Now that I thought about it a bit more, it seems there is a third approach, something very generic which can turn any grid into a layered grid... will have to play with it but it's an interesting idea.
     
    Last edited: Jan 30, 2014
  44. Spungo

    Spungo

    Joined:
    Apr 10, 2013
    Posts:
    3
    Yup, your torus spider/dragon game demonstrates pretty much exactly what I'm looking for, so I'll be buying.

    Weirdly enough, the second 'octagonal tube grid' test I did was an endless runner thing with the tube modulated along a spline. But after the first two people I showed it to got devastating motion sickness straight after I shoved the tablet in their hands, I ditched it - seriously, it was almost bucket mop time for one of them. I suspect the brain just has problems resolving the moving checker pattern on the 'horizon' actually. I might try again later.

    Anyway, it strikes me one of the most powerful things setting Grids apart from some others in the asset store is it lets you tie a 2D grid to basically any shape you can map. Once you've done that you can do all kinds of things in 3D space - it'd be a shame to keep things completely flat;)
     
  45. Herman-Tulleken

    Herman-Tulleken

    Joined:
    Nov 20, 2009
    Posts:
    358
    @Spungo

    Yes the effects of such things can be very surprising! (But very exciting too!)

    Indeed. To me, it's not the grids per se that are so cool, but the maps. The power of maps was not intended, though, but a happy consequence of another problem we set out to solve: we tried very hard to figure out aligning a grid in a useful way, without having to specify a million parameters. We could not figure out were the methods should go, or how they should look (should they be part of the grid? a collection of static methods?) Eventually we realized the solution is to keep them out of it altogether, and invent the new abstraction. The extra benefits we discovered slowly over time (two others are mesh creation and texture mapping); weird discovering "emergent", useful properties of tech you designed!

    Good luck, and don't hesitate to drop a mail if you need help!
     
    Last edited: Jan 30, 2014
  46. Spungo

    Spungo

    Joined:
    Apr 10, 2013
    Posts:
    3
    Thanks, will do. I've got a few old scribbled notes somewhere for a cellular automaton that influences (and is influenced by) the slope on any given point of a mesh - Grids might be a good tool for trying it out with but I'm basically a Unity noob and will no doubt get stuck at some point...
     
  47. Silly_Rollo

    Silly_Rollo

    Joined:
    Dec 21, 2012
    Posts:
    501
    Have you by any chance ever tried to integrate this with Astar Pathfinding Project to sync the current pathfinding grid to a visualized square grid while taking advantage of their more flexible pathfinding? It seems like your map structure would be useful for holding game data.

    I do wish you had some form of editor positioning script. It looks like your asset is more focused on procedural puzzle game kind of projects, but ideally I'd like to create grids in the editor and then be able to build a level using the grid to keep objects aligned on it. I could whip something up to do that but built in is always nice.
     
  48. Herman-Tulleken

    Herman-Tulleken

    Joined:
    Nov 20, 2009
    Posts:
    358
    Fuzzy_Slippers, I have not tried it. However, I can imagine it should be quite straightforward. (I always assumed people will integrate a more heavy duty AStar if they needed it).

    Hmmm, editor positioning is a very good idea, it should be easy to add with the new editor editable grids we are working on. We will play around and see if it works well, keep an eye out!
     
  49. EmeralLotus

    EmeralLotus

    Joined:
    Aug 10, 2012
    Posts:
    1,459
    "Yes, we get a lot of requests for the games. There are 7 simple games included in the examples with Grids, but we will see if we can make a plan with the 30 other games (and a few others in our basement) too."

    Very cool. The more demos and examples, the better as it helps to showcase the power and flexibility of the system to potential buyers.

    Cheers.
     
  50. Tinjaw

    Tinjaw

    Joined:
    Jan 9, 2014
    Posts:
    518
    I was able to grab grids at the sale price yesterday. I haven't even imported it yet. I am new to Unity and I have been working solely with Playmaker to date. I haven't written any code. I plan to learn at some point, but for now Playmaker is working fantastically.

    My question is will Grids ever have Playmaker support? I would love to be able to use Grids with Playmaker.

    Thanks