AndresTraks / BulletSharpPInvoke

.NET wrapper for the Bullet physics library using Platform Invoke

Home Page:http://andrestraks.github.io/BulletSharp/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Integration with Unity - static vs instance callbacks

VISTALL opened this issue · comments

Hello. As i said in (#73) i am working on integration BulletSharpPInvoke in Unity.

I'm already fixed all problems, and most of them - i wrote in prev issue.

And now - library works as is in Unity(desktop, mac). But for mobile platforms Unity use IL2CPP (https://docs.unity3d.com/Manual/IL2CPP.html) and library not work (at android for example)

There a simple problem - Unity can't convert code with instance callbacks. @Phong13 already fix that problem here https://github.com/Phong13/BulletSharpUnity3d and here https://github.com/Phong13/BulletSharpPInvoke

Here example

https://github.com/AndresTraks/BulletSharpPInvoke/blob/master/BulletSharp/LinearMath/MotionState.cs#L34

		void GetWorldTransformUnmanaged(out Matrix worldTrans)

this method must be static and it provide problem about accessing to this. Now need receive it from wrapper (need new field in C++ wrapper code). And do those changes to all callbacks

(AOT attribute required by IL2CPP)

		#if ENABLE_IL2CPP
		[AOT.MonoPInvokeCallbackAttribute(typeof(GetWorldTransformUnmanagedDelegate))]
		#endif
		static void GetWorldTransformUnmanaged(IntPtr thisPtr, out Matrix worldTrans)

(also those change https://github.com/Phong13/BulletSharpUnity3d/blob/master/Plugins/BulletUnity/BulletSharp/Native.cs)

Without those changes, it can not be integrated into Unity as is. It's a small changes, almost without any overhead.

What do you think ?

Yes, that looks fine to me.
Not sure when I'll get to this, but I accept pull requests :)