You can connect the SharedLogic library (or your fork of it) to multiple projects as a submodule, making it easy to reuse and update in all of them.
⚠️ Note: This setup is not required for everyone and involves some extra steps for configuration. Consider whether you really need this flexibility, or if simply maintaining your own fork is enough for your workflow.
Below, we describe how to add SharedLogic as a submodule to your project and keep it up to date.
⚠️ Note: We can’t use Unity UPM (Package manager from Unity) to connect everything, because the SharedLogic library has backend project, it isn’t for UPM.
Your repository should be organized as follows:
/Root
/UnityProject <-- your main Unity project
/SharedLogic <-- submodule of the SharedLogic library (this repository)
/GamePlugin <-- your own game plugin project
First you should create folder /Root and init empty git repository here, then create new Unity project called
UnityProject
(or put in folder UnityProject
your existing project)
Go to /Root folder. Run command:
git submodule add git@github.com:NikolayLezhnev/sharedlogic.git SharedLogic
Unpack the Template
Unzip /Root/SharedLogic/docs/GamePluginTemplate.zip
into the /Root/GamePlugin/
folder.
Open the Solution
Open /Root/GamePlugin/GamePlugin.sln
in Visual Studio or JetBrains Rider. All projects should be recognized automatically.
Configure UnityProject
In your /Root/UnityProject/Packages/manifest.json
, add the following two entries to the "dependencies"
section:
"com.nlezhnev.sharedlogic": "file:../../SharedLogic/SharedLogic/Runtime",
"com.nlezhnev.gameplugin": "file:../../GamePlugin/Runtime"
Example dependencies block:
{
"dependencies": {
...
"com.unity.modules.xr": "1.0.0",
"com.nlezhnev.sharedlogic": "file:../../SharedLogic/SharedLogic/Runtime",
"com.nlezhnev.gameplugin": "file:../../GamePlugin/Runtime"
}
}
Note: This type of GamePlugin linkage gives you opportunity to keep GamePlugin source code in one folder and use it on both server and client
Develop Your Plugin
GamePlugin/
folder.SharedLogic/
unless you are maintaining the shared library itself.Integrate in Unity
Copy the file from /Root/SharedLogic/UnityClient/Assets/UnityClient.cs to Root/UnityProject/Assets/UnityClient.cs. Edit it to fit your needs. Don’t forget to specify the correct server port in the Inspector.
Debugging
Example of full resulting structure:
Root/
/.git
/UnityProject/ <-- your main Unity project
/Assets/
/Packages/
/ProjectSettings/
/Library/
/SharedLogic/ <-- submodule of the SharedLogic library (this repository)
/Benchmark/
/SharedLogic/
/SharedLogicServer/
/SpecificGamePlugin/
/UnityClient/
/SharedLogic.sln
/GamePlugin/ <-- your own game plugin project
/Runtime/
/GamePlugin.cs
/GamePlugin.asmdef
/package.json
/GamePlugin.csproj
/GamePlugin.sln
If the upstream SharedLogic library is updated, you can update your local submodule with:
git submodule update --remote SharedLogic