SDKs code references for Unity
Easily embed Xsolla services with this ready-to-use libraries for Unity applications and games
|
The SDK consists of the following parts:
Login
namespace that contains methods and classes for working with user authentication, the friend system, and for obtaining user information, etc.Store
namespace that contains methods and classes for working with virtual items and virtual currencies, making purchases, payment processing, managing a shopping cart, opening the payment UI, etc.Core
namespace that contains lower-level classes that are common to the rest of the SDK. For example, common methods for calling APIs, built-in browser, SDK settings, methods for integrating with third-party solutions, etc.Demo
namespace.To send requests to Xsolla servers and receive responses, the SDK provides the XsollaStore
and XsollaLogin
classes. If you want to implement your own logic for buying items or inventory management, and don’t want to write boilerplate code for API calls, these classes are a good place to start.
The XsollaLogin
class includes methods to implement the following features:
The XsollaStore
class includes methods to implement the following features:
The XsollaStore
and XsollaLogin
classes contain methods to refer to the WebRequestHelper
class, which uses the standard UnityWebRequest class. Since the methods for API calls use coroutines for requests to Xsolla servers, delegates act for them as parameters. Delegates are called when a response is received from the server.
public void GetUserInfo(string token, Action <UserInfo> onSuccess, Action <Error> onError = null)
GetUserInfo
method for getting user information has two delegate parameters: OnSuccess
delegate is called if the server responds successfully. The UserInfo
parameter contains information about the user (nickname, email, etc.). OnError
delegate is called if an error arises from the server. The Error
parameter contains the error code and its description. In addition to methods for calling the APIs, the SDK contains data and classes for making requests to the API and receiving a response — data transfer objects.
CartItem
class describes a cart item (name, type, and other attributes). UserSocialFriends
is data that describes a user's list of friends. The built-in browser is a separate module designed to open web pages inside the application. It is usually used to open a payment UI and to log a user in via third-party services.
The BrowserHelper
class is a convenient entry point for interacting with the built-in browser. That class contains the necessary methods for using the browser.
Use the Open
method to open a webpage, passing the required URL as a parameter.
To open the payment UI via the built-in browser, use the BrowserHelper
class and the OpenPurchase
method, passing as parameters:
Url
— Pay Station API endpoint.Token
— Pay Station token.IsSandbox
— payment processing mode.The SDK provides utility classes to work with Unity or third-party modules and solutions.
SteamManager
class manages authentication via Steam. Demo project classes represent one of the possible logics for the login system, inventory, and in-game store. You can use the demo project in two ways:
Most of the demo project module is the ordinary MonoBehaviour classes that use the SDK:
LoginPageController
manages the user's login page. It determines whether the user is authorized, and if not, it can display a sign-up page or a registration page.CartControls
class builds a page with information about the cart data (e.g., the number of items to purchase) and counts and shows the total purchase price, etc.