Robmaister / SharpNav

Advanced Pathfinding for C#
sharpnav.com
Other
537 stars 129 forks source link

Add more integrations #39

Open Robmaister opened 9 years ago

Robmaister commented 9 years ago

Comment if you're interested in seeing an integration for any of these engines (or suggest a new one):

Also if you'd like to see better integration (asset pipeline, etc):

If you are going to submit a pull request with engine integration, please reference this issue. This should be considered an ongoing issue.

SetoKaiba commented 7 years ago

What about add integration with Unity3D? The most popular game engine with C# support.

Robmaister commented 7 years ago

Unity3D uses a different naming convention for everything, so my method of cross-engine support fails. I assume regular C# naming conventions are used - for example, that in Vector3, the three components are X, Y, and Z. In Unity, however, they follow a different naming convention, so the components are x, y, and z. Simple namespace substitution won't work here.

If you take a look at the top of a most of the C# files in the project, you'll see this block:

using SharpNav.Geometry;

#if MONOGAME
using Vector3 = Microsoft.Xna.Framework.Vector3;
#elif OPENTK
using Vector3 = OpenTK.Vector3;
#elif SHARPDX
using Vector3 = SharpDX.Vector3;
#endif

(example: https://github.com/Robmaister/SharpNav/blob/master/Source/SharpNav/Heightfield.cs)

If performance weren't a concern (trying to be realtime-ish, so it is), I would try to wrap Unity vectors in some sort of a wrapper class but since there's a lot of vector math, I wouldn't be surprised if SharpNav ran at less than half the speed it does now.

Another option would be a ToUnityVector() function and/or implicit cast in the Standalone Vector3 implementation, but this would still have a fair bit of overhead when you want to do anything with the navmesh from Unity (internally stored in the Standalone Vector3 format) and only be syntax sugar over the same way you'd use SharpNav in Unity with the Standalone build.

To make the Unity version act the same way as other versions (internal storage in the engine Vector format), there would need to be some more complex preprocessor or IL stage manipulation of the program to use the engine Vector format.