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. fmarkus

    fmarkus

    Joined:
    May 22, 2010
    Posts:
    181
    Cooool! Thanks!
     
  2. barjed

    barjed

    Joined:
    May 9, 2013
    Posts:
    70
    Hi Herman,

    please imagine a isometric diamond grid and a 2d object moving along a path calculated with your AStar algorithm. I want to change "facing" of the character when it "turns" during movement. Do Grids have some kind of relative coordinate system for neighbors (as in "point A is south to point B") I could tap into or should I calculate relative position difference and guess the direction based on that (x+/y+ is north, etc).
     
  3. Herman-Tulleken

    Herman-Tulleken

    Joined:
    Nov 20, 2009
    Posts:
    358
    There are constants defined on DiamondPoint that should serve your purpose (from http://www.gamelogic.co.za/documentation/grids/struct_gamelogic_1_1_grids_1_1_diamond_point.html):

    static readonly DiamondPoint NorthEast = new DiamondPoint(0, 1)
    static readonly DiamondPoint NorthWest = new DiamondPoint(-1, 0)
    static readonly DiamondPoint SouthWest = new DiamondPoint(0, -1)
    static readonly DiamondPoint SouthEast = new DiamondPoint(1, 0)
    static readonly DiamondPoint East = NorthEast + SouthEast
    static readonly DiamondPoint North = NorthEast + NorthWest
    static readonly DiamondPoint West = NorthWest + SouthWest
    static readonly DiamondPoint South = SouthEast + NorthEast
    static readonly DiamondPoint Zero = new DiamondPoint(0, 0)

    So for example, to get the point north east of A, you simply say:

    Code (csharp):
    1. var pointNorthEastOfA = A + DiamondPoint.NorthEast;
    Similarly, if A and B are neighbors, you can write something like:

    Code (csharp):
    1. if (A - B == DiamondPoint.South)
    2. {
    3.    //A is South of B
    4. }
    I find it's better to always use addtion, so I'd rather write the above as:

    Code (csharp):
    1. if (A == B + DiamondPoint.South)
    2. {
    3.    //A is South of B
    4. }
     
  4. fmarkus

    fmarkus

    Joined:
    May 22, 2010
    Posts:
    181
    Hi!
    I need to have objects over the grid, like new GUI text, and some Images. But they always appear behind the grid sprite... Any idea on how to solve this?
    THanks!
     
    Last edited: Sep 29, 2014
  5. fmarkus

    fmarkus

    Joined:
    May 22, 2010
    Posts:
    181
    So Maybe there is another way but I think the grids are looking for a sprite. What if I want to have a Unity gui Image instead?
     
  6. Herman-Tulleken

    Herman-Tulleken

    Joined:
    Nov 20, 2009
    Posts:
    358
    You will have to make a special cell. The easiest way would be to replicate SpriteCell (Call it GuiImageSprite), and just modify the methods to work with the GUI image instead. (SpriteCell is quite simple, so it should not take too long).
     
  7. fmarkus

    fmarkus

    Joined:
    May 22, 2010
    Posts:
    181
    Thanks for the tips!
    Maybe it's something to think about because sprite priorities are a pain now with the new gui. :)
     
    Herman-Tulleken likes this.
  8. fmarkus

    fmarkus

    Joined:
    May 22, 2010
    Posts:
    181
    Image Cell, if anyone is looking for it :)


    //----------------------------------------------//
    // Gamelogic Grids //
    // http://www.gamelogic.co.za //
    // Copyright (c) Gamelogic (Pty) Ltd //
    //----------------------------------------------//

    using UnityEngine;
    using UnityEngine.UI;

    namespace Gamelogic.Grids
    {
    /**
    A tile cell that uses a Unity image to render.

    @link_making_your_own_cells for guidelines on making your own cell.

    @version1_8
    @ingroup UnityComponents
    */

    [AddComponentMenu("Gamelogic/Cells/ImageCell")]
    public class ImageCell : TileCell, IGLScriptableObject
    {
    [SerializeField] private Color color;

    [Tooltip("The possible frames that this image supports.")]
    [SerializeField]
    private Image[] images =
    new Image[0];

    [SerializeField] private int frameIndex;

    [SerializeField] private bool highlightOn;

    public bool HighlightOn
    {
    get { return highlightOn; }

    set
    {
    highlightOn = value;
    __UpdatePresentation(true);
    }
    }

    public override Color Color
    {
    get { return color; }

    set
    {
    color = value;
    __UpdatePresentation(true);
    }
    }

    /**
    Sets the current image by indexing into the
    list of images set up in the inspector.
    */

    public int FrameIndex
    {
    get { return frameIndex; }

    set
    {
    frameIndex = value;
    __UpdatePresentation(true);
    }
    }

    protected Image Image
    {
    get
    {

    var image = transform.FindChild("Image").GetComponent<Image>();

    if (image == null)
    {
    Debug.LogError("The cell needs a child with a SpriteRenderer component attached");
    }

    return image;
    }
    }

    public override Vector2 Dimensions
    {
    get { return Image.sprite.bounds.size; }
    }

    public void Awake()
    {
    highlightOn = false;
    }

    public override void __UpdatePresentation(bool forceUpdate)
    {
    //for now, always update
    if (frameIndex < images.Length)
    {
    Image.sprite = images[frameIndex].sprite;
    }

    Image.color = highlightOn ? Color.Lerp(color, Color.white, 0.8f) : color;
    }

    public override void SetAngle(float angle)
    {
    Image.transform.SetLocalRotationZ(angle);
    }

    public override void AddAngle(float angle)
    {
    Image.transform.RotateAroundZ(angle);
    }

    public void OnClick()
    {
    highlightOn = !highlightOn;
    __UpdatePresentation(true);
    }
    }
    }
     
    Herman-Tulleken likes this.
  9. MikeTon

    MikeTon

    Joined:
    Jan 10, 2013
    Posts:
    57
    Hey Herman,

    Really digging Grids and are really happy the asset y'all have offered here.

    I was wondering if you could give me a pointer to how a grid determines which camera it's using for events.

    What I want to do is use a grid for my terrain, and use a different grid for my UI. And I was going to have 2 cameras, one for my game (perspective) and one for my GUI (ortho).

    And MousePosition currently only supports ortho cameras:

    /**
    Get's the mouse position in Grid coordinates.
    Currentlyitisonlyusefulfor2Dgrids, renderedwith
    orthographiccameras.
    */
    publicTPointMousePosition{
    get { returnGridBuilder.MousePosition; }
    }

    How can I specify/configure my GUI grid to read from my GUI camera (ortho).

    Any thoughts or suggestion would be welcome. Thank you for your time and consideration so far.

    -Mike Ton
     
  10. Herman-Tulleken

    Herman-Tulleken

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

    Glad you are enjoying Grids!

    For 3D and other more complicated setups (such as cameras not orthogonal to grid planes), you will have to use a different method for working with mouse input.

    The most common way is to include an Update method in your GridBehaviour, and perform a raycast when the mouse is clicked. The hit point can then be used with the Map to get the appropriate grid point.

    (For this to work, you need to add colliders to cells. You may also want to include some layer filtering when you do the cast.).

    Something like this (where of course you can replace Camera.main with the appropriate camera):
    Code (csharp):
    1.  
    2. public void Update()
    3.     {
    4.         if (Input.GetMouseButtonDown(0))
    5.         {
    6.             var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
    7.  
    8.             RaycastHit hit;
    9.  
    10.             if (Physics.Raycast(ray, out hit))
    11.             {
    12.                 Vector3 worldPosition = transform.InverseTransformPoint(hit.point);
    13.                 Debug.Log("mouse pos: " + Input.mousePosition + ", world_pos:" + worldPosition);
    14.  
    15.                 var hexPoint = Map[worldPosition];
    16.  
    17.                 if (Grid.Contains(hexPoint))
    18.                 {
    19.                     Debug.Log("Grid hit: " + hexPoint);
    20.                 }
    21.             }
    22.         }
    23.     }
    24.  
    Right now the built in mouse functionality uses the camera tagged as the main camera... And there is no non-hacky way to change it, unfortunately.

    So to force the UI grid to use the UI camera, you can either tag that as main and the other camera as something else (if you do not require the tag for other purposes), or you can look in the GridBuilderUtil script and change the camera used in the ScreenToWorld calculation.

    Neither of these options are very nice, I will make a note to look at it in the future.
     
  11. MikeTon

    MikeTon

    Joined:
    Jan 10, 2013
    Posts:
    57
    thanks Herman! This works great!

    -mike
     
  12. Jay18001

    Jay18001

    Joined:
    Sep 4, 2013
    Posts:
    3
    I'm having problems compiling the dll. It runs fine inside of unity but I get when I go to build

    Code (CSharp):
    1. Internal compiler error. See the console log for more information. output was:
    2. Unhandled Exception: System.Reflection.ReflectionTypeLoadException: The classes in the module cannot be loaded.
    3.  
    4.   at (wrapper managed-to-native) System.Reflection.Assembly:GetTypes (bool)
    5.  
    6.   at System.Reflection.Assembly.GetTypes () [0x00000] in <filename unknown>:0
    7.  
    8.   at Mono.CSharp.RootNamespace.ComputeNamespaces (System.Reflection.Assembly assembly, System.Type extensionType) [0x00000] in <filename unknown>:0
    9.  
    10.   at Mono.CSharp.RootNamespace.ComputeNamespace (Mono.CSharp.CompilerContext ctx, System.Type extensionType) [0x00000] in <filename unknown>:0
    11.  
    12.   at Mono.CSharp.GlobalRootNamespace.ComputeNamespaces (Mono.CSharp.CompilerContext ctx) [0x00000] in <filename unknown>:0
    13.  
    14.   at Mono.CSharp.Driver.LoadReferences () [0x00000] in <filename unknown>:0
    15.  
    16.   at Mono.CSharp.Driver.Compile () [0x00000] in <filename unknown>:0
    17.  
    18.   at Mono.CSharp.Driver.Main (System.String[] args) [0x00000] in <filename unknown>:0
    19.  
    I tried removing the lib and it works fine.

    Edit: The this from the log file
    Code (csharp):
    1. The following assembly referenced from F:\User\Dive\Development\TestGame\Assets\Gamelogic\Plugins\Grids.dll could not be loaded:
    2.  
    3.      Assembly:   UnityEditor    (assemblyref_index=2)
    4.  
    5.      Version:    0.0.0.0
    6.  
    7.      Public Key: (none)
    8.  
    9. The assembly was not found in the Global Assembly Cache, a path listed in the MONO_PATH environment variable, or in the location of the executing assembly (F:\User\Dive\Development\TestGame\Assets\Gamelogic\Plugins\).
    10.  
     
    Last edited: Oct 13, 2014
  13. Herman-Tulleken

    Herman-Tulleken

    Joined:
    Nov 20, 2009
    Posts:
    358
    Hi Jay18001, I sent you an email.
     
  14. kilju

    kilju

    Joined:
    Nov 4, 2013
    Posts:
    127
    hi i just bought ur asset and its been really nice to play with :D can u guys give me some advice how i could make map + grid like civilization 5? would be nice to know how should i start this kind of project.
    keep up the good work guys
     
  15. Herman-Tulleken

    Herman-Tulleken

    Joined:
    Nov 20, 2009
    Posts:
    358
    There is a lot of tech in Civ 5 to make happen what they do.

    You probably would like to create your own mesh, especially if you want a big world. You can check out this example to get you started:

    http://gamelogic.co.za/grids/featur...mesh-generation-script-with-proper-texturing/

    I would imagine doing grids in code (rather than the editor) may be the best way to go; not only because you will make your own mesh, but also so you have more control on the various issues.

    There are a few tutorials under the section Grids in code here:
    http://gamelogic.co.za/grids/documentation-contents/

    Of course, if you have any specific questions, we would be glad to answer them.
     
  16. RDeluxe

    RDeluxe

    Joined:
    Sep 29, 2013
    Posts:
    117
    Hi guys. Just wanted to keep you updated about our 3D objets + 2D tiles system.
    After looking (and playing) more into Shaworun methods, we applied more or less the same.

    Basically, we have some rounded 3D cubes (for most objects), and we project our sprites (cars, walls, etc) on those cubes (for this we need to generate a new UV map).
    After this is done, our objects are now 3D objects, and we can sort them and our characters easily (it's just the native 3D sorting). Moreover, we can now play with lights.



    Thanks a lot for your help Herman.

    We are now trying to extend Grids functionnalities to create a nice map editor within unity. Creating objects is pretty easy, but we need to make the process of changing a tile sprite simpler, to save the map (we should have a nice solution for this), to extend the map without redrawing it, etc.
     
    Last edited: Oct 25, 2014
    Herman-Tulleken likes this.
  17. Steve-Tack

    Steve-Tack

    Joined:
    Mar 12, 2013
    Posts:
    1,240
    I'm looking into using this asset for some PlayStation Vita games (via PlayStation Mobile), but that platform is currently limited to using a special version of Unity 4.3.4. So the Unity 4.5 features used in Grids is messing me up a bit. I commented out the (several) references to the Tooltip attribute, but there's one last compile error I'm not sure what to do with. In TransformExtensions, the Sort extension method does this:

    sortedChildren.SetSiblingIndex(i);

    I guess SetSiblingIndex is a 4.5 feature? Is there an easy workaround, or perhaps just a way to download an older 4.3 compatible version?
     
  18. Herman-Tulleken

    Herman-Tulleken

    Joined:
    Nov 20, 2009
    Posts:
    358
    Awesome :) Thanks for keeping us up to date :) Look forward to see what you come up with in terms of editing the map.
     
  19. Herman-Tulleken

    Herman-Tulleken

    Joined:
    Nov 20, 2009
    Posts:
    358
    Hi Steve, I sent you an email with an older compatible version.

    However, you should not need the Sort method (it's not used internally), and if you need it for your own purposes you should be able to roll out your own pretty easily with whatever sorting method your rendering method provides. (You also don't need the SortAlphabetical method that calls Sort; that was mostly implemented to compensate for the fact that Transforms are not sorted alphabetically by default anymore).
     
  20. Herman-Tulleken

    Herman-Tulleken

    Joined:
    Nov 20, 2009
    Posts:
    358
    Grids themselves can be very big; we have a proof of concept with 250 000 hexes included with the library (including the trial): see Examples/Scenes/Grids with Code/)

    (We also have this example running here: http://gamelogic.co.za/grids/features/examples-that-ship-with-grids/250-000-hexes/ but for some reason it does not want to run in my browser ATM.)

    Note this example is considerably slower in the editor; but it's generally fine when compiled. Creation of the objects is quite slow; in this example we create them over several frames.

    The reason why you are seeing such a degradation is probably because you are using editor Grids. Check whether the examples in Grids with Code perform well when you scale them up. (The reason grids in the editor are slow is probably because of extra drawcalls because of duplicated materials. This has only recently brought to our attention so we haven't addressed it yet. It most certainly is the coloring of cells that is the issue.)

    Even with using grids in code, you may need to perform some optimizations, which may include things such as limiting the rendered range or the range over which algorithms execute, or using a single mesh instead of separate objects. These are usually implemented (relatively) easy with "window"grids. We have one example of that here (although this is 2D):

    http://gamelogic.co.za/grids/featur...-only-a-section-of-a-very-big-scrolling-grid/

    Big grids themselves are not slow, but anything you may do with them are. The range of optimizations is not quite so easy to solve in the general case, but I think we provide a good framework that can make specific solutions easier to implement.
     
    Last edited: Oct 27, 2014
  21. Herman-Tulleken

    Herman-Tulleken

    Joined:
    Nov 20, 2009
    Posts:
    358
    Ah OK :) I am glad to hear it's something simple! It did not even occur to me that that could be the issue so it's useful to remember if someone else runs into it. So thanks for posting the solution!
     
    Last edited: Oct 27, 2014
  22. PKrawczynski88

    PKrawczynski88

    Joined:
    Nov 14, 2013
    Posts:
    15
    Hey I have a simple question, let me show you image example first to illustrate:
    https://www.dropbox.com/s/g6d7itaa5c76snd/Zrzut ekranu 2014-10-29 22.46.43.png?dl=0

    On the left is what I get with flat hex, and rectangle grid.
    On the right is exactly same thing except coordinates are easier to navigate (although arguably I would say I like your method of starting with 0,0 in left bottom screen, instead of in top like that another image).

    Is there something I can do (except writing my own conversion utility because thats pretty easy - looks like couple minutes tops) to configure grids library to have similiar output? Currently when I move to the 2 tiles to right, my Y tiles are moving one space to the top wchich results in larger and larger negative numbers that appear on the bottom of rectangle.

    I highly suspect there is very good reason it works like that currently in library.

    TL'DR: is it possible to do something inside library to not have to deal with negative index numbers that appear the further you go on the positive x axis.
     
  23. Herman-Tulleken

    Herman-Tulleken

    Joined:
    Nov 20, 2009
    Posts:
    358
    Do you want to do this for the players sake, (the coordinates you want to display), or your sake (the coordinates in terms of which you want to design your algorithms).

    If it's the first, then an extension method on hex points is probably the best option, and unfortunately you have to do that yourself. In this case, you will only use the other coordinate system for display purposes, so your design will still be in terms of the provided system.

    (Which, as you suspect, has been chosen for a very good reason. One of the early prototypes did in fact have the coordinate system in that picture. After implementing a few games, I changed it to the current system because it drastically simplified algorithms. With the current system, it is very easy to work with points as vectors. You can for example write this:

    Code (csharp):
    1. var pointThreeUnitsNorthEastOfReference = reference + 3*PointyHexPoint.NorthEast;
    Anything geometric is much simpler, including equations of lines, circles, and thus polygons and so on.

    ).

    If for some reason your algorithms will simplify using the other coordinate system, then it would be best to implement your own point type (something that implements the IGridPoint interface), and wrap your grid in a class that does the conversion.

    Code (csharp):
    1. class MyPoint : IGridPoint<MyPoint>
    2. {
    3. ...
    4. }
    5.  
    6. public class MyGrid<TCellType> : IGrid<TCellType, MyPoint>
    7. {
    8.    private PointyHexGrid<TCellType> internalGrid;
    9.  
    10.    public this[MyPoint point]
    11.    {
    12.        get { return internalGrid[Convert(point)]; }
    13.        set { internalGrid[Convert(point)] = value; }
    14.    }
    15.  
    16.    //And so on
    17. }

    There are ways to do transformations of the coordinates, but it's very difficult to use these consistently, and I generally don't recommend using them. (Check out the methods SetGridPointTransforms). One issue is that the meaning of adding two points changes with certain transformations, so that it becomes hard to track of statements that should be simple.
     
  24. PapperWing

    PapperWing

    Joined:
    Nov 3, 2014
    Posts:
    4
    Hi,
    we are planning to use grids in our game, but I would like to ask you, if it's possible to work with edges like path finding on edges and getting right edges and vertices. As example we would like to use edges like roads, similar like in the Settlers of Catan board game. I was looking into documentation and I didn't notice any tools for this.

    I am sorry about my English and thank you for your advice.

    Best regards
    Jakub Peschel
     
  25. MikeTon

    MikeTon

    Joined:
    Jan 10, 2013
    Posts:
    57
    Hey Herman,

    I'm beta testing Unity 5, and I'm getting the following message from Grid:

    Assets/Gamelogic/Plugins/Common/Extensions/GLMonoBehaviour.cs(24,33): error CS0425: The constraints for type parameter `T' of method `Gamelogic.GLMonoBehaviour.Instantiate<T>(T)' must match the constraints for type parameter `T' of interface method `UnityEngine.Object.Instantiate<T>(T)'. Consider using an explicit interface implementation instead

    I tried it in an empty project. Any thoughts on what may be happening? Thanks.

    -Mike
     
  26. Herman-Tulleken

    Herman-Tulleken

    Joined:
    Nov 20, 2009
    Posts:
    358
    There are some tools for this. There is also a neat strategy you can follow that does not require special support.

    First: what support we have (this is only supported in the full library). Each grid has an associated edge grid. For hex grids, these are rhomb grids. You can get an idea of how it works from this post: http://gamelogic.co.za/2013/06/27/what-is-a-rhombille-grid/

    In this case, you will have two grids: a hex grid for the faces, and a rhomb grid for the edges. There are functions to find edges of a face and the faces of an edge. Since you have two grids to represent the entire thing visually, you have a lot of flexibility in how your edges look (they can be full-blown tiles, and are not just lines as some implementations provide).

    Second: a trick. You can represent the edges and faces of a hex grid simultaneously as a hex grid. 1/7 of the cellss are faces, the remainder are edges. We use this technique to generate a maze on a hex grid using Prim's algorithm in one of the examples. The math for this is very elegant, since you can use simple vector addition to find different geometric elements. See the example live here: http://gamelogic.co.za/grids/featur...aze-generation-algorithm-on-a-hexagonal-grid/

    Code (csharp):
    1. var northEastEdge = face + PointyHexPoint.NorthEast;
    2. var northEastNeighbor = face + 2 * PointyHexPoint.NorthEast;
    3.  
    As the case of two grids, you have great flexibility in your visual presentation. (And keep in mind cells need not be the same size). The partitioning (between faces and edges of different orientations) is done with a simple "coloring" function, which you can read more on here: http://gamelogic.co.za/2013/12/18/what-are-grid-colorings/

    Let me know if you have any more questions.
     
  27. Herman-Tulleken

    Herman-Tulleken

    Joined:
    Nov 20, 2009
    Posts:
    358
    Hmmm, it looks like Unity duplicated one of the functions in our library. (It's not the first time this happened; the last time was with Tooltip attributes and before that FindObjectOfType)...

    Try commenting out the method and see what happens.
     
    MikeTon likes this.
  28. MikeTon

    MikeTon

    Joined:
    Jan 10, 2013
    Posts:
    57
    Thanks Herman. Commenting it out made it work...??? will I need to do that for future updates???

    -Mike

     
  29. PapperWing

    PapperWing

    Joined:
    Nov 3, 2014
    Posts:
    4
    Thanks Herman. We decided to use grids :)

    I have a small problem with setting up own grid in code. I only paste code from here ( http://gamelogic.co.za/grids/documentation-contents/quick-start-tutorial/ ) and unity start to send me errors. The first thing is, that it has problem with namespace of GLMonoBehaviour. I used Gamelogic.GLMB instead GLMB. And it started to send me errors about types coming from makeEdgeGrid.

    Here is error stack:
    Assets/scripts/SecondGrid.cs(27,17): error CS0029: Cannot implicitly convert type `Gamelogic.Grids.PointyHexGrid<Gamelogic.Grids.SpriteCell>' to `Gamelogic.Grids.PointyHexGrid<Cell>'

    Assets/scripts/SecondGrid.cs(36,43): error CS0309: The type `UnityEngine.Vector2' must be convertible to `UnityEngine.Component' in order to use it as parameter `T' in the generic type or method `Gamelogic.GLMonoBehaviour.Instantiate<T>(T)

    Assets/scripts/SecondGrid.cs(45,51): error CS0117: `ExampleUtils' does not contain a definition for `colors'

    Assets/scripts/SecondGrid.cs(47,25): error CS0266: Cannot implicitly convert type `Gamelogic.Grids.SpriteCell' to `Cell'. An explicit conversion exists (are you missing a cast?)


    Again I only copied the tutorial code.

    Thank you for you response.

    Best regards,
    Jakub Peschel
     
  30. PapperWing

    PapperWing

    Joined:
    Nov 3, 2014
    Posts:
    4
    Hi :) again me :D

    In my project I used PHG as public attribute.
    Here is piece of code:
    -----------------------------------------------------------------------
    using UnityEngine;
    using Gamelogic.Grids;

    public class StationSettingScript : MonoBehaviour {

    public GameObject station;
    public PointyHexGrid<Cell> grid;
    public int numberOfStations = 5;

    void Start () {
    -----------------------------------------------------------------------
    Grid up there is used for getting new edge grid. My problem is, that in the editor, there isn't any place to insert PHG.
    There is cell for station also for numberOfStations, but cell for grid is missing.

    Thank you for your advice.
    Best regards
    Jakub Peschel
     
  31. moliver

    moliver

    Joined:
    Nov 6, 2014
    Posts:
    5
    Hello, I've purchased your asset and am trying to build a 3D scene with the grid viewed at an angle. I do not want to use an orthographic camera.

    I am casting a ray and detecting what hex is being clicked on, but I am having trouble figuring out how to talk to the tile that has been clicked. How can I for example change that tiles color, once the raycast detects it collides with a tile at grid location 0,0?

    Also, in SpriteCell code, there is an OnClick() function. Where/how does this get called?
     
    Last edited: Nov 7, 2014
  32. robertwahler

    robertwahler

    Joined:
    Mar 6, 2013
    Posts:
    43
    I'm seeing high CPU usage in the editor as well and I'm keen to both understand the problem (so I don't make the same mistake in my own code) and have it fixed. I'd like it fixed because most of the example grids, even the small ones, hit my CPU twice as hard as any Unity scene I've ever worked with. Listening to laptop fans kick on/off is high on my list of irritating noises. Thanks for looking into this.
     
    Herman-Tulleken likes this.
  33. Culzean

    Culzean

    Joined:
    Jan 25, 2014
    Posts:
    48
    Hi there,
    Sorry if this has been asked before. I working with a hex grid system and am trying to hook it up with a map editor.

    I'm using this method to build the grid using custom hexes in a pointy hex grid. This has been based on some of the examples provided.

    publicvoidBuildGrid()
    {
    vargrid = PointyHexGrid<HexCell>.Rectangle(staticWorld.ScenarioColumns, staticWorld.ScenarioRows);

    varbaseMap = newPointyHexMap(hillPrefab.Dimensions);

    varcellMap = baseMap
    .WithWindow(ExampleUtils.ScreenRect)
    .AnchorCellTop()
    .To3DXY();

    foreach (varpointingrid)
    {
    varworldPosition = cellMap[point];
    PointyHexPointoffset = staticWorld.ConvertAxialToOffset(point);

    GameObjectprefab = Instantiate( staticWorld.SelectHillPrefab(grid,point) ) asGameObject;
    HexCellcell = prefab.GetComponent<HexCell>();

    HexDatacellData = staticWorld.GetHexData(point);

    ... ...

    grid[point] = cell;

    }
    }

    The trouble I'm having is, I want to the origin in the top left corner. But with an "even-r" horizontal layout. If this isn't clear then maybe a picture will help. It seem the pointy grid is always coming out as an odd-r horizontal layout. Is there some argument I can set to get the layout I'm looking for? Or do I have to create this differently?

    Thanks

    grid.jpg
     
  34. barjed

    barjed

    Joined:
    May 9, 2013
    Posts:
    70
    Hi Herman,

    I would like to achieve something like this with Grids:

    I have a standard DiamondGrid. I also have a method that selects a movement range (using the algorithm you have helped me earlier) and the selected points are stored in a separate List.

    Now I would like to have a "pulse" coming from the center of the selected subset (resulting in, for example, change of color) from time to time (I am using DOTween for this). The problem is, of course, calculating the pulse "steps".

    Is something like this possible with Grids?

    Thanks!
     
  35. moliver

    moliver

    Joined:
    Nov 6, 2014
    Posts:
    5
    Ignore this I was able to figure it out.

    However I am now running into a bad error:


    Internal compiler error. See the console log for more information. output was:
    Unhandled Exception: System.NotSupportedException: Operation is not supported.

    at System.Reflection.MonoGenericClass.GetCustomAttributes (System.Type attributeType, Boolean inherit) [0x00000] in <filename unknown>:0


    Some additional information from the log file:


    at System.Reflection.MonoGenericClass.GetCustomAttributes (System.Type attributeType, Boolean inherit) [0x00000] in <filename unknown>:0

    at Mono.CSharp.TypeManager.IsValidProperty (System.Reflection.PropertyInfo pi) [0x00000] in <filename unknown>:0

    at Mono.CSharp.TypeManager.IsSpecialMethod (System.Reflection.MethodBase mb) [0x00000] in <filename unknown>:0

    at Mono.CSharp.TypeManager.CSharpSignature (System.Reflection.MethodBase mb, Boolean show_accessor) [0x00000] in <filename unknown>:0

    at Mono.CSharp.TypeManager.CSharpSignature (System.Reflection.MethodBase mb) [0x00000] in <filename unknown>:0

    at Mono.CSharp.MethodGroupExpr.Error_InvalidArguments (Mono.CSharp.ResolveContext ec, Location loc, Int32 idx, System.Reflection.MethodBase method, Mono.CSharp.Argument a, Mono.CSharp.AParametersCollection expected_par, System.Type paramType) [0x00000] in <filename unknown>:0

    at Mono.CSharp.MethodGroupExpr.VerifyArgumentsCompat (Mono.CSharp.ResolveContext ec, Mono.CSharp.Arguments& arguments, Int32 arg_count, System.Reflection.MethodBase method, Boolean chose_params_expanded, Boolean may_fail, Location loc) [0x00000] in <filename unknown>:0

    at Mono.CSharp.MethodGroupExpr.OverloadResolve (Mono.CSharp.ResolveContext ec, Mono.CSharp.Arguments& Arguments, Boolean may_fail, Location loc) [0x00000] in <filename unknown>:0

    at Mono.CSharp.IndexerAccess.ResolveAccessor (Mono.CSharp.ResolveContext ec, Mono.CSharp.Expression right_side) [0x00000] in <filename unknown>:0

    at Mono.CSharp.IndexerAccess.DoResolve (Mono.CSharp.ResolveContext ec) [0x00000] in <filename unknown>:0

    at Mono.CSharp.Expression.Resolve (Mono.CSharp.ResolveContext ec, ResolveFlags flags) [0x00000] in <filename unknown>:0

    at Mono.CSharp.Expression.Resolve (Mono.CSharp.ResolveContext ec) [0x00000] in <filename unknown>:0

    at Mono.CSharp.ElementAccess.DoResolve (Mono.CSharp.ResolveContext ec) [0x00000] in <filename unknown>:0

    at Mono.CSharp.Expression.Resolve (Mono.CSharp.ResolveContext ec, ResolveFlags flags) [0x00000] in <filename unknown>:0

    at Mono.CSharp.Expression.Resolve (Mono.CSharp.ResolveContext ec) [0x00000] in <filename unknown>:0

    at Mono.CSharp.Probe.DoResolve (Mono.CSharp.ResolveContext ec) [0x00000] in <filename unknown>:0

    at Mono.CSharp.As.DoResolve (Mono.CSharp.ResolveContext ec) [0x00000] in <filename unknown>:0

    at Mono.CSharp.Expression.Resolve (Mono.CSharp.ResolveContext ec, ResolveFlags flags) [0x00000] in <filename unknown>:0

    at Mono.CSharp.Expression.Resolve (Mono.CSharp.ResolveContext ec) [0x00000] in <filename unknown>:0

    at Mono.CSharp.Assign.DoResolve (Mono.CSharp.ResolveContext ec) [0x00000] in <filename unknown>:0

    at Mono.CSharp.SimpleAssign.DoResolve (Mono.CSharp.ResolveContext ec) [0x00000] in <filename unknown>:0

    at Mono.CSharp.Expression.Resolve (Mono.CSharp.ResolveContext ec, ResolveFlags flags) [0x00000] in <filename unknown>:0

    at Mono.CSharp.Expression.Resolve (Mono.CSharp.ResolveContext ec) [0x00000] in <filename unknown>:0

    at Mono.CSharp.ExpressionStatement.ResolveStatement (Mono.CSharp.BlockContext ec) [0x00000] in <filename unknown>:0

    at Mono.CSharp.StatementExpression.Resolve (Mono.CSharp.BlockContext ec) [0x00000] in <filename unknown>:0

    at Mono.CSharp.Block.Resolve (Mono.CSharp.BlockContext ec) [0x00000] in <filename unknown>:0

    at Mono.CSharp.Block.Resolve (Mono.CSharp.BlockContext ec) [0x00000] in <filename unknown>:0

    at Mono.CSharp.ToplevelBlock.Resolve (Mono.CSharp.FlowBranching parent, Mono.CSharp.BlockContext rc, Mono.CSharp.ParametersCompiled ip, IMethodData md) [0x00000] in <filename unknown>:0
     
  36. Herman-Tulleken

    Herman-Tulleken

    Joined:
    Nov 20, 2009
    Posts:
    358
    Yup indeed. The Unity functionality probably duplicates exactly what we have done (It's a very obvious addition, something they should have added years ago. I am glad to hear they finally did.)
     
  37. Herman-Tulleken

    Herman-Tulleken

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

    Thanks for pointing this out. There are a few outdated things in those tutorials. I will have a look at them today and update them.
     
  38. Herman-Tulleken

    Herman-Tulleken

    Joined:
    Nov 20, 2009
    Posts:
    358
    Hi,

    I think you also sent an email to support. If so, I sent you a reply there. Otherwise let me know and I will respond in full.
     
  39. Herman-Tulleken

    Herman-Tulleken

    Joined:
    Nov 20, 2009
    Posts:
    358
    If I understand you correctly, what you want is concentric "circles" (which are really rings in hex shape) around a given point.

    To get the ring of radius r, you can use the following:

    var ringOfPoints = Grid.Where(p => (center - p).Magnitude == r);

    When using this for different values of r, you should be able to create the pulse effect.

    Let me know if I understood you correctly and whether this works for you.
     
  40. Herman-Tulleken

    Herman-Tulleken

    Joined:
    Nov 20, 2009
    Posts:
    358
    What version of Unity are you using? Is this an error you get just with a clean copy of Grids (none of your own)?
     
  41. c-Row

    c-Row

    Joined:
    Nov 10, 2009
    Posts:
    853
    Could you give a more detailed explanation of your approach? I'd love to try something similar with Grids.
     
  42. PapperWing

    PapperWing

    Joined:
    Nov 3, 2014
    Posts:
    4
    Hi,

    I've got one more question. How to cast for example IGrid to PointyHexGrid? All functions return IGrid and Unity throw me errors like

    Cannot implicitly convert type Gamelogic.Grids.IGrid<Gamelogic.Grids.TileCell,Gamelogic.Grids.PointyHexPoint>' to `Gamelogic.Grids.PointyHexGrid<Cell>'

    Sorry if it's some basic knowledge of C# i started with C# last week :)

    Thank for your help
    Jakub Peschel
     
    Last edited: Nov 12, 2014
  43. RDeluxe

    RDeluxe

    Joined:
    Sep 29, 2013
    Posts:
    117
    Hi,
    I did not code that part, and I just have basic understanding of how it works. My colleague is a bit busy right now, but he will try to explain this in detail asap !
     
    c-Row and Herman-Tulleken like this.
  44. Herman-Tulleken

    Herman-Tulleken

    Joined:
    Nov 20, 2009
    Posts:
    358
    You must just make sure the Cell types are the same, for example, if your cell is SpriteCell, then your cast must look like this:

    Code (csharp):
    1. var castGrid = (PointyHexGrid<SpriteCell>) gridInterface;
    It's also possible that some functions return grids that are not one of the obvious grids. Could you please give where you are trying to cast, just so I can make sure it's nit the case? (In general, these situations arise in very specific situations, so if you encounter them I would be interested to know).
     
  45. gamesmythe

    gamesmythe

    Joined:
    Apr 18, 2013
    Posts:
    1
    I'm trying to combine a GameLogic grid with the TouchScript multitouch library (so that I don't have to roll my own gesture support, for one). The problem I'm running into is that TouchScript requires the objects in the scene to have colliders in order for the raycasting to work. If I add a collider & rigidbody to the sprite on my SpriteCell descendant, the cells repel each other and, if gravity is left on, drop off the bottom of the screen.

    Does anyone have experience with adding polygon colliders & riigidbodies to sprite cells? Or is there a better way to do my gesture support? I need:
    • Works with win8 touch (for testing) as well as iOS/Andriod
    • Gestures for tap, double-tap, and camera drag (to see off-screen parts of the grid, but not scrolling past the edge of the grid)
     
  46. Herman-Tulleken

    Herman-Tulleken

    Joined:
    Nov 20, 2009
    Posts:
    358
    It should work if you switch on IsKinematic on the Rigidbody2D, if you don't need it off for some other reason (and I understand you correctly).
     
  47. ltkwan

    ltkwan

    Joined:
    Jul 27, 2014
    Posts:
    2
    Hello. How well does this work on Android? I looked around, and theres no indication that it does not work, but also no explicit indication that it does. The Trial package at least, does not compile for Android out-of-the-box.
     
  48. RDeluxe

    RDeluxe

    Joined:
    Sep 29, 2013
    Posts:
    117
    We have no problem compiling for Android with the Diamond package (paid). What errors do you get while compiling ?
     
  49. ltkwan

    ltkwan

    Joined:
    Jul 27, 2014
    Posts:
    2
    It was a quick and dirty test: I imported the Trial package into an empty project, opened the RectTest scene, switched the build to Android and tried to build it.

    Code (csharp):
    1.  
    2. Internal compiler error. See the console log for more information. output was:
    3. Unhandled Exception: System.Reflection.ReflectionTypeLoadException: The classes in the module cannot be loaded.
    4.  
    5.   at (wrapper managed-to-native) System.Reflection.Assembly:GetTypes (bool)
    6.  
    7.   at System.Reflection.Assembly.GetTypes () [0x00000] in <filename unknown>:0
    8.  
    9.   at Mono.CSharp.RootNamespace.ComputeNamespaces (System.Reflection.Assembly assembly, System.Type extensionType) [0x00000] in <filename unknown>:0
    10.  
    11.   at Mono.CSharp.RootNamespace.ComputeNamespace (Mono.CSharp.CompilerContext ctx, System.Type extensionType) [0x00000] in <filename unknown>:0
    12.  
    13.   at Mono.CSharp.GlobalRootNamespace.ComputeNamespaces (Mono.CSharp.CompilerContext ctx) [0x00000] in <filename unknown>:0
    14.  
    15.   at Mono.CSharp.Driver.LoadReferences () [0x00000] in <filename unknown>:0
    16.  
    17.  
    If you say the paid version works for you though I guess i'll give it a try.
     
  50. Wambli

    Wambli

    Joined:
    Feb 14, 2013
    Posts:
    13
    Hello there,
    a couple of questions
    • Is possible to define a different cell spacing for each axis in a regular grid?
    • Is there a way to define a grid with incremental cell spacing? (for each row for example)
    Thank you