The creator-centric platform for building live games in Unity

Easily add social, commerce, and content management features to your live game with low-code, drag-and-drop prefabs fully integrated with your Unity workflow.

Adding Microservices With DLLs

Overview

The purpose of this guide is for game makers to create and deploy server-authoritative C# functionality within their games with Beamable Microservices.

Here is everything needed to use the Microservices feature in the "Beamable SDK for Unity".

šŸ“˜

Related Feature

ā€¢ More details are covered in related feature page(s). See Microservices for more info.

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: Here the implementation of the Microservice itself may be lean/empty. The goal is to demonstrate a Microservice call and response with no errors

Step 2. Import DLLs

The Beamable Microservices FeatureFeature - An individual aspect of the Beamable product used to create a great user experience works with DLL which is .Net-compatible (version "net45"). This includes a vast subset of .NET-compatible DLLs.

For the purposes of this demonstration, Amazon's DynamoDB will be used.

Amazon DynamoDB is a key-value and document database that delivers single-digit millisecond performance at any scale. It's a fully managed, multi-region, multi-active, durable database with built-in security, backup and restore, and in-memory caching for internet-scale applications. DynamoDB can handle more than 10 trillion requests per day and can support peaks of more than 20 million requests per second.

The process of integrating non-Amazon DLL's is similar. Use the steps below as a reference.

NameDetail
1. Locate & Download the primary DLL(s)ā€¢ Download from the developers (e.g. Amazon's DynamoDB Resources)

Note: This may download more or less than the set of DLL(s) for the project's needs.
2. Locate & Download any dependency DLL(s)There are 2 solution paths here. Choose the one path that works best for the needs of the project...

2.1 - Use Nuget In the Web Browser



ā€¢ Search the DLL at Nuget.org Resources)
ā€¢ Expand the 'Dependencies'
ā€¢ Download each dependency (and dependency of each dependency, etc...)
ā€¢ Rename the *.nupkg file to *.zip and unzip
ā€¢ Drag the *.dll file from the file system to any folder within the Unity Project Window.

Note: Some unzipped packages will include multiple copies of the DLL file. When in doubt, choose the 'net45' version.

2.2 - Or Use the NugetForUnity Package

ā€¢ See Github.com/GlitchEnzo/NuGetForUnity for more info
ā€¢ Search and import the DLLs needed

3. Add the DLL(s) to the Assembly Definition

ā€¢ Add each DLL to the appropriate Asmdef file

Note: Beamable creates an instance of a Unity's Assembly Definition (Asmdef) file for each Microservice

Step 3. Use DLLs

Work within the Microservice created in Step 1 above.

NameDetail
1. Add appropriate 'using' statementscsharp using Amazon.DynamoDBv2;

Note: Some code editors will auto-complete this step for you
2. Complete the implementationcsharp AmazonDynamoDBConfig config = new AmazonDynamoDBConfig();

Note: The details of this step will vary for each use case
3. "Build" the Microserviceā€¢ See Microservices Manager for more info
4. "Start" the Microserviceā€¢ See Microservices Manager for more info
5. Run the Unity sceneā€¢ Enjoy!

With each newly created Microservice, there is auto-generated code. This serves as a working template for the game maker, who will write the actual implementation.

Example

šŸ“˜

Beamable SDK Examples

ā€¢ This and all examples are available for download at GitHub.com/Beamable_Microservices_Examples

Project Window

The MyADBMicroserviceExample folder contains the DLL files, Scene, and Scripts for the complete example.

Code

In this MyADBMicroserviceExample.cs example, the MyADBMicroservice.cs allows read/write access to the database.

using UnityEngine;
using Beamable.Server.Clients;

namespace Beamable.Examples.Features.Microservices.MyADBMicroserviceExample
{
    /// <summary>
    /// Demonstrates <see cref="Microservices"/>.
    /// </summary>
    public class MyADBMicroserviceExample : MonoBehaviour
    {
        //  Properties  -----------------------------------
        
        //  Fields  ---------------------------------------
        private MyADBMicroserviceClient  _myAdbMicroserviceClient;
        
        //  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}");
            
            _myAdbMicroserviceClient = new MyADBMicroserviceClient();
            
            // #1 - Call Microservice
            bool isSuccess = await _myAdbMicroserviceClient.ConnectToDatabase();
                
            // #2 - IsSuccess = true
            Debug.Log ($"GetPlayerLevel() IsSuccess = {isSuccess}");
        }
    }
}
using System;
using System.Threading.Tasks;
using Amazon;
using Amazon.DynamoDBv2;
using Amazon.Runtime;
using UnityEngine;

namespace Beamable.Server.MyADBMicroservice.MyADBMicroserviceExample
{
   [Microservice("MyADBMicroservice")]
   public class MyADBMicroservice : Microservice
   {
      [ClientCallable]
      public async Task<bool> ConnectToDatabase()
      {
         // TODO: Create an account with https://aws.amazon.com/dynamodb/ 
         // TODO: And add your keys here
         string accessKey = "replace-with-your-access-key";
         string secretKey = "replace-with-your-secret-key";
         
         try
         {
            // Credentials
            var credentials = new BasicAWSCredentials(accessKey, secretKey);
            
            // Configuration
            var config = new AmazonDynamoDBConfig()
            {
               RegionEndpoint = RegionEndpoint.USWest2
            };
            
            // Client
            AmazonDynamoDBClient client = 
               new AmazonDynamoDBClient(credentials, config);
            
            Debug.Log($"CallADB() Success!");
            
         }
         catch (Exception e)
         {
            Debug.Log($"CallADB() Failure! Message = {e.Message}");
            return false;
         }

         return true;
      }
   }
}

šŸš§

Gotchas

Here are hints to help explain some of the trickier concepts.

ā€¢ The MyADBMicroserviceExample.cs will compile and run as shown above. However,
ā€¢ The game maker must create an account with https://aws.amazon.com/dynamodb/ and update the C# code to use those credentials to properly connect with Amazon DynamoDB

Advanced

This section contains any advanced configuration options and workflows.

Updated 9 days ago


Adding Microservices With DLLs


Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.