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:
using TriumphSDK;
public class MainMenuUIManager : MonoBehaviour
{
[SerializeField] Button startGameButton;
void Start()
{
// instead of starting the game, the button will now launch the Triumph SDK
startGameButton.onClick.AddListener(() => /* StartGame() */ Triumph.PresentTriumphViewController());
}
// to run the integration, the logic for this method should be moved to TriumphUnityNativeMethods.TriumphGameDidStart()
private void StartGame()
{
SceneManager.LoadScene("Game");
}
}
using TriumphSDK;
public class GameUIManager : MonoBehaviour
{
[SerializeField] TMP_Text scoreText;
[SerializeField] TMP_Text secondaryText;
[SerializeField] Button updateScoreButton;
[SerializeField] Button reportScoreButton;
void Start()
{
PlayerPrefs.SetFloat("Score", 0f);
updateScoreButton.onClick.AddListener(() => UpdateScore());
reportScoreButton.onClick.AddListener(() => ReportRandomScore());
}
private void Update()
{
// the two labels should be updated using the strings provided by Triumph
scoreText.text = /* PlayerPrefs.GetFloat("Score") */ Triumph.GetTriumphPrimaryLabel();
secondaryText.text = /* "I am the smaller text" */ Triumph.GetTriumphSecondaryLabel();
}
private void UpdateScore()
{
// 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 change
Triumph.UpdateScore(PlayerPrefs.GetFloat("Score"));
}
private void ReportRandomScore()
{
SceneManager.LoadScene("GameOver");
// show the Triumph SDK when the game ends
Triumph.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.