public static Leaderboard GetLeaderboardFromFile(string fileName) { // Path.Combine combines strings into a file path // Application.StreamingAssets points to Assets/StreamingAssets in the Editor, and the StreamingAssets folder in a build string filePath = Path.Combine(Application.streamingAssetsPath, fileName); Leaderboard leaderboard = new Leaderboard(); if (File.Exists(filePath)) { // Read the json from the file into a string string dataAsJson = File.ReadAllText(filePath); // Pass the json to JsonUtility, and tell it to create a Leaderboard object from it var entries = JsonHelper.FromJson <LeaderboardEntry>(dataAsJson); if (entries.Length > 0) { for (int i = 0; i < entries.Length; i++) { leaderboard.AddNewEntry(entries[i]); } } } else { Debug.Log("Cannot load leaderboard! File is non-existent!"); } return(leaderboard); }
public void On(OnResolutionScreen message) { /// Do here all sorts of leaderboard stuff before updating /// the LeaderboardView Leaderboard leaderboard = GetLeaderboardForCurrentMode(); currentPlayerPlace = leaderboard.GetPlaceOnLeaderboardForPlayer(message.score); bool isOnLeaderboard = currentPlayerPlace <= maxPlayersOnLeaderboard; string sceneName = GlobalState.instance.playerDeathSceneName; int playerScore = GlobalState.instance.playerScore; Vector3 playerDeathPosition = GlobalState.instance.playerDeathPosition; leaderboard.AddNewEntry(new LeaderboardEntry("You", playerScore, playerDeathPosition, sceneName, true)); new OnLeaderboardDisplay(leaderboard, new LeaderboardViewInfo(isOnLeaderboard, currentPlayerPlace, playerScore)) .SetDeliveryType(MessageDeliveryType.Immediate) .PostEvent(); }