// Notes about posting a score: // // If the user is not logged in, the score will not be submitted successfully. // // When submitting a score natively, if the score submission fails, the score is cached locally on the device and resubmitted // when the user logs in or next time the app loads, whichever comes first. // // Metadata (optional) is stored and retrieved with each score. It can be used // to save additional state information with each score. // // The display string can be used to append units or create a custom format // for your score to be displayed. The score value, passed in constructor, // is only used for sorting scores on the backend (to determine which is best), // the display string is used for displaying scores in the UI. void SubmitSampleScore() { int lapTime = 5400; // value in hundredths int total_sec = lapTime / 100; int total_min = total_sec / 60; int hour = total_min / 60; int min = total_min % 60; int sec = total_sec % 60; int hun = lapTime % 100; string scoreString = "" + hour.ToString("00") + ":" + min.ToString("00") + ":" + sec.ToString("00") + "." + hun.ToString("00"); OKScore score = new OKScore(lapTime, SampleLeaderboardID); score.gameCenterLeaderboardCategory = "openkitlevel3"; score.displayString = scoreString + " seconds"; Action<bool, string> nativeHandle = (success, errorMessage) => { if (success) { Debug.Log("Score submitted successfully!"); } else { Debug.Log("Score did not submit. Error: " + errorMessage); } }; Action<OKScore, OKException> defaultHandle = (retScore, err) => { if (err == null) { Debug.Log("Score submitted successfully: " + retScore.ToString()); } else { Debug.Log("Score post failed: " + err.Message); } }; bool dropToNative = true; if (dropToNative) { score.SubmitScoreNatively(nativeHandle); } else { score.MetadataBuffer = new byte[] { 0x20, 0x20, 0x20, 0x20, 0x80 }; score.SubmitScore(defaultHandle); } }
// Notes about posting a score: // // If the user is not logged in, the score will not be submitted successfully. // // When submitting a score natively, if the score submission fails, the score is cached locally on the device and resubmitted // when the user logs in or next time the app loads, whichever comes first. // // Metadata (optional) is stored and retrieved with each score. It can be used // to save additional state information with each score. // // The display string can be used to append units or create a custom format // for your score to be displayed. The score value, passed in constructor, // is only used for sorting scores on the backend (to determine which is best), // the display string is used for displaying scores in the UI. void SubmitSampleScore() { int lapTime = 5400; // value in hundredths int total_sec = lapTime / 100; int total_min = total_sec / 60; int hour = total_min / 60; int min = total_min % 60; int sec = total_sec % 60; int hun = lapTime % 100; string scoreString = "" + hour.ToString("00") + ":" + min.ToString("00") + ":" + sec.ToString("00") + "." + hun.ToString("00"); OKScore score = new OKScore(lapTime, SampleLeaderboardID); score.displayString = scoreString; score.gameCenterLeaderboardCategory = SampleLeaderboardGameCenterCategory; // OKScore can be submitted to OpenKit in C# native unity, or platform native code (e.g. iOS and Android native cdoe). // When possible you should use the platform native versions of OKScore.SubmitScore because both iOS and Android SDKs // have local caching built in, as well as features like submit to GameCenter (iOS). Action<bool, string> nativeHandle = (success, errorMessage) => { if (success) { Debug.Log("Score submitted successfully!"); } else { Debug.Log("Score did not submit. Error: " + errorMessage); } }; Action<OKScore, OKException> defaultHandle = (retScore, err) => { if (err == null) { Debug.Log("Score submitted successfully: " + retScore.ToString()); } else { Debug.Log("Score post failed: " + err.Message); } }; if(submitScoreNatively) { score.SubmitScoreNatively(nativeHandle); } else { score.MetadataBuffer = new byte[] { 0x20, 0x20, 0x20, 0x20, 0x80 }; score.SubmitScore(defaultHandle); } }