void displayVertices() { baseGraphData baseGraph = new baseGraphData(); baseGraph.size = this.size; for (int i = 0; i < size; i++) { for (int j = 0; j < size; j++) { GameObject vertex = Instantiate(vertexGO, new Vector3(transform.position.x + j, transform.position.y - i, 0), Quaternion.identity); vertex.name = graphNo + " - " + i + "," + j; vertex.transform.parent = gameObject.transform; vertexScript vs = vertex.GetComponent <vertexScript>(); if ((graphNo == 1) && (i == 0 || i == size - 1 || j == 0 || j == size - 1)) { if (!startingPointSet && UnityEngine.Random.Range(0f, 1f) <= 0.5f) { vs.setStartingPoint(true); startingPointSet = true; startingPointGO = vs.gameObject; startingPoingScript = vs; } borderVertices.Add(vs); } vs.setName(vertexNumbering); vertexNumbering++; } } }
public IEnumerator exportBaseGraphData() { yield return(new WaitForSeconds(1)); baseGraphData baseGraph = new baseGraphData(); baseGraph.size = this.size; GameObject[] vertexGOs = new GameObject[transform.childCount]; //vertexGOs = GameObject.FindGameObjectsWithTag("vertex"); for (int i = 0; i < transform.childCount; i++) { vertexGOs[i] = transform.GetChild(i).gameObject; } foreach (GameObject vertex in vertexGOs) { vertexData vertexData = new vertexData(); vertexScript vs = vertex.GetComponent <vertexScript>(); GameObject[] edgeGOs = new GameObject[vertex.transform.childCount]; //Debug.Log("This vertex has " + vertex.transform.childCount + " children"); for (int i = 0; i < vertex.transform.childCount; i++) { edgeGOs[i] = vertex.transform.GetChild(i).gameObject; } bool[] activeEdges = new bool[8]; for (int j = 0; j < edgeGOs.Length - 1; j++) { //Debug.Log("J - " + j + ", edgesGOs Length - " + edgeGOs.Length); if (edgeGOs[j].GetComponent <MeshRenderer>().enabled == true) { if (vs.isEdgeConnected(edgeGOs[j].GetComponent <edgeScript>()) != -1) { activeEdges[vs.isEdgeConnected(edgeGOs[j].GetComponent <edgeScript>())] = true; } } } vertexData.setVertexData(vs.getPos(), activeEdges, vs.getStartingPoint(), vs.getObjectivePoint()); baseGraph.addVertex(vertexData); } string baseGraphString = JsonUtility.ToJson(baseGraph); DirectoryInfo dir = new DirectoryInfo("Assets/baseGraphJSONs/"); FileInfo[] fileInfo = dir.GetFiles(); System.IO.File.WriteAllText("Assets/baseGraphJSONs/BaseGraphData" + fileInfo.Count() + ".json", baseGraphString); baseGraphString = ""; baseGraph.clear(); }