public IEnumerable <Vector2> Neighbors(Grid2DVertexComponent v) // may also want to use node? { foreach (Vector2 dir in Directions) { Vector2 next = new Vector2(v.vertexPos.x + dir.x, v.vertexPos.y + dir.y); if (InBounds(next) && IsValid(next)) { yield return(next); } } }
/* Fill each vertex of the grid with a GameObject. */ private void SpawnVerticies(GameObject grid2D) { int boardDimensions = vertices.Length; for (int i = 0; i < boardDimensions; i++) { GameObject vObj = new GameObject("vertex " + i); Grid2DVertexComponent vRef = vObj.AddComponent <Grid2DVertexComponent> ( ); if (areVertexInteractable) { vObj.gameObject.AddComponent <BoxCollider2D> ( ); } vObj.transform.SetParent(grid2D.transform); vObj.transform.position = vertices[i]; vObj.transform.rotation = Quaternion.identity; vRef.InitOnStart( ); vertexTable.Add(vertices[i], vObj); } }