Integrate Triumph scoring in your game. Estimated Time: 10 minutes.
Start Game
Triumph needs to start an instance of your game when a match is initiated. We will call a function TriumphGameDidStart when we would like a game to start. You will implement this function with logic to start an instance of your game.
Implement the TriumphUnityNativeMethods component of the TriumphAPI prefab.
usingUnityEngine;usingTriumphSDK;publicclassTriumphUnityNativeMethods:MonoBehaviour,ITriumphUnityNativeMethods {/* * TODO: implement this method, which we will call when. * a user has initiated a tournament. */publicvoidTriumphStartedGame() {StartYourGame(); } // MARK: -- Optional /* * If you provided `hasTutorial` flag within configuration options, * this method will be called when Triumph wants to show the tutorial. * You can start a fullscreen video with your gameplay mechanics * or launch a playable game with hints to onboard new players. */publicvoidTriumphRequestsTutorial() {StartYourTutorial(); }/* * The below methods can be used for logging purposes, * left blank, or whatever you'd like. * Please leave them in the code (even if blank). */ // We call this when the triumph SDK is dismissed.publicvoidTriumphDidDismiss() { } // Called when the SDK presentspublicvoidTriumphDidPresent() { } // Called right before the SDK dismissespublicvoidTriumphWillDismiss() { } // Called right before the SDK presentspublicvoidTriumphWillPresent() { }}
When you finished presenting tutorial to a new player, do not forget to present Triumph again:
usingTriumphSDK;publicclassTutorialScene:MonoBehaviour { // Called when your tutorial has finished playingpublicvoidTutorialFinished() {Triumph.present() }}
Navigate to the file where your gameplay lifecycle is managed, i.e. where you have the ability to start and end games.
Set Triumph.delegate = self in the viewDidLoad function of this class, and conform to TriumphDelegate. This allows us to pass data between your game and Triumph.
importTriumphSDKclassYourGameViewController:TriumphDelegate {// Allows Triumph to communicate with your game funcviewDidLoad() { Triumph.delegate = self }// Required: reset and start your game here. functriumphStartedGame() {startYourGame() }// MARK: -- Optional /* * If you provided `hasTutorial` flag within configuration options, * this method will be called when Triumph wants to show the tutorial. * You can start a fullscreen video with your gameplay mechanics * or launch a playable game with hints to onboard new players. */functriumphRequestsTutorial() {startYourTutorial() }/* * The below methods can be used for logging purposes, * left blank, or whatever you'd like. * Please leave them in the code (even if blank). */// Tells you that Triumph will presentfunctriumphWillPresent() {}// Tells you that Triumph did presentfunctriumphDidPresent() {}// Tells you that Triumph will dismissfunctriumphWillDismiss() {}// Tells you that Triumph was dismissfunctriumphDidDismiss() {}}
When you finished presenting tutorial to a new player, do not forget to present Triumph again:
classYourTutorialViewController {// Called when your tutorial has finished playingfunctutorialFinished() { Triumph.present() }}
These method implementations will be called on our end when appropriate. Do not call these methods anywhere yourself.
Game pause/resume
(Optional) If you have pausing functionality in your game, please add the following Triumph functions. This allows us to optimize replay recordings of your game.
usingTriumphSDK;publicclassGameScene:MonoBehaviour { // Your pause game business logicvoidPause() { // Add this Triumph functionTriumph.GamePaused(); } // Your resume game business logicvoidResume() { // Add this Triumph functionTriumph.GameResumed(); }}
importTriumphSDKclassYourGameViewController {// Your pause game business logicfuncpause() {// Add this Triumph function Triumph.gamePaused() }// Your resume game business logicfuncresume() {// Add this Triumph function Triumph.gameResume() }}
Report Score
Triumph needs to record scores from your game. There are two functions that you will call:
updateScore should be called whenever the score of your game changes, passing the current score as a parameter. This allows us to keep intermediate scores stored in the state of our SDK, so if a game crashes before completion, we have something for the user's score rather than simply reporting 0.
gameOver should be called when a game ends, passing the final score of the game as a parameter. This will submit the final score and resummon Triumph's UI.
usingTriumphSDK;publicclassGameScene:MonoBehaviour {publicint score =0; // Whenever a score changes, call updateScore with the current score. // @Params: score: doublepublicvoidIncreaseScore(int increment) { score += increment;Triumph.UpdateScore(score: score); } // Your game logic when the user loses and the game ends // @Params: score: doublepublicvoidEndGame(int finalScore) {Triumph.GameOver(score: finalScore); }}
importTriumphSDKclassYourGameViewController {// Whenever a score changes, call updateScore with the current score.// Doing this on a didSet ensures we call this on every score update, // although your implementation may differ// @Params: score: Doublevar gameScore: Double? {didSet { Triumph.updateScore(score: gameScore) } }// User got a headshot! (or whatever your game logic is)funcheadShot() {let HEADSHOT_SCORE_VALUE =10.0// Changing the score will trigger the didSet// that updates the labels and calls the updateScore // function gameScore = gameScore + HEADSHOT_SCORE_VALUE }// Your game logic when a game endsfunconGameOver() {// When the game ends, call this function with the user's final// score to resummon Triumph. // @Params: score: Double Triumph.gameOver(score: gameScore) }}
Score Labels
Triumph requires your to have two in-game score labels: a large, primary label, and a small, secondary label. These labels will display different things based on the game mode the user is playing.
For example, in a 1v1 tournament, the primary label will display the user's score, and the secondary label will display the user's tournament name. In a blitz tournament, the primary label will display the user's winnings in dollars, and the secondary label will display the user's score.
We will give you two methods that you use to get the string values for the primary and secondary label. Every time the score of your game changes, you should also update these labels.
importTriumphSDKclassYourGameViewController {let largeLabel: UILabel =UILabel()let smalLabel: UILabel =UILabel()var gameScore: Double? {didSet {// Whenever a score changes, we call updateScore with the new total score.// Doing this on a didSet ensures we call this on every score update, // although your implementation may differ// @Params: score: Double Triumph.updateScore(gameScore)// Now that Triumph has an updated score for your game, we get the // primary and secondary labels to display largeLabel.text= Triumph.primaryLabel smallLabel.text= Triumph.secondaryLabel } }// User got a headshot! funcheadShot() {let HEADSHOT_SCORE_VALUE =10.0// Changing the score will trigger the didSet// that updates the labels and calls the updateScore // function gameScore = gameScore + HEADSHOT_SCORE_VALUE }// Your game logic when the user loses and the game endsfunconGameOver() {// When the game ends, call this function with the user's final// score to resummon Triumph. // @Params: with: Double Triumph.gameOver(with: gameScore) }}