Skip to content

2 Unicorn Battle Client Guide

Paul Gilmore edited this page Nov 14, 2017 · 20 revisions

Unicorn Battle (UB) is a straight-forward Unity game designed to showcase deep integration with PlayFab. UB is targeted towards iOS and Android devices; however, testing within the Unity editor, on web or desktop is enabled, but not all features will be available. This game was designed to be viewed in 16:9 aspect ratio, but most common ratios should display reasonably well.

Prerequisite:

Ensure that you have completed the Back-end Guide, and configured your own custom title with your own Title ID

Client Setup:

There are two ways to setup the Unicorn Battle client. You can download the Unity source code, compile it yourself, and run on the device of your choice. Or, you can download and install our pre-compiled Unicorn Battle app directly from the Google Play store for Android.

Download from Google Play:

PLEASE NOTE! This option is out-of-date. The version in the Google Store is out of date, and we've discovered a bug where titleId hot-swapping does not work as described. Please skip ahead to "Download source and compile yourself" below.

  1. Go to the Unicorn Battle App on the Google Play store, and install it on your Android phone.

  2. Run the game, but do not yet press Play.

  3. Click the Settings button in the bottom left corner.

  4. Choose "Set Title ID" and enter the custom Title ID. This will tell the game to connect to your custom back end. Accept the new title ID.

  5. Press the red "back arrow" in the bottom left corner to return to the main menu.

  6. You may now press "Play Unicorn Battle" to start your game. If you have your browser open to the Game Manager for your Unicorn Battle title, you should see your phone connect in the PlayStream debugger. That's how you know it's working!

Download source and compile yourself:

To compile yourself in Unity, you'll want to first download this entire Unicorn Battle Source Project onto your local PC.

Setting up the Unity Editor Extension

The project is already set up to use our PlayFab Editor Extension for Unity. For convenience, you can:

  1. Login to your PlayFab account in the editor extension

  2. Select the title ID you set up previously.

You can read more about the Editor Extensions on their GitHub repository page.

Configuring the Project.

Prior to running Unicorn Battle you will need to set your Title ID in GlobalStrings.cs so the app knows how to communicate with your custom back-end.

  1. Locate the GlobalStrings.cs file in the Assets/Scripts/Misc folder

  2. Locate the UB_TITLE_ID constant in the GlobalStrings.cs file, and change its value to the Title ID of the back-end you configured earlier.

Building and Testing

At this point you should be able to build and test the game locally; however, some features will need to be reconfigured to work with other titles:

  • To Use Facebook:
    • Update the FacebookSDK with your own Facebook AppID
  • To Use GooglePlay or iTunes receipt validation:
    • Update the OpenIAB plugin & Init scripts
    • Ensure your Google and Apple projects have items corresponding to CatalogItems
    • Build a signed version of this game using your own developer certificate
  • To Use Push Notifications:
    • Ensure you have followed these steps
    • Update the PlayFab Push Plugin to use your Google ProjectId
    • Build a signed version of this game using your own developer certificate

Player Account Settings

After authentication, you should see the interstitial loading screen and then the Account Settings dialog. This dialog presents several account-level options that are often configured after an initial install:

  • Set a DisplayName: This is the name that others will see via leaderboards
  • Register your account: Supplying an email address, user name and password enables the account recovery feature.
  • Link a Facebook account: Links FB credentials with the current account
  • Toggle Push Notifications: (iOS or Android only)
  • Toggle showing this dialog on subsequent logins: State saved to PlayerData and will persist across devices.

General Settings Menu

The settings button is located in the bottom left corner of UB . This button will open a contextual settings menu depending on what scene is currently loaded. The following can be accessed from this menu:

  • Account Settings
  • Redeem Coupon
  • Community Website
  • Set TitleId (to point the client to another backend during runtime)
  • Leave Battle
  • Switch Characters
  • Log out

How does the Unicorn Battle work?

UB is comprised of 5 major scenes, a few static helper classes, some reusable UI GameObjects and a simple message system for keeping everything in sync.

###Scenes

  • Authenticate - Allows for Device Id or Facebook authentication and loads Character Select upon successful login.
  • Character Select - Players can create & select characters to play, as well as view the three character class types. Players are granted 2 Character Slots by default but they may purchase more in exchange for Gems. Loads Profile after a character has been selected.
  • Profile - The main "hub" of the game, visit stores, view friends and leaderboards, and start quests via the Gameplay scene.
  • Gameplay - Plays quests (a series of encounters that the player must win) and displays the results. Saves results and returns to the Profile scene after a successful questing.
  • Splash - Animated PlayFab splash screen, loads the Authenticate scene when complete.

###PlayFab Static Helper Classes

These files contain the data models and corresponding PlayFab interactions. They are grouped by subject and appropriately named.

Unicorn Battle performs player data and game state refreshes when loading many scenes. These calls usually use static methods to refresh the data models shared across scenes.

###Reusable UI The majority of UI panels and dialogs are initially loaded in the Authenticate scene and reused throughout the game session.

###Messaging System Simple but effective messages keep subscribers in-sync with the various component updates. This enables uniform handling of logging and error messages.

Tips for working with PlayFab API calls:

  • Most PlayFab API calls will return the data that was changed. This "delta" can be used to update the client locally without having to perform a full Inventory or Data refresh.
  • Never trust the client when it comes to security. Always validate the data values submitted by clients.
  • Cloud Script batchs and validates client activity. Cloud Script can take arbitrary parameters and return custom object structures.
  • "Bridge" and helper classes optimize local data usage across game systems
  • Build custom systems around our data models to enhance functionality. The Unicorn Battle Inventory system automatically stacks and cross-references the CatalogItems with the ItemInstances. This can be quite handy when working with the CustomData property on virtual items.
  • Use a loading prompt when calls will take longer than a moment, or a success is required before continuing.
  • Callbacks and closures can help preserve scope and enforce order needed to properly process API responses

Next Steps