Exemplo n.º 1
0
    // Start is called before the first frame update
    void Start()
    {
        _lineRenderMaterial = new Material(Shader.Find("Legacy Shaders/Particles/Alpha Blended Premultiply"));

        //Extract the springnodes from the node gameobjects to be used in the graph
        _nodes = new List <SpringNode>(_goNodes.Select(g => g.GetComponent <SpringNode>()));

        //Initialise lists
        _edges     = new List <Edge <SpringNode> >();
        _edgeLines = new List <GameObject>();

        //Set all the edges between nodes, including their weights
        _edges.Add(new Edge <SpringNode>(_nodes[0], _nodes[1], 7));
        _edges.Add(new Edge <SpringNode>(_nodes[1], _nodes[2], 3));
        _edges.Add(new Edge <SpringNode>(_nodes[2], _nodes[3], 4));
        _edges.Add(new Edge <SpringNode>(_nodes[1], _nodes[3], 2));
        _edges.Add(new Edge <SpringNode>(_nodes[4], _nodes[3], 3));
        _edges.Add(new Edge <SpringNode>(_nodes[4], _nodes[0], 15));

        //Create Graph out of edges
        _undirectedGraph = new UndirecteGraph <SpringNode, Edge <SpringNode> >(_edges);

        //Draw graphlines
        ResetGraphLines();
    }
Exemplo n.º 2
0
    // Start is called before the first frame update
    void Start()
    {
        GameObject voxelPrefab = Resources.Load <GameObject>("Prefabs/Node");

        _grid  = new GameObject[_gridDimensions.x, _gridDimensions.y];
        _edges = new List <Edge <GameObject> >();

        for (int x = 0; x < _gridDimensions.x; x++)
        {
            for (int y = 0; y < _gridDimensions.y; y++)
            {
                _grid[x, y] = GameObject.Instantiate(voxelPrefab, new Vector3(x * 2, 0, y * 2), Quaternion.identity);
                if (x > 0)
                {
                    _edges.Add(new Edge <GameObject>(_grid[x, y], _grid[x - 1, y]));
                }
                if (y > 0)
                {
                    _edges.Add(new Edge <GameObject>(_grid[x, y], _grid[x, y - 1]));
                }
            }
        }
        _undirectedGraph = new UndirecteGraph <GameObject, Edge <GameObject> >(_edges);
        _dijkstra        = new Dijkstra <GameObject, Edge <GameObject> >(_undirectedGraph);

        _edgeLines = new List <GameObject>();

        ResetGraphLines();
        SetGradient();
    }
    public void CreateGraph()
    {
        AllEmptyVoxels = new List <Voxel>();
        _edges         = new List <Edge <Voxel> >();


        for (int x = 0; x < GridSize.x; x++)
        {
            for (int y = 0; y < GridSize.y; y++)
            {
                for (int z = 0; z < GridSize.z; z++)
                {
                    if (x < GridSize.x - 1)
                    {
                        _edges.Add(new Edge <Voxel>(Voxels[x, y, z], Voxels[x + 1, y, z]));
                    }
                    if (y < GridSize.y - 1)
                    {
                        _edges.Add(new Edge <Voxel>(Voxels[x, y, z], Voxels[x, y + 1, z]));
                    }
                    if (z < GridSize.z - 1)
                    {
                        _edges.Add(new Edge <Voxel>(Voxels[x, y, z], Voxels[x, y, z + 1]));
                    }
                }
            }
        }

        VoxelGraph = new UndirecteGraph <Voxel, Edge <Voxel> >(_edges);
        _edgeLines = new List <GameObject>();
        //Status = LineType.Empty;
        ResetGraphLines();
    }
Exemplo n.º 4
0
    // Start is called before the first frame update
    void Start()
    {
        _edges = new List <Edge <GameObject> >();

        _edges.Add(new Edge <GameObject>(_nodes[0], _nodes[1]));
        _edges.Add(new Edge <GameObject>(_nodes[1], _nodes[2]));
        _edges.Add(new Edge <GameObject>(_nodes[2], _nodes[3]));
        _edges.Add(new Edge <GameObject>(_nodes[1], _nodes[3]));

        _undirectedGraph = new UndirecteGraph <GameObject, Edge <GameObject> >(_edges);
        _edgeLines       = new List <GameObject>();
        ResetGraphLines();
    }
Exemplo n.º 5
0
    public void CalculateVelocity(UndirecteGraph <HouseNode, Edge <HouseNode> > graph, float speed)
    {
        List <Edge <HouseNode> > connectedEdges = graph.GetConnectedEdges(this);
        Vector3 velocity = Vector3.zero;

        foreach (var edge in connectedEdges)
        {
            HouseNode connectedVertex = edge.GetOtherVertex(this);
            float     weight          = (float)edge.Weight;
            Vector3   direction       = connectedVertex.Position - this.Position;
            velocity += direction * (direction.magnitude - weight);
        }
        _velocity = velocity * speed;
    }