Domanda

Now, I have resource-consuming C# script, uses Unity API. If I try to write external library (due to performance reasons), can I access Unity3D API from C/C++ code (e.g. Physics.OverlapSphere or Physics.SphereCast functions)?

È stato utile?

Soluzione

No, you cannot. The Unity3d classes are only accessible to C# code. C++ plugins cannot call Unity3d functions. The only exception are rendering plugins, as described in here.

As a aside: The Physics functions are likely heavily optimized in the Unity engine, so if the main cost of your resource-consuming script comes from the usage of these functions, the gain would be minimal or even negative due to the need of marshalling the data for passing them to the C++ plugin and back. You can check this using the script profiler is you have the Pro version.

As another aside, you will likely get faster and better answers on https://answers.unity3d.com/, the dedicated Q&A site for Unity.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top