예제 #1
0
        private void UpdatePlayerInfo(ISN_GKLocalPlayer player)
        {
            var localPlayer = new UM_IOSPlayer(player);
            var playerInfo  = new UM_PlayerInfo(UM_PlayerState.SignedIn, localPlayer);

            UpdateSignedPlater(playerInfo);
        }
예제 #2
0
 public void SaveGame(string name, byte[] data, Action <SA_Result> callback)
 {
     ISN_GKLocalPlayer.SavedGame(name, data, (result) => {
         ReportGameSave(name, result);
         callback.Invoke(result);
     });
 }
    private void Start()
    {
        if (Monetization.isSupported)
        {
            Monetization.Initialize(ADS_GAMEID, ADS_TESTMODE);
        }
#if UNITY_IOS
        ISN_GKLocalPlayer.Authenticate((SA_Result result) =>
        {
            if (result.IsSucceeded)
            {
                _localPlayer = ISN_GKLocalPlayer.LocalPlayer;
            }
            else
            {
                _localPlayer = null;
            }
        });
#elif UNITY_ANDROID
        PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder().Build();
        PlayGamesPlatform.InitializeInstance(config);
        PlayGamesPlatform.Activate();
        Social.localUser.Authenticate((bool success) =>
        {
            if (success)
            {
                _localPlayer = Social.localUser;
            }
        });
#endif
    }
예제 #4
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) => {
                    });
                }
            });
        }
예제 #5
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);
            });
        }
    public GameControllerScript()
    {
        _resetPlayerPrefs = false;
#if UNITY_IOS
        _localPlayer = null;
#elif UNITY_ANDROID
        _localPlayer = null;
#endif
    }
예제 #7
0
    private void Start()
    {
        m_SingInButton.onClick.AddListener(() =>
        {
            ISN_GKLocalPlayer.Authenticate(result => {
                if (result.IsSucceeded)
                {
                    Debug.Log("Authenticate is succeeded!");

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

                    SendMessage("Player Authenticate", "Alias: " + player.Alias + " ID: " + player.PlayerID);
                    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
                {
                    SendMessage("Failed", "Error with code: " + result.Error.Code + " and description: " + result.Error.Message);
                    Debug.Log("Authenticate is failed! Error with code: " + result.Error.Code + " and description: " + result.Error.Message);
                }
            });
        });

        m_LeaderboardsUI.onClick.AddListener(() =>
        {
            var viewController       = new ISN_GKGameCenterViewController();
            viewController.ViewState = ISN_GKGameCenterViewControllerState.Leaderboards;
            viewController.Show();
        });

        m_AchievementsUI.onClick.AddListener(() =>
        {
            var viewController       = new ISN_GKGameCenterViewController();
            viewController.ViewState = ISN_GKGameCenterViewControllerState.Achievements;
            viewController.Show();
        });
    }
예제 #8
0
 protected override void StartSingInFlow(Action <SA_Result> callback)
 {
     ISN_GKLocalPlayer.Authenticate(result =>
     {
         if (result.IsSucceeded)
         {
             ISN_GKLocalPlayer player = ISN_GKLocalPlayer.LocalPlayer;
             UpdatePlayerInfo(player);
         }
         callback.Invoke(result);
     });
 }
예제 #9
0
        public override void Test()
        {
            ISN_GKLocalPlayer.setAuthenticateHandler((SA_Result result) => {
                if (result.IsSucceeded)
                {
                    ISN_GKLocalPlayer player = ISN_GKLocalPlayer.LocalPlayer;
                    ISN_Logger.Log("player.PlayerID: " + player.PlayerID);
                    ISN_Logger.Log("player.Alias: " + player.Alias);
                    ISN_Logger.Log("player.DisplayName: " + player.DisplayName);
                    ISN_Logger.Log("player.Authenticated: " + player.Authenticated);
                    ISN_Logger.Log("player.Underage: " + player.Underage);
                }

                SetAPIResult(result);
            });
        }
        public override void Test()
        {
            ISN_GKLocalPlayer player = ISN_GKLocalPlayer.LocalPlayer;

            player.GenerateIdentityVerificationSignatureWithCompletionHandler((signatureResult) => {
                if (signatureResult.IsSucceeded)
                {
                    ISN_Logger.Log("signatureResult.PublicKeyUrl: " + signatureResult.PublicKeyUrl);
                    ISN_Logger.Log("signatureResult.Timestamp: " + signatureResult.Timestamp);
                    ISN_Logger.Log("signatureResult.Salt.Length: " + signatureResult.Salt.Length);
                    ISN_Logger.Log("signatureResult.Signature.Length: " + signatureResult.Signature.Length);
                }

                SetAPIResult(signatureResult);
            });
        }
예제 #11
0
        public void FetchSavedGames(Action <UM_SavedGamesMetadataResult> callback)
        {
            ISN_GKLocalPlayer.FetchSavedGames((result) => {
                UM_SavedGamesMetadataResult loadResult;

                if (result.IsSucceeded)
                {
                    loadResult = new UM_SavedGamesMetadataResult();
                    foreach (var game in result.SavedGames)
                    {
                        var isn_meta = new UM_IOSSavedGameMetadata(game);
                        loadResult.AddMetadata(isn_meta);
                    }
                }
                else
                {
                    loadResult = new UM_SavedGamesMetadataResult(result.Error);
                }

                callback.Invoke(loadResult);
            });
        }
예제 #12
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");
                });
            }
        }
예제 #13
0
        public void SignInRequest(Action <bool> resultCallback = null, bool ignorePrefs = false)
        {
            if (IsSignedIn()) //if already signed in
            {
                _currentPlayerData = ISN_GKLocalPlayer.LocalPlayer;
                GetSignedInPlayerData();

                _isSigninIgnored = false;
                PlayerPrefs.SetInt("IsSigninIgnored", 0);

                resultCallback.SafeInvoke(true);
                OnGCenterAuth.SafeInvoke(true);

                return;
            }

            if (!ignorePrefs)
            {
                if (_isSigninIgnored)
                {
                    _currentPlayerData = null;

                    resultCallback.SafeInvoke(false);
                    return;
                }
            }

            //note: new authentication method introduced in 2020.6
            ISN_GKLocalPlayer.SetAuthenticateHandler(result =>
            {
                if (result.IsSucceeded)
                {
                    Debug.Log("Authenticate is succeeded!");
                    _currentPlayerData = ISN_GKLocalPlayer.LocalPlayer;

                    _isSigninIgnored = false;
                    PlayerPrefs.SetInt("IsSigninIgnored", 0);

                    resultCallback.SafeInvoke(true);
                    OnGCenterAuth.SafeInvoke(true);
                }
                else
                {
                    Debug.Log("Authenticate is failed! Error with code: " + result.Error.Code + " and description: " +
                              result.Error.Message);
                    _currentPlayerData = null;

                    _isSigninIgnored = true;
                    PlayerPrefs.SetInt("IsSigninIgnored", 1);

                    resultCallback.SafeInvoke(false);
                    OnGCenterAuth.SafeInvoke(false);
                }
            });

            //note:removed in the new update 2020.6

            /*ISN_GKLocalPlayer.Authenticate(result =>
             * {
             *  if (result.IsSucceeded)
             *  {
             *      Debug.Log("Authenticate is succeeded!");
             *      _currentPlayerData = ISN_GKLocalPlayer.LocalPlayer;
             *
             *      _isSigninIgnored = false;
             *      PlayerPrefs.SetInt("IsSigninIgnored", 0);
             *
             *      resultCallback.SafeInvoke(true);
             *      OnGCenterAuth.SafeInvoke(true);
             *  }
             *  else
             *  {
             *      Debug.Log("Authenticate is failed! Error with code: " + result.Error.Code + " and description: " +
             *                result.Error.Message);
             *      _currentPlayerData = null;
             *
             *      _isSigninIgnored = true;
             *      PlayerPrefs.SetInt("IsSigninIgnored", 1);
             *
             *      resultCallback.SafeInvoke(false);
             *      OnGCenterAuth.SafeInvoke(false);
             *  }
             * });*/
        }
예제 #14
0
        public void Delete(UM_iSavedGameMetadata game, Action <SA_Result> callback)
        {
            var isn_meta = (UM_IOSSavedGameMetadata)game;

            ISN_GKLocalPlayer.DeleteSavedGame(isn_meta.NativeMeta, callback);
        }