public void ReportScore(EditorScore _newScore)
        {
            string _instanceID = _newScore.GetInstanceID();

            // Couldnt verify user
            if (!VerifyUser())
            {
                OnReportScoreFinished(_instanceID, null, Constants.kGameServicesUserAuthMissingError);
                return;
            }

            // Get leaderboard info
            EGCLeaderboard _gcLeaderboard = GetLeaderboardWithID(_newScore.LeaderboardID);

            if (_gcLeaderboard == null)
            {
                OnReportScoreFinished(_instanceID, null, Constants.kGameServicesIdentifierInfoNotFoundError);
                return;
            }

            // Add score info
            EGCScore _newGCScore = new EGCScore(_gcLeaderboard.Identifier, _newScore.User.Identifier, _newScore.Value);

            _gcLeaderboard.AddNewScoreInfo(_newGCScore);
            OnReportScoreFinished(_instanceID, _newGCScore, null);
        }
        public void OnReportScoreFinished(string _callbackInstanceID, EGCScore _newGCScore, string _error)
        {
            IDictionary _dataDict = new Dictionary <string, object>();

            if (_error != null)
            {
                _dataDict[kErrorKey] = _error;
            }

            if (_newGCScore != null)
            {
                _dataDict[kScoreInfoKey] = _newGCScore;
            }

            if (NPBinding.GameServices != null)
            {
                NPBinding.GameServices.InvokeMethod(kReportScoreFinishedEvent, new object[] {
                    _callbackInstanceID,
                    _dataDict
                }, new Type[] {
                    typeof(string),
                    typeof(IDictionary)
                });
            }
        }
Пример #3
0
        public void ReportScore(Score _userScore, Action <EditorScore> _onCompletion)
        {
            // Couldnt verify user
            if (!VerifyUser())
            {
                // Send callback
                if (_onCompletion != null)
                {
                    _onCompletion(null);
                }

                return;
            }

            // Get leaderboard info
            EGCLeaderboard _gcLeaderboard = GetLeaderboardWithID(_userScore.LeaderboardID);

            if (_gcLeaderboard == null)
            {
                if (_onCompletion != null)
                {
                    _onCompletion(null);
                }

                return;
            }

            // Add this new score info
            string          _reportedUserID     = _userScore.User.Identifier;
            List <EGCScore> _scoreHistory       = _gcLeaderboard.Scores;
            int             _existingScoreEntry = _scoreHistory.FindIndex(_score => _score.User.Identifier.Equals(_reportedUserID));
            EGCScore        _newScoreEntry      = new EGCScore(_userScore.LeaderboardID, _reportedUserID, _userScore.Value);

            // Dint find any score record for this user
            if (_existingScoreEntry != -1)
            {
                _scoreHistory.RemoveAt(_existingScoreEntry);
            }

            // Add new entry and sort the list
            _scoreHistory.Add(_newScoreEntry);
            _scoreHistory.Sort(CompareScore);

            // Update Ranks
            for (int _iter = 0; _iter < _scoreHistory.Count; _iter++)
            {
                (_scoreHistory[_iter] as EGCScore).SetRank(_iter + 1);
            }

            // Complete action on finishing task
            if (_onCompletion != null)
            {
                _onCompletion(_newScoreEntry.GetEditorFormatData());
            }
        }
		internal EditorScore (EGCScore _scoreInfo)
		{
			string	_leaderboardID	= _scoreInfo.LeaderboardID;

			// Set properties
			LeaderboardGlobalID		= GameServicesIDHandler.GetLeaderboardGID(_leaderboardID);
			LeaderboardID			= _leaderboardID;
			User					= new EditorUser(_scoreInfo.User);
			Value					= _scoreInfo.Value;
			Date					= _scoreInfo.Date;
			Rank					= _scoreInfo.Rank;
		}
Пример #5
0
        internal EditorScore(EGCScore _scoreInfo)
        {
            string _leaderboardID = _scoreInfo.LeaderboardID;

            // Set properties
            LeaderboardGlobalID = GameServicesIDHandler.GetLeaderboardGID(_leaderboardID);
            LeaderboardID       = _leaderboardID;
            User  = new EditorUser(_scoreInfo.User);
            Value = _scoreInfo.Value;
            Date  = _scoreInfo.Date;
            Rank  = _scoreInfo.Rank;
        }
Пример #6
0
 private int CompareScore(EGCScore _score1, EGCScore _score2)
 {
     if (_score1.Value > _score2.Value)
     {
         return(-1);
     }
     else if (_score2.Value > _score1.Value)
     {
         return(0);
     }
     else
     {
         return(_score1.User.Name.CompareTo(_score2.User.Name));
     }
 }
Пример #7
0
        private void LoadScores(EGCLeaderboard _gcLeaderboard, eLeaderboardTimeScope _timeScope, eLeaderboardUserScope _userScope, Action <EditorScore[], EditorScore> _onCompletion)
        {
            EGCScore[] _filteredScoreList = GetFilteredScoreList(_gcLeaderboard, _timeScope, _userScope);
            EGCScore   _gcLocalUserScore  = _gcLeaderboard.GetScoreWithUserID(m_localUser.Info.Identifier);

            // Now get final list
            EditorScore[] _formattedScoreList      = EGCScore.ConvertToEditorScoreList(_filteredScoreList);
            EditorScore   _formattedLocalUserScore = _gcLocalUserScore == null ? null : _gcLocalUserScore.GetEditorFormatData();

            // Invoke on finished action
            if (_onCompletion != null)
            {
                _onCompletion(_formattedScoreList, _formattedLocalUserScore);
            }
        }
Пример #8
0
        protected override void ReportScoreFinished(IDictionary _dataDict)
        {
            string   _error       = _dataDict.GetIfAvailable <string>(EditorGameCenter.kErrorKey);
            EGCScore _gcScoreInfo = _dataDict.GetIfAvailable <EGCScore>(EditorGameCenter.kScoreInfoKey);

            if (_gcScoreInfo != null)
            {
                // Update properties
                Value = _gcScoreInfo.Value;
                Date  = _gcScoreInfo.Date;
                Rank  = _gcScoreInfo.Rank;
            }

            ReportScoreFinished(_error == null, _error);
        }
Пример #9
0
        public void LoadPlayerCenteredScores(eLeaderboardTimeScope _timeScope, eLeaderboardUserScope _userScope, int _maxResults, out string _error)
        {
            // Initial value
            _error = null;

            // Compute range based on player rank
            EGCUser  _localUserInfo  = EditorGameCenter.Instance.GetLocalUserInfo();
            EGCScore _localUserScore = GetScoreWithUserID(_localUserInfo.Identifier);

            if (_localUserScore == null)
            {
                _error = "The operation could not be completed because local user score info not found.";
                return;
            }

            int   _localPlayerRank = _localUserScore.Rank;
            int   _loadFrom        = Mathf.Max(1, _localPlayerRank - Mathf.FloorToInt(_maxResults * 0.5f));
            Range _newRange        = new Range(_loadFrom, _maxResults);

            // Load scores
            FilterScoreList(_timeScope, _userScope, _newRange);
        }
Пример #10
0
        public void AddNewScoreInfo(EGCScore _newScore)
        {
            // Add this new score info
            string _userID             = _newScore.User.Identifier;
            int    _existingScoreEntry = m_scores.FindIndex(_curScore => _curScore.User.Identifier.Equals(_userID));

            // Already records exist
            if (_existingScoreEntry != -1)
            {
                m_scores.RemoveAt(_existingScoreEntry);
            }

            // Add new entry and sort the list
            m_scores.Add(_newScore);
            m_scores.Sort(CompareScore);

            // Update Ranks
            for (int _iter = 0; _iter < m_scores.Count; _iter++)
            {
                m_scores[_iter].Rank = (_iter + 1);
            }
        }
Пример #11
0
        protected override void LoadScoresFinished(IDictionary _dataDict)
        {
            EditorScore[] _scores         = null;
            EditorScore   _localUserScore = null;

            // Parse received information
            string         _error           = _dataDict.GetIfAvailable <string>(EditorGameCenter.kErrorKey);
            EGCLeaderboard _leaderboardInfo = _dataDict.GetIfAvailable <EGCLeaderboard>(EditorGameCenter.kLeaderboardInfoKey);

            if (_leaderboardInfo != null)
            {
                string     _title             = _leaderboardInfo.Title;
                EGCScore[] _egcScores         = _leaderboardInfo.GetLastQueryResults();
                EGCScore   _egcLocalUserScore = _leaderboardInfo.LocalUserScore;

                if (_egcScores != null)
                {
                    int _count = _egcScores.Length;
                    _scores = new EditorScore[_count];

                    for (int _iter = 0; _iter < _count; _iter++)
                    {
                        _scores[_iter] = new EditorScore(_egcScores[_iter]);
                    }
                }

                if (_egcLocalUserScore != null)
                {
                    _localUserScore = new EditorScore(_egcLocalUserScore);
                }

                // Update leaderboard properties
                this.Title = _title;
            }

            // Invoke finish handler
            LoadScoresFinished(_scores, _localUserScore, _error);
        }
Пример #12
0
        private void SetScores(EGCScore[] _scoresList, EGCScore _localScore)
        {
            // Set default values
            Scores         = null;
            LocalUserScore = null;

            // Set scores list
            if (_scoresList != null)
            {
                int _count = _scoresList.Length;
                Scores = new EditorScore[_count];

                for (int _iter = 0; _iter < _count; _iter++)
                {
                    Scores[_iter] = new EditorScore(_scoresList[_iter]);
                }
            }

            // Set local score info
            if (_localScore != null)
            {
                LocalUserScore = new EditorScore(_localScore);
            }
        }
		internal void ShowLeaderboardUI (EGCScore[] _scoreList, Action _onCompletion)
		{
			// Set properties
			m_isShowingLeaderboardUI	= true;
			m_leaderboardScoreList		= _scoreList;
			m_showingUIFinishedEvent	= _onCompletion;

			// Make component ready before showing UI
			OnShowingGameCenterUI();
		}
Пример #14
0
        public void LoadScoresWithID(Leaderboard _leaderboard, string[] _userIDs, Action <EditorScore[]> _onCompletion)
        {
            // Check if user has logged in
            if (!VerifyUser())
            {
                if (_onCompletion != null)
                {
                    _onCompletion(null);
                }

                return;
            }

            // Check if user id's are valid
            if (_userIDs == null)
            {
                DebugPRO.Console.LogError(Constants.kDebugTag, "[GameServices] UserID list is null.");

                if (_onCompletion != null)
                {
                    _onCompletion(null);
                }

                return;
            }

            // Get leaderboard
            EGCLeaderboard _gcLeaderboard = GetLeaderboardWithID(_leaderboard.Identifier);

            if (_gcLeaderboard == null)
            {
                if (_onCompletion != null)
                {
                    _onCompletion(null);
                }

                return;
            }

            // Gather score info
            List <EGCScore> _finalScoreList = new List <EGCScore>();

            foreach (string _userID in _userIDs)
            {
                EGCScore _userScore = _gcLeaderboard.Scores.First(_score => _score.User.Identifier.Equals(_userID));

                if (_userScore == null)
                {
                    DebugPRO.Console.LogWarning(Constants.kDebugTag, string.Format("[GameServices] Couldnt find score of User with ID={0}.", _userID));
                }
                else
                {
                    _finalScoreList.Add(_userScore);
                }
            }

            if (_onCompletion != null)
            {
                _onCompletion(EGCScore.ConvertToEditorScoreList(_finalScoreList.ToArray()));
            }
        }
		private void SetScores (EGCScore[] _scoresList, EGCScore _localScore)
		{
			// Set default values
			Scores			= null;
			LocalUserScore	= null;
			
			// Set scores list
			if (_scoresList != null)
			{
				int	_count	= _scoresList.Length;
				Scores		= new EditorScore[_count];
				
				for (int _iter = 0; _iter < _count; _iter++)
					Scores[_iter]	= new EditorScore(_scoresList[_iter]);
			}
			
			// Set local score info
			if (_localScore != null)
				LocalUserScore		= new EditorScore(_localScore);
		}