public void CreatePaths() { _emptyVoxels = _voxelGrid.AllEmptyVoxels; // targetPool = Queue<Voxel>(_targets) object Queue <Voxel> targetPool = new Queue <Voxel>(_targets); // How to Change the _voxelGrid.VoxelGraph to the emptyVoxels Dijkstra <Voxel, Edge <Voxel> > dijkstra = new EasyGraph.Dijkstra <Voxel, Edge <Voxel> >(_voxelGrid.VoxelGraph); //Dijkstra<Voxel, Edge<Voxel>> dijkstra = new EasyGraph.Dijkstra<Voxel, Edge<Voxel>>(_AllEmptyVoxels); _publicPath.AddRange(dijkstra.GetShortestPath(targetPool.Dequeue(), targetPool.Dequeue())); while (targetPool.Count > 0) { //Get the distance from the next point to all the points in path //take the shortest distance //store the shortest path into path Voxel nextVoxel = targetPool.Dequeue(); SetNextShortestPath(nextVoxel, _publicPath, dijkstra); } foreach (var voxel in _publicPath) { voxel.SetAsPublicPath(); //voxel.SetAsPublicVoxel(); //_voxelGrid.SetAsPrivateLine(); Debug.Log("public " + _publicPath.Count); } }
public void GeneratePrivatePaths() { Dijkstra <Voxel, Edge <Voxel> > dijkstra = new EasyGraph.Dijkstra <Voxel, Edge <Voxel> >(_voxelGrid.VoxelGraph); int createdPaths = 0; while (createdPaths < _targetPrivateAmount) { // get a random voxel for boundary var origin = GetRandomBoundaryVoxel(); //_privateNode.AddRange(dijkstra.DijkstraCalculateWeights(origin)); //var origin = GetRandomBoundaryVoxel(_privateNode); //var origin = _privateNode.GetRandomBoundaryVoxel().ToList(); dijkstra.DijkstraCalculateWeights(origin); // try to connect to the closest point in the public path of this layer // if none available, use the closest point Voxel target; var targetsOnLayer = _publicPath.Where(v => v.Index.y == origin.Index.y).ToList(); if (targetsOnLayer.Count > 0) { target = targetsOnLayer.MinBy(v => dijkstra.VertexWeight(v)); } else { target = _publicPath.MinBy(v => dijkstra.VertexWeight(v)); } var path = dijkstra.GetShortestPath(origin, target); foreach (var voxel in path) { if (!_publicPath.Contains(voxel)) { voxel.SetAsPrivatePath(); //voxel.SetAsPrivateVoxel(); if (!_privatePath.Contains(voxel)) { _privatePath.Add(voxel); } } } createdPaths++; // createdPaths = createdPaths + 1; Debug.Log("private path " + _privatePath.Count); } }
private IEnumerator GeneratePrivatePathsAnimated() { Dijkstra <Voxel, Edge <Voxel> > dijkstra = new EasyGraph.Dijkstra <Voxel, Edge <Voxel> >(_voxelGrid.VoxelGraph); int createdPaths = 0; while (createdPaths < _targetPrivateAmount) { // get a random voxel var origin = GetRandomBoundaryVoxel(); foreach (var voxel in _privateNode) { Debug.Log("private node " + _privateNode.Count); } dijkstra.DijkstraCalculateWeights(origin); // try to connect to the closest point in the public path of this layer // if none available, use the closest point Voxel target; var targetsOnLayer = _publicPath.Where(v => v.Index.y == origin.Index.y).ToList(); if (targetsOnLayer.Count > 0) { target = targetsOnLayer.MinBy(v => dijkstra.VertexWeight(v)); } else { target = _publicPath.MinBy(v => dijkstra.VertexWeight(v)); } var path = dijkstra.GetShortestPath(origin, target); foreach (var voxel in path) { if (!_publicPath.Contains(voxel)) { voxel.SetAsPrivateVoxel(); if (!_privatePath.Contains(voxel)) { _privatePath.Add(voxel); } Debug.Log("private path " + _privatePath.Count); } } createdPaths++; yield return(new WaitForSeconds(0.1f)); } }
private IEnumerator CreatePathAnimated() { Queue <Voxel> targetPool = new Queue <Voxel>(_targets); Dijkstra <Voxel, Edge <Voxel> > dijkstra = new EasyGraph.Dijkstra <Voxel, Edge <Voxel> >(_voxelGrid.VoxelGraph); _publicPath.AddRange(dijkstra.GetShortestPath(targetPool.Dequeue(), targetPool.Dequeue())); while (targetPool.Count > 0) { //Get the distance from the next point to all the points in path //take the shortest distance //store the shortest path into path Voxel nextVoxel = targetPool.Dequeue(); SetNextShortestPath(nextVoxel, _publicPath, dijkstra); } Debug.Log("public " + _publicPath.Count); foreach (var voxel in _publicPath) { voxel.SetAsPublicVoxel(); yield return(new WaitForSeconds(0.1f)); } }