How to connect your game

Getting started with Connect for Unity

Pointvoucher Connect is a plugin for Unity 5.4.0 or higher that provides a simple API for connecting your game to the Pointvoucher platform. You can prepare for this integration in four easy steps.

  • Contact Pointvoucher to obtain a unique Connect API key for your game.
  • Download the latest unitypackage. The download link is in development 👀
  • In Unity, choose Assets → Import Package → Custom Package and select the downloaded file. In the Unity Package Manager, select all files and press Import.
  • In Unity, choose Assets → Pointvoucher Connect → Settings and register your Connect API key.

Connect should be initialized somewhere in your first scene.

using Pointvoucher.Connect;

public class PointvoucherIntegrationExample : MonoBehaviour
{
  public void Start()
  {
    // log potential errors
    PvConnect.OnError(Debug.Log);

    // initialize Connect
    PvConnect.Init(() => {

      // trigger first action
      PvConnect.Action(PvConnect.CONTEXT_TITLE_SCREEN);
    });
  }
}

Once initialized, you can at any time invoke the Action method to trigger a user facing notification message. The method takes a context string and an optional callback as arguments. CONTEXT_TITLE_SCREEN may for example trigger a notification that invites the user to join Pointvoucher.

PvConnect.Action(PvConnect.CONTEXT_TITLE_SCREEN, () => {
 Debug.Log("Let's play!");
});

If provided, the callback gets invoked as soon as the user is done interacting with Connect, for example when the user swipes the invitation away or when the signup process has been completed. The SDK may also decide, not to show a notification at this point in time, in which case the callback gets invoked immediately. Connect adapts its behavior to the following contexts.

CONTEXT_TITLE_SCREEN
Used before the user presses Play. A notification may advertise the integration with Pointvoucher and invite the user to sign up.
CONTEXT_LEVEL_COMPLETE
Used in between game levels or some equivalent break in active gameplay. A notification may display points earned.
CONTEXT_GAME_OVER
When the game ends, a notification may display points earned.

Remember that Connect may always decide, not to show a notification when the Action method is called, for example when the user has accumulated zero voucher points since the last status update.

PvConnect

MethodParamsReturnsDescription
Action
  • string context
  • delegate callback
void

Instruct Connect to display an appropriate notification based on the given context. The optional callback is invoked when the notification gets dismissed or closes automatically.

Init
  • string apiKey
  • delegate callback
void

Initialize Connect whenever the user opens the game. The optional callback is invoked when initialization either succeeded or failed. Make sure to configure method OnError to identify the cause of potential failure.

OnError
  • delegate callback
void

Get an angle on potential errors since Connect is otherwise designed to fail silently. The callback receives an object with a Message property.

OpenAccount
  • delegate callback
void

Open the user's account page via Pointvouchers website. The optional callback is invoked when the popup is closed.

OpenShop
  • delegate callback
void

Open the voucher shop via Pointvouchers website. The optional callback is invoked when the popup is closed.