Example #1
0
    public void RebuildGraph()
    {
        graph.Init(50, 50);

        foreach (var tile in tiles)
        {
            var tileGraph     = tile.GetComponent <Graph>();
            var tileGraphView = tileGraph.GetComponent <GraphView>();

            foreach (var wall in tile.walls)
            {
                graphView.AddWall(wall);
            }

            foreach (var tileNode in tileGraph.Nodes)
            {
                var nodeView = tileNode.nodeView;
                nodeView.tileId = tile.tileId;

                var nodeWorldPos = nodeView.transform.position;
                var newNode      = graph.CreateNode(nodeWorldPos);

                newNode.position = new Vector3(nodeWorldPos.x, nodeWorldPos.y, nodeWorldPos.z);
                newNode.nodeType = tileNode.nodeType;

                tile.GetComponent <GraphView>().drawGizmo = false;

                graph.AddNode(newNode);
                nodeToTile.Add(newNode.NodeIndex, tile);
            }

            var nodeViews = tile.GetComponentsInChildren <NodeView>();
            foreach (var nodeView in nodeViews)
            {
                nodeView.gameObject.SetActive(false);
            }
        }

        graphView.CreateNodeViews(graph);
        graphView.CreateEdgesBetweenNodes();

        foreach (var node in graph.Nodes)
        {
            node.nodeView = graphView.nodeViews.Single(x => x.nodeIndex == node.NodeIndex);
        }

        setupComplete.Invoke();
    }