Robmaister / SharpNav

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

Fail to compile against .NET 3.5 #67

Closed cr4yz closed 7 years ago

cr4yz commented 7 years ago

The type or namespace name 'Tasks' does not exist in the namespace 'System.Threading'. File: Source\SharpNav\Heightfield.cs line 6

The type or namespace name 'Tasks' does not exist in the namespace 'System.Threading'. File: Source\SharpNav\Heightfield.Rasterization.cs line 6

The type or namespace name 'Tuple<,>' could not be found. File: Source\SharpNav\AreaGenerator.cs line 28

Robmaister commented 7 years ago

Ah, forgot I was using the new threading stuff.

I'll see what I can do about this, will probably look into extra preprocessors to make it so that this functionality disappears when you're compiling for an older version of .NET

cr4yz commented 7 years ago

Thanks :)

cr4yz commented 7 years ago

Unity's latest release supports compiling with .NET 4.4 so my issue in particular is resolved. I'm not sure if there's another reason to support 3.5, should I go ahead and close the issue?

Robmaister commented 7 years ago

Yes, I saw that! About time! I read that it was just a compiler update and not a full runtime update - I would first check that it doesn't crash/not compile in Unity since tasks are part of the BCL and not the language syntax.

If it works just fine, then feel free to close it out. Otherwise leave it open and I will eventually get around to it. You could also go and manually change my Parallel.For calls to regular for loops and compile it that way for now.

AngelKyriako commented 7 years ago

Hello, I would like to use this library within unity client and an asp .net core server.

1) The STANDALONE variable should be fine for a .net mvc server ? 2) I tried to set the compilation variable to UNITY3D but the project produces errors as it cannot find Vector3 dependency from UnityEngine. Is there any documentation I am missing or further customization is needed to build the library for unity ?

@Chabinka you sure about that ? last time I checked I needed to target 3.5 for a class library that targets unity.

cr4yz commented 7 years ago

@AngelKyriako The term Unity3d does appear in SharpNav in a few places but afaik it serves no purpose, Unity support seems to have been removed, but it isn't too difficult to get it working in Unity. One option would be to compile SharpNav as is without the Unity reference and write a function to convert between SharpNav.Geometry.Vector3<->UnityEngine's Vector3. The other, more difficult, option is to look at how SharpNav implements Vector3 from various platforms (MonoGame, OpenTK, SharpDX) and implement Unity's Vector3 in a similar fashion.

You may still be missing the System.Threading.Tasks namespace & the Tuple class, but I believe both of these have been created to work with 3.5 you will just need to find them on the web somewhere. It also wouldn't be too difficult to replace SharpNav's use of Tuple & System.Threading.Tasks as they are used in only 1 or 2 files

edit: I'm going to close this thread, maybe open a new issue if you need further support from the dev :)

Robmaister commented 7 years ago

@AngelKyriako

  1. yep, standalone should work fine anywhere

  2. Support was removed, as it would complicate things significantly. If it's still in any documentation, then the documentation is outdated. Unity uses it's own naming convention that differs from MonoGame, OpenTK, and SharpDX. The differences between those three are minimal, so basically just swapping out the namespace using the preprocessor would provide support (with the occasional extension method for properties vs methods, etc.). It's pretty hacky, but allows multiple engine support with zero overhead.

Supporting Unity would mean either an abstraction over vectors (probably a bad idea for performance) or a custom C# preprocessor (or utility that modifies IL directly) to change between the various implementations. The abstraction could still exist for Unity, but at that point, why not just use Standalone and convert SharpNav.Geometry.Vector3 to UnityEngine.Vector3?

If you have a good idea for some middle ground or other solution, feel free to open another issue to discuss that.

For reference, one of the main Unity API differences is in casing. Unity uses .x, .y, and .z for components, and the rest use .X, .Y, .Z

AngelKyriako commented 7 years ago

@Robmaister using standalone and converting unity's vector3 to the lib's vector3 seems the best option to me as well. However more than this change is required with a first look.

Thanks for the answer. If I find the time and any other idea on how to integrate unity I will let you know.