private void CreateGrids()
{
//by default, masks are active
m_maskActive = true;
//random seeder for testing
System.Random testIntGenerator = new System.Random();
//Game object which is the parent of all the hex tiles
if(GameObject.Find("HexGrids") == null)
{
InitDebugStates();
InitList();
//parent object to all the grids
GameObject hexGridGroup = new GameObject("HexGrids");
for (int y = 0; y < m_gridNumVer; y++)
{
//row
//alternating pattern
int gridsToDraw = (y%2==0)?m_gridNumHor:m_gridNumHor-1;
for (int x = 0; x < gridsToDraw; x++)
{
//col
GameObject hex = (GameObject)Instantiate(m_hexPrefab);
hex.name = String.Format("Grid[{0}][{1}]",y,x);
//get world coordinates of grid
hex.transform.position = CalcWorldCoord(x,y);
//assign parent
hex.transform.parent = hexGridGroup.transform;
Vector2 grid2DPosition = new Vector2(hex.transform.position.x, hex.transform.position.z);
//initialise model
hex.GetComponent<HexGridModel>().Initialise(grid2DPosition,y,x); //x,y denoting col and row of grid
hex.GetComponent<TnGAttribute>().m_height = 1;
hex.GetComponent<TnGAttribute>().m_terrainType = TerrainType.normal;
hex.tag = "Grid";
//add mask to the grid as children
GameObject mask = (GameObject)Instantiate(m_hexMaskPrefab);
mask.name = "mask";
hex.GetComponent<MaskManager>().InitMasks(mask,m_hexRedMaskMat,m_hexDarkRedMaskMat,m_hexGreenMaskMat,m_hexBlueMaskMat,m_hexOutlineMaskMat);
//set the test bit in terrain component of hexmap to test reference
int testInt = testIntGenerator.Next(0,m_gridNumHor);
//test case set to 1
if(testInt == 1)
m_hexGridRefTestNum ++;
hex.GetComponent<TestAttribute>().testNum = testInt;
m_grids.Add(hex);
}
}
}
}