a path find for tilebase game in unity
12.05.2019
- change open list to
PriorityQueue
to gain some performance. - add max loop limiting in case path find run too long. @see more at CEPathFind.MAX_SEARCH_TIME
- replace CEVector2Int with unity build in Vector2Int
- rename some class for clearly the purpose.
- fix some spelling mistake
before you use CEPathFind
, you shoud provide an pathfind engine with overrde this class CEPathFindMapAgent.cs
//Get an tile property
//you can check A start path find wiki for more info about score.
override public void GetTileProperty (int _tileX, int _tileY,
CEPathFindNode _star, CEPathFindNode _end,
out bool _isWalkable, out int _score)
{
_isWalkable = true;
_score = 1;
}
override public bool isTileWalkable (int _tileX, int _tileY)
{
return true;
}
override public TILE_SERACH_TYPE GetTileSerachType ()
{
return TILE_SERACH_TYPE.EIGHT_DIRECTION_FIX_CORNER;
}
there is two way to use it.
- Immediate return
CEPathFindResult result = CEPathFind.FindPath (starTileX, starTileY, endTileX, endTileY, findEngine);
Debug.Log(result.toString());
in this way,the function will return the result immediately.
- Async call back
CEPathFind.FindPathAsync (starTileX, starTileY, endTileX, endTileY, findEngine,ShowPath);
private void ShowPath (CEPathFindResult _result)
{
Debug.Log(result.toString());
}
in this way ,you need provide an callback(Action<(CEPathFindResult >
),when the path find finish ,it will call back.
Attaction: if you use this way, you should attach CEPathFind.cs to an gameObject.
also you can change the each tick search node num in CEPathFindAgent.cs
private const int EACH_TICK_SEARCH_NODE_NUM = 50;
e-mail: [email protected]
thanks.
Eran