Getting Started with the UDP package
This section explains how to install and start using the UDP package in your Unity project.
Note: If you want to use the UDP package and the Unity IAP package, see UDP implementation.
Installing the UDP package
You can install the UDP package from:
- The Package Manager
- The Asset Store
Installing the UDP package from the Package Manager
To install the UDP package via the Package Manager:
- In the Unity Editor, select Window > Package Manager.
- In the Packages filter select All Packages.
- Select the Unity Distribution Portal package and select Install.
Installing the UDP package from the Asset Store
To install the UDP package from the Asset Store:
- Download the UDP package from the Asset Store.
- In the Unity Editor, select Assets > Import Package > Custom Package.
- Select the package and select Open > Import.
Linking your Unity project to UDP
To be able to use the UDP Settings window, you need to link your Unity project to a UDP Client.
Prerequisites
You have:
To link your Unity project to a UDP client:
- In the Unity Editor, select Window > Unity Distribution Portal > Settings.
- In the UDP Client ID field, enter your UDP Client ID.
The Client ID is displayed in the Integration Information section of the Game Info page in the UDP console. - Select Link project to this UDP game.
This creates a link between the Unity project and the UDP client.
Your project is now set up to use UDP. The relevant settings from the UDP console are included in the UDP Settings window. These settings are stored in the UDPSettings.asset file.
Creating a UDP client ID from the Unity Editor
Unity recommends creating your UDP client in the UDP console and linking it to your project, as described above. Alternatively, to create a UDP client from the Unity Editor:
- In the Unity Editor, select Window > Unity Distribution Portal > Settings.
- Select Create your UDP game directly from inside the Unity Editor.
- Select Generate new UDP client.
When you generate your UDP client, your game is automatically created in the UDP console. This also creates a UDP settings file for your project.
Initialize the UDP SDK
To access the UDP SDK, declare the UDP namespace in your game manager script.
using UnityEngine.UDP;
To initialize the UDP SDK, your game needs to have a UDPSettings.asset file linked to a UDP client.
In your game manager script, define the initialization listener:
IInitListener listener = new InitListener();
In the Start() function, call the Initialize
method.
StoreService.Initialize(listener);
Note: This is required to be able to publish your game to app stores via UDP.
The InitListener then returns a success or failure message to inform your game if the initialization was successful.
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 been consumed.
}
public void OnInitializeFailed(string message)
{
Debug.Log("Initialization failed: " + message);
}
}
Sample scene
The UDP package contains a sample scene, which provides example methods to help you implement and test UDP in your game. The table below describes these example methods.
If you installed UDP from the Asset Store, the sample is included in the package.
If you installed UDP from the Package Manager, the sample is supported in Unity Editor version 2019.1 and above. To import the sample scene, go to Package Manager > Unity Distribution Portal and select Samples > Import.
Method | Description |
---|---|
Init | Initializes the UDP SDK. On successful initialization, you will be asked to login with your sandbox credentials. This simulates a player opening the game. |
Buy | Attempts to purchase an IAP product in the game. Returns whether the purchase succeeded or failed. |
Buy & consume | Purchases a product and consumes it. Returns whether or not the IAP product was consumed. |
Query inventory | Queries the IAPs configured in the game, and the IAPs you’ve |
Query & consume | Consumes all unconsumed IAPs. This lets you return to the riginal status after the game is initialized. |