Implement the Skillz Delegate
Overview
Control of your application is given to Skillz when you launch the Skillz UI. Because of this, you'll need to implement the Skillz Delegate interface, which contains callbacks that will be invoked for key events. There are two events that are essential for interacting with Skillz:
- When a match is starting.
- When the user is exiting the Skillz UI (via the sidebar menu).
The following sections describe how to implement these two methods of the Skillz Delegate for each platform.
For iOS, the Skillz Delegate is available as a protocol named SkillzDelegate
. It is common to conform to this protocol in the interface that conforms to UIApplicationDelegate
.
#import <UIKit/UIKit.h>
#import <Skillz/Skillz.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate, SkillzDelegate>
@end
@implementation AppDelegate
- (void)tournamentWillBegin:(NSDictionary * _Nonnull)gameParameters
withMatchInfo:(SKZMatchInfo * _Nonnull)matchInfo {
}
- (void)skillzWillExit {
}
@end
Don't worry about implementing these methods for now. We'll discuss how later.
For iOS, the Skillz Delegate is available as an interface named SkillzDelegate
. It is common to adhere to this in the class that adheres to UIApplicationDelegate
.
import UIKit
import Skillz
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, SkillzDelegate {
func tournamentWillBegin(_ gameParameters: [AnyHashable : Any]!, with matchInfo: SKZMatchInfo!) {
}
func skillzWillExit() {
}
}
Don't worry about implementing these methods for now. We'll discuss how later.
For Android, the Skillz Delegate takes the form of special <meta-data>
tags that are added inside the <application>
element of your app's AndroidManifest.xml
.
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="<your_package_name>" xmlns:tools="http://schemas.android.com/tools">
<application>
<meta-data android:name="skillz_game_activity" android:value="<your_game_activity>" />
<meta-data android:name="skillz_exit_activity" android:value="<your_activity_on_skillz_exit>" />
</application>
</manifest>
The skillz_game_activity
tag tells the Skillz SDK which activity to launch when a match starts. skillz_exit_activity
tells the Skillz SDK which activity to launch if the user exits the Skillz UI.
For Unity, you need to implement the SkillzMatchDelegate
interface as a regular C# class. This will be instantiated when launching Skillz later.
using SkillzSDK;
using UnityEngine;
public sealed class GameController : SkillzMatchDelegate
{
private const string GameSceneName = "Level1";
private const string StartMenuSceneName = "StartMenu";
public void OnMatchWillBegin(Match matchInfo)
{
}
public void OnSkillzWillExit()
{
}
}
Implementation of these methods will be covered later.
The Skillz Delegate is available as a Javascript class. It is located in the path relative to your Cordova game's location: plugins/skillz-crossplatform-cordova/www/SkillzDelegateCordova.js
. This assumes you have the Skillz Cordova SDK installed. The class looks like:
class SkillzDelegateCordova {
constructor() {
this.matchInfo = null;
}
// void
static OnMatchWillBegin(matchInfoString) {
// This block of code will be called when the user is about to begin a match.
// You can use this match object to instantiate variables in your game.
const matchInfoObject = JSON.parse(matchInfoString);
console.log(
'SkillzDelegateCordova: OnMatchWillBegin was called. Here is the match information: %s',
JSON.stringify(matchInfoObject)
);
this.matchInfo = matchInfoObject;
}
// void
static onSkillzWillExit() {
}
static getMatchInfo() {
return this.matchInfo;
}
}
new SkillzDelegateCordova();
Warning
Changes to this file can be lost easily by removing and re-adding the Skillz Cordova SDK. To mitigate this issue, it is recommended that you keep a copy of this file with your changes in a safe location in your project.
We'll cover implementation of these methods later.