Join Jesse Freeman for an in-depth discussion in this video Storing the node, part of Unity 5 2D: Pathfinding.
- Now we need to create our graph classes constructor.…We'll do this by making a public method…called Graph with no return.…And our constructor will accept a 2D array type int…and we'll call it grid.…A 2D array is a type of array…that has nested arrays inside of it.…In this case, it's going to represent…the rows and columns of our grid.…In our constructor, let's set the value…for those two fields of our class.…We'll start by setting the rows…to the grid length of item zero.…
And for columns, we'll get the index of one.…Now we're going to need to set up our nodes array.…Since each node is going to store reference…to its own neighbors, we can actually keep…all of the node data as a flat array inside of our graph.…In order to do this though, we're going to need to create…enough spaces in the array to match the length of the grid.…We can do this by sending the nodes field…to a new node array.…And inside of it, we'll use the grid's Length.…Next, we're going to loop through all the spaces…in the array and create an empty node.…
- What is A*?
- Adding node classes and properties
- Storing and indexing graph nodes
- Building the search class
- Traversing the nodes
- Searching adjacent nodes
- Testing the search
- Building a test map
- Creating and coloring a grid