Struct NodeGraph
A simple graph structure that connects vertices/nodes together in 3D space. Nodes can have additional cost and flags associated with them.
Namespace: AnyPath.Graphs.Node
Assembly: AnyPath.dll
Syntax
public struct NodeGraph : IGraph<NodeGraphNode>, IDisposable
Remarks
This is a good option if your usecase only requires agents to go from point to point, and they always know themselves at which node (id) they are. If your usecase is more complicated, such as being able to travel arbitrary distances along the edges between points, have a look at LineGraph
This type of graph can also used in hierarichal pathfinding. If you have a very large world, you could have a NodeGraph where the Id's point to more detailed graphs. At first, you would run a query on the NodeGraph to see if two locations are connected, and if so, you run more detailed queries on the graphs that match these Id's.
Constructors
NodeGraph(Allocator)
Constructs an empty node graph
Declaration
public NodeGraph(Allocator allocator)
Parameters
| Type | Name | Description |
|---|---|---|
| Allocator | allocator |
Methods
Clear()
Clears the graph
Declaration
public void Clear()
ConnectNodes(int, int)
Make the edge between two nodes traversable in both directions
Declaration
public void ConnectNodes(int id1, int id2)
Parameters
| Type | Name | Description |
|---|---|---|
| int | id1 | |
| int | id2 |
ConnectNodesDirected(int, int)
Make the edge between from and to traversable only in a forward direction
Declaration
public void ConnectNodesDirected(int fromId, int toId)
Parameters
| Type | Name | Description |
|---|---|---|
| int | fromId | |
| int | toId |
GetNode(int)
Returns the node for a given Id
Declaration
public NodeGraphNode GetNode(int id)
Parameters
| Type | Name | Description |
|---|---|---|
| int | id |
Returns
| Type | Description |
|---|---|
| NodeGraphNode |
SetNode(int, float3)
Adds or sets the position of a vertex/node
Declaration
public void SetNode(int id, float3 position)
Parameters
| Type | Name | Description |
|---|---|---|
| int | id | The id of the node |
| float3 | position | The position of the node |
SetNode(int, float3, float, int)
Adds or sets the position of a vertex/node, as well as additional cost and flags
Declaration
public void SetNode(int id, float3 position, float enterCost, int flags)
Parameters
| Type | Name | Description |
|---|---|---|
| int | id | The id of the node |
| float3 | position | The position of the node |
| float | enterCost | Additional cost associated with visiting this node. |
| int | flags | Custom flags associated with the node |
TryGetNode(int, out NodeGraphNode)
Returns the node for a given Id
Declaration
public bool TryGetNode(int id, out NodeGraphNode node)
Parameters
| Type | Name | Description |
|---|---|---|
| int | id | |
| NodeGraphNode | node |
Returns
| Type | Description |
|---|---|
| bool |