This tutorial gives you a starting point for implementing license management and copy protection into a Unity application. The included custom package is based on the PLUSManaged Read-Only License Sample, and uses our PLUSManaged for .NET Standard library.
For .NET Standard 2.0, the minimum supported version of Unity is 2018.1: https://docs.microsoft.com/en-us/dotnet/standard/net-standard
The .unitypackage file is included with Protection PLUS 5 SDK .NET Edition and installed to the Windows directory:
%PUBLIC%\Documents\SoftwareKey\Protection PLUS 5\Samples\Samples-Microsoft .NET\Unity
Use the Unity menu Assets / Import Package / Custom Package… and import the PLUSManaged_ReadOnlyLicense package.
The user interface in this custom package requires the Unity UI package. Use the menu Windows / Package Manager to add Unity UI to your project.
While you have the option to use the included sample user interface, you can also implement your own user interface.
This section will demonstrate how to create a license in SOLO Server, perform an online activation, remotely modify the license and have it refresh on the client machine, and deactivate a license. While additional functionality is available in the source code, this sample is currently configured to demonstrate these main features.
In the Unity Project window, open the LicenseManagementSample scene under the Assets / SoftwareKey License Management / Scenes folder.
You can ignore any “field is assigned but its value is never used” warning messages from the LicenseConfiguration class.
Press the play button to run the application. In the Game window, the License Management user interface will be prompted, and should display:
This sample is configured to use a read-only license, which must be acquired through an activation process. The user must activate and have a valid license, and then they will be allowed to access the rest of the application.
The easiest way to activate is to use our central license server, SOLO Server Automation. This sample currently only demonstrates the online activation method.
For ease of use, all of the Protection PLUS 5 SDK sample applications are configured to use a generic Test Author account with its own Encryption Key data. We will use this Test Author account to generate a License ID and Activation Password for this sample.
More details will be provided later in this tutorial for updating the License Object in the Unity Inspector so you can use licenses generated from your own SOLO Server account.
To log into SOLO Server, use the Test Author credentials:
To add a test license, go to the menu Customers / Add Test License.
Select the Protection PLUS 5 SDK Sample 1-Year License and click Add New Test License. Other "Protection PLUS 5 SDK" time-limited licenses are also supported, and the "Sample Full License" is a perpetual license.
On the Add Test License page, do not change the default values and click Add License.
Test Licenses are meant for software development integration and testing purposes ONLY and should never be sent to a real customer. Test Licenses are DELETED from the license database on the first day of every month.
The test license has now been created based on the Protection PLUS 5 SDK Sample Full License Product Option settings and attached to a new, unregistered customer record.
Click on the License ID in the Licenses & Other Items section to load the License Details page.
Return to the activation prompt in the Unity sample.
Enter the License ID and Activation Password in their respective fields and, optionally, an Installation Name. The Installation Name will be listed in the SOLO Serveractivation history and can be useful for identifying a particular installation.
The Error/Status text field will show whether the activation was successful or what the error was.
If successful, the License text field will be updated with details about the license. With a valid license, the Refresh, Deactivation, and Launch buttons will be interactable.
Pressing the Launch button will run the rest of the application. For this sample, it is simply pausing the scene by setting Time.timeScale = 0f at startup. After pressing Launch, the scene is unpaused (Time.timeScale = 1f) and the License Management object is set to inactive.
The only functionality in this sample scene is a rotating cube and a button to set the License Management dialog as active again. Depending on your application, you can implement other approaches that do not allow the user to access the main functionality of your application until it has a valid license.
A license Refresh will get a new/updated license from SOLO Server, which can include an updated expiration date or any other license parameters. It will also validate that the license is still valid, and will enforce a remote deactivation if applicable.
In SOLO Server, use the drop-down License / Edit, and update the Download Until date (which is used as the license expiration date in this case).
After updating the date, press the Submit button at the bottom of the page.
In the Unity application, press the Refresh button to get an updated license file with the updated expiration date. You should see that the Refresh was successful, and the new expiration date will be reflected in the License text field.
The Protection PLUS 5 SDK Sample 1-Year License Product Option is configured with License Validation Options, and will always require validation with SOLO Server. This is helpful for testing purposes, but we generally recommend using more lenient validation periods, as requiring validation with the license server every time could restrict legitimate users from accessing your software if they don’t have a stable internet connection. Note that your software will still be validating against the local license file each time you perform a license check.
You can allow the user to deactivate their installation directly through the application, which will delete the local license file, disable the Launch button, and set that particular installation to a deactivated status in SOLO Server. It will also increment the Activations Left count on the License ID in SOLO Server, allowing the user to activate on another computer.
See this topic for more general information and recommendations on deactivations.
The LicenseManagement prefab can be dropped into an existing scene to give you a starting point for implementing the licensing and copy protection. This is the same prefab that is used in the LicenseManagementSample scene.
The LicenseManagement prefab is in the Project Assets / SoftwareKey License Management / Prefabs folder.
This sample is configured to perform the license check when the scene loads. If you have multiple scenes that need license enforcement, you will need to validate the license at the beginning of each scene and/or validate the license before any critical functionality.
With our sample, the License Management dialog is always shown when the scene is run, but you could change it to silently validate the license and only prompt the License Management dialog if the validation fails, which then gives the user the option to activate.
The License Object script is used to update some of the main settings from the License Configuration class.
By default, it uses settings from our generic SOLO Server Test Author account. You can use these values for evaluation purposes, but to use your own SOLO Server account, you will need to update the Envelope Key, Envelope, and Product ID values.
The read-only license file will be saved to the project's _Data folder when the application is built. In the Unity Editor, it will be saved to the Assets folder.
The System Identifier Algorithms are how the copy protection is enforced. In this sample, we just included the system identifiers that are supported on the most .NET Standard platforms, but you can use other system identifiers, including custom identifiers, depending on the platform and the data that will be available to your application. You can also choose the validation logic for each identifier. See this copy-protection topic for more details.
The License Management dialog functionality is all in the License UI script. You can use this script with your own license dialog, or simply modify the License Dialog and License UI script to meet your needs.
Note that the canvas is configured for a 16:9 ratio (1920x1080 Reference Resolution), so this may need to be modified depending on the screen ratio(s) you need to support.
This sample is a starting point for implementing SoftwareKey licensing into a Unity application. See our overview and implementation topics and API reference for more details, and our Best Practices for Security and Performance.
Please let us know if you have any questions or feedback.