Dungeon Architect  17.0.0
SharpNav.Crowds.Crowd Class Reference

The Crowd class manages pathfinding for multiple agents simulatenously. More...

Public Member Functions

 Crowd (int maxAgents, float maxAgentRadius, ref TiledNavMesh navMesh)
 Initializes a new instance of the Crowd class. More...
 
ObstacleAvoidanceQuery.ObstacleAvoidanceParams GetObstacleAvoidanceParams (int idx)
 
void SetObstacleAvoidanceParams (int idx, ObstacleAvoidanceQuery.ObstacleAvoidanceParams parameters)
 
int GetAgentCount ()
 
Agent GetAgent (int idx)
 
int AddAgent (Vector3 pos, AgentParams parameters)
 Add an agent to the crowd. More...
 
bool RemoveAgent (int index)
 The agent is deactivated and will no longer be processed. It can still be reused later. More...
 
int GetActiveAgents (Agent[] agents)
 The crowd contains active and inactive agents. Only add all the active agents to a separate array. More...
 
int GetAgentIndex (Agent agent)
 Get the agent's index in the array More...
 
void Update (float dt)
 Update the crowd pathfinding periodically More...
 
void UpdateMoveRequest ()
 Change the move requests for all the agents More...
 
void UpdateTopologyOptimization (Agent[] agents, int numAgents, float dt)
 Reoptimize the path corridor for all agents More...
 
void CheckPathValidity (Agent[] agents, int agentCount, float dt)
 Make sure that each agent is taking a valid path More...
 
bool OverOffmeshConnection (Agent ag, float radius)
 
void CalcSmoothSteerDirection (Agent ag, ref Vector3 dir)
 Calculate a vector based off of the map More...
 
void CalcStraightSteerDirection (Agent ag, ref Vector3 dir)
 Calculate a straight vector to the destination More...
 
float GetDistanceToGoal (Agent ag, float range)
 Find the crowd agent's distance to its goal More...
 
int GetNeighbours (Vector3 pos, float height, float range, Agent skip, CrowdNeighbor[] result, int maxResult, Agent[] agents, ProximityGrid< Agent > grid)
 Get the crowd agent's neighbors. More...
 
int AddNeighbour (Agent agent, float dist, CrowdNeighbor[] neis, int nneis, int maxNeis)
 Add a CrowdNeighbor to the array More...
 
int AddToPathQueue (Agent newag, Agent[] agents, int numAgents, int maxAgents)
 Add the CrowdAgent to the path queue More...
 
int AddToOptQueue (Agent newag, Agent[] agents, int numAgents, int maxAgents)
 Add the CrowdAgent to the optimization queue More...
 

Detailed Description

The Crowd class manages pathfinding for multiple agents simulatenously.

Definition at line 22 of file Crowd.cs.

Constructor & Destructor Documentation

◆ Crowd()

SharpNav.Crowds.Crowd.Crowd ( int  maxAgents,
float  maxAgentRadius,
ref TiledNavMesh  navMesh 
)

Initializes a new instance of the Crowd class.

Parameters
maxAgentsThe maximum agents allowed
maxAgentRadiusThe maximum radius for an agent
navMeshThe navigation mesh

Definition at line 70 of file Crowd.cs.

Member Function Documentation

◆ AddAgent()

int SharpNav.Crowds.Crowd.AddAgent ( Vector3  pos,
AgentParams  parameters 
)

Add an agent to the crowd.

Parameters
posThe agent's position
parametersThe settings
Returns
The id of the agent (-1 if there is no empty slot)

Definition at line 156 of file Crowd.cs.

◆ AddNeighbour()

int SharpNav.Crowds.Crowd.AddNeighbour ( Agent  agent,
float  dist,
CrowdNeighbor[]  neis,
int  nneis,
int  maxNeis 
)

Add a CrowdNeighbor to the array

Parameters
AgentThe neighbor
distDistance from current agent
neisThe neighbors array
nneisThe number of neighbors
maxNeisThe maximum number of neighbors allowed
Returns
An updated neighbor count

Definition at line 1108 of file Crowd.cs.

◆ AddToOptQueue()

int SharpNav.Crowds.Crowd.AddToOptQueue ( Agent  newag,
Agent[]  agents,
int  numAgents,
int  maxAgents 
)

Add the CrowdAgent to the optimization queue

Parameters
newagThe new CrowdAgent
agentsThe current CrowdAgent array
numAgentsThe number of CrowdAgents
maxAgentsThe maximum number of agents allowed
Returns
An updated agent count

Definition at line 1214 of file Crowd.cs.

◆ AddToPathQueue()

int SharpNav.Crowds.Crowd.AddToPathQueue ( Agent  newag,
Agent[]  agents,
int  numAgents,
int  maxAgents 
)

Add the CrowdAgent to the path queue

Parameters
newagThe new CrowdAgent
agentsThe current CrowdAgent array
numAgentsThe number of CrowdAgents
maxAgentsThe maximum number of agents allowed
Returns
An updated agent count

Definition at line 1168 of file Crowd.cs.

◆ CalcSmoothSteerDirection()

void SharpNav.Crowds.Crowd.CalcSmoothSteerDirection ( Agent  ag,
ref Vector3  dir 
)

Calculate a vector based off of the map

Parameters
agThe agent
dirThe resulting steer direction

Definition at line 991 of file Crowd.cs.

◆ CalcStraightSteerDirection()

void SharpNav.Crowds.Crowd.CalcStraightSteerDirection ( Agent  ag,
ref Vector3  dir 
)

Calculate a straight vector to the destination

Parameters
agThe agent
dirThe resulting steer direction

Definition at line 1026 of file Crowd.cs.

◆ CheckPathValidity()

void SharpNav.Crowds.Crowd.CheckPathValidity ( Agent[]  agents,
int  agentCount,
float  dt 
)

Make sure that each agent is taking a valid path

Parameters
agentsThe agent array
agentCountThe number of agents
dtTime until next update

Definition at line 863 of file Crowd.cs.

◆ GetActiveAgents()

int SharpNav.Crowds.Crowd.GetActiveAgents ( Agent[]  agents)

The crowd contains active and inactive agents. Only add all the active agents to a separate array.

Parameters
agentsThe array of active agents
Returns
The number of active agents

Definition at line 208 of file Crowd.cs.

◆ GetAgentIndex()

int SharpNav.Crowds.Crowd.GetAgentIndex ( Agent  agent)

Get the agent's index in the array

Parameters
agentThe agent
Returns
The index

Definition at line 228 of file Crowd.cs.

◆ GetDistanceToGoal()

float SharpNav.Crowds.Crowd.GetDistanceToGoal ( Agent  ag,
float  range 
)

Find the crowd agent's distance to its goal

Parameters
agThw crowd agent
rangeThe maximum range
Returns
Distance to goal

Definition at line 1045 of file Crowd.cs.

◆ GetNeighbours()

int SharpNav.Crowds.Crowd.GetNeighbours ( Vector3  pos,
float  height,
float  range,
Agent  skip,
CrowdNeighbor[]  result,
int  maxResult,
Agent[]  agents,
ProximityGrid< Agent grid 
)

Get the crowd agent's neighbors.

Parameters
posCurrent position
heightThe height
rangeThe range to search within
skipThe current crowd agent
resultThe neihbors array
maxResultThe maximum number of neighbors that can be stored
agentsArray of all crowd agents
gridThe ProximityGrid
Returns
The number of neighbors

Definition at line 1069 of file Crowd.cs.

◆ RemoveAgent()

bool SharpNav.Crowds.Crowd.RemoveAgent ( int  index)

The agent is deactivated and will no longer be processed. It can still be reused later.

Parameters
indexThe agent's id
Returns
A value indicating whether the agent was successfully removed.

Definition at line 194 of file Crowd.cs.

◆ Update()

void SharpNav.Crowds.Crowd.Update ( float  dt)

Update the crowd pathfinding periodically

Parameters
dtTh time until the next update

Definition at line 243 of file Crowd.cs.

◆ UpdateMoveRequest()

void SharpNav.Crowds.Crowd.UpdateMoveRequest ( )

Change the move requests for all the agents

Definition at line 603 of file Crowd.cs.

◆ UpdateTopologyOptimization()

void SharpNav.Crowds.Crowd.UpdateTopologyOptimization ( Agent[]  agents,
int  numAgents,
float  dt 
)

Reoptimize the path corridor for all agents

Parameters
agentsThe agents array
numAgentsThe number of agents
dtTime until next update

Definition at line 826 of file Crowd.cs.


The documentation for this class was generated from the following file: