We have created a public repository that contains a demo integration of the Triumph SDK in a template game.
If you wish to run this demo, be sure to include the following scenes in your build:
The Triumph methods are called in MainMenuUIManager and GameUIManager, with the code that would go in their place contained in a block comment to their left:
usingTriumphSDK;publicclassMainMenuUIManager:MonoBehaviour{ [SerializeField] Button startGameButton;voidStart() { // instead of starting the game, the button will now launch the Triumph SDKstartGameButton.onClick.AddListener(() =>/* StartGame() */Triumph.PresentTriumphViewController()); } // to run the integration, the logic for this method should be moved to TriumphUnityNativeMethods.TriumphGameDidStart()privatevoidStartGame() {SceneManager.LoadScene("Game"); }}
usingTriumphSDK;publicclassGameUIManager:MonoBehaviour{ [SerializeField] TMP_Text scoreText; [SerializeField] TMP_Text secondaryText; [SerializeField] Button updateScoreButton; [SerializeField] Button reportScoreButton;voidStart() {PlayerPrefs.SetFloat("Score",0f);updateScoreButton.onClick.AddListener(() =>UpdateScore());reportScoreButton.onClick.AddListener(() =>ReportRandomScore()); }privatevoidUpdate() { // the two labels should be updated using the strings provided by TriumphscoreText.text=/* PlayerPrefs.GetFloat("Score") */Triumph.GetTriumphPrimaryLabel();secondaryText.text=/* "I am the smaller text" */Triumph.GetTriumphSecondaryLabel(); }privatevoidUpdateScore() { // all instances of randomness (i.e. Random.Range()) should be replaced with TriumphSDK.GetRandom()PlayerPrefs.SetFloat("Score",PlayerPrefs.GetFloat("Score",0f) +/* Random.Range(0f, 10f) */Triumph.GetRandom(0f,10f)); // whenever the score is updated, be sure to notify the Triumph SDK of the changeTriumph.UpdateScore(PlayerPrefs.GetFloat("Score")); }privatevoidReportRandomScore() {SceneManager.LoadScene("GameOver"); // show the Triumph SDK when the game endsTriumph.PresentTriumphGameOver(PlayerPrefs.GetFloat("Score")); }}
Note that when playing the game, you are presented with two buttons, one labeled "Update Score" and one labeled "Report Score". The former increases the score by a random amount, and the latter completes the current game and reports the final score to the Triumph SDK, which will open the Triumph window.