Microservice UPM¶
Sharing a Microservice with Unity via UPM
Dependencies¶
Before you can use Distribute a Microservice with UPM, you need to complete the Getting-Started Guide. That means having Dotnet 8 installed, and getting the Beam CLI.
You can confirm you have everything installed checking the versions of the tools.
1 2 | |
You also need to have a local .beamable workspace with a Beamable
Standalone Microservice. As a reminder, you can create one quickly using the commands below.
1 2 3 | |
Steps¶
Standalone Microservice projects can be distributed as Unity Package Manager (UPM) packages, which allows downstream Unity projects to re-use an existing Microservice.
However, there are several configuration steps required in the Standalone Microservice project.
Preparing the Microservice¶
Follow these steps to convert an existing Standalone Microservice into a UPM compatible Microservice.
- Rename "services" folder to "services~"
- Modify the
.slnfile to mirror the folder name change. - Create a local
Assetsfolder next to the.beamablefolder - Create a
Runtimefolder and aRuntime/Clientfolder next to the.beamablefolder - Create a file in the
.beamablefolder calledlinked-projects.json,1 2 3 4 5
{ "unityProjectsPaths": [ "." ] }
So far, your folder structure should at least have these files.
1 2 3 4 5 6 7 8 9 10 11 12 | |
- In the
Runtime/Clientfolder, create a file calledService.Client. asmdef(replace"Service"with your service name), and paste the following,Make sure to replace1 2 3 4 5 6 7 8 9 10 11 12
{ "references":[ "Beamable.Platform", "Unity.Beamable", "Unity.Beamable.Runtime.Common", "Unity.Beamable.Server.Runtime", "Unity.Beamable.Server.Runtime.Common", "Unity.Beamable.Customer.Common" ], "name": "Service.Client", "autoReferenced": true }"Service"in the"name"field with your service name. - Now you are ready to generate the client code. To do this, run the
following command AFTER building your Microservice. This command
should be run from the
/services~/Servicefolder.1dotnet beam project generate-client ./bin/Debug/net8.0/Service.dll --output-links --output-path-hints "Service=Runtime/Client/ServiceClient.cs" --logs v - You need to create a
package.jsonfile. Place it next to the/Assetsfolder in the Microservice project.1 2 3 4 5
{ "name": "com.service", "version": "0.0.0", "displayName": "Demo" }
Finally, your project structure should look similar to this,
So far, your folder structure should at least have these files.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | |
Preparing the Unity Project¶
Now that the Microservice is ready, in order to import it into a Unity project as a UPM package, follow these steps.
- Ensure that the Unity project is referencing Beamable's packages.
At least Beamable version
com.beamableandcom.beamable.server2.1.3 is required. - In Unity Package Manager, add a package from disk, and select the path to
your created
package.jsonfrom the previous steps. - Modify the
.beamable/additional-project-paths.jsonfile in the Unity project and add the path to the UPM project folder.1["/path/to/Project"]