Unity 3D / Mono
In this post we have summarized the necessary steps to add software licensing into a Unity game. Unity uses Mono runtime, which means that a special version of our .NET client library can be used.
To implement license key verification a Unity game, we can use a special build of the client library for .NET that is platform independent. You can download it here. Make sure to select the binaries that are in the “Without System.Management” folder.
License key verification
- Add the Cryptolens.Licensing.dll and Newtonsoft.Json.dll into the Assets folder.
- Include the license key verification logic.
Note: we recommend to avoid using Key.Activate that takes in an ActivateModel since signature verification will not work on some platforms. Instead, we recommend to use a special version of Key.Activate as shown below:
// call to activate var result = Key.Activate(token: auth, productId: 3349, key: "GEBNC-WZZJD-VJIHG-GCMVD", machineCode: "foo"); // obtaining the license key (and verifying the signature automatically). var license = LicenseKey.FromResponse("RSAPubKey", result);
Also, when implementing offline verification, please call
LoadFromString with the RSAPubKey. The format of the license file should be set to Other languages (see more here) when downloading it in the dashboard or using Activation Forms.
You can download a sample project here.
Other licensing models
Since Unity uses C# as the scripting interface, you can use all of the .NET examples provided in this wiki. As a next step, please take a look at the available licensing models.
Please keep in mind if you use the version of Key.Activate that was suggested earlier,
you would need to create a license key object from the response such as
LicenseKey.FromResponse(result).SaveToFile() to be able to use the extension methods, eg.
result.LicenseKey.SaveToFile() will not work.
IsOnRightMachine() methods require root access on Linux.