Well, after struggling with this for a while because the documentation wasnt very helpful (unclear, typos in the code etc). Here is the solution of “Initializing the UDP SDK” for newbies :
- Create a new C# file (the file name is not important) and put the following code inside (the code from the documentation contains some errors that I fixed btw) :
using UnityEngine;
using UnityEngine.UDP;
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);
}
}
- Now go to your game main file and add using UnityEngine.UDP; at the top then put the following code in the Awake() or Start() method. In my case, I have a GameManager file that handle the game cycle, so I put this code inside its Awake() method.
# Instantiate the listener
IInitListener listener = new InitListener();
# Use the listener to initialize the UDP stuff
StoreService.Initialize(listener);
- Finally, build your project and run it on a real device (emulators may work but not the unity simulator). when the game launches you will be prompted by the UDP authentication dialog. Use the Sand box test account(s) to login and voilà!
Cheers!