Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding external project to unity solution

Tags:

unity3d

unity5

I am trying to add an external project to my unity solution. It works fine using mono develop but whenever I switch back to unity it seems to remove the reference from the solution.

Is there a way to prevent unity from doing this ?

Thanks,

like image 569
LibreLancier Avatar asked Jul 27 '17 15:07

LibreLancier


Video Answer


2 Answers

Unity rebuilds (i.e., removes the existing file and build it again from scratch) MyProject.sln file whenever it finds changes from ~/Assets folder. As such, any manual modification done by you or outside Unity's automated process on MyProject.sln will be discarded each time Unity compiles.

As @Kamalen mentioned, the usual way to import an external project is to have the external project be a library project, build *.dll from it, and put the *.dll file somewhere under ~/Assets. When there are *.dll files under ~/Assets, you have a reference to the classes and methods defined in the library file from any code you put under ~/Assets.

However, it seems that you have the access to the source code and tend to modify the external project often from your comment.

In that case, you could consider putting the source code of the external project under ~/Assets. The folder structure would then look like:

MyProject/
MyProject/MyProject.sln  // this is rebuilt again each time by Unity
MyProject/Assets/
MyProject/Assets/ExternalProject/...  // This could be a git submodule
MyProject/Assets/scripts/...

You can of course have the ExternalProject be a git submodule and maintain it as a separate git repo. Then you can either make changes to the ExternalProject from inside Untiy folder, or the original location of ExternalProject and then sync the ExternalProject under Unity folder with a pull from git.

As a rule of thumb, import *.dll files if you know the library is complete and it is unlikely to have changes in the library project, which includes the case when you do not have access to its source code. When there exist *.dll files in a project, it's common to assume the library is complete, unlikely to change, and outside of our control, and hence it's called an external project.

like image 68
Matt Avatar answered Oct 21 '22 00:10

Matt


Your best way to have an external project into Unity is to... not have an external project directly. Unity does rebuild the solution file regulary and is almost like a temporary file.

What you can do is configure your external project as a library project, and configure the project (or an external tool) to output the generated DLL in any subfolder of the Assets folder.

If your external project uses Unity classes, it will need to have references to UnityEngine.dll and UnityEditor.dll, located in folders :

  • Applications/Unity.app/Contents/Frameworks/Managed/UnityEngine.dll for Mac
  • Program Files\Unity\Editor\Data\Managed\UnityEngine.dll for Windows
like image 42
Kamalen Avatar answered Oct 21 '22 00:10

Kamalen