void Start()
    {
        // use anonymous delegates for this simple example for gathering data from GameCenter. In production you would want to
        // add and remove your event listeners in OnEnable/OnDisable!
        GameCenterManager.categoriesLoaded += delegate(List <GameCenterLeaderboard> leaderboards)
        {
            _leaderboards       = leaderboards;
            _hasLeaderboardData = _leaderboards != null && _leaderboards.Count > 0;
        };

        GameCenterManager.achievementMetadataLoaded += delegate(List <GameCenterAchievementMetadata> achievementMetadata)
        {
            _achievementMetadata = achievementMetadata;
            _hasAchievementData  = _achievementMetadata != null && _achievementMetadata.Count > 0;
        };

        // after authenticating grab the players profile image
        GameCenterManager.playerAuthenticated += () =>
        {
            GameCenterBinding.loadProfilePhotoForLocalPlayer();
            loadFriends();
        };

        // always authenticate at every launch
        GameCenterBinding.authenticateLocalPlayer();
    }
Exemple #2
0
        public static void Report(Leaderboard leaderboard, long score)
        {
            if (!instanceExists)
            {
                return;
            }

            int leaderboardIndex = (int)leaderboard;

            if (leaderboardIndex >= instance.leaderboardInfos.Length)
            {
                Debug.LogFormat("LeaderboardManager:Report - leaderboard index ({0}) out of bound.", leaderboardIndex);
                return;
            }

            if (instance.debugMode)
            {
                Debug.LogFormat("LeaderboardManager:Report({0},{1})", leaderboard, score);
            }

#if UNITY_IOS || UNITY_TVOS
            GameCenterBinding.reportScore(score, instance.leaderboardInfos[leaderboardIndex].leaderboardId);
#elif UNITY_ANDROID && !CHS
            if (PlayGameCenterManager.isAuthenticated)
            {
                PlayGameServices.submitScore(instance.leaderboardInfos[leaderboardIndex].leaderboardId, score);
            }
            else
            {
                SetCachedHighScore(leaderboard, score);
            }
#endif
        }
        public static void TryAuthentication(bool forceMode = false)
        {
            if (instanceExists && instance.debugMode)
            {
                Debug.LogFormat("PlayGameCenterManager:TryAuthentication({0}) - isAuthenticated={1}, isLastAuthenticationFailed={2}", forceMode, isAuthenticated, isLastAuthenticationFailed);
            }

            if (IsSingedIn())             // If already logined, skip here
            {
                return;
            }

            if (isLastAuthenticationFailed && !forceMode)             // If last login failed, don't do it again (unless in forceMode)
            {
                return;
            }

            _isForcingAuthentication = forceMode;

#if UNITY_IOS
            GameCenterBinding.authenticateLocalPlayer(forceMode);             // Authenticate the player
#elif UNITY_ANDROID && !CHS
            if (forceMode)
            {
                PlayGameServices.authenticate();                 // Authenticate with UI
            }
            else
            {
                PlayGameServices.attemptSilentAuthentication();                 // Authenticate Silently (with no UI)
            }
#endif
        }
Exemple #4
0
        public void ShowLeaderboard(ButtonEventArgs args)
        {
#if UNITY_IOS
#if GAMECENTER
            if (GameCenterBinding.isPlayerAuthenticated())
            {
                GameCenterBinding.showLeaderboardWithTimeScope(GameCenterLeaderboardTimeScope.AllTime);
            }
            else
            {
                StartLeaderboard();
            }
#else
            Core.Utility.Popup.PopupMessages.Me.NativeFuncionNonAvailableMessage();
#endif
#endif

#if UNITY_ANDROID
#if GPGSERVIES
            if (!PlayGameServices.isSignedIn())
            {
                StartLeaderboard(false);
            }
            else
            {
                PlayGameServices.showLeaderboards();
            }
#else
            Core.Utility.Popup.PopupMessages.Me.NativeFuncionNonAvailableMessage();
#endif
#endif
        }
Exemple #5
0
        private void LoadAchievement()
        {
#if UNITY_IOS || UNITY_TVOS
            // For new install with progress / multiple decies achievement sync
            GameCenterBinding.getAchievements();
#endif
        }
Exemple #6
0
        private void CheckshouldLoadTopScores()
        {
            if (shouldLoadMyScores)
            {
                foreach (LeaderboardInfo li in leaderboardInfos)
                {
#if UNITY_IOS || UNITY_TVOS
                    GameCenterBinding.retrieveScoresForPlayerIds(new string[1] {
                        GameCenterBinding.playerIdentifier()
                    }, li.leaderboardId);
#elif UNITY_ANDROID && !CHS
                    PlayGameServices.loadCurrentPlayerLeaderboardScore(li.leaderboardId, GPGLeaderboardTimeScope.AllTime, false);
#endif
                }
            }

#if UNITY_ANDROID
            CheckOfflineHighScores();
#endif

            if (shouldLoadTopScores)
            {
                DownloadAllLeaderboardTopScores(TimeScope.AllTime);
            }
        }
Exemple #7
0
        public void StartLeaderboard(bool autoStart = false)
        {
            if (!Network.IsInternetConnection() && !autoStart)
            {
                Core.Utility.Popup.PopupMessages.Me.InternetConnectionMessgae();
                return;
            }
#if UNITY_IOS && GAMECENTER
            if (!GameCenterBinding.isPlayerAuthenticated())
            {
                GameCenterBinding.authenticateLocalPlayer();
            }
#endif
#if UNITY_ANDROID
#if GPGSERVIES && !AMAZONSTORE
            GPGManager.authenticationFailedEvent += (string error) => {
                MyDebug.Log("Prime[31] Google Play service authenticate fail with error:\n" + error);
            };
            GPGManager.authenticationSucceededEvent += (string data) => {
                MyDebug.Log("Prime[31] Google Play service authenticate compelete with data:\n" + data);
            };
            if (!PlayGameServices.isSignedIn())
            {
#if MYDEBUG
                PlayGameServices.enableDebugLog(true);
#endif
                PlayGameServices.authenticate();
            }
#endif
#endif
        }
Exemple #8
0
        public void RequestScore(string leaderboardID, ScoreController.TimeScope timeScope, bool friendsOnly, int start, int end)
        {
                        #if UNITY_IPHONE && API_SCORE_GAMECENTER
            if (Enabled)
            {
                GameCenterLeaderboardTimeScope convertedScope = GameCenterLeaderboardTimeScope.AllTime;

                switch (timeScope)
                {
                case ScoreController.TimeScope.Today:
                    convertedScope = GameCenterLeaderboardTimeScope.Today;
                    break;

                case ScoreController.TimeScope.Week:
                    convertedScope = GameCenterLeaderboardTimeScope.Week;
                    break;

                case ScoreController.TimeScope.AllTime:
                default:
                    convertedScope = GameCenterLeaderboardTimeScope.AllTime;
                    break;
                }

                GameCenterBinding.retrieveScores(friendsOnly, convertedScope, start, end, leaderboardID);
            }
            else
            {
                Login();
            }
                        #endif
        }
Exemple #9
0
 // Authenticates the player.  This needs to be called before using anything in GameCenter and should
 // preferalbly be called shortly after application launch.
 public void AuthenticatePlayer()
 {
     //Debug.Log ("GameCenter::AuthenticatePlayer");
     if (!IsPlayerAuthenticated())
     {
         GameCenterBinding.authenticateLocalPlayer();
     }
 }
    void playerAuthenticated()
    {
        Debug.Log("playerAuthenticated");

        GameCenterBinding.loadProfilePhotoForLocalPlayer();

        GameCenterBinding.retrieveFriends(true, false);
    }
Exemple #11
0
 public void SetHighScore(int highScore)
 {
     if (_hasLeaderboardData)
     {
         Debug.Log("SUBMITTING HIGH SCORE TO LEADERBOARD:" + _leaderboards[0].leaderboardId.ToString());
         GameCenterBinding.reportScore(highScore, _leaderboards[0].leaderboardId);
     }
 }
Exemple #12
0
    public static void SetScore(long score, ulong context, string leaderboardId)
    {
        AuthenticateUser();

#if UNITY_IPHONE
        GameCenterBinding.reportScore(score, context, leaderboardId);
#endif
    }
Exemple #13
0
 // Se o usuario esta autenticado
 // Apos ser a classe ser isntanciada, é necessario autenticar o usuario com a Apple para fazer as checagens
 public static bool UserIsAuthenticated()
 {
             #if UNITY_IPHONE
     return(GameCenterBinding.isPlayerAuthenticated());
             #else
     return(false);
             #endif
 }
Exemple #14
0
 // Se o GameCenter esta ativo na plataforma
 // ps: Se o método for executado em qualquer plataforma que não seja iOS, retornara false
 public static bool GameCenterAvailable()
 {
             #if UNITY_IPHONE
     return(GameCenterBinding.isGameCenterAvailable());
             #else
     return(false);
             #endif
 }
        public static bool IsSingedIn()
        {
#if UNITY_IOS
            return(GameCenterBinding.isPlayerAuthenticated());
#elif UNITY_ANDROID
            return(PlayGameServices.isSignedIn());
#endif
            return(false);
        }
Exemple #16
0
    //=============================================================================

    public void DisplayAchievements()
    {
                #if UNITY_IPHONE
        GameCenterBinding.showAchievements();
                #endif

                #if UNITY_ANDROID
        PlayGameServices.showAchievements();
                #endif
    }
        public static string GetPlayerName()
        {
#if UNITY_IOS
            return(GameCenterBinding.playerAlias());
#elif UNITY_ANDROID && !CHS
            return(PlayGameServices.getLocalPlayerInfo().name);
#else
            return(string.Empty);
#endif
        }
Exemple #18
0
    //=============================================================================

    public void DisplayScoreboards()
    {
                #if UNITY_IPHONE
        GameCenterBinding.showLeaderboardWithTimeScope(GameCenterLeaderboardTimeScope.AllTime);
                #endif

                #if UNITY_ANDROID
        PlayGameServices.showLeaderboards();
                #endif
    }
Exemple #19
0
 // Sends a request to get the current scores with the given criteria.  End MUST be between 1 and 100 inclusive.
 public void LoadScores(bool shouldOnlyLoadFriends, GameCenterLeaderboardTimeScope timeScope, int start, int end, string leaderboardId)
 {
     if (end < 1 || end > 100)
     {
         Debug.Log("GameCenter::LoadScores - Variable 'end' not within bounds  1 < end < 100 : " + end);
         Debug.Log("GameCenter::LoadScores - Failed to load scores");
         return;
     }
     GameCenterBinding.retrieveScores(shouldOnlyLoadFriends, timeScope, start, end, leaderboardId);
 }
Exemple #20
0
    void Start()
    {
        if (Instance == null)
        {
            Instance = this;
        }

        displayMainMenu       = false;
        displayGameOver       = false;
        displayMainMenuPaused = false;

        sW                 = Screen.width;
        sH                 = Screen.height;
        buttonWidth        = sW * 0.6f;
        buttonHeight       = sH / 20.0f;
        storeKitController = GetComponent <StoreKitController>();

        // always authenticate at every launch
        GameCenterBinding.authenticateLocalPlayer();
        GameCenterBinding.loadLeaderboardTitles();

        //Get in-app purchase product data
        storeKitController.RequestProductData();

        showAds = true;
        int Ads = EncryptedPlayerPrefs.GetInt("removeadverts");

        if (Ads == 1)
        {
            if (EncryptedPlayerPrefs.CheckEncryption("removeadverts", "int", "1"))
            {
                showAds = false;
            }
        }
        else
        {
            //start loading ad
            AdBinding.initializeInterstitial();
            //start iAd
            AdBinding.createAdBanner(true);
        }

        // hack to detect iPad 3 until Unity adds official support
        this.isPad = (Screen.width >= 1536 || Screen.height >= 1536);
        if (isPad)
        {
            customButtonStyle.fontSize    = 64;
            customHighlightStyle.fontSize = 64;
            customPaddedStyle.fontSize    = 64;
        }

        //keep this object in memory
        DontDestroyOnLoad(transform.gameObject);
    }
        private void OnAuthenticationSucceeded()
        {
            if (debugMode)
            {
                Debug.LogFormat("PlayGameCenterManager:OnAuthenticationSucceeded()");
            }

            ProcessAuthenticationSucceeded();

            playerNameLoadedEvent?.Invoke(GameCenterBinding.playerAlias());
        }
Exemple #22
0
 public void Login()
 {
                 #if UNITY_IPHONE && API_SCORE_GAMECENTER
     if (!GameCenterBinding.isPlayerAuthenticated())
     {
         ZedLogger.Log("trying to authenticate local player");
         GameCenterBinding.authenticateLocalPlayer(false);
         GameCenterBinding.showCompletionBannerForAchievements();
     }
                 #endif
 }
Exemple #23
0
 void hitByRayCast()
 {
     if (GameCenterBinding.isPlayerAuthenticated())
     {
         GameCenterBinding.showLeaderboardWithTimeScope(GameCenterLeaderboardTimeScope.AllTime);
     }
     else
     {
         EtceteraBinding.showAlertWithTitleMessageAndButtons("Oops!", "You have to be logged into Game Center to do that!", new string[] { "OK" });
     }
 }
    private void loadFriends()
    {
        GameCenterManager.playerDataLoaded += friends =>
        {
            _friends    = friends;
            _hasFriends = _friends != null && _friends.Count > 0;
        };

        Debug.Log("player is authenticated so we are loading friends");
        GameCenterBinding.retrieveFriends(true, true);
    }
Exemple #25
0
        public static void ShowPlayGameCenterLeaderboards()
        {
            if (!PlayGameCenterManager.isAuthenticated)
            {
                PlayGameCenterManager.TryAuthentication(true);
            }
#if UNITY_IOS || UNITY_TVOS
            GameCenterBinding.showLeaderboardWithTimeScope(GameCenterLeaderboardTimeScope.AllTime);
#elif UNITY_ANDROID && !CHS
            PlayGameServices.showLeaderboards();
#endif
        }
Exemple #26
0
        public static void ShowPlayGameCenterAchievements()
        {
            if (!PlayGameCenterManager.isAuthenticated)
            {
                PlayGameCenterManager.TryAuthentication(true);
            }
#if UNITY_IOS || UNITY_TVOS
            GameCenterBinding.showAchievements();
#elif UNITY_ANDROID && !CHS
            PlayGameServices.showAchievements();
#endif
        }
Exemple #27
0
    // Tenta autenticar o usuario com a Apple e instancia a Prefab GameCenterManager (caso necessario)
    public static void AuthenticateUser()
    {
        Setup();

        if (!GameCenterAvailable() || UserIsAuthenticated())
        {
            return;
        }

                #if UNITY_IPHONE
        GameCenterBinding.authenticateLocalPlayer();
                #endif
    }
Exemple #28
0
 public void DisplayLeaderboardsList()
 {
                 #if UNITY_IPHONE && API_SCORE_GAMECENTER
     if (Enabled)
     {
         GameCenterBinding.showLeaderboardWithTimeScope(GameCenterLeaderboardTimeScope.Week);
     }
     else
     {
         Login();
     }
                 #endif
 }
Exemple #29
0
 public void DisplayDefaultView()
 {
                 #if UNITY_IPHONE && API_SCORE_GAMECENTER
     if (Enabled)
     {
         GameCenterBinding.showGameCenterViewController(GameCenterViewControllerState.Default);
     }
     else
     {
         Login();
     }
                 #endif
 }
Exemple #30
0
 public void DisplayAchievementsList()
 {
                 #if UNITY_IPHONE && API_SCORE_GAMECENTER
     if (Enabled)
     {
         GameCenterBinding.showAchievements();
     }
     else
     {
         Login();
     }
                 #endif
 }