Stratis and Unity Integration Release

Unity is a cross-platform game engine with a built-in IDE developed by Unity Technologies. It is used to develop video games for web plugins, desktop platforms, consoles and mobile devices. It is arguably, one of the most popular gaming engines currently available along with Unreal and GameMaker.

Scripts for Unity are primarily written in C#, and hence it attracted a lot of attention from the Stratis development team. Stratis envisages gaming to become one of the first real use cases for blockchain integration, making games more immersive, private and decentralized. It can blur boundaries between games and push power into the user’s hands.

Stratis platform features smart contracts which can be used in games. Using smart contracts will enable some exciting features in games there were not explored before or were highly centralized. One of the most common examples of it would be tokenization. Gamers are very much familiar with this concept. In-game gold tokens can now be purchased with real fiat currency. However, these tokens are highly centralized and cannot be efficiently utilized across games.

Stratis Platform has published unity specific packages that target .NETStandard 2.0 Framework allowing them to be used for various application development platforms such as Unity, Xamarin, ASP.NET etc. The packages currently available are:

More packages will be made available as required. These packages should allow developers to utilize most of the features of the Stratis Platform, including Smart Contracts in C#.

Stratis’ Unity SDK will be unveiled in the new year, incorporating full documentation and additional API’s specifically targeted at those utilizing Stratis Technologies within Unity Game development. Also, Stratis is excited to announce that their upcoming hackathon will focus on building games within Unity using the Stratis Unity SDK. Stratis has already created a gaming development focused channel within its Discord Server to ignite thought-provoking conversations to prepare for the official hackathon announcement.

Environment Setup

Register and Install Unity IDE

  1. Once registered download and install Unity Hub: https://unity3d.com/get-unity/download
  2. Make sure you have Microsoft Visual Studio installed (or any other IDE of your choice for writing C# code like Rider, Visual Studio Code etc.).
  3. Create a new Unity project. You can select a blank project or choose one of the provided templates, such as simple 2D Adventure Game or a more advanced Lego Racing 3D game as an example.

5. Navigate to Scripts section and add a new script

This should open your new C# script in an IDE of your choice, such as Visual Studio.

Now it is time to bring Stratis packages in to add some blockchain functionality to our game. Right-click on the solution in the solution explorer and select Manage NuGet Packages. This should open NuGet Package Manager.

Make sure preview packages option is ticked (currently NETStandard Stratis packages are in preview only).

Now you can code using standard Stratis Features. Once you are done with your script, you can close IDE, and the script will be available in your Unity project. If you have any errors, please follow this article to resolve NuGet package issues https://jonfoust.medium.com/using-gcp-nuget-packages-with-unity-8dbd29c42cc4.

Alternatively, packages can be imported using a Unity plugin, which is available here: https://github.com/GlitchEnzo/NuGetForUnity. It should automatically download all the required dependencies and place libraries in the correct folders.

Lets, now create some basic code such as generating private/public key combination. Ensure your newly created script is open in Visual Studio (if it is not, double click on it inside the unity project explorer).

Add new NuGet package: Stratis.Sidechains.Networks.NETStandard as per the instructions above. Once the package is installed, add the following code on the link below:

https://www.stratisplatform.com/2020/12/23/stratis-and-unity-integration/

Now you have a basic service that will allow you to generate a private/public key pair, sign a message using your private key and verify a message.

You could use this to generate a wallet address for a user that can then be funded with tokens.

Running External Node

Even though the game may not necessarily have a node running, you could still generate all the addresses, fund them outside the game and use offline transactions to propagate to a node.

Here is an example of the basic gaming setup, where a game can use basic blockchain functionality locally and interact with an external node via API to get more advanced functionality.

Stratis is powerful and flexible Blockchain Development Platform designed for the needs of real world financial services and businesses.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store