The motivation behind developing SpriteRendererNAV stemmed from the desire to recreate the NAVMesh pathfinding tool, originally developed for a 2D scene editor in Cocos2d-X, within Unity. Additionally, users have expressed the need for a quick development tool that includes pathfinding functionality for 2D scenes, but they do not want to use the traditional A* algorithm, as it often creates a grid-like appearance unless the grid is made extremely fine, which can severely impact performance. As a result, I embarked on the development of the SpriteRendererNAV asset.
The related videos for the custom Cocos2d-x scene editor:
The entire process is not very complicated. The following are the steps involved:
- Add the World quad mesh to MeshBuildSources.
- Create Mesh colliders for all SpriteRenderers.
- Use Physics.BoxCast to scan all Colliders in the scene and generate the corresponding block line data.
- Based on the block line data, create a block line mesh and add it to MeshBuildSources.
- Create NavMeshData, use NavMeshBuilder.UpdateNavMeshData, and pass in MeshBuildSources.
- Finally, add the generated NavMeshData to the NavMesh.
For pathfinding testing, the PathCalculator script is provided to directly call NavMesh.CalculatePath and add NavMeshObstacle (Dynamic Obstacle) for pathfinding tests.
沒有留言:
張貼留言