Skip to content

Instantly share code, notes, and snippets.

@corycorvus
Created September 15, 2020 20:51
Show Gist options
  • Save corycorvus/8f2cd4461d7927291e18eb0f50786b94 to your computer and use it in GitHub Desktop.
Save corycorvus/8f2cd4461d7927291e18eb0f50786b94 to your computer and use it in GitHub Desktop.
UDP Test (Unity Distribution Portal)
using UnityEngine;
using UnityEngine.UDP;
public class TestUDP : MonoBehaviour
{
void Start()
{
InitListener initListener = new InitListener();
LicenseCheckListener licenseCheckListener = new LicenseCheckListener();
#if UNITY_ANDROID && !UNITY_EDITOR
StoreService.LicenseCheck(licenseCheckListener);
#endif
StoreService.Initialize(initListener);
}
}
public class InitListener : IInitListener
{
public void OnInitialized(UserInfo userInfo)
{
Debug.Log("Initialization succeeded");
// You can call the QueryInventory method here
// to check whether there are purchases that haven’t be consumed.
}
public void OnInitializeFailed(string message)
{
Debug.Log("Initialization failed: " + message);
}
}
// Call the LicenseCheck method in your game code (typically, before calling the UDP Init method):
// StoreService.LicenseCheck(ILicensingListener listener)
public class LicenseCheckListener : ILicensingListener
{
public void allow(LicensingCode code, string message)
{
//LicensingCode enum:
//RETRY, LICENSED, NOT_LICENSED, STORE_NOT_SUPPORT
//Show(message); //some meaningful message
Debug.Log("allow: " + message);
}
public void dontAllow(LicensingCode code, string message)
{
//LicensingCode enum:
//RETRY, LICENSED, NOT_LICENSED, STORE_NOT_SUPPORT
//Show(message); //some meaningful message
Debug.Log("dont allow: " + message);
}
public void applicationError(LicensingErrorCode code, string message)
{
//LicensingErrorCode enum:
//ERROR_INVALID_PACKAGE_NAME, ERROR_NON_MATCHING_UID, ERROR_NOT_MARKET_MANAGED, ERROR_CHECK_IN_PROGRESS, ERROR_INVALID_PUBLIC_KEY, ERROR_MISSING_PERMISSION
//Show(message); //some meaningful message
Debug.LogError("applicationError: " + message);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment