Skip to content

Wortal SDK

Installation

  • Install the Wortal SDK Unity package via git URL:

    https://github.com/Digital-Will-Inc/wortal-sdk-unity.git

  • Install the Wortal WebGL template via toolbar:

    Wortal/Install WebGL Template

  • Set the necessary project settings via toolbar:

    Wortal/Set Project Settings

How to Use

Ads

API Reference

Interstitial ads can be shown at various points in the game such as a level end, restart or a timed interval in games with longer levels.

// Player reached the next level.
Wortal.Ads.ShowInterstitial(Placement.Next, "NextLevel", PauseGame, ResumeGame);

// Player paused the game.
Wortal.Ads.ShowInterstitial(Placement.Pause, "PausedGame", PauseGame, ResumeGame);

// Player opened the IAP shop.
Wortal.Ads.ShowInterstitial(Placement.Browse, "BrowseShop", PauseGame, ResumeGame);

Rewarded ads can be shown too. These are longer, optional ads that the player can earn a reward for watching. The player must be notified of the ad and give permission to show before it can be shown.

// This example shows the game flow independent of the outcome of the ad.
// Ex: Player gets bonus coins for watching the ad, but the game continues regardless of the outcome.
Wortal.Ads.ShowRewarded("BonusCoins", PauseGame, ResumeGame, DontReward, RewardPlayer);

// This example shows the game flow depending on the outcome of the ad.
// Ex: Player dies and can revive by watching an ad, but if they skip the ad they lose the level.
Wortal.Ads.ShowRewarded("ReviveAndContinue", PauseGame, ResumeAudio, EndGame, RevivePlayerAndContinue);

NOTE: Players should only be rewarded in the AdViewed callback.

Analytics

API Reference

The Analytics API can be used to track game events that can help better understand how players are interacting with the game. This data will be available for viewing in the Wortal dashboard.

// Logs the start of the level.
Wortal.Analytics.LogLevelStart("Level 3");

// Logs the end of the level. Will track the time spent playing the level if the name matches
// the name of the last logLevelStart() call.
Wortal.Analytics.LogLevelEnd("Level 3", "100", true);

// Logs a choice the player made in the game. This can be useful for balancing the game
// and seeing what content your players interact with the most.
Wortal.Analytics.LogGameChoice("Character", "Blue");

Context

API Reference

The Context API is used to connect players and allow them to interact in the game session, share their content and send messages to each other.

// Invite a friend to play the game. Does not switch the player's current context.
Wortal.Context.Invite(payload,
    () => Debug.Log("Invite sent"),
    error => Debug.Log("Error Code: " + error.Code + "\nError: " + error.Message));

// Share your game activity with friends.
Wortal.Context.Share(payload,
    shareResult => Debug.Log("Number of shares: " + shareResult),
    error => Debug.Log("Error Code: " + error.Code + "\nError: " + error.Message));

Context Payload Templates

To make it easier to create and manage payloads for use with the Context API, you can create templates from the Wortal menu. These templates are ScriptableObjects that can be easily designed and modified in the Unity Editor without writing any code. See this discussion for more details and limitations of the templates.

In-App Purchases

API Reference

The In-App Purchases (IAP) API is used to provide an interface for in-game transactions on the platforms. This process will differ based on what platform the game is being played on, but the API remains the same.

// Get the catalog of products the player can purchase.
Wortal.IAP.GetCatalog(
    catalog => Debug.Log(catalog[0].Title),
    error => Debug.Log("Error Code: " + error.Code + "\nError: " + error.Message));

// Purchase a product.
Wortal.IAP.MakePurchase(new WortalIAP.PurchaseConfig
    {
        ProductID = "id.code.for.product",
    },
    purchase => Debug.Log(purchase.PurchaseToken), // Use this token to consume purchase
    error => Debug.Log("Error Code: " + error.Code + "\nError: " + error.Message));

Leaderboards

API Reference

The Leaderboard API gives the game access to the platform's leaderboard functionality. This is where you can track player's scores and compare them to other players.

// Get the top 10 entries on the global leaderboard.
Wortal.Leaderboard.GetEntries("global", 10,
    entries => Debug.Log("Score: " + entries[0].Score),
    error => Debug.Log("Error Code: " + error.Code + "\nError: " + error.Message));

// Add the player's score to the leaderboard.
Wortal.Leaderboard.SendEntry("global", 100,
    entry => Debug.Log("Score: " + entry.Score),
    error => Debug.Log("Error Code: " + error.Code + "\nError: " + error.Message));

Notifications

API Reference

The Notifications API is used to send notifications to the player. These can be used to notify the player of an event in the game or to remind them to come back and play.

// Schedule a notification to send to the player.
Wortal.Notifications.Schedule(payload,
    result => Debug.Log(result),
    error => Debug.Log("Error Code: " + error.Code + "\nError: " + error.Message));

// Cancel a scheduled notification.
Wortal.Notifications.Cancel("notification-id-123",
    () => Debug.Log("Notification cancelled"),
    error => Debug.Log("Error Code: " + error.Code + "\nError: " + error.Message));

Notification Payload Templates

To make it easier to create and manage payloads for use with the Notifications API, you can create templates from the Wortal menu. These templates are ScriptableObjects that can be easily designed and modified in the Unity Editor without writing any code. See this discussion for more details and limitations of the templates.

Player

API Reference

You can find details about the current player via the Player API.

// Get a list of the player's friends who have also played this game.
Wortal.Player.GetConnectedPlayers(payload,
    players => Debug.Log(players[0].GetName()),
    error => Debug.Log("Error Code: " + error.Code + "\nError: " + error.Message));

// Save the player's data to the platform
Dictionary<string, object> data = new()
{
    { "items", new Dictionary<string, int>
        {
            { "coins", 100 },
            { "boosters", 2 },
        }
    },
    { "lives", 3 },
};
Wortal.Player.SetData(data,
    () => Debug.Log("Data set"),
    error => Debug.Log("Error Code: " + error.Code + "\nError: " + error.Message));

// Get player's save data from the platform
Wortal.Player.GetData(new[] { "items", "lives" },
    data =>
    {
        // Check the return values types before casting or operating on them.
        foreach (KeyValuePair<string, object> kvp in data)
        {
            Debug.Log("Key name: " + kvp.Key);
            Debug.Log("Value type: " + kvp.Value.GetType());
        }

        // Nested objects should de-serialize as IDictionary<string, object>
        var items = (Dictionary<string, object>)data["items"];
        Debug.Log("Coins: " + items["coins"]);
    },
    error => Debug.Log("Error Code: " + error.Code + "\nError: " + error.Message));

Session

API Reference

Details about the current session can be accessed in the Session API.

// Get the entry point of where the game started from.
Wortal.Session.GetEntryPoint(
    entryPoint => Debug.Log(entryPoint),
    error => Debug.Log("Error Code: " + error.Code + "\nError: " + error.Message));

// Get the entry point data from a social invite or share.
// This is useful for tracking where players are coming from or
// providing a reward for players who were invited to play.
var entryPointData = Wortal.Session.GetEntryPointData();
foreach (KeyValuePair<string, object> kvp in data)
{
    // Do stuff with the data.
}

Tournament

API Reference

The Tournament API is used to create and manage tournaments for your game.

// Create a tournament.
Wortal.Tournament.Create(createPayload,
    tournament => Debug.Log("Tournament ID: " + tournament.ID),
    error => Debug.Log("Error Code: " + error.Code + "\nError: " + error.Message));

// Post a score to a tournament.
Wortal.Tournament.PostScore(200,
    () => Debug.Log("Score posted!"),
    error => Debug.Log("Error Code: " + error.Code + "\nError: " + error.Message));