VRRSS vrenaissance

VRRSS // DEVELOPER DOCUMENTATION

API, Unity SDK и интеграция проверки лицензий

Integration of the License Verification System in Unity. #

This guide describes how to integrate the RRSS license verification system into your Unity game.

Package Installation #

To integrate the license verification system, you will need the following packages:

Name URL
VRenaissance SDK - Hub API https://git.vrrss.com/vrrss/unity/sdk/hubapi.git
VRenaissance SDK - Threading https://git.vrrss.com/vrrss/unity/sdk/threading.git

To install a package, open the Unity Package Manager by selecting Window → Package Manager from the menu.


In the Package Manager, expand the dropdown menu with the “+” sign and select “Install package from Git URL”.

In the window that appears, enter the URL of the required package from the table and click the “Install” button.



Implementing License Verification #

Create an empty C# script in your project. Name it as you prefer.

Wrap the created script in a compilation condition: UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN. This will avoid compilation issues on other platforms, as the API package only supports the Windows platform.
Add the static modifier to the automatically created class.
Change the access modifier of the automatically created class to internal.
Add using directives:

using VRRSS.SDK.HubAPI;
using VRRSS.SDK.Threading;

Define a private static void method called OnLicenseVerificationCompleted, which takes a LicenseStatus as an argument.

private static void OnLicenseVerificationCompleted(LicenseStatus status)

This method is intended to handle the results of the license verification. It takes one argument — LicenseStatus, which will represent the verification result. For a basic implementation, handling just two statuses is sufficient: LicenseStatus.Success, which indicates successful license verification, and LicenseStatus.Canceled, which signals that the verification was manually stopped. All other statuses indicate that the license could not be confirmed for some reason. You can find more detailed information about them on the LicenseStatus documentation page.
The recommended basic handling involves checking the license status. It is necessary to ensure the status is not Success or Canceled. If it isn’t, you should display an error message via the VRenaissance HUB using the VRHub.ShowMessage method, and then quit the application.

private static void OnLicenseVerificationCompleted(LicenseStatus status)
{
    if (status != LicenseStatus.Success && status != LicenseStatus.Canceled)
    {
        VRHub.ShowMessage("The validity of the license could not be confirmed. " +
                "Please make sure that you have an active license for this product and that you have sufficient funds on your balance. " +
                "If you still encounter this error after meeting these conditions, please contact VRenaissance support.",
            "Failed to verify license validity",
            MessageType.Error);
        Dispatcher.Invoke(Application.Quit);
    }
}

This method will not be called on the main Unity thread. Therefore, to call Application.Quit, you need to use the Dispatcher.Invoke method.

Define a private static void method named VerifyLicense with no parameters.
Add the RuntimeInitializeOnLoadMethod attribute to the method.

[RuntimeInitializeOnLoadMethod]
private static void VerifyLicense()

Before starting the license verification, we need to connect the previously created OnLicenseVerificationCompleted method to the event that signals the completion of the verification. To do this, we subscribe OnLicenseVerificationCompleted to the VRHub.LicenseVerificationCompleted event.

VRHub.LicenseVerificationCompleted += OnLicenseVerificationCompleted;

After that, you should start the license verification process using the VRHub.InitializeGameWithLicense method. You need to pass the game ID, which is defined in the games section of the VRenaissance developer panel, to this method.

VRHub.InitializeGameWithLicense("com.stvdev.netoa");

Note

In this code snippet, “com.stvdev.netoa” is used as an example. You should replace it with your game’s ID.



This completes the license verification integration.

// If the platform is not Windows, the script will not be compiled.
#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN

using UnityEngine;
using VRRSS.SDK.HubAPI;
using VRRSS.SDK.Threading;

internal static class LicenseCheck
{
    // Method to handle verification results.
    private static void OnLicenseVerificationCompleted(LicenseStatus status)
    {
        // If the license is not confirmed or its verification was not stopped.
        if (status != LicenseStatus.Success && status != LicenseStatus.Canceled)
        {
            // Display an error message via the VRenaissance Hub.
            VRHub.ShowMessage("The validity of the license could not be confirmed. " +
                "Please make sure that you have an active license for this product and that you have sufficient funds on your balance. " +
                "If you still encounter this error after meeting these conditions, please contact VRenaissance support.",
                "Failed to verify license validity",
                MessageType.Error);

            // Quit the game. Since the method is not called on the main thread, use Dispatcher.
            Dispatcher.Invoke(Application.Quit);
        }
    }

    // Specifies that the method should be executed when the game starts.
    [RuntimeInitializeOnLoadMethod]
    // Method to start license verification.
    private static void VerifyLicense()
    {
        // Subscribe the handler method to the event.
        VRHub.LicenseVerificationCompleted += OnLicenseVerificationCompleted;

        // Start license verification. Pass the game ID from the developer panel.
        VRHub.InitializeGameWithLicense("com.stvdev.netoa");
    }
}

#endif

Tip

Using RuntimeInitializeOnLoadMethod is just a basic recommendation for defining the entry point to start license verification. You can call this method yourself based on your game’s logic. However, it is important to note that license verification should be performed exclusively on the game server, and not, for example, on VR headsets.