// sellkeys Auth – Unity example: checks a license key on start and re-checks every 5 minutes. // Put SellkeysAuthUnity.cs and this file into Assets/, add the component to a GameObject and fill in the fields. using System.Collections; using Sellkeys; using UnityEngine; public class SellkeysAuthExample : MonoBehaviour { [SerializeField] private string appId = "APP_ID"; [SerializeField] private string publicKey = "PUBLIC_KEY"; [SerializeField] private string licenseKey = ""; // in a real game: read it from your login UI private SellkeysAuth _auth; private async void Start() { _auth = new SellkeysAuth(appId, publicKey, Application.version); try { await _auth.InitAsync(); var lic = await _auth.LicenseAsync(licenseKey); Debug.Log($"License ok: level {lic.Level}, expires {(lic.ExpiresAt?.ToString("yyyy-MM-dd") ?? "never")}"); StartCoroutine(RecheckLoop()); } catch (SellkeysAuthException e) { Debug.LogError($"License check failed: {e.Code} {e.Message}"); if (e.Code == "update_required" && !string.IsNullOrEmpty(_auth.UpdateUrl)) Application.OpenURL(_auth.UpdateUrl); else Application.Quit(); } } private IEnumerator RecheckLoop() { while (true) { yield return new WaitForSecondsRealtime(300); var check = _auth.CheckAsync(); yield return new WaitUntil(() => check.IsCompleted); if (check.IsFaulted) { var e = check.Exception?.InnerException as SellkeysAuthException; if (e == null || e.Code != "network_error") // ignore short network hiccups, stop on ban/expiry/session end { Debug.LogError($"License no longer valid: {e?.Code ?? check.Exception?.Message}"); Application.Quit(); } } } } private async void OnApplicationQuit() { try { if (_auth != null) await _auth.LogoutAsync(); } catch (SellkeysAuthException) { /* the session expires on its own */ } } }