private void OnReportProgressFinished(string _callbackInstanceID, EGCAchievement _gcAchievementInfo, string _error) { IDictionary _dataDict = new Dictionary <string, object>(); if (_error != null) { _dataDict[kErrorKey] = _error; } if (_gcAchievementInfo != null) { _dataDict[kAchievementInfoKey] = _gcAchievementInfo; // Show banner if achievement is completed if (_gcAchievementInfo.Completed && m_canShowAchievementBanner) { ShowAchievementBanner(GetAchievementDescription(_gcAchievementInfo.Identifier)); } } // Send notification if (NPBinding.GameServices != null) { NPBinding.GameServices.InvokeMethod(kReportProgressFinishedEvent, new object[] { _callbackInstanceID, _dataDict }, new Type[] { typeof(string), typeof(IDictionary) }); } }
public void ReportProgress(Achievement _reportedAchievement, Action <EditorAchievement> _onCompletion) { if (!VerifyUser()) { OnReportProgressFinished(null, _onCompletion); return; } AchievementDescription _reportedAchievementDescription = GetAchievementDescription(_reportedAchievement.Identifier); if (_reportedAchievementDescription == null) { OnReportProgressFinished(null, _onCompletion); return; } bool _isAchivementCompleted = _reportedAchievement.PointsScored >= _reportedAchievementDescription.MaximumPoints; DateTime _currentTime = DateTime.Now; // Iterate and update gamecenter data copy foreach (EGCAchievement _curAchievement in m_achievementsList) { if (_curAchievement.Identifier.Equals(_reportedAchievement.Identifier)) { // Update gamecenter copy of achievement _curAchievement.SetCompleted(_isAchivementCompleted); _curAchievement.SetLastReportedDate(_currentTime); // Action on finishing report OnReportProgressFinished(_curAchievement.GetEditorFormatData(), _onCompletion); return; } } // Check if new achievement was reported foreach (EGCAchievementDescription _curAchievementDescription in m_achievementDescriptionList) { if (_curAchievementDescription.Identifier.Equals(_reportedAchievement.Identifier)) { // Current achivement is set as visible _curAchievementDescription.SetIsHidden(false); // Create new achievement entry for game center EGCAchievement _newAchievement = new EGCAchievement(_reportedAchievement.Identifier, _reportedAchievement.PointsScored, _isAchivementCompleted, _currentTime); // Add it to the list m_achievementsList.Add(_newAchievement); // Action on finishing report OnReportProgressFinished(_newAchievement.GetEditorFormatData(), _onCompletion); return; } } // Failed to achievement info OnReportProgressFinished(null, _onCompletion); DebugPRO.Console.LogError(Constants.kDebugTag, string.Format("[GameServices] Failed to report achievement progress. Couldnt find achievement with ID = {0}", _reportedAchievement.Identifier)); }
public EditorAchievement (EGCAchievement _gcAchievementInfo) { // Set properties from info object Identifier = _gcAchievementInfo.Identifier; PointsScored = _gcAchievementInfo.PointsScored; Completed = _gcAchievementInfo.Completed; LastReportedDate = _gcAchievementInfo.LastReportedDate; // Set global identifier GlobalIdentifier = GameServicesIDHandler.GetAchievementGID(Identifier); }
public EditorAchievement(EGCAchievement _gcAchievementInfo) { // Set properties from info object Identifier = _gcAchievementInfo.Identifier; PointsScored = _gcAchievementInfo.PointsScored; Completed = _gcAchievementInfo.Completed; LastReportedDate = _gcAchievementInfo.LastReportedDate; // Set global identifier GlobalIdentifier = GameServicesIDHandler.GetAchievementGID(Identifier); }
public EditorAchievement(EGCAchievement _gcAchievementInfo) { // Set properties from info object Identifier = _gcAchievementInfo.Identifier; PercentageCompleted = _gcAchievementInfo.PercentageCompleted; Completed = _gcAchievementInfo.Completed; LastReportedDate = _gcAchievementInfo.LastReportedDate; // Set global identifier GlobalIdentifier = GameServicesUtils.GetAchievementGID(Identifier); }
public void ReportProgress(EditorAchievement _reportedAchievement) { string _instanceID = _reportedAchievement.GetInstanceID(); if (!VerifyUser()) { OnReportProgressFinished(_instanceID, null, Constants.kGameServicesUserAuthMissingError); return; } EGCAchievementDescription _reportedAchievementDescription = GetAchievementDescription(_reportedAchievement.Identifier); if (_reportedAchievementDescription == null) { OnReportProgressFinished(_instanceID, null, Constants.kGameServicesIdentifierInfoNotFoundError); return; } int _pointsScored = _reportedAchievement.PointsScored; int _maxPoints = _reportedAchievementDescription.MaximumPoints; bool _isAchivementCompleted = _pointsScored >= _maxPoints; string _achievementID = _reportedAchievement.Identifier; EGCAchievement _gcAchievement = GetAchievementWithID(_achievementID); if (_gcAchievement != null) { // Update values _gcAchievement.UpdateProgress(_pointsScored, _maxPoints, _isAchivementCompleted); // Invoke handler OnReportProgressFinished(_instanceID, _gcAchievement, null); return; } // Mostly its reported for first time EGCAchievementDescription _gcDescription = GetAchievementDescription(_achievementID); if (_gcDescription != null) { // Update properties of this description _gcDescription.IsHidden = false; // Create new achievement entry EGCAchievement _newAchievement = new EGCAchievement(_achievementID, _reportedAchievement.PointsScored, _maxPoints, _isAchivementCompleted); // Add it to the list m_achievementsList.Add(_newAchievement); // Action on finishing report OnReportProgressFinished(_instanceID, _newAchievement, null); return; } }
public void LoadAchievements(Action <EditorAchievement[]> _onCompletion) { // Verify authentication state if (!VerifyUser()) { _onCompletion(null); return; } // Send achievement list using completion handler if (_onCompletion != null) { _onCompletion(EGCAchievement.ConvertToEditorAchievementList(m_achievementsList.ToArray())); } }
protected override void ReportProgressFinished(IDictionary _dataDict) { string _error = _dataDict.GetIfAvailable <string>(EditorGameCenter.kErrorKey); EGCAchievement _gcAchievementInfo = _dataDict.GetIfAvailable <EGCAchievement>(EditorGameCenter.kAchievementInfoKey); if (_gcAchievementInfo != null) { // Update properties PointsScored = _gcAchievementInfo.PointsScored; Completed = _gcAchievementInfo.Completed; LastReportedDate = _gcAchievementInfo.LastReportedDate; } ReportProgressFinished(_error == null, _error); }
public void ShowAchievementsUI(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] Available in play mode only."); if (_onCompletion != null) { _onCompletion(); } return; } // Gather data required to display properties Dictionary <EGCAchievementDescription, EGCAchievement> _gcAchievementMap = new Dictionary <EGCAchievementDescription, EGCAchievement>(); foreach (EGCAchievementDescription _gcAchievementDesc in m_achievementDescriptionList) { string _gcDescriptionID = _gcAchievementDesc.Identifier; EGCAchievement _gcAchievement = m_achievementsList.FirstOrDefault(_curAchievement => _curAchievement.Identifier.Equals(_gcDescriptionID)); // Add each entry _gcAchievementMap.Add(_gcAchievementDesc, _gcAchievement); } // Show UI if (m_gameCenterUI == null) { CreateGameCenterUIInstance(); } m_gameCenterUI.ShowAchievementUI(_gcAchievementMap, _onCompletion); }
public void ShowAchievementsUI() { // Check if user has logged in if (!VerifyUser()) { OnShowAchievementViewFinished(Constants.kGameServicesUserAuthMissingError); return; } // Application needs to be in play mode if (!Application.isPlaying) { OnShowAchievementViewFinished("The operation could not be completed because view is available only in play mode."); return; } // Gather data required to display properties Dictionary <EGCAchievementDescription, EGCAchievement> _gcAchievementMap = new Dictionary <EGCAchievementDescription, EGCAchievement>(); foreach (EGCAchievementDescription _gcAchievementDesc in m_achievementDescriptionList) { string _gcDescriptionID = _gcAchievementDesc.Identifier; EGCAchievement _gcAchievement = m_achievementsList.FirstOrDefault(_curAchievement => _curAchievement.Identifier.Equals(_gcDescriptionID)); // Add each entry _gcAchievementMap.Add(_gcAchievementDesc, _gcAchievement); } // Show UI if (m_gameCenterUI == null) { CreateGameCenterUIInstance(); } m_gameCenterUI.ShowAchievementUI(_gcAchievementMap, () => { // Invoke handler OnShowAchievementViewFinished(null); }); }
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; }