Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to share c# source between Unity projects?

Tags:

c#

unity3d

We have two projects underway and want to share some classes between them. The shared source must be in a single location so when a programmer on Project1 updates the code those changes are immediately seen in Project2.

The important part is that we do not want to maintain multiple copies of the same code. i think we would agree that its simply bad practise to do so.

The only option appears to be putting the code in a class library and load it as a plugin into each project. But I don't believe this works when referencing Unity types like GameObject or transform.

In C/C++ land we could put the source in a directory and include it into any solution we wanted - doesn't seem to be so easy in Unity-land. Is their a better way to share code between unity projects?

EDIT: All projects, including the shared code, are already under source control. This is not a Source Control question, its a framework issue. (And obviously I need to write better questions!)

Lets say the directory structure looks like this...

C:\ Project1\ Assets\ CodeForProject1\ StandardAssets\ Library\

C:\ Project2\ Assets\ CodeForProject2\ Resources\ Library\

D:\ UsefulCode\ PlayerClass\ WeaponsClass\ DataAccessClass\

Can Unity reference code from other projects? Can Unity reference code outside of its own Assets folder? If so, how?

like image 707
Nguyễn Đoàn Ngọc Giàu Avatar asked Jun 17 '17 05:06

Nguyễn Đoàn Ngọc Giàu


People also ask

What does C$ mean in Windows?

It means it is an "admin" share or "hidden" share.

How do you share C drive to another computer in Windows 10?

To share a file or folder over a network in File Explorer, do the following: Right-click (or long-press) a file, and then select Show more options > Give access to > Specific people. Select a user on the network to share the file with, or select Everyone to give all network users access to the file.

What is C$ admin share?

By default, Windows creates the following admin shares: Admin$ — Remote admin (this is the %SystemRoot% directory) IPC$ — Remote IPC (used in named pipes) C$ — Default Drive Share.


1 Answers

I understand exactly what you're facing, we faced the same problem here some time ago.

The idea of our shared code is to be sort of a middleware, so it is natural that it will evolve through. Our solution was to create a git module for the shared code. I know you said that it's not a source control question, but at least here in my company, create a dll was not a good solution since we are changing the shared code constantly (we tried soft-links too, but it was very painful to maintain in all machines).

Here we created two projects: one for the middleware and another just for the tests. The last one have only the gitmodule to the middleware and a bunch of unit tests. We did it to ensure that there is no dependency to other projects. Both are in the source control. So when someone wants to implement a new feature inside the middleware, he/she make it inside the tests project, and when it's done commits to both projects.

Oh! And you can make a dll with Unity types and use them normally.

like image 141
Kleber Avatar answered Sep 19 '22 11:09

Kleber