Esempio n. 1
0
    //public void Traverse_PostGen(Graph.Cell cell)
    //{

    //    visitedcells.Add(cell);

    //    List<Graph.Edge> unvisistedEdges = cell.Edges.FindAll(v => !visitedcells.Contains(v.Cell1) || !visitedcells.Contains(v.Cell2));

    //    if (unvisistedEdges.Count == 0)
    //    {
    //        Traverse_PostGen(path.Pop());
    //    }
    //    else
    //    {
    //        path.Push(cell);
    //        Shuffle(unvisistedEdges);
    //        foreach (Graph.Edge edge in unvisistedEdges)
    //        {
    //            Destroy(edge.Wall);
    //            Traverse_PostGen(visitedcells.Contains(edge.Cell1) ? edge.Cell2 : edge.Cell1);
    //        }
    //    }
    //}

    public void Traverse_PostGen(Graph.Cell cell)
    {
        visitedcells.Add(cell);

        List <Graph.Edge> unvisistedEdges = cell.Edges.FindAll(v => !visitedcells.Contains(v.Cell1) || !visitedcells.Contains(v.Cell2));

        Shuffle(unvisistedEdges);

        if (unvisistedEdges.Count == 0)
        {
            if (path.Count > 0)
            {
                Traverse_PostGen(path.Pop());
            }
            else
            {
                return;
            }
        }
        else
        {
            path.Push(cell);
            Graph.Edge chosenEdge = unvisistedEdges[r.Next(0, unvisistedEdges.Count)];
            Destroy(chosenEdge.Wall);
            Traverse_PostGen(visitedcells.Contains(chosenEdge.Cell1) ? chosenEdge.Cell2 : chosenEdge.Cell1);
        }
    }
Esempio n. 2
0
    //#region Post-Generation DFS
    public void DepthFirstSearch_PostGen(Graph graph)
    {
        visitedcells = new List <Graph.Cell>();
        path         = new Stack <Graph.Cell>();

        Graph.Cell root = graph.cells[r.Next(0, graph.cells.Count)];

        Traverse_PostGen(root);
    }
Esempio n. 3
0
    private void OnDrawGizmos()
    {
        Gizmos.color = Color.white;
        for (int i = 0; i < borders.Count; i++)
        {
            Gizmos.DrawLine(borders[i], borders[(i + 1) % borders.Count]);
        }

        Gizmos.color = Color.green;
        foreach (Vector3 p in seeds)
        {
            Gizmos.DrawWireSphere(p, debugSize);
        }

        if (graph != null)
        {
            Gizmos.color = Color.grey;
            Gizmos.DrawLine(graph.boundaries.min, new Vector3(graph.boundaries.min.x, 0, graph.boundaries.max.z));
            Gizmos.DrawLine(new Vector3(graph.boundaries.min.x, 0, graph.boundaries.max.z), graph.boundaries.max);
            Gizmos.DrawLine(graph.boundaries.max, new Vector3(graph.boundaries.max.x, 0, graph.boundaries.min.z));
            Gizmos.DrawLine(new Vector3(graph.boundaries.max.x, 0, graph.boundaries.min.z), graph.boundaries.min);

            Gizmos.color = Color.red;
            foreach (KeyValuePair <Vector2, Graph.Node> entry in graph.nodesDictionary)
            {
                Vector2 p = entry.Key;
                Gizmos.DrawWireCube(new Vector3(p.x, 0, p.y), debugSize * Vector3.one);
            }

            Gizmos.color = Color.yellow;
            foreach (KeyValuePair <int, Graph.Link> entry in graph.links)
            {
                Vector2 p1 = entry.Value.start.position;
                Vector2 p2 = entry.Value.end.position;
                Gizmos.DrawLine(new Vector3(p1.x, 0, p1.y), new Vector3(p2.x, 0, p2.y));
            }

            Ray ray = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);
            if (ray.direction.y != 0f)
            {
                Vector3 mousep = ray.origin - (ray.origin.y / ray.direction.y) * ray.direction;
                Gizmos.color = Color.blue;
                Gizmos.DrawWireSphere(mousep, debugSize);

                Graph.Cell c = graph.GetCellAt(new Vector2(mousep.x, mousep.z));
                if (c != null)
                {
                    Gizmos.DrawWireSphere(new Vector3(c.barycenter.x, 0, c.barycenter.y), debugSize);
                }
            }

            foreach (KeyValuePair <int, Graph.Cell> entry in graph.cells)
            {
                if (entry.Value.classified == 1)
                {
                    Gizmos.color = Color.cyan;
                    Gizmos.DrawWireSphere(new Vector3(entry.Value.barycenter.x, 0, entry.Value.barycenter.y), debugSize);
                }
                else if (entry.Value.classified == 2)
                {
                    Gizmos.color = Color.black;
                    Gizmos.DrawWireSphere(new Vector3(entry.Value.barycenter.x, 0, entry.Value.barycenter.y), debugSize);
                }
            }
        }
    }