Exemplo n.º 1
0
    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();
    }