private void Awake() { IsWalkable = true; HaxCoordinate = new HaxCoordinate(); AstarProperties = new AStarProperties(); BreadthFirstProperties = new BreadthFirstProperties(); m_Mesh = GetComponent <HaxMesh>(); }
private void CreateGrid() { m_Nodes = new HaxNode[m_GridSize.x, m_GridSize.y]; m_SpacingSize = new Vector2(Mathf.Sqrt(3) * m_CellSize, 2 * m_CellSize); GameObject cell = new GameObject(); cell.AddComponent <HaxNode>(); cell.AddComponent <HaxMesh>(); SphereCollider col = cell.AddComponent <SphereCollider>(); col.radius = m_CellSize; cell.name = "Cell"; for (int x = 0; x < m_GridSize.x; x++) { for (int y = 0; y < m_GridSize.y; y++) { m_Nodes[x, y] = Instantiate(cell).GetComponent <HaxNode>(); m_Nodes[x, y].transform.parent = this.transform; m_Nodes[x, y].SetCoordinate(new Vector2Int(x, y)); m_Nodes[x, y].gameObject.name = "Node" + x.ToString() + " " + y.ToString(); HaxMesh haxCell = m_Nodes[x, y].GetComponent <HaxMesh>(); haxCell.m_CellSize = m_CellSize; haxCell.transform.position = new Vector3(haxCell.transform.position.x, haxCell.transform.position.y, -(y * m_SpacingSize.y * 0.75F)); if (y % 2 == 0) { haxCell.transform.position = new Vector3(x * m_SpacingSize.x, haxCell.transform.position.y, haxCell.transform.position.z); } else { haxCell.transform.position = new Vector3(m_SpacingSize.x * 0.5f + x * m_SpacingSize.x, haxCell.transform.position.y, haxCell.transform.position.z); } } } Destroy(cell); }