Loading...
Searching...
No Matches
CityBuilderCore.WalkingPath Class Reference

Detailed Description

collection of map points or world positions that can be followed by a walker

Classes

class  WalkingPathData
 

Public Member Functions

 WalkingPath (Vector2Int[] points)
 
 WalkingPath (Vector3[] positions)
 
IEnumerable< Vector2Int > GetPoints ()
 gets all the points in the path in order
 
Vector2Int GetPoint (int index)
 gets the map point at a specific position
 
IEnumerable< Vector3 > GetPositions ()
 gets all the positions in the path in order
 
Vector3 GetPosition (int index)
 gets the world position at a specific position
 
Vector3 GetPosition (int index, float time, float timePerStep)
 interpolates a position between the one at the index and the next one
 
bool HasEnded (int index)
 checks if the index points to the last element in the path or beyond
 
Vector2Int GetPreviousPoint (int index)
 returns the starting point of the n-th segment in the path
 
Vector2Int GetNextPoint (int index)
 returns the ending point of the n-th segment in the path
 
Vector3 GetPreviousPosition (int index)
 returns the starting position of the n-th segment in the path
 
Vector3 GetNextPosition (int index)
 returns the ending position of the n-th segment in the path
 
float GetDistance (int index)
 returns the length of the n-th segment in the path
 
Vector3 GetDirection (int index)
 returns the direction of the n-th segment in the path
 
float GetDistance ()
 calculates the total length of the path in the world
 
WalkingPath GetReversed ()
 creates a new path going in the opposite direction of this one
 
IEnumerator Walk (Walker walker, float delay, Action finished, Action< Vector2Int > moved=null)
 initializes the walkers walking state and starts moving the walker along the walking path
 
IEnumerator ContinueWalk (Walker walker, Action finished, Action< Vector2Int > moved=null)
 when the game is loaded and the walker was previously walking it is continued here
 
IEnumerator WalkAgent (Walker walker, float delay, Action finished, Action< Vector2Int > moved=null)
 initializes the walkers agent walking state and starts setting destinations for the navmesh agent along the path
 
WalkingPathData GetData ()
 

Static Public Member Functions

static IEnumerator WalkAgent (Walker walker, Vector3 destination, float delay, Action finished, Action< Vector2Int > moved=null)
 initializes the walkers agent walking state and starts setting destinations for the navmesh agent along the path
 
static IEnumerator ContinueWalkAgent (Walker walker, Action finished, Action< Vector2Int > moved=null)
 when the game is loaded and the walker was previously walking it is continued here
 
static IEnumerator TryWalk (Walker walker, float delay, Func< WalkingPath > pathGetter, Action planned, Action finished, Action canceled=null, Action< Vector2Int > moved=null)
 tries to walk a path that is calculated externaly, if no path is found the walker waits a second and retries until WalkerInfo.MaxWait times it out
 
static IEnumerator TryWalk (Walker walker, float delay, Func< PathQuery > queryGetter, Action planned, Action finished, Action canceled=null, Action< Vector2Int > moved=null)
 
static IEnumerator TryWalk< T > (Walker walker, float delay, Func< BuildingComponentPathQuery< T > > queryGetter, Action< BuildingComponentPath< T > > planned, Action finished, Action canceled=null, Action< Vector2Int > moved=null)
 
static IEnumerator TryWalk< Q, P > (Walker walker, float delay, Func< Q > preparer, Func< Q, P > planner, Func< P, WalkingPath > planned, Action finished, Action canceled=null, Action< Vector2Int > moved=null)
 
static IEnumerator TryWalk (Walker walker, float delay, IBuilding structure, PathType pathType, object pathTag, Action planned, Action finished, Action canceled=null, Action< Vector2Int > moved=null)
 tries to walk to a structure, if no path is found the walker waits a second and retries until WalkerInfo.MaxWait times it out
 
static IEnumerator Roam (Walker walker, float delay, Vector2Int start, int memoryLength, int range, PathType pathType, object pathTag, Action finished, Action< Vector2Int > moved=null)
 walker starts walking around semi randomly, visited points are memorized and avoided
 
static IEnumerator ContinueRoam (Walker walker, int memoryLength, int range, PathType pathType, object pathTag, Action finished, Action< Vector2Int > moved=null)
 continues roaming when the game is loaded and the walker was roaming previously
 
static WalkingPath FromData (WalkingPathData data)
 

Properties

int Length [get]
 how many points/positions the path contains, not physical world distance
 
Vector2Int StartPoint [get]
 first map point in the path
 
Vector3 StartPosition [get]
 first world position in the path
 
Vector2Int EndPoint [get]
 last map point in the path
 
Vector3 EndPosition [get]
 last world position in the path
 

Member Function Documentation

◆ ContinueRoam()

static IEnumerator CityBuilderCore.WalkingPath.ContinueRoam ( Walker walker,
int memoryLength,
int range,
PathType pathType,
object pathTag,
Action finished,
Action< Vector2Int > moved = null )
inlinestatic

continues roaming when the game is loaded and the walker was roaming previously

Parameters
walkerthe walker to move
memoryLengthhow many points the walker will memorize and try to avoid
rangehow many steps the walker roams before returning
pathTypewhich kind of pathfinding will be performed to check which points are available
pathTagadditional parameter for pathfinding
finishedcalled when roaming is finished(regularly or canceled)
movedcalled whenever a new point is reached
Returns
the coroutine enumarator

◆ ContinueWalk()

IEnumerator CityBuilderCore.WalkingPath.ContinueWalk ( Walker walker,
Action finished,
Action< Vector2Int > moved = null )
inline

when the game is loaded and the walker was previously walking it is continued here

Parameters
walkerthe walker that will be moved
finishedcalled when walking is finished either by reaching the end or cancellation
movedcalled whenever the walker reaches on of the path points
Returns
the coroutine enumerator

◆ ContinueWalkAgent()

static IEnumerator CityBuilderCore.WalkingPath.ContinueWalkAgent ( Walker walker,
Action finished,
Action< Vector2Int > moved = null )
inlinestatic

when the game is loaded and the walker was previously walking it is continued here

Parameters
walkerthe walker that will be moved
finishedcalled when walking is finished either by reaching the end or cancellation
movedcalled whenever the walker reaches on of the path points
Returns
the coroutine enumerator

◆ GetDirection()

Vector3 CityBuilderCore.WalkingPath.GetDirection ( int index)
inline

returns the direction of the n-th segment in the path

Parameters
indexindex of the segment(0 is the segment between points 0 and 1)
Returns
a vector(end-start)

◆ GetDistance() [1/2]

float CityBuilderCore.WalkingPath.GetDistance ( )
inline

calculates the total length of the path in the world

Returns

◆ GetDistance() [2/2]

float CityBuilderCore.WalkingPath.GetDistance ( int index)

returns the length of the n-th segment in the path

Parameters
indexindex of the segment(0 is the segment between points 0 and 1)
Returns
world distance between the points

◆ GetNextPoint()

Vector2Int CityBuilderCore.WalkingPath.GetNextPoint ( int index)
inline

returns the ending point of the n-th segment in the path

Parameters
indexindex of the segment(0 is the segment between points 0 and 1)
Returns
a map point

◆ GetNextPosition()

Vector3 CityBuilderCore.WalkingPath.GetNextPosition ( int index)
inline

returns the ending position of the n-th segment in the path

Parameters
indexindex of the segment(0 is the segment between points 0 and 1)
Returns
a world position

◆ GetPoint()

Vector2Int CityBuilderCore.WalkingPath.GetPoint ( int index)
inline

gets the map point at a specific position

Parameters
indexwhich point to get, starting at 0
Returns
a single map point

◆ GetPoints()

IEnumerable< Vector2Int > CityBuilderCore.WalkingPath.GetPoints ( )
inline

gets all the points in the path in order

Returns
map points

◆ GetPosition() [1/2]

Vector3 CityBuilderCore.WalkingPath.GetPosition ( int index)
inline

gets the world position at a specific position

Parameters
indexwhich position to get, starting at 0
Returns
a single world position

◆ GetPosition() [2/2]

Vector3 CityBuilderCore.WalkingPath.GetPosition ( int index,
float time,
float timePerStep )

interpolates a position between the one at the index and the next one

Parameters
indexindex of the start point
timehow long the walker has already walked
timePerSteptotal time the walker needs to walk between the two points
Returns
a world position

◆ GetPositions()

IEnumerable< Vector3 > CityBuilderCore.WalkingPath.GetPositions ( )
inline

gets all the positions in the path in order

Returns
world positions

◆ GetPreviousPoint()

Vector2Int CityBuilderCore.WalkingPath.GetPreviousPoint ( int index)
inline

returns the starting point of the n-th segment in the path

Parameters
indexindex of the segment(0 is the segment between points 0 and 1)
Returns
a map point

◆ GetPreviousPosition()

Vector3 CityBuilderCore.WalkingPath.GetPreviousPosition ( int index)
inline

returns the starting position of the n-th segment in the path

Parameters
indexindex of the segment(0 is the segment between points 0 and 1)
Returns
a world position

◆ GetReversed()

WalkingPath CityBuilderCore.WalkingPath.GetReversed ( )
inline

creates a new path going in the opposite direction of this one

Returns
the reversed path

◆ HasEnded()

bool CityBuilderCore.WalkingPath.HasEnded ( int index)

checks if the index points to the last element in the path or beyond

Parameters
index
Returns
true if there is no next point

◆ Roam()

static IEnumerator CityBuilderCore.WalkingPath.Roam ( Walker walker,
float delay,
Vector2Int start,
int memoryLength,
int range,
PathType pathType,
object pathTag,
Action finished,
Action< Vector2Int > moved = null )
inlinestatic

walker starts walking around semi randomly, visited points are memorized and avoided

Parameters
walkerthe walker to move
delayduration in seconds the walker waits before starting to roam
startthe point to start roaming from
memoryLengthhow many points the walker will memorize and try to avoid
rangehow many steps the walker roams before returning
pathTypewhich kind of pathfinding will be performed to check which points are available
pathTagadditional parameter for pathfinding
finishedcalled when roaming is finished(regularly or canceled)
movedcalled whenever a new point is reached
Returns
the coroutine enumarator

◆ TryWalk() [1/2]

static IEnumerator CityBuilderCore.WalkingPath.TryWalk ( Walker walker,
float delay,
Func< WalkingPath > pathGetter,
Action planned,
Action finished,
Action canceled = null,
Action< Vector2Int > moved = null )
inlinestatic

tries to walk a path that is calculated externaly, if no path is found the walker waits a second and retries until WalkerInfo.MaxWait times it out

Parameters
walkerthe walker that is moved
delayduration in seconds the walker will always wait before moving(instead of the default WalkerInfo.Delay)
pathGetterfunction that returns the path the walker should walk or null if no path could be found currently
plannedcalled when a path is found
finishedcalled when the walker reaches its target
canceledcalled if the walker finds no path and times out or waiting gets canceled
movedcalled whenever the walker reaches on of the path points
Returns
the coroutine enumerator

◆ TryWalk() [2/2]

static IEnumerator CityBuilderCore.WalkingPath.TryWalk ( Walker walker,
float delay,
IBuilding structure,
PathType pathType,
object pathTag,
Action planned,
Action finished,
Action canceled = null,
Action< Vector2Int > moved = null )
inlinestatic

tries to walk to a structure, if no path is found the walker waits a second and retries until WalkerInfo.MaxWait times it out

Parameters
walkerthe walker that is moved
delayduration in seconds the walker will always wait before moving(instead of the default WalkerInfo.Delay)
startthe point to start from
structurethe target structure to walk to
pathTypewhich kind of pathfinding will be performed to check which points are available
pathTagadditional parameter for pathfinding
plannedcalled when a path is found
finishedcalled when the walker reaches its target
canceledcalled if the walker finds no path and times out or waiting gets canceled
movedcalled whenever the walker reaches on of the path points
Returns
the coroutine enumerator

◆ TryWalk< T >()

static IEnumerator CityBuilderCore.WalkingPath.TryWalk< T > ( Walker walker,
float delay,
Func< BuildingComponentPathQuery< T > > queryGetter,
Action< BuildingComponentPath< T > > planned,
Action finished,
Action canceled = null,
Action< Vector2Int > moved = null )
inlinestatic
Type Constraints
T :IBuildingComponent 

◆ Walk()

IEnumerator CityBuilderCore.WalkingPath.Walk ( Walker walker,
float delay,
Action finished,
Action< Vector2Int > moved = null )
inline

initializes the walkers walking state and starts moving the walker along the walking path

Parameters
walkerthe walker that will be moved
delayduration to wait before starting to walk in seconds(immediately moving can look abrupt)
finishedcalled when walking is finished either by reaching the end or cancellation
movedcalled whenever the walker reaches on of the path points
Returns
the coroutine enumerator

◆ WalkAgent() [1/2]

IEnumerator CityBuilderCore.WalkingPath.WalkAgent ( Walker walker,
float delay,
Action finished,
Action< Vector2Int > moved = null )

initializes the walkers agent walking state and starts setting destinations for the navmesh agent along the path

Parameters
walkerthe walker that will be moved
delayduration to wait before starting to walk in seconds(immediately moving can look abrupt)
finishedcalled when walking is finished either by reaching the end or cancellation
movedcalled whenever the walker reaches on of the path points
Returns
the coroutine enumerator

◆ WalkAgent() [2/2]

static IEnumerator CityBuilderCore.WalkingPath.WalkAgent ( Walker walker,
Vector3 destination,
float delay,
Action finished,
Action< Vector2Int > moved = null )
inlinestatic

initializes the walkers agent walking state and starts setting destinations for the navmesh agent along the path

Parameters
walkerthe walker that will be moved
delayduration to wait before starting to walk in seconds(immediately moving can look abrupt)
finishedcalled when walking is finished either by reaching the end or cancellation
movedcalled whenever the walker reaches on of the path points
Returns
the coroutine enumerator