void ShowLoginUI() { OKLog.Info("Showing login UI"); OKManager.ShowLoginToOpenKitWithDismissCallback(() => { OKLog.Info("Finished showing OpenKit login window, in the callback"); }); }
void GetScoresWithMetadata() { var leaderboard = new OKLeaderboard(SampleLeaderboardID); var request = new GhostScoresRequest(leaderboard); request.Get(response => { switch (response.Status) { case OKIOStatus.Cancelled: OKLog.Info("Cancelled the ghost scores request."); break; case OKIOStatus.FailedWithError: OKLog.Info("Ghost scores request failed with error: " + response.Err.Message); break; case OKIOStatus.Succeeded: OKLog.Info("Ghost ghost scores!"); WriteMetadata(response.scores); break; } }); // Cancel the request anytime with: // request.Cancel(); // new System.Threading.Timer(CancelGhostRequest, request, 150, -1); }
void OnGUI() { #if !UNITY_EDITOR GUI.matrix = GetScaleMatrix(); #endif Rect area = (IsPortraitOrientation() ? new Rect(0, 0, 320, 480) : new Rect(0, 0, 480, 320)); GUILayout.BeginArea(area); GUILayoutOption h = GUILayout.Height(35); GUILayout.Label("OpenKit Demo Scene"); if (GUILayout.Button("Show Leaderboards & Achievements", h)) { ShowLeaderboards(); } if (GUILayout.Button("Show Single Leaderboard", h)) { // Instead of showing a list of leaderboards, show a single specified leaderboard ID OKManager.ShowLeaderboard(SampleLeaderboardID);; } if (GUILayout.Button("Show Login UI", h)) { ShowLoginUI(); } if (GUILayout.Button("Submit Score to Level 1 Leaderboard", h)) { SubmitSampleScore(); } if (GUILayout.Button("Unlock Achievement", h)) { UnlockSampleAchievement(); } if (GUILayout.Button("Logout from OpenKit", h)) { OKManager.LogoutCurrentUserFromOpenKit(); OKLog.Info("logout of OpenKit"); } if (GUILayout.Button("Get Leaderboards in C#", h)) { GetLeaderboards(); } if (GUILayout.Button("Get social scores", h)) { GetSocialScores(); } if (GUILayout.Button("Get my best score (in C#)", h)) { GetMyBestScore(); } GUILayout.EndArea(); }
// 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) { OKLog.Info("Score submitted successfully!"); } else { OKLog.Info("Score did not submit. Error: " + errorMessage); } }; Action <OKScore, OKException> defaultHandle = (retScore, err) => { if (err == null) { OKLog.Info("Score submitted successfully: " + retScore.ToString()); } else { OKLog.Info("Score post failed: " + err.Message); } }; if (submitScoreNatively) { score.SubmitScoreNatively(nativeHandle); } else { score.MetadataBuffer = new byte[] { 0x20, 0x20, 0x20, 0x20, 0x80 }; score.SubmitScore(defaultHandle); } }
void GetSocialScores() { OKLeaderboard leaderboard = new OKLeaderboard(SampleLeaderboardID); OKLog.Info("Getting scores for leaderboard ID: " + leaderboard.LeaderboardID + " named: " + leaderboard.Name); leaderboard.GetFacebookFriendsScores((List <OKScore> scores, OKException exception2) => { if (exception2 == null) { OKLog.Info("Got facebook friends scores scores in the callback"); } else { OKLog.Info("Error getting facebook friends scores: " + exception2); } }); }
void UnlockSampleGamecenterAchievementOnly() { OKAchievementScore score = new OKAchievementScore(); score.GameCenterAchievementIdentifier = "achievement2"; score.GameCenterAchievementPercentComplete = 100f; score.submitAchievementScore((success, errorMessage) => { if (success) { OKLog.Info("GC achievement score/progress submitted successfully!"); } else { OKLog.Info("GC achievement score/progress did not submit. Error: " + errorMessage); } }); }
private void WriteMetadata(List <OKScore> scores) { foreach (OKScore score in scores) { if (score.MetadataBuffer == null) { OKLog.Info("Score does not have a metadata buffer: " + score.ScoreID); continue; } OKLog.Info("Writing first five bytes of metadataBuffer for score: " + score.ScoreID); String s; for (int i = 0; i < 5; i++) { s = String.Format("Byte {0} - Hex: {1:X}", i, score.MetadataBuffer[i]); OKLog.Info("Got back: " + s); } } }
public OKUser GetCurrentUser() { int okID = OKAndroidPlugin.CallStatic <int>("getCurrentUserOKID"); OKLog.Info("Current openkit user id: " + okID); if (okID == 0) { return(null); } else { OKUser user = new OKUser(); user.OKUserID = okID; user.UserNick = OKAndroidPlugin.CallStatic <string>("getCurrentUserNick"); user.FBUserID = OKAndroidPlugin.CallStatic <string>("getCurrentUserFBID"); OKLog.Info("Current user: " + user); return(user); } }
public OKUser getCurrentUser() { int okID = OKBridgeGetCurrentUserOKID(); OKLog.Info("!!!!!! Got user ID" + okID); if (okID == 0) { return(null); } else { OKUser user = new OKUser(); user.OKUserID = okID; user.userNick = OKBridgeGetCurrentUserNick(); user.FBUserID = OKBridgeGetCurrentUserFBID(); user.twitterUserID = OKBridgeGetCurrentUserTwitterID(); return(user); } }
void Setup() { // Authenticate the local player with GameCenter (iOS only). OKManager.authenticateGameCenterLocalPlayer(); // Listen for native openkit view events. OKManager.ViewWillAppear += ViewWillAppear; OKManager.ViewDidAppear += ViewDidAppear; OKManager.ViewWillDisappear += ViewWillDisappear; OKManager.ViewDidDisappear += ViewDidDisappear; if (OKManager.IsCurrentUserAuthenticated()) { OKLog.Info("Found OpenKit user"); } else { ShowLoginUI(); OKLog.Info("Did not find OpenKit user"); } }
public OKUser GetCurrentUser() { int okID = OKBridgeGetCurrentUserOKID(); OKLog.Info("Current openkit user id: " + okID); if (okID == 0) { return(null); } else { OKUser user = new OKUser(); user.OKUserID = okID; user.UserNick = OKBridgeGetCurrentUserNick(); user.FBUserID = OKBridgeGetCurrentUserFBID(); OKLog.Info("Current user: " + user); return(user); } }
void RetrieveSampleDictionary() { OKCloud.Get("keyDict", (object obj, OKCloudException err) => { OKLog.Info("In get dictionary handler! Obj is of class: " + obj.GetType().Name); Dictionary <string, object> dict = (Dictionary <string, object>)obj; if (err == null) { OKLog.Info("Object for property1:\nclass: " + dict["prop1"].GetType().Name + "\nvalue: " + dict["prop1"]); OKLog.Info("Object for property2:\nclass: " + dict["prop2"].GetType().Name + "\nvalue: " + dict["prop2"]); OKLog.Info("Object for property3:\nclass: " + dict["prop3"].GetType().Name); ArrayList arr = (ArrayList)dict["prop3"]; OKLog.Info("Elements of array:"); OKLog.Info("Element 0, class: " + arr[0].GetType().Name + " value: " + arr[0]); OKLog.Info("Element 1, class: " + arr[1].GetType().Name + " value: " + arr[1]); } else { OKLog.Info("Error fetching dictionary: " + err); } }); }
void UnlockSampleAchievement() { int SampleAchievementID = 189; int SampleAchievementProgress = 10; string SampleAchievementGamecenterID = "achievement2"; OKAchievementScore achievementScore = new OKAchievementScore(SampleAchievementProgress, SampleAchievementID); // On iOS, we can also support GameCenter achievements with this simple wrapper achievementScore.GameCenterAchievementIdentifier = SampleAchievementGamecenterID; achievementScore.GameCenterAchievementPercentComplete = 100.0f; achievementScore.submitAchievementScore((success, errorMessage) => { if (success) { OKLog.Info("Achievement score/progress submitted successfully!"); } else { OKLog.Info("Achievement score/progress did not submit. Error: " + errorMessage); } }); }
// Get the list of leaderboards in C# (native unity) void GetLeaderboards() { OKLeaderboard.GetLeaderboards((List <OKLeaderboard> leaderboards, OKException exception) => { if (leaderboards != null) { OKLog.Info("Received " + leaderboards.Count + " leaderboards "); OKLeaderboard leaderboard = (OKLeaderboard)leaderboards[0]; OKLog.Info("Getting scores for leaderboard ID: " + leaderboard.LeaderboardID + " named: " + leaderboard.Name); leaderboard.GetGlobalScores(1, (List <OKScore> scores, OKException exception2) => { if (exception2 == null) { OKLog.Info("Got global scores in the callback"); } }); } else { OKLog.Info("Error getting leaderboards"); } }); }
void GetMyBestScore() { OKLeaderboard leaderboard = new OKLeaderboard(); leaderboard.LeaderboardID = SampleLeaderboardID; leaderboard.GetUsersTopScore((score, err) => { if (err == null) { if (score == null) { OKLog.Info("User does not have a score for this leaderboard."); } else { OKLog.Info("Got user's best score: " + score); } } else { OKLog.Info("Error getting best score: " + err.Message); } }); }
void StoreSampleDictionary() { Dictionary <string, object> x = new Dictionary <string, object>(); x.Add("prop1", "Foo!"); x.Add("prop2", 99); ArrayList arr = new ArrayList(); arr.Add("Hello"); arr.Add(-99); x.Add("prop3", arr); OKCloud.Set(x, "keyDict", (OKCloudException err) => { if (err == null) { OKLog.Info("Stored Dictionary!"); } else { OKLog.Info("Error storing dictionary: " + err); } }); }
void OnGUI() { ///Scale the button sizes for retina displays float screenScale = (float)(Screen.width / 480.0); Matrix4x4 scaledMatrix = Matrix4x4.Scale(new Vector3(screenScale, screenScale, screenScale)); GUI.matrix = scaledMatrix; if (GUI.Button(new Rect(30, 10, 400, 100), "Show Leaderboards & Achievements")) { // Show leaderboards. // If the user is not logged into OpenKit, the login UI // will be shown ontop of the leaderboards OKManager.ShowLeaderboards(); } if (GUI.Button(new Rect(30, 120, 400, 100), "Show Login UI")) { // Show the OpenKit Login UI OKManager.ShowLoginToOpenKit(); } if (GUI.Button(new Rect(30, 230, 400, 100), "Submit Score to Level 3 Leaderboard")) { #if !UNITY_EDITOR // Submit a score to a leaderboard, with a value of 2134 to leaderboard ID 4 // If the user is not logged in, the score will not be submitted successfully string scoreString = "" + DateTime.Now.Month; scoreString += DateTime.Now.Day; scoreString += DateTime.Now.Hour; scoreString += DateTime.Now.Minute; long scoreValue = long.Parse(scoreString); OKScore score = new OKScore(scoreValue, 4); // Set the displayString to include the units of the score score.displayString = score.scoreValue + " points"; // Store some metadata in the score-- this is not used by OpenKit but is stored and returned with each score score.metadata = 1; score.submitScore(scoreSubmitHandler); #endif } if (GUI.Button(new Rect(30, 340, 400, 100), "Unlock Achievement")) { //Unlock achievement by setting its progress for the current user // to 5. The achievement ID is pulled from the OpenKit dashboard, // and we know that the target goal of the achievement is also 5 which is set in the dashboard, // so this unlocks the achievement OKAchievementScore achievementScore = new OKAchievementScore(5, 3); achievementScore.submitAchievementScore(achievementScoreSubmitHandler); } if (GUI.Button(new Rect(30, 450, 400, 100), "Store dictionary")) { //Store a dictionary ArrayList y = new ArrayList(); y.Add("First element."); y.Add("Second!"); Dictionary <string, object> x = new Dictionary <string, object>(); x.Add("prop1", "YEAAAAAAH BUDDY."); x.Add("prop2", 99); x.Add("prop3", y); // Cloud store. OKCloud.Set(x, "aKey", delegate(object obj, OKCloudException err) { if (err == null) { OKLog.Info("Stored object of type: " + obj.GetType().Name); } else { OKLog.Info("Error during store: " + err); } }); } if (GUI.Button(new Rect(30, 560, 400, 100), "Retrieve dictionary")) { //Retrieve the dictionary OKCloud.Get("aKey", delegate(JSONObject obj, OKCloudException err) { if (err == null) { OKLog.Info("Retrieved object of type: " + obj.GetType().Name); OKLog.Info("Obj: " + obj); OKLog.Info("Can I get an element of an Array? " + obj.GetField("prop3")[1]); } else { OKLog.Info("Error during store: " + err); } }); } }
void OnGUI() { #if !UNITY_EDITOR GUI.matrix = GetScaleMatrix(); #endif Rect area = (IsPortraitOrientation() ? new Rect(0, 0, 320, 480) : new Rect(0, 0, 480, 320)); GUILayout.BeginArea(area); GUILayoutOption h = GUILayout.Height(35); GUILayout.Label("Testing OpenKit..."); if (GUILayout.Button("Show Leaderboards & Achievements", h)) { ShowLeaderboards(); } if (GUILayout.Button("Show Leaderboards Landscape Only (iOS)", h)) { // For Android, to show Leaderboards landscape only you simply need to modify the AndroidManifest.xml file OKManager.ShowLeaderboardsLandscapeOnly(); } if (GUILayout.Button("Show Login UI", h)) { ShowLoginUI(); } if (GUILayout.Button("Submit Score to Level 2 Leaderboard", h)) { SubmitSampleScore(); } if (GUILayout.Button("Unlock Achievement", h)) { UnlockSampleAchievement(); } if (GUILayout.Button("Store dictionary", h)) { StoreSampleDictionary(); } if (GUILayout.Button("Retrieve Dictionary", h)) { RetrieveSampleDictionary(); } if (GUILayout.Button("Logout from OpenKit", h)) { OKManager.LogoutCurrentUserFromOpenKit(); OKLog.Info("logout of OpenKit"); } if (GUILayout.Button("Get Leaderboards", h)) { OKLeaderboard.GetLeaderboards((List <OKLeaderboard> leaderboards, OKException exception) => { if (leaderboards != null) { Debug.Log("Received " + leaderboards.Count + " leaderboards "); OKLeaderboard leaderboard = (OKLeaderboard)leaderboards[0]; Debug.Log("Getting scores for leaderboard ID: " + leaderboard.LeaderboardID + " named: " + leaderboard.Name); leaderboard.GetGlobalScores(1, (List <OKScore> scores, OKException exception2) => { if (exception2 == null) { Debug.Log("Got global scores in the callback"); } }); } else { Debug.Log("Error getting leaderboards"); } }); } if (GUILayout.Button("Get social scores Friends", h)) { GetSocialScores(); } if (GUILayout.Button("Get my best score!", h)) { GetMyBestScore(); } GUILayout.EndArea(); }
public bool IsCurrentUserAuthenticated() { OKLog.Error("Can't check for OKUser in unity, must use iOS or Android"); return(false); }
void OnGUI() { #if !UNITY_EDITOR GUI.matrix = GetScaleMatrix(); #endif Rect area = (IsPortraitOrientation() ? new Rect(0, 0, 320, 480) : new Rect(0, 0, 480, 320)); GUILayout.BeginArea(area); GUILayoutOption h = GUILayout.Height(35); GUILayout.Label("OpenKit Demo Scene"); if (GUILayout.Button("Show Leaderboards", h)) { ShowLeaderboards(); } if (GUILayout.Button("Show Achievements", h)) { ShowAchievements(); } if (GUILayout.Button("Show Single Leaderboard", h)) { // Instead of showing a list of leaderboards, show a single specified leaderboard ID OKManager.ShowLeaderboard(SampleLeaderboardID);; } if (GUILayout.Button("Show Leaderboards & Achievements", h)) { OKManager.ShowLeaderboardsAndAchivements(); } if (GUILayout.Button("Show Login UI", h)) { ShowLoginUI(); } if (GUILayout.Button("Submit Score to Level 1 Leaderboard", h)) { SubmitSampleScore(); } if (GUILayout.Button("Unlock Achievement", h)) { UnlockSampleAchievement(); } if (GUILayout.Button("Logout from OpenKit", h)) { OKManager.LogoutCurrentUserFromOpenKit(); OKLog.Info("logout of OpenKit"); } if (GUILayout.Button("Get Leaderboards and global scores in C#", h)) { GetLeaderboards(); } if (GUILayout.Button("Get my best score (in C#)", h)) { GetMyBestScore(); } if (GUILayout.Button("Get friends scores in C#", h)) { GetSocialScores(); } /* * if(GUILayout.Button("FB SDK Test",h)) { * * if(FB.IsLoggedIn) { * GetFBInfo(); * return; * } * * FB.Init(() => { * OKLog.Info("FB Init called"); * * if(FB.IsLoggedIn) { * OKLog.Info("logged into FB in Unity"); * GetFBInfo(); * } else { * OKLog.Info("not logged into FB unity"); * FB.Login("email",(FBResult result) => { * OKLog.Info("Result of calling fb login: "******"Get scores with metadata", h)) { GetScoresWithMetadata(); } GUILayout.EndArea(); }
static void ViewDidDisappear(object sender, EventArgs e) { OKLog.Info("OK ViewDidDisappear"); }
static void ViewWillAppear(object sender, EventArgs e) { OKLog.Info("OK ViewWillAppear"); }
void GetFBInfo() { FB.API("/me?fields=id,first_name,friends.limit(100).fields(first_name,id)", Facebook.HttpMethod.GET, (FBResult result) => { OKLog.Info("Unity Result from FB is: " + result.Text); }); }