public void LoadMoreScores(EditorLeaderboard _leaderboard, eLeaderboardPageDirection _pageDirection)
        {
            string _instanceID = _leaderboard.GetInstanceID();

            // Check if user has logged in
            if (!VerifyUser())
            {
                OnLoadScoresFinished(_instanceID, null, Constants.kGameServicesUserAuthMissingError);
                return;
            }

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

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

            // Load scores
            string _error;

            _gcLeaderboard.LoadMoreScores(_leaderboard.TimeScope, _leaderboard.UserScope, _leaderboard.MaxResults, _pageDirection, out _error);
            OnLoadScoresFinished(_instanceID, _gcLeaderboard, _error);
        }
        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);
        }
Ejemplo n.º 3
0
        public void LoadTopScores(Leaderboard _leaderboard, Action <EditorScore[], EditorScore> _onCompletion)
        {
            // Check if user has logged in
            if (!VerifyUser())
            {
                if (_onCompletion != null)
                {
                    _onCompletion(null, null);
                }

                return;
            }

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

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

                return;
            }

            // Set score fetch range
            _gcLeaderboard.Range = new Range(1, _leaderboard.MaxResults);

            // Load scores
            LoadScores(_gcLeaderboard, _leaderboard.TimeScope, _leaderboard.UserScope, _onCompletion);
        }
Ejemplo n.º 4
0
        public void ShowLeaderboardUI(string _leaderboardID, eLeaderboardTimeScope _timeScope, Action _onCompletion)
        {
            // Check if user has logged in
            if (!VerifyUser())
            {
                if (_onCompletion != null)
                {
                    _onCompletion();
                }

                return;
            }

            // Application needs to be in play mode
            if (!Application.isPlaying)
            {
                DebugPRO.Console.LogError(Constants.kDebugTag, "[GameServices] Works in play mode only.");

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

                return;
            }

            // Get leaderboard info
            EGCLeaderboard _gcLeaderboard = GetLeaderboardWithID(_leaderboardID);

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

                return;
            }

            // Set leaderboard score fetch range
            Range _oldRange = _gcLeaderboard.Range;
            Range _newRange = new Range(1, int.MaxValue);

            _gcLeaderboard.Range = _newRange;

            // Fetch scores from leaderboard
            EGCScore[] _scoreList = GetFilteredScoreList(_gcLeaderboard, _timeScope, eLeaderboardUserScope.GLOBAL);

            // Reset range to old value
            _gcLeaderboard.Range = _oldRange;

            // Show UI
            if (m_gameCenterUI == null)
            {
                CreateGameCenterUIInstance();
            }

            m_gameCenterUI.ShowLeaderboardUI(_scoreList, _onCompletion);
        }
Ejemplo n.º 5
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());
            }
        }
Ejemplo n.º 6
0
        public EditorLeaderboard(EGCLeaderboard _gcLeaderboardInfo)
        {
            // Set properties from info object
            Identifier     = _gcLeaderboardInfo.Identifier;
            Title          = _gcLeaderboardInfo.Title;
            Scores         = null;
            LocalUserScore = null;

            // Set global identifier
            GlobalIdentifier = GameServicesUtils.GetLeaderboardGID(Identifier);
        }
Ejemplo n.º 7
0
        public void LoadPlayerCenteredScores(Leaderboard _leaderboard, Action <EditorScore[], EditorScore> _onCompletion)
        {
            // Check if user has logged in
            if (!VerifyUser())
            {
                if (_onCompletion != null)
                {
                    _onCompletion(null, null);
                }

                return;
            }

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

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

                return;
            }

            // Compute range based on player rank
            Score _localUserScore = _gcLeaderboard.GetScoreWithUserID(m_localUser.Info.Identifier);

            if (_localUserScore == null)
            {
                DebugPRO.Console.LogError(Constants.kDebugTag, "[GameServices] Local user score not found.");

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

                return;
            }

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

            _gcLeaderboard.Range = new Range(_loadFrom, _maxResults);

            // Load scores
            LoadScores(_gcLeaderboard, _leaderboard.TimeScope, _leaderboard.UserScope, _onCompletion);
        }
Ejemplo n.º 8
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);
            }
        }
Ejemplo n.º 9
0
        protected override void LoadScoresFinished(IDictionary _dataDict)
        {
            string         _error           = _dataDict.GetIfAvailable <string>(EditorGameCenter.kErrorKey);
            EGCLeaderboard _leaderboardInfo = _dataDict.GetIfAvailable <EGCLeaderboard>(EditorGameCenter.kLeaderboardInfoKey);

            if (_leaderboardInfo != null)
            {
                // Update title
                Title = _leaderboardInfo.Title;

                // Update scores
                SetScores(_leaderboardInfo.GetLastQueryResults(), _leaderboardInfo.LocalUserScore);
            }

            // Call finish handler
            LoadScoresFinished(Scores, LocalUserScore, _error);
        }
Ejemplo n.º 10
0
        public void ShowLeaderboardUI(string _leaderboardID, eLeaderboardTimeScope _timeScope)
        {
            // Check if user has logged in
            if (!VerifyUser())
            {
                OnShowLeaderboardViewFinished(Constants.kGameServicesUserAuthMissingError);
                return;
            }

            // Application needs to be in play mode
            if (!Application.isPlaying)
            {
                OnShowLeaderboardViewFinished("The operation could not be completed because view is available only in play mode.");
                return;
            }

            // Get leaderboard info
            EGCLeaderboard _gcLeaderboard = GetLeaderboardWithID(_leaderboardID);

            if (_gcLeaderboard == null)
            {
                OnShowLeaderboardViewFinished(Constants.kGameServicesIdentifierInfoNotFoundError);
                return;
            }

            // Set leaderboard score fetch range
            Range _oldRange = _gcLeaderboard.Range;
            Range _newRange = new Range(1, int.MaxValue);

            // Fetch scores from leaderboard
            _gcLeaderboard.FilterScoreList(_timeScope, eLeaderboardUserScope.GLOBAL, _newRange);

            // Reset range to old value
            _gcLeaderboard.Range = _oldRange;

            // Show UI
            if (m_gameCenterUI == null)
            {
                CreateGameCenterUIInstance();
            }

            m_gameCenterUI.ShowLeaderboardUI(_gcLeaderboard.GetLastQueryResults(), () => {
                // Invoke handler
                OnShowLeaderboardViewFinished(null);
            });
        }
Ejemplo n.º 11
0
        private EGCLeaderboard GetLeaderboardWithID(string _leaderboardID)
        {
            if (string.IsNullOrEmpty(_leaderboardID))
            {
                DebugPRO.Console.LogError(Constants.kDebugTag, "[GameServices] Leaderboard id is null/empty.");
                return(null);
            }

            // Find leaderboard with given id
            EGCLeaderboard _gcLeaderboard = m_leaderboardList.FirstOrDefault(_curLeaderboard => _curLeaderboard.Identifier.Equals(_leaderboardID));

            if (_gcLeaderboard == null)
            {
                DebugPRO.Console.LogError(Constants.kDebugTag, "[GameServices] Couldnt find leaderboard.");
                return(null);
            }

            return(_gcLeaderboard);
        }
Ejemplo n.º 12
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);
        }
Ejemplo n.º 13
0
        private void OnLoadScoresFinished(string _callbackInstanceID, EGCLeaderboard _gcLeaderboardInfo, string _error)
        {
            IDictionary _dataDict = new Dictionary <string, object>();

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

            if (NPBinding.GameServices != null)
            {
                NPBinding.GameServices.InvokeMethod(kLoadScoresFinishedEvent, new object[] {
                    _callbackInstanceID,
                    _dataDict
                }, new Type[] {
                    typeof(string),
                    typeof(IDictionary)
                });
            }
        }
Ejemplo n.º 14
0
        public void Refresh()
        {
            IDContainer[]                    _leaderboardIDCollection       = NPSettings.GameServicesSettings.LeaderboardIDCollection;
            IDContainer[]                    _achievementIDCollection       = NPSettings.GameServicesSettings.AchievementIDCollection;
            List <EGCLeaderboard>            _newLeaderboardList            = new List <EGCLeaderboard>();
            List <EGCAchievementDescription> _newAchievementDescriptionList = new List <EGCAchievementDescription>();
            List <EGCAchievement>            _newAchievementList            = new List <EGCAchievement>();

            // Update leaderboard info
            foreach (IDContainer _entry in _leaderboardIDCollection)
            {
                string _curLeaderboardID  = _entry.GetCurrentPlatformID();
                string _curLeaderboardGID = _entry.GetGlobalID();

                // Ignore null/empty identifiers
                if (string.IsNullOrEmpty(_curLeaderboardID))
                {
                    continue;
                }

                EGCLeaderboard _curLeaderboard = GetLeaderboardWithID(_curLeaderboardID);

                if (_curLeaderboard == null)
                {
                    _curLeaderboard = new EGCLeaderboard(_identifier: _curLeaderboardID, _title: _curLeaderboardGID);
                }

                // Add this entry to the new list
                _newLeaderboardList.Add(_curLeaderboard);
            }

            // Update descriptions and achievements info
            foreach (IDContainer _entry in _achievementIDCollection)
            {
                string _curAchievementID  = _entry.GetCurrentPlatformID();
                string _curAchievementGID = _entry.GetGlobalID();

                // Ignore null/empty identifiers
                if (string.IsNullOrEmpty(_curAchievementID))
                {
                    continue;
                }

                EGCAchievementDescription _curDescription = GetAchievementDescription(_curAchievementID);
                EGCAchievement            _curAchievement = GetAchievementWithID(_curAchievementID);

                if (_curDescription == null)
                {
                    _curDescription = new EGCAchievementDescription(_identifier: _curAchievementID,
                                                                    _title: _curAchievementGID,
                                                                    _achievedDescription: "Achieved description",
                                                                    _unachievedDescription: "Unachieved description",
                                                                    _maxPoints: 1,
                                                                    _image: null,
                                                                    _isHidden: false);
                }

                // Add entries to the new list
                _newAchievementDescriptionList.Add(_curDescription);

                if (_curAchievement != null)
                {
                    _newAchievementList.Add(_curAchievement);
                }
            }

            // Set these new values
            m_leaderboardList            = _newLeaderboardList;
            m_achievementsList           = _newAchievementList;
            m_achievementDescriptionList = _newAchievementDescriptionList;
        }
Ejemplo n.º 15
0
        public void LoadMoreScores(Leaderboard _leaderboard, eLeaderboardPageDirection _pageDirection, Action <EditorScore[], EditorScore> _onCompletion)
        {
            // Check if user has logged in
            if (!VerifyUser())
            {
                if (_onCompletion != null)
                {
                    _onCompletion(null, null);
                }

                return;
            }

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

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

                return;
            }

            // Compute score fetch range
            Range _curRange = _gcLeaderboard.Range;

            if (_curRange.from == 0)
            {
                LoadTopScores(_leaderboard, _onCompletion);
                return;
            }

            // Based on page direction, compute range of score to be loaded
            int   _maxResults = _leaderboard.MaxResults;
            Range _newRange   = new Range(0, _maxResults);

            if (_pageDirection == eLeaderboardPageDirection.PREVIOUS)
            {
                if (_curRange.from == 1)
                {
                    if (_onCompletion != null)
                    {
                        _onCompletion(null, null);
                    }

                    return;
                }

                _newRange.from = Mathf.Max(1, _curRange.from - _maxResults);
            }
            else if (_pageDirection == eLeaderboardPageDirection.NEXT)
            {
                _newRange.from = _curRange.from + _maxResults;

                if (_newRange.from > _gcLeaderboard.Scores.Count)
                {
                    if (_onCompletion != null)
                    {
                        _onCompletion(null, null);
                    }

                    return;
                }
            }

            // Set score fetch range
            _gcLeaderboard.Range = _newRange;

            // Load scores
            LoadScores(_gcLeaderboard, _leaderboard.TimeScope, _leaderboard.UserScope, _onCompletion);
        }
Ejemplo n.º 16
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()));
            }
        }
Ejemplo n.º 17
0
        private EGCScore[] GetFilteredScoreList(EGCLeaderboard _gcLeaderboard, eLeaderboardTimeScope _timeScope, eLeaderboardUserScope _userScope)
        {
            List <EGCScore> _gcScores = _gcLeaderboard.Scores;

            // User scope based filtering
            List <EGCScore> _usScoreList = new List <EGCScore>();

            if (_userScope == eLeaderboardUserScope.GLOBAL)
            {
                _usScoreList.AddRange(_gcScores);
            }
            else
            {
                string[] _friendIDList = m_localUser.Info.Friends;

                foreach (EGCScore _curScore in _gcScores)
                {
                    string _curUserID = _curScore.User.Identifier;

                    if (_friendIDList.Any(_curFriendID => _curFriendID.Equals(_curUserID)))
                    {
                        _usScoreList.Add(_curScore);
                    }
                }
            }

            // Time scope based filtering
            List <EGCScore> _tsScoreList = new List <EGCScore>();

            if (_timeScope == eLeaderboardTimeScope.ALL_TIME)
            {
                _tsScoreList.AddRange(_usScoreList);
            }
            else
            {
                TimeSpan _timespan;

                if (_timeScope == eLeaderboardTimeScope.TODAY)
                {
                    _timespan = TimeSpan.FromDays(1);
                }
                else
                {
                    _timespan = TimeSpan.FromDays(7);
                }

                long _intervalStartTick = DateTime.Now.Subtract(_timespan).Ticks;
                long _intervalEndTick   = DateTime.Now.Ticks;

                foreach (EGCScore _curScore in _usScoreList)
                {
                    long _curScoreTicks = _curScore.Date.Ticks;

                    if (_curScoreTicks >= _intervalStartTick && _curScoreTicks <= _intervalEndTick)
                    {
                        _tsScoreList.Add(_curScore);
                    }
                }
            }

            // Now get elements based on range
            Range           _range      = _gcLeaderboard.Range;
            List <EGCScore> _finalScore = new List <EGCScore>();
            int             _startIndex = _range.from - 1;
            int             _endIndex   = _startIndex + _range.count;

            for (int _iter = _startIndex; (_iter < _tsScoreList.Count && _iter < _endIndex); _iter++)
            {
                _finalScore.Add(_tsScoreList[_iter]);
            }

            return(_finalScore.ToArray());
        }