Exemple #1
0
 private void Awake()
 {
     pathFinder = GameObject.Find("PathGraph").GetComponent <PathfindingGraph>();
     rb2d       = GetComponent <Rigidbody2D>();
     speed      = GetComponent <NPC>().moveSpeed;
     n          = GetComponent <NPC>();
 }
 protected override void OnStartRunning()
 {
     base.OnStartRunning();
     sw     = new Stopwatch();
     graph  = GameHandler.instance.pathfindingGraph;
     marker = GameHandler.instance.markerPrefab;
 }
    private void Awake()
    {
        instance      = this;
        entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
        //selectionBox.gameObject.SetActive( false );

        pathfindingGraph = new PathfindingGraph();
        UnitSpawner unitSpawner = new UnitSpawner(unitMesh, unitMaterial);
    }
    AStar astar; // Calculation of path on graph

	// Use this for initialization
	void Start () {
        if (Instance == null){
            Instance = this;
        }
        else {
            Debug.LogError("Only one instance of PathfindingManager can be created");
        }
        graph = new PathfindingGraph();
        
    }
Exemple #5
0
        public void FindShortestPath()
        {
            var g = new PathfindingGraph <char>();

            g.AddVertex('A', new Dictionary <char, int>()
            {
                { 'B', 7 }, { 'C', 8 }
            });
            g.AddVertex('B', new Dictionary <char, int>()
            {
                { 'A', 7 }, { 'F', 2 }
            });
            g.AddVertex('C', new Dictionary <char, int>()
            {
                { 'A', 8 }, { 'F', 6 }, { 'G', 4 }
            });
            g.AddVertex('D', new Dictionary <char, int>()
            {
                { 'F', 8 }
            });
            g.AddVertex('E', new Dictionary <char, int>()
            {
                { 'H', 1 }
            });
            g.AddVertex('F', new Dictionary <char, int>()
            {
                { 'B', 2 }, { 'C', 6 }, { 'D', 8 }, { 'G', 9 }, { 'H', 3 }
            });
            g.AddVertex('G', new Dictionary <char, int>()
            {
                { 'C', 4 }, { 'F', 9 }
            });
            g.AddVertex('H', new Dictionary <char, int>()
            {
                { 'E', 1 }, { 'F', 3 }
            });

            var path = g.ShortestPath(0, 'A', 'H');

            path.ShouldNotBeNull();
            path.Count.ShouldBe(3);
        }
Exemple #6
0
/*
 * Graph section
 */
    public void InitializeGraph()
    {
        _graph = new PathfindingGraph();
        PathfindingMap.CompressBounds();

        //analyze pathfinding map and build pathfinding graph
        foreach (Vector3Int pos in PathfindingMap.cellBounds.allPositionsWithin)
        {
            BattleTile tile = PathfindingMap.GetTile <BattleTile>(pos);
            if (tile != null)
            {
                Node centralTileNode = _graph.GetNode(pos);
                if (centralTileNode == null)
                {
                    centralTileNode               = new Node();
                    centralTileNode.Coords        = pos;
                    centralTileNode.ProcessStatus = Node.NodeProcessStatus.NotVisited;
                    if (tile.IsBlocked)
                    {
                        centralTileNode.GameStatus = Node.TileGameStatus.Block;
                    }
                    else
                    {
                        centralTileNode.GameStatus = Node.TileGameStatus.Empty;
                    }
                    centralTileNode.Influences = new List <KeyValuePair <int, Node.InfluenceStatus> >();
                    _graph.AddNode(centralTileNode);
                }

                //adding connections
                if (centralTileNode.GameStatus == Node.TileGameStatus.Empty)
                {
                    for (int i = 0; i < 4; ++i)
                    {
                        Vector3Int currentTileLocation = pos + offsets[i];
                        BattleTile offsetTile          = PathfindingMap.GetTile <BattleTile>(currentTileLocation);
                        if (offsetTile != null)
                        {
                            Node offsetTileNode = _graph.GetNode(currentTileLocation);
                            if (offsetTileNode == null)
                            {
                                offsetTileNode               = new Node();
                                offsetTileNode.Coords        = currentTileLocation;
                                offsetTileNode.ProcessStatus = Node.NodeProcessStatus.NotVisited;
                                if (offsetTile.IsBlocked)
                                {
                                    offsetTileNode.GameStatus = Node.TileGameStatus.Block;
                                }
                                else
                                {
                                    offsetTileNode.GameStatus = Node.TileGameStatus.Empty;
                                }
                                offsetTileNode.Influences = new List <KeyValuePair <int, Node.InfluenceStatus> >();
                                _graph.AddNode(offsetTileNode);
                            }
                            if (offsetTileNode.GameStatus == Node.TileGameStatus.Empty)
                            {
                                centralTileNode.AddConnection(offsetTileNode);
                            }
                        }
                    }
                }
            }
        }
    }
Exemple #7
0
 public AStar(PathfindingGraph graph)
 {
     this.graph = graph;
 }