Skip to content

Tunied/cepathfind

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 

Repository files navigation

CEPathFind

a path find for tilebase game in unity

img1

Update

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

How to use

Extend base engine

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;
	}

Call pathfind

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;

PathFindType

4 direction

img1

8 direction

img1

8 direction with fix corner

img1

Issue

e-mail: [email protected]

thanks.
Eran

Releases

No releases published

Packages

No packages published

Languages