Search Unity

Huge grid question

Discussion in 'Scripting' started by Fluzing, Jul 28, 2014.

  1. Fluzing

    Fluzing

    Joined:
    Apr 5, 2013
    Posts:
    815
    Hi All,

    I am trying to make an huge grid in the style of Minesweeper. What I want the player to be able to do is to scroll around the grid and to zoom in and out to see the whole grid or a specific part of it. Each grid tile has a number or a symbol on it.

    I am a bit confused on how to tackle this. Making a huge grid made up of quads is not a good way of doing this I would guess, since that would be inefficient. Does anyone have a suggestion on how to tackle this?
     
  2. smitchell

    smitchell

    Joined:
    Mar 12, 2012
    Posts:
    702
    How big is the grid actually going to be? I personally wouldn't create a grid of actual objects.
     
  3. smitchell

    smitchell

    Joined:
    Mar 12, 2012
    Posts:
    702
    Wait maybe you might have to since each grid item would have to be modifiable right?
     
  4. Fluzing

    Fluzing

    Joined:
    Apr 5, 2013
    Posts:
    815
    Yeah, each tile would be modifiable. Not too hard to store that in a 2D array though. The problem is scrolling trough a huge number of tiles. There is no use them actually existing if they are not in view.
     
  5. smitchell

    smitchell

    Joined:
    Mar 12, 2012
    Posts:
    702
    how big is the grid going to be? I'm sure it'll be fine unless it's something like 10k x 10k ..
     
  6. smitchell

    smitchell

    Joined:
    Mar 12, 2012
    Posts:
    702
    The largest grid I worked with was 100 x 100 and that performed fine.
     
  7. willemsenzo

    willemsenzo

    Joined:
    Nov 15, 2012
    Posts:
    585
    You have some options.

    - Use a projector with grid texture
    - Use dirctional light with cookie set to gridmaterial
    - Use GL class to render lines

    GL class is maybe most flexible but a projector is easier to set up. However, I noticed some bug where the grid isnt completely projected whenever I zoom out too much. A directional light with cookie doesnt have this issue but it dramatically increases drawcalls. Projectors work good on flat surfaces, on a sloped surface the texture might get noticeablely stretched.

    Last of all choices would be line renderer but since a line renderer means a drawcall it's not a viable option.
     
  8. Fluzing

    Fluzing

    Joined:
    Apr 5, 2013
    Posts:
    815
    But how would I use that when scrolling? Also, I want to depict numbers on the different grid tiles. How would I do that efficiently?
     
  9. smitchell

    smitchell

    Joined:
    Mar 12, 2012
    Posts:
    702
    You could have a class for your grid item. Which has the value on. Then Instantiate the prefab on start

    Something like this(pseudo code)

    Public Class gridItem {
    Int xPos
    Int yPos
    Int value
    }

    Public class your mono behavior {
    Public gridItem[] myGridItemsArray;

    Start () {
    //initialise your grid
    }
    }