예제 #1
0
        private void HasConflictingSavedGames(ISN_GKSavedGameFetchResult result)
        {
            ISN_GKSavedGame resultGame = null;
            var             conflictedSavedGamesIds = new List <string>();

            foreach (var game in result.SavedGames)
            {
                conflictedSavedGamesIds.Add(game.Id);

                if (resultGame == null)
                {
                    resultGame = game;
                }
                else
                {
                    var gameUnixTime      = SA_Unix_Time.ToUnixTime(game.ModificationDate);
                    var currentResultTime = SA_Unix_Time.ToUnixTime(resultGame.ModificationDate);
                    if (gameUnixTime > currentResultTime)
                    {
                        resultGame = game;
                    }
                }
            }

            ISN_GKLocalPlayer.LoadGameData(resultGame, (dataLoadResult) => {
                if (dataLoadResult.IsSucceeded)
                {
                    ISN_GKLocalPlayer.ResolveConflictingSavedGames(conflictedSavedGamesIds, dataLoadResult.BytesArrayData, (resResult) => {
                    });
                }
            });
        }
예제 #2
0
        public void LoadFromGameKitData(UM_iSavedGameMetadata game, bool parseMeta, Action <UM_SavedGameDataLoadResult> callback)
        {
            var isn_meta = (UM_IOSSavedGameMetadata)game;

            ISN_GKLocalPlayer.LoadGameData(isn_meta.NativeMeta, (result) => {
                UM_SavedGameDataLoadResult loadResult;
                if (result.IsSucceeded)
                {
                    if (parseMeta)
                    {
                        var meta = new UM_SaveInfo();
                        meta.SetProgressValue(BitConverter.ToInt64(result.BytesArrayData, 0));
                        meta.SetPlayedTimeMillis(BitConverter.ToInt64(result.BytesArrayData, 8));

                        var userData = new byte[result.BytesArrayData.Length - 16];
                        Array.Copy(result.BytesArrayData, 16, userData, 0, userData.Length);
                        loadResult = new UM_SavedGameDataLoadResult(userData, meta);
                    }
                    else
                    {
                        loadResult = new UM_SavedGameDataLoadResult(result.BytesArrayData, new UM_SaveInfo());
                    }
                }
                else
                {
                    loadResult = new UM_SavedGameDataLoadResult(result.Error);
                }

                callback.Invoke(loadResult);
            });
        }
예제 #3
0
        private void OnGUI()
        {
            //ISN_GKLocalPlayer info

            if (GUI.Button(new Rect(0, 0, 250, 50), "Authenticate"))
            {
                ISN_GKLocalPlayer.Authenticate((SA_Result result) => {
                    if (result.IsSucceeded)
                    {
                        Debug.Log("Authenticate is succeeded!");

                        ISN_GKLocalPlayer player = ISN_GKLocalPlayer.LocalPlayer;
                        Debug.Log(player.PlayerID);
                        Debug.Log(player.Alias);
                        Debug.Log(player.DisplayName);
                        Debug.Log(player.Authenticated);
                        Debug.Log(player.Underage);


                        player.GenerateIdentityVerificationSignatureWithCompletionHandler((signatureResult) => {
                            if (signatureResult.IsSucceeded)
                            {
                                Debug.Log("signatureResult.PublicKeyUrl: " + signatureResult.PublicKeyUrl);
                                Debug.Log("signatureResult.Timestamp: " + signatureResult.Timestamp);
                                Debug.Log("signatureResult.Salt.Length: " + signatureResult.Salt.Length);
                                Debug.Log("signatureResult.Signature.Length: " + signatureResult.Signature.Length);
                            }
                            else
                            {
                                Debug.Log("IdentityVerificationSignature has failed: " + signatureResult.Error.FullMessage);
                            }
                        });
                    }
                    else
                    {
                        Debug.Log("Authenticate is failed! Error with code: " + result.Error.Code + " and description: " + result.Error.Message);
                    }
                });
            }



            if (GUI.Button(new Rect(250, 0, 250, 50), "Get GKLocalPlayer"))
            {
                ISN_GKLocalPlayer localPlayer = ISN_GKLocalPlayer.LocalPlayer;

                Debug.Log("PlayerID: " + localPlayer.PlayerID + " | Alias: " + localPlayer.Alias + " | DisplayName: " + localPlayer.DisplayName);
            }


            if (GUI.Button(new Rect(0, 50, 250, 50), "Is Authenticated?"))
            {
                Debug.Log(ISN_GKLocalPlayer.LocalPlayer.Authenticated);
            }


            if (GUI.Button(new Rect(250, 50, 250, 50), "Is Underage?"))
            {
                Debug.Log(ISN_GKLocalPlayer.LocalPlayer.Underage);
            }


            if (GUI.Button(new Rect(0, 200, 250, 50), "Fetch saved games"))
            {
                ISN_GKLocalPlayer.FetchSavedGames((ISN_GKSavedGameFetchResult result) => {
                    if (result.IsSucceeded)
                    {
                        Debug.Log("Loaded " + result.SavedGames.Count + " saved games");
                        foreach (ISN_GKSavedGame game in result.SavedGames)
                        {
                            Debug.Log(game.Name);
                            Debug.Log(game.DeviceName);
                            Debug.Log(game.ModificationDate);
                        }
                    }
                    else
                    {
                        Debug.Log("Fetching saved games is failed! " +
                                  "With: " + result.Error.Code + " and description: " + result.Error.Message);
                    }
                });
            }



            if (GUI.Button(new Rect(250, 200, 250, 50), "Save a game"))
            {
                byte[] data = Encoding.UTF8.GetBytes("data A");
                Debug.Log("Sends byte array length " + data.Length);

                ISN_GKLocalPlayer.SavedGame("file_name", data, (ISN_GKSavedGameSaveResult result) => {
                    if (result.IsSucceeded)
                    {
                        Debug.Log(result.SavedGame.Name);
                        Debug.Log(result.SavedGame.DeviceName);
                        Debug.Log(result.SavedGame.ModificationDate);
                    }
                    else
                    {
                        Debug.Log("SavedGame is failed! With: " + result.Error.Code + " and description: " + result.Error.Message);
                    }
                });
            }



            if (GUI.Button(new Rect(0, 250, 250, 50), "Save a game 2"))
            {
                byte[] data = Encoding.UTF8.GetBytes("data AAA");
                Debug.Log("Sends byte array length " + data.Length);

                ISN_GKLocalPlayer.SavedGame("new_file_name", data, (ISN_GKSavedGameSaveResult result) => {
                    if (result.IsSucceeded)
                    {
                        Debug.Log("SavedGame is succeeded! Device name = " + result.SavedGame.DeviceName + " | game name = " + result.SavedGame.Name + " | modification Date = " + result.SavedGame.ModificationDate.ToString());
                    }
                    else
                    {
                        Debug.Log("SavedGame is failed! With: " + result.Error.Code + " and description: " + result.Error.Message);
                    }
                });
            }



            if (GUI.Button(new Rect(250, 250, 250, 50), "Delete a game"))
            {
                ISN_GKLocalPlayer.DeleteSavedGame(m_fetchedSavedGames[0], (SA_Result result) => {
                    if (result.IsSucceeded)
                    {
                        Debug.Log("DeleteSavedGame is succeeded!");
                    }
                    else
                    {
                        Debug.Log("DeleteSavedGame is failed! Error with code: " + result.Error.Code + " and description: " + result.Error.Message);
                    }
                });
            }


            if (GUI.Button(new Rect(0, 300, 250, 50), "Load saved game data"))
            {
                ISN_GKLocalPlayer.LoadGameData(m_fetchedSavedGames[0], (ISN_GKSavedGameLoadResult result) => {
                    if (result.IsSucceeded)
                    {
                        Debug.Log("Loading game data is succeeded! " +
                                  "StringData = " + result.StringData + " " +
                                  "byte array length " + result.BytesArrayData.Length);
                    }
                    else
                    {
                        Debug.Log("Loading game data is failed! Error with code: " + result.Error.Code + " and description: " + result.Error.Message);
                    }
                });
            }

            if (GUI.Button(new Rect(250, 300, 250, 50), "Resolve Saved Games Conflicts"))
            {
                //Choose correct data
                byte[] data = Encoding.UTF8.GetBytes("data AAA");
                Debug.Log("Sends byte array length " + data.Length);
                ISN_GKLocalPlayer.ResolveConflictingSavedGames(m_conflictedSavedGames, data, (ISN_GKSavedGameFetchResult result) => {
                    if (result.IsSucceeded)
                    {
                        Debug.Log("Resolve Conflicted Saved Games is succeeded!");
                    }
                    else
                    {
                        Debug.Log("Resolve Conflicted Saved Games is failed!");
                    }
                });
            }

            /*
             * if (GUI.Button(new Rect(0, 500, 250, 50), "Show")) {
             *  ISN_GKGameCenterViewController gKGameCenterViewController = new ISN_GKGameCenterViewController();
             *  gKGameCenterViewController.LeaderboardIdentifier = "my_first_leaderboard";
             *  gKGameCenterViewController.LeaderboardTimeScope = ISN_GKLeaderboardTimeScope.AllTime;
             *  gKGameCenterViewController.ViewState = ISN_GKGameCenterViewControllerState.Leaderboards;
             *
             *  ISN_GKGameCenterViewController.Show(JsonUtility.ToJson(gKGameCenterViewController));
             * }
             *
             */


            if (GUI.Button(new Rect(0, 400, 250, 50), "Load Achivemnets"))
            {
                ISN_GKAchievement.LoadAchievements((result) => {
                    if (result.IsSucceeded)
                    {
                        Debug.Log("Loaded: " + result.Achievements.Count + " Achievements");
                        // m_achivemnets = result.Achievements;
                    }
                    else
                    {
                        Debug.Log("LoadAchievements failed! With: " + result.Error.Code + " and description: " + result.Error.Message);
                    }
                });
            }

            if (GUI.Button(new Rect(250, 400, 250, 50), "Reset Achivemnets"))
            {
                ISN_GKAchievement.ResetAchievements((result) => {
                    if (result.IsSucceeded)
                    {
                        Debug.Log("ResetAchievements succeeded");
                    }
                    else
                    {
                        Debug.Log("LoadAchievements failed! With: " + result.Error.Code + " and description: " + result.Error.Message);
                    }
                });
            }


            if (GUI.Button(new Rect(0, 450, 250, 50), "Report Achievements"))
            {
                ISN_GKAchievement achievement1 = new ISN_GKAchievement("my_first_achievement");
                achievement1.PercentComplete = 50.0f;

                achievement1.Report((result) => {
                    if (result.IsSucceeded)
                    {
                        Debug.Log("ReportAchievements succeeded");
                    }
                    else
                    {
                        Debug.Log("LoadAchievements failed! With: " + result.Error.Code + " and description: " + result.Error.Message);
                    }
                });
            }

            if (GUI.Button(new Rect(250, 450, 250, 50), "SHOW Achievements UI"))
            {
                ISN_GKGameCenterViewController viewController = new ISN_GKGameCenterViewController();
                viewController.ViewState = ISN_GKGameCenterViewControllerState.Achievements;
                viewController.Show();
            }


            if (GUI.Button(new Rect(0, 500, 250, 50), "SHOW Leaderboards "))
            {
                ISN_GKGameCenterViewController viewController = new ISN_GKGameCenterViewController();
                viewController.ViewState = ISN_GKGameCenterViewControllerState.Leaderboards;
                viewController.Show();
            }


            if (GUI.Button(new Rect(250, 500, 250, 50), "SHOW Challenges "))
            {
                ISN_GKGameCenterViewController viewController = new ISN_GKGameCenterViewController();
                viewController.ViewState = ISN_GKGameCenterViewControllerState.Challenges;
                viewController.Show(() => {
                    Debug.Log("Challenges hideed");
                });
            }
        }