1
\$\begingroup\$

The aim is to build a relatively simple (2D) game in Unity with most of the game logic in a non-visual AI. The AI needs a lot of testing and debugging independently of any visuals (which is best done using VS tools), and the API connecting them is one class and a few methods/properties. [A future version might not even use Unity.]

So the question is how to set up a VS solution file to build the AI for testing and debugging while remaining compatible with the Mono build environment used by Unity. Yes, I know it has to be C# 4, but beyond that? At present I'm copying CS files around and that doesn't feel right.


Just to make it crystal clear, the AI has no dependency on Unity and will be built in a project that has VS testing and code analysis but no Unity tools or imports. In future it may be used with a different engine.

\$\endgroup\$
3
\$\begingroup\$

It's very simple; all you need to do is start a new class library project.

Then, add a reference to the UnityEngine DLL. By default, it should be in C:\Program Files\Unity\Editor\Data\Managed\UnityEngine.dll.

Finally, you need to setup your project's target framework. I advise you download Visual Studio Tools for Unity, then go to your project's properties window. Choose Unity 3.5 .net full Base Class Libraries in the Target Framework dropdown menu.

To use the library in Unity, build the solution, navigate to the bin folder, grab the DLL, paste it in your Assets folder of your Unity project, and you should be set.

\$\endgroup\$
  • \$\begingroup\$ thanks for the answer, but I don't think you quite understand the question. The AI has no dependency on Unity, does not use or require Unity tools or imports. See edit. Are you saying that the DLL from a VS build can be used in a WebGL build, without recompiling in Mono? \$\endgroup\$ – david.pfx Feb 5 '17 at 3:15
  • \$\begingroup\$ I understand now. So to keep the library agnostic, don't include the UnityEngine DLL, but do set the target framework to Unity 3.5 .net full Base Class Libraries whenever you're exporting it to Unity. And yes, all that is needed is a copy-paste of the DLL, no matter what platform you're exporting to. \$\endgroup\$ – WindyKeeper Feb 5 '17 at 12:01
  • \$\begingroup\$ Got it. The answer is that Unity can import a .Net DLL as an asset by simply adding it to an Assets folder, with no need for source code. It works for C# 4, but if you want to use it in the editor it has to be C# 3.5 or earlier. If you care to update your answer I'll be happy to accept it. \$\endgroup\$ – david.pfx Feb 6 '17 at 23:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.