Exemple #1
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);
            }
        }
        public static string GetPlayerId()
        {
#if UNITY_IOS
            return(GameCenterBinding.playerIdentifier());
#elif UNITY_ANDROID && !CHS
            return(PlayGameServices.getLocalPlayerInfo().playerId);
#else
            return(string.Empty);
#endif
        }
    public void ProcessScores()
    {
        //Lets clear the list and add the scores as they are loaded.
        //Grab the scores and store them into the loaded scores.
        List <SocialCenter.LeaderBoardScore> loadedscores = SocialCenter.Instance._loadedScores;

        loadedscores.Clear();


        int index = 0;

        foreach (GameCenterScore s in _scores)
        {
            //Create a new score.
            SocialCenter.LeaderBoardScore newScore = new SocialCenter.LeaderBoardScore();

            //Set each one.
            newScore.gcScore = s;

            Debug.LogError("CATEGORY!  ::::: " + s.category);

            //Deady but a nested loop here to check for photos and who the current player is.
            if (_friends != null)
            {
                foreach (GameCenterPlayer p in _friends)
                {
                    //Set the profile photo. and break this loop since we found the player.
                    if (p.playerId == s.playerId)
                    {
                        //We will attempt to load the image right here and store it in the score.
                        newScore.ProfilePicturePath = p.profilePhotoPath;
                        break;
                    }
                }
            }

            //Set player alias to ME if its ourselves.
            if (GameCenterBinding.playerIdentifier() == s.playerId)
            {
                newScore.Alias = "Me";
            }

            //Add to the list.
            loadedscores.Add(newScore);

            Debug.Log(s);
            index++;
        }
    }
    void leaderboardsGUI()
    {
        if (GUILayout.Button("Load Leaderboard Data"))
        {
            GameCenterBinding.loadLeaderboardTitles();
        }


        if (GUILayout.Button("Show Leaderboards"))
        {
            GameCenterBinding.showLeaderboardWithTimeScope(GameCenterLeaderboardTimeScope.AllTime);
        }


        if (!_hasLeaderboardData)
        {
            GUILayout.Label("Load leaderboard data to see more options");
            return;
        }

        if (GUILayout.Button("Post Score"))
        {
            Debug.Log("about to report a random score for leaderboard: " + _leaderboards[0].leaderboardId);
            GameCenterBinding.reportScore(Random.Range(1, 99999), _leaderboards[0].leaderboardId);
        }


        if (GUILayout.Button("Issue Score Challenge"))
        {
            var playerIds = new string[] { "player1", "player2" };
            var score     = Random.Range(1, 9999);
            GameCenterBinding.issueScoreChallenge(score, 0, _leaderboards[0].leaderboardId, playerIds, "Beat this score!");
        }


        if (GUILayout.Button("Get Raw Score Data"))
        {
            GameCenterBinding.retrieveScores(false, GameCenterLeaderboardTimeScope.AllTime, 1, 25, _leaderboards[0].leaderboardId);
        }


        if (GUILayout.Button("Get Scores for Me"))
        {
            GameCenterBinding.retrieveScoresForPlayerId(GameCenterBinding.playerIdentifier(), _leaderboards[0].leaderboardId);
        }
    }
    void OnGUI()
    {
        float yPos       = 5.0f;
        float xPos       = 5.0f;
        float width      = (Screen.width >= 960 || Screen.height >= 960) ? 320 : 160;
        float height     = (Screen.width >= 960 || Screen.height >= 960) ? 80 : 40;
        float heightPlus = height + 5.0f;


        if (GUI.Button(new Rect(xPos, yPos, width, height), "Authenticate"))
        {
            GameCenterBinding.authenticateLocalPlayer();
        }


        if (GUI.Button(new Rect(xPos, yPos += heightPlus, width, height), "Load Achievement Metadata"))
        {
            GameCenterBinding.retrieveAchievementMetadata();
        }


        if (GUI.Button(new Rect(xPos, yPos += heightPlus, width, height), "Get Raw Achievements"))
        {
            GameCenterBinding.getAchievements();
        }


        if (GUI.Button(new Rect(xPos, yPos += heightPlus, width, height), "Post Achievement"))
        {
            if (achievementMetadata != null && achievementMetadata.Count > 0)
            {
                int percentComplete = (int)Random.Range(2, 60);
                Debug.Log("sending percentComplete: " + percentComplete);
                GameCenterBinding.reportAchievement(achievementMetadata[0].identifier, percentComplete);
            }
            else
            {
                Debug.Log("you must load achievement metadata before you can post an achievement");
            }
        }


        if (GUI.Button(new Rect(xPos, yPos += heightPlus, width, height), "Issue Achievement Challenge"))
        {
            if (achievementMetadata != null && achievementMetadata.Count > 0)
            {
                var playerIds = new string[] { "player1", "player2" };
                GameCenterBinding.issueAchievementChallenge(achievementMetadata[0].identifier, playerIds, "I challenge you");
            }
            else
            {
                Debug.Log("you must load achievement metadata before you can issue an achievement challenge");
            }
        }


        if (GUI.Button(new Rect(xPos, yPos += heightPlus, width, height), "Show Achievements"))
        {
            GameCenterBinding.showAchievements();
        }


        if (GUI.Button(new Rect(xPos, yPos += heightPlus, width, height), "Reset Achievements"))
        {
            GameCenterBinding.resetAchievements();
        }


        if (GUI.Button(new Rect(xPos, yPos += heightPlus, width, height), "Multiplayer Scene"))
        {
            Application.LoadLevel("GameCenterMultiplayerTestScene");
        }


        // Second Column
        xPos = Screen.width - width - 5.0f;
        yPos = 5.0f;


        if (GUI.Button(new Rect(xPos, yPos, width, height), "Get Player Alias"))
        {
            string alias = GameCenterBinding.playerAlias();
            Debug.Log("Player alias: " + alias);
        }



        if (GUI.Button(new Rect(xPos, yPos += heightPlus, width, height), "Load Leaderboard Data"))
        {
            GameCenterBinding.loadLeaderboardTitles();
        }


        if (GUI.Button(new Rect(xPos, yPos += heightPlus, width, height), "Post Score"))
        {
            // We must have a leaderboard to post the score to
            if (leaderboards != null && leaderboards.Count > 0)
            {
                Debug.Log("about to report a random score for leaderboard: " + leaderboards[0].leaderboardId);
                GameCenterBinding.reportScore(Random.Range(1, 99999), leaderboards[0].leaderboardId);
            }
        }


        if (GUI.Button(new Rect(xPos, yPos += heightPlus, width, height), "Issue Score Challenge"))
        {
            // We must have a leaderboard to post the score to
            if (leaderboards != null && leaderboards.Count > 0)
            {
                var playerIds = new string[] { "player1", "player2" };
                var score     = Random.Range(1, 9999);
                GameCenterBinding.issueScoreChallenge(score, 0, leaderboards[0].leaderboardId, playerIds, "Beat this score!");
            }
            else
            {
                Debug.Log("you must load your leaderboards before you can issue a score challenge");
            }
        }


        if (GUI.Button(new Rect(xPos, yPos += heightPlus, width, height), "Show Leaderboards"))
        {
            GameCenterBinding.showLeaderboardWithTimeScope(GameCenterLeaderboardTimeScope.AllTime);
        }


        if (GUI.Button(new Rect(xPos, yPos += heightPlus, width, height), "Get Raw Score Data"))
        {
            // We must have a leaderboard to retrieve scores from
            if (leaderboards != null && leaderboards.Count > 0)
            {
                GameCenterBinding.retrieveScores(false, GameCenterLeaderboardTimeScope.AllTime, 1, 25, leaderboards[0].leaderboardId);
            }
            else
            {
                Debug.Log("Load leaderboard data before attempting to retrieve scores");
            }
        }


        if (GUI.Button(new Rect(xPos, yPos += heightPlus, width, height), "Get Scores for Me"))
        {
            // We must have a leaderboard to retrieve scores from
            if (leaderboards != null && leaderboards.Count > 0)
            {
                GameCenterBinding.retrieveScoresForPlayerId(GameCenterBinding.playerIdentifier(), leaderboards[0].leaderboardId);
            }
            else
            {
                Debug.Log("Load leaderboard data before attempting to retrieve scores");
            }
        }


        if (GUI.Button(new Rect(xPos, yPos += heightPlus, width, height), "Retrieve Friends"))
        {
            GameCenterBinding.retrieveFriends(true);
        }
    }
Exemple #6
0
 // Gets the playerIdentifier of the current player.
 public string GetPlayerIdentifier()
 {
     //Debug.Log ("GameCenter::getIdentifier");
     PlayerIdentifier = GameCenterBinding.playerIdentifier();
     return(PlayerIdentifier);
 }
    void OnGUI()
    {
        beginColumn();

        if (GUILayout.Button("Find Match"))
        {
            matchDataStringAsBytes();
            GameCenterTurnBasedBinding.findMatch(2, 8, true);
        }


        if (GUILayout.Button("End Turn For Match"))
        {
            // we will just find any player that is not us to use as the next player
            var ourPlayerId  = GameCenterBinding.playerIdentifier();
            var nextPlayerId = string.Empty;

            foreach (var p in _currentMatch.participants)
            {
                if (p.playerId != ourPlayerId)
                {
                    nextPlayerId = p.playerId;
                    break;
                }
            }

            GameCenterTurnBasedBinding.endTurnWithNextParticipant(nextPlayerId, matchDataStringAsBytes());
        }


        if (GUILayout.Button("Is it my Turn?"))
        {
            Debug.Log("is it my turn? " + GameCenterTurnBasedBinding.isCurrentPlayersTurn());
        }


        GUILayout.Space(50);
        if (GUILayout.Button("End Match In Turn"))
        {
            // you cannot end a match without first setting the matchOutcome for all players in the match
            foreach (var p in _currentMatch.participants)
            {
                GameCenterTurnBasedBinding.setMatchOutcomeForParticipant(GKTurnBasedMatchOutcome.Tied, p.playerId);
            }

            GameCenterTurnBasedBinding.endMatchInTurnWithMatchData(matchDataStringAsBytes());
        }


        if (GUILayout.Button("Quit Out of Turn"))
        {
            GameCenterTurnBasedBinding.participantQuitOutOfTurnWithOutcome(GKTurnBasedMatchOutcome.Quit);
        }


        endColumn(true);


        if (GUILayout.Button("Load All Matches"))
        {
            GameCenterTurnBasedBinding.loadMatches();
        }


        if (GUILayout.Button("Remove Current Match"))
        {
            GameCenterTurnBasedBinding.removeCurrentMatch();
        }


        if (GUILayout.Button("Rematch Current Match"))
        {
            // this will only work for a completed match on iOS 6+
            GameCenterTurnBasedBinding.rematchCurrentMatch();
        }


        if (GUILayout.Button("Set Match Message"))
        {
            // this can only be set if it is the current player's turn
            GameCenterTurnBasedBinding.setMatchMessage("The match's message!");
        }

        endColumn();


        if (bottomLeftButton("Back to 1st Scene"))
        {
            Application.LoadLevel(0);
        }
    }