Official Unity SDK for LicenseChain - Secure license management for Unity games and applications.
- π Secure Authentication - User registration, login, and session management
- π License Management - Create, validate, update, and revoke licenses
- π‘οΈ Hardware ID Validation - Prevent license sharing and unauthorized access
- π Webhook Support - Real-time license events and notifications
- π Analytics Integration - Track license usage and performance metrics
- β‘ High Performance - Optimized for Unity's runtime
- π Async Operations - Non-blocking HTTP requests and data processing
- π οΈ Easy Integration - Simple API with comprehensive documentation
- Open Unity Package Manager
- Click the "+" button
- Select "Add package from git URL"
- Enter:
https://github.com/LicenseChain/LicenseChain-Unity-SDK.git
- Download the latest release from GitHub Releases
- Extract the
.unitypackage
file - Import the package into your Unity project
- Place the
LicenseChain
folder in yourAssets
directory
# Add as submodule
git submodule add https://github.com/LicenseChain/LicenseChain-Unity-SDK.git Assets/LicenseChain
# Update submodule
git submodule update --init --recursive
using LicenseChain.Unity;
public class LicenseManager : MonoBehaviour
{
private LicenseChainClient client;
void Start()
{
// Initialize the client
var config = new LicenseChainConfig
{
ApiKey = "your-api-key",
AppName = "your-app-name",
Version = "1.0.0"
};
client = new LicenseChainClient(config);
// Connect to LicenseChain
StartCoroutine(ConnectToLicenseChain());
}
private IEnumerator ConnectToLicenseChain()
{
var connectTask = client.ConnectAsync();
yield return new WaitUntil(() => connectTask.IsCompleted);
if (connectTask.IsFaulted)
{
Debug.LogError($"Failed to connect: {connectTask.Exception}");
}
else
{
Debug.Log("Connected to LicenseChain successfully!");
}
}
}
// Register a new user
public IEnumerator RegisterUser(string username, string password, string email)
{
var registerTask = client.RegisterAsync(username, password, email);
yield return new WaitUntil(() => registerTask.IsCompleted);
if (registerTask.IsFaulted)
{
Debug.LogError($"Registration failed: {registerTask.Exception}");
}
else
{
var user = registerTask.Result;
Debug.Log($"User registered successfully! ID: {user.Id}");
}
}
// Login existing user
public IEnumerator LoginUser(string username, string password)
{
var loginTask = client.LoginAsync(username, password);
yield return new WaitUntil(() => loginTask.IsCompleted);
if (loginTask.IsFaulted)
{
Debug.LogError($"Login failed: {loginTask.Exception}");
}
else
{
var user = loginTask.Result;
Debug.Log($"User logged in successfully! Session ID: {user.SessionId}");
}
}
// Validate a license
public IEnumerator ValidateLicense(string licenseKey)
{
var validateTask = client.ValidateLicenseAsync(licenseKey);
yield return new WaitUntil(() => validateTask.IsCompleted);
if (validateTask.IsFaulted)
{
Debug.LogError($"License validation failed: {validateTask.Exception}");
}
else
{
var license = validateTask.Result;
Debug.Log($"License is valid! Key: {license.Key}, Status: {license.Status}");
Debug.Log($"Expires: {license.Expires}, Features: {string.Join(", ", license.Features)}");
}
}
// Get user's licenses
public IEnumerator GetUserLicenses()
{
var licensesTask = client.GetUserLicensesAsync();
yield return new WaitUntil(() => licensesTask.IsCompleted);
if (licensesTask.IsFaulted)
{
Debug.LogError($"Failed to get licenses: {licensesTask.Exception}");
}
else
{
var licenses = licensesTask.Result;
Debug.Log($"Found {licenses.Count} licenses:");
for (int i = 0; i < licenses.Count; i++)
{
var license = licenses[i];
Debug.Log($" {i + 1}. {license.Key} - {license.Status} (Expires: {license.Expires})");
}
}
}
// Get hardware ID (automatically generated)
public string GetHardwareId()
{
var hardwareId = client.GetHardwareId();
Debug.Log($"Hardware ID: {hardwareId}");
return hardwareId;
}
// Validate hardware ID with license
public IEnumerator ValidateHardwareId(string licenseKey, string hardwareId)
{
var validateTask = client.ValidateHardwareIdAsync(licenseKey, hardwareId);
yield return new WaitUntil(() => validateTask.IsCompleted);
if (validateTask.IsFaulted)
{
Debug.LogError($"Hardware ID validation failed: {validateTask.Exception}");
}
else
{
var isValid = validateTask.Result;
if (isValid)
{
Debug.Log("Hardware ID is valid for this license!");
}
else
{
Debug.Log("Hardware ID is not valid for this license.");
}
}
}
// Set up webhook handler
public void SetupWebhookHandler()
{
client.SetWebhookHandler((eventName, data) =>
{
Debug.Log($"Webhook received: {eventName}");
switch (eventName)
{
case "license.created":
Debug.Log($"New license created: {data["licenseKey"]}");
break;
case "license.updated":
Debug.Log($"License updated: {data["licenseKey"]}");
break;
case "license.revoked":
Debug.Log($"License revoked: {data["licenseKey"]}");
break;
}
});
// Start webhook listener
StartCoroutine(StartWebhookListener());
}
private IEnumerator StartWebhookListener()
{
var startTask = client.StartWebhookListenerAsync();
yield return new WaitUntil(() => startTask.IsCompleted);
if (startTask.IsFaulted)
{
Debug.LogError($"Failed to start webhook listener: {startTask.Exception}");
}
else
{
Debug.Log("Webhook listener started successfully!");
}
}
var config = new LicenseChainConfig
{
ApiKey = "your-api-key",
AppName = "your-app-name",
Version = "1.0.0",
BaseUrl = "https://api.licensechain.com" // Optional
};
var client = new LicenseChainClient(config);
// Connect to LicenseChain
var connectTask = client.ConnectAsync();
// Disconnect from LicenseChain
var disconnectTask = client.DisconnectAsync();
// Check connection status
bool isConnected = client.IsConnected;
// Register a new user
var registerTask = client.RegisterAsync(username, password, email);
// Login existing user
var loginTask = client.LoginAsync(username, password);
// Logout current user
var logoutTask = client.LogoutAsync();
// Get current user info
var userTask = client.GetCurrentUserAsync();
// Validate a license
var validateTask = client.ValidateLicenseAsync(licenseKey);
// Get user's licenses
var licensesTask = client.GetUserLicensesAsync();
// Create a new license
var createTask = client.CreateLicenseAsync(userId, features, expires);
// Update a license
var updateTask = client.UpdateLicenseAsync(licenseKey, updates);
// Revoke a license
var revokeTask = client.RevokeLicenseAsync(licenseKey);
// Extend a license
var extendTask = client.ExtendLicenseAsync(licenseKey, days);
// Get hardware ID
string hardwareId = client.GetHardwareId();
// Validate hardware ID
var validateTask = client.ValidateHardwareIdAsync(licenseKey, hardwareId);
// Bind hardware ID to license
var bindTask = client.BindHardwareIdAsync(licenseKey, hardwareId);
// Set webhook handler
client.SetWebhookHandler(handler);
// Start webhook listener
var startTask = client.StartWebhookListenerAsync();
// Stop webhook listener
var stopTask = client.StopWebhookListenerAsync();
// Track event
var trackTask = client.TrackEventAsync(eventName, properties);
// Get analytics data
var analyticsTask = client.GetAnalyticsAsync(timeRange);
Configure the SDK through Unity's Project Settings or a configuration file:
// Assets/LicenseChain/Config/LicenseChainSettings.asset
[CreateAssetMenu(fileName = "LicenseChainSettings", menuName = "LicenseChain/Settings")]
public class LicenseChainSettings : ScriptableObject
{
[Header("API Configuration")]
public string apiKey;
public string appName;
public string version;
public string baseUrl = "https://api.licensechain.com";
[Header("Advanced Settings")]
public int timeout = 30;
public int retries = 3;
public bool debug = false;
}
Set these in your build process or through Unity Cloud Build:
# Required
export LICENSECHAIN_API_KEY=your-api-key
export LICENSECHAIN_APP_NAME=your-app-name
export LICENSECHAIN_APP_VERSION=1.0.0
# Optional
export LICENSECHAIN_BASE_URL=https://api.licensechain.com
export LICENSECHAIN_DEBUG=true
var config = new LicenseChainConfig
{
ApiKey = "your-api-key",
AppName = "your-app-name",
Version = "1.0.0",
BaseUrl = "https://api.licensechain.com",
Timeout = 30, // Request timeout in seconds
Retries = 3, // Number of retry attempts
Debug = false, // Enable debug logging
UserAgent = "MyGame/1.0.0" // Custom user agent
};
The SDK automatically generates and manages hardware IDs to prevent license sharing:
// Hardware ID is automatically generated and stored
string hardwareId = client.GetHardwareId();
// Validate against license
var validateTask = client.ValidateHardwareIdAsync(licenseKey, hardwareId);
- All API requests use HTTPS
- API keys are securely stored and transmitted
- Session tokens are automatically managed
- Webhook signatures are verified
- Real-time license validation
- Hardware ID binding
- Expiration checking
- Feature-based access control
// Track custom events
var properties = new Dictionary<string, object>
{
["level"] = 1,
["playerCount"] = 10
};
var trackTask = client.TrackEventAsync("app.started", properties);
// Track license events
var licenseProperties = new Dictionary<string, object>
{
["licenseKey"] = "LICENSE-KEY",
["features"] = "premium,unlimited"
};
var licenseTrackTask = client.TrackEventAsync("license.validated", licenseProperties);
// Get performance metrics
var metricsTask = client.GetPerformanceMetricsAsync();
yield return new WaitUntil(() => metricsTask.IsCompleted);
if (metricsTask.IsCompletedSuccessfully)
{
var metrics = metricsTask.Result;
Debug.Log($"API Response Time: {metrics.AverageResponseTime}ms");
Debug.Log($"Success Rate: {metrics.SuccessRate:P}");
Debug.Log($"Error Count: {metrics.ErrorCount}");
}
try
{
var license = await client.ValidateLicenseAsync("invalid-key");
}
catch (InvalidLicenseException ex)
{
Debug.LogError("License key is invalid");
}
catch (ExpiredLicenseException ex)
{
Debug.LogError("License has expired");
}
catch (NetworkException ex)
{
Debug.LogError($"Network connection failed: {ex.Message}");
}
catch (LicenseChainException ex)
{
Debug.LogError($"LicenseChain error: {ex.Message}");
}
// Automatic retry for network errors
var config = new LicenseChainConfig
{
ApiKey = "your-api-key",
AppName = "your-app-name",
Version = "1.0.0",
Retries = 3, // Retry up to 3 times
Timeout = 30 // Wait 30 seconds for each request
};
# Run tests in Unity Test Runner
# Or via command line
Unity -batchmode -quit -projectPath . -runTests -testResults results.xml
# Test with real API
# Use Unity Test Runner with integration test category
See the Examples/
directory for complete examples:
LicenseChainExample.cs
- Basic SDK usageAdvancedFeaturesExample.cs
- Advanced features and configurationWebhookIntegrationExample.cs
- Webhook handling
We welcome contributions! Please see our Contributing Guide for details.
- Clone the repository
- Install Unity 2021.3 or later
- Open the project in Unity
- Install dependencies
- Run tests in Unity Test Runner
This project is licensed under the MIT License - see the LICENSE file for details.
- Documentation: https://docs.licensechain.com/unity
- Issues: GitHub Issues
- Discord: LicenseChain Discord
- Email: support@licensechain.com
Made with β€οΈ for the Unity community