Microsoft Azure is the leading cloud solution and a personal favorite when it comes to secure and compliant cloud providers. It’s easy to use, provides a lot of customizable services and has global availability with 50 regions worldwide. So, when it comes to developing a project with global reach, Microsoft Azure is a good and reliable option. Unity3D is the leading game development and Mixed Reality engine, currently touching more than 770 million gamers globally.

If you are an application developer, connecting a powerful engine with a powerful Cloud system is crucial for reaching more customers. However, as of now, there was no Azure support for Unity3D.

Today, this is changing. LightBuzz is presenting the first complete Azure SDK for Unity3D. The SDK allows you to consume remote Azure App Services and even store data locally in a SQLite database. Everything is secured using HTTPS. The framework supports all of the major Unity platforms, including Android, iOS, Windows Standalone, Mac OS, UWP, and HoloLens.

Oh, did I mention that it’s open-source, too?

Download the SDK

LightBuzz is a New York-based company that has been developing Mobile and Cloud solutions for Fortune 500 and ambitious startup companies since 2012.

Contact us

LightBuzz Azure SDK for Unity

The whole project is hosted on GitHub — remember to give it a thumbs-up! Now, I am going to give you an overview of the Azure SDK for Unity.

LightBuzz Azure SDK for Unity - Screenshot demo

Azure App Services

The LightBuzz Azure SDK for Unity consumes Azure App Service APIs. Azure App Service Web Apps (or just Web Apps) are cloud services for hosting web applications, REST APIs, and mobile backends. The SDK supports all of the HTTP(S) method requests on every platform.

  • GET
  • POST
  • PUT
  • PATCH
  • DELETE

HTTPS support

The LightBuzz SDK is built with security in mind. The native Microsoft HttpClient modules do not support HTTPS in Unity. Our team has built the HTTP requests from scratch using the UnityWebRequest class. This way, your data is encrypted and transmitted securely. You do not need to do any special changes to support HTTPS, other than providing the “https://” URL to your Azure Web App.

SQLite

Unlike most of the available SDKs, the LightBuzz Azure SDK for Unity fully supports local database storage. This means you can use the Azure App Services to store data into a local SQLite database. You can sync your local data with the remote server, performing pull and push operations.

As a result, your customers can use your app or game without an active Internet connection! Your app will store the data locally and will sync with the remote server when an active Internet connection is available.

The local database is using the official version of SQLite. SQLite is the most popular and lightweight relational database system for desktop and mobile devices. For UWP, we are using SQLitePCL, which is Microsoft’s recommendation for Windows Store apps.

Supported Platforms

The LightBuzz Azure SDK for Unity supports every major Unity platform:

  • Unity Editor
  • Android
  • iOS
  • Windows Desktop (Standalone)
  • MacOS (Standalone)
  • Universal Windows Platform (UWP) + HoloLens

LightBuzz Azure SDK for Unity - HoloLens demo

Requirements

To use the SDK, Unity 2017 LTS or Unity 2018 is recommended.

Scripting Runtime

The SDK is built with the latest C# features, so you need to use the .NET 4.x Scripting Runtime version.

In Unity 2018, the scripting runtime is set to 4.x by default.

Scripting Runtime Unity 2018

In Unity 2017, you need to explicitly select Experimental (.NET 4.6 Equivalent).

Scripting Runtime Unity 2017

Build Settings

Using the SDK, you can apply the proper Unity Build Settings automatically. On the Unity menu bar, select LightBuzz → Apply Build Settings for… and then select the target platform.

LightBuzz Azure SDK for Unity - Build Settings

We have done all of the heavy-lifting, so the SDK will automatically apply the proper build settings for you!

How to use

In the included samples, we have created a simple demo that implements Microsoft’s ToDo List example. To use the sample, you need to sign up for a free Azure account and create an App Service with a simple ToDo table.

After you clone or download the repository, open the Samples folder and locate the Sample.cs file.

For your convenience, the SDK is using the LightBuzz service URL by default:

private string mobileAppUri = "https://testtodolightbuzz.azurewebsites.net";

You can also specify whether you would like to have local SQLite database support:

private bool supportLocalDatabase = true;

We have implemented an abstract LightBuzzMobileServiceClient class that handles all of the underlying Azure functionality and the data-to-C# object mapping. Simply define your database tables by implementing the 2 abstract methods in LightBuzzMobileServiceClient. An example is included in the Unity Package (SampleMobileClient.cs).

We also provide a generic Data Access Object for you to use, called AppServiceTableDAO. The AppServiceTableDAO supports all of the common CRUD operations, such as Get, Insert, Delete, etc. All you need to do is call the proper C# methods.

Using the code is fairly simple. Let me show you…

Initialization

The first thing you need to do is declare your Azure client and Data Access Object. You can do that in your main Unity MonoBehavior class.

private LightBuzzMobileServiceClient azureClient;
private AppServiceTableDAO<TodoItem> todoTableDAO;

Then, you need to initialize the Azure client, as well as the data access object, specifying whether you want local SQLite support.

private async Task Init()
{
    azureClient = new SampleMobileClient(mobileAppUri, supportLocalDatabase);
    await azureClient.InitializeLocalStore();

    todoTableDAO = new AppServiceTableDAO<TodoItem>(azureClient);
}

Get data

This is how to list all of the ToDo items of the table:

private async Task Get()
{
    List<TodoItem> list = await todoTableDAO.FindAll();

    foreach (TodoItem item in list)
    {
        Debug.Log("Text: " + item.Text);
    }
}

As you can see, there is no need to type SQL commands — just plain good C#. The Data Access Object is handling that for you!

Insert data

This is a POST request that inserts data:

private async Task Insert()
{
    TodoItem item = new TodoItem
    {
        Text = "Hello World!"
    };

    await todoTableDAO.Insert(item);
}

Delete data

Finally, this is how to delete an item from the list:

private async Task Delete()
{
    List<TodoItem> list = await todoTableDAO.FindAll();

    TodoItem item = list.LastOrDefault();

    if (item != null)
    {
        await todoTableDAO.Delete(item);
    }
}

Sync local and remote data

In case you are using the local SQLite database for offline functionality, here is how to perform the pull and push requests:

private async Task Sync()
{
    await azureClient.Sync();
}

So, do you like the Azure SDK for Unity? Have any questions? Let me know in the comments below! And… enjoy your cloud adventures!

Resources

A series of detailed tutorials and new features will follow.

Download the SDK

LightBuzz is a New York-based company that has been developing Mobile and Cloud solutions for Fortune 500 and ambitious startup companies since 2012.

Contact us
Georgia Makoudi

Georgia Makoudi

Georgia is a Cloud Specialist at LightBuzz. During the past ten years, she's been developing secure backend systems for financial institutions and healthcare companies. She's passionately writing about Microsoft Azure. Did we mention that she loves Escape Rooms?

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.