Microservices - Distributing

Create and deploy server-authoritative C# [CLCP-Microservices-08]

The purpose of this guide is for game makers to distribute server-authoritative C# functionality via Beamable Microservices.

Distribution

  • Game makers can distribute the Microservice internally within their organization and share it across several game projects
  • Or distribute the Microservice publicly for use by the community

Game Maker User Experience

During development, the game maker's user experience is as follows: There are 3 major parts to the process.

Steps

Follow these steps to get started:

Step 1. Setup Microservice

NameDetail
1. Setup Docker
2. Create Microservice
3. Call Microservice
• See Adding Microservices for more info

Note: Ensure that Microservice development is complete before continuing

Step 2. Package Microservice

Work within the same project created in Step 1 above.

NameDetail
1. Open the Source Unity projectNote: This Unity project will be the source of the Unity custom package
2. Create the Unity custom package• See Unity's docs.unity3d.com/Manual/CustomPackages.html for more info
3. Host the Unity custom package• Ex. Github.com
4. Distribute the Unity custom package• See Unity's Docs.unity3d.com/Manual/cus-share.html for more info

Note: There are several options. For this example, Beamable uses the Via Git URL solution

Step 3. Import Microservice

NameDetail
1. Open the Destination Unity projectNote: This Unity project will be the destination, where the Unity custom package will be used
2. Import the Unity custom package
• See Unity's docs.unity3d.com/Manual/upm-ui-giturl.html for more info

Note: There are several options. For this example, Beamable uses the Via Git URL solution with a url of https://github.com/beamable/Microservices-TimedRewards.git

🚧

Missing Beamable.Customer.Common Assembly Definition

If you plan on sharing a Microservice, make sure to remove the existing reference to Beamable.Customer.Common. That assembly definition is only created by the Unity Editor when a Microservice is created using the Microservice Manager. If it doesn't exist when importing a Microservice that depends on it, you'll see a AssemblyDefinitionNotFoundException error.

Example

Here are examples which cover common programming needs.

📘

Beamable SDK Examples

Source Unity Project - Github.com/beamable/Microservices-TimedRewards
Destination Unity Project - Github.com/beamable/Beamable_Microservices_Examples

Source - Microservices TimedRewards

This demonstrates;

  • How to create a Unity custom package as a Microservice
  • And its a production-ready Microservice which adds a "Timed Rewards" feature

Destination - Beamable Microservices Examples

This demonstrates;

  • How to import a Unity custom package as a Microservice
  • And its an example usage of the "Timed Rewards" feature

Code
Here are examples which cover common programming needs.

The TimedRewardsMicroserviceExample.cs demonstrates the custom code added to the destination project to properly consume the imported source project.

using UnityEngine;
using Beamable.Server.Clients;

namespace Beamable.Examples.Features.Microservices.TimedRewardsMicroserviceExample
{
    /// <summary>
    /// Demonstrates <see cref="Microservices"/>.
    /// </summary>
    public class TimedRewardsMicroserviceExample : MonoBehaviour
    {
        //  Properties  -----------------------------------
        
        //  Fields  ---------------------------------------
        [SerializeField] 
        private TimeRewardRef _timeRewardRef = null;
        
        private TimedRewardServiceClient  _timedRewardServiceClient;
        
        //  Unity Methods  --------------------------------

        protected void Start()
        {
            Debug.Log("Start() Instructions...\n" + 
            "* Complete docker setup per https://docs.beamable.com/docs/microservices-feature\n" +
            "* Start the server per https://docs.beamable.com/docs/microservices-feature\n" +
            "* Play This Scene\n" + 
            "* Enjoy!\n\n\n");
            
            SetupBeamable();
        }
        
        //  Methods  --------------------------------------
        private async void SetupBeamable()
        {
            var beamableAPI = await Beamable.API.Instance;

            Debug.Log($"beamableAPI.User.id = {beamableAPI.User.id}");
            
            _timedRewardServiceClient = new TimedRewardServiceClient();
            
            // #1 - Call Microservice
            bool isSuccess = await _timedRewardServiceClient.Claim(_timeRewardRef);
                
            // #2 - Result = true
            Debug.Log ($"AddMyValues() isSuccess = {isSuccess}");
        }
    }
}

Advanced

This section contains any advanced configuration options and workflows.