Example #1
0
        private void DrawLeaderboardWindow()
        {
            GUILayout.Box("Leaderboard");

            // Show score list
            GUILayoutOption _nameElementWidth = GUILayout.Width(GetWindowWidth() * 0.5f);
            GUILayoutOption _rankElementWidth = GUILayout.Width(GetWindowWidth() * 0.15f);

            RootScrollView.BeginScrollView();
            {
                foreach (EGCScore _curScore in m_leaderboardScoreList)
                {
                    EGCUser _user = _curScore.User;

                    GUILayout.BeginHorizontal();
                    {
                        GUILayout.Box(_curScore.Rank.ToString(), _rankElementWidth);
                        GUILayout.FlexibleSpace();
                        GUILayout.Label(_user.Name, _nameElementWidth);
                    }
                    GUILayout.EndHorizontal();
                }
            }
            RootScrollView.EndScrollView();
        }
        public void GetUserImage(EditorUser _userInfo)
        {
            EGCUser     _gcUser   = GetUserWithID(_userInfo.Identifier);
            IDictionary _dataDict = new Dictionary <string, object>();

            if (_gcUser == null)
            {
                _dataDict[kErrorKey] = Constants.kGameServicesIdentifierInfoNotFoundError;
            }
            else if (_gcUser.Image == null)
            {
                _dataDict[kErrorKey] = "Image not found.";
            }
            else
            {
                _dataDict[kImageKey] = _gcUser.Image;
            }

            // Send event
            if (NPBinding.GameServices != null)
            {
                NPBinding.GameServices.InvokeMethod(kRequestForUserImageFinishedEvent, new object[] {
                    _userInfo.GetInstanceID(),
                    _dataDict
                }, new Type[] {
                    typeof(string),
                    typeof(IDictionary)
                });
            }
        }
Example #3
0
 public EditorUser(EGCUser _user)
 {
     // Initialize properties
     Identifier = _user.Identifier;
     Name       = _user.Name;
     Alias      = _user.Alias;
 }
Example #4
0
 public EGCUser(EGCUser _user)
 {
     // Initialize properties
     Identifier = _user.Identifier;
     Name       = _user.Name;
     Image      = _user.Image;
     Friends    = _user.Friends;
 }
        public void Authenticate()
        {
            // Check if user has already authenticated
            if (m_localUser != null && m_localUser.IsAuthenticated)
            {
                OnAuthenticationFinished(m_localUser, null);
                return;
            }

            // As user isnt logged in, show login prompt
            NPBinding.UI.ShowLoginPromptDialog("Editor Game Center", "Login to start using Game Center.", "user identifier", "password", new string[] {
                "Log in", "Cancel"
            }, (string _button, string _loginID, string _password) => {
                string _error = null;

                if (_button.Equals("Cancel"))
                {
                    DebugPRO.Console.LogWarning(Constants.kDebugTag, "[GameServices] User cancelled login prompt.");
                    _error = "The operation couldnot be completed because user cancelled the login prompt.";
                }
                else
                {
                    if (string.IsNullOrEmpty(_loginID))
                    {
                        _loginID = "urgent_user";
                    }

                    EGCUser _regUserInfo = GetUserWithID(_loginID);

                    // Copy details of logged in user
                    if (_regUserInfo == null)
                    {
                        _regUserInfo = new EGCUser(_loginID);

                        // Add it to registered user list
                        m_registeredUsers.Add(_regUserInfo);
                    }

                    // Update local user info
                    m_localUser = new EGCLocalUser(_regUserInfo, true);
                }

                OnAuthenticationFinished(m_localUser, _error);
                return;
            });
        }
Example #6
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);
        }
Example #7
0
        public void LoadUsers(string[] _userIDList, Action <EditorUser[]> _onCompletion)
        {
            if (_onCompletion == null)
            {
                return;
            }

            // Check if user is authenticated
            if (!VerifyUser())
            {
                _onCompletion(null);
                return;
            }

            // Check if input is valid
            if (_userIDList == null)
            {
                DebugPRO.Console.LogError(Constants.kDebugTag, "[GameServices] Failed to user info.");
                _onCompletion(null);
                return;
            }

            // Fetch user info
            List <EGCUser> _userList = new List <EGCUser>();

            foreach (string _curUserID in _userIDList)
            {
                EGCUser _curUserInfo = GetUserWithID(_curUserID);

                if (_curUserInfo != null)
                {
                    _userList.Add(_curUserInfo);
                }
            }

            _onCompletion(EGCUser.ConvertToEditorUserList(_userList.ToArray()));
        }
        private EGCUser[] GetUserInfo(string[] _userIDList)
        {
            // Check if input is valid
            if (_userIDList == null)
            {
                DebugPRO.Console.LogError(Constants.kDebugTag, "[GameServices] Failed to user info.");
                return(null);
            }

            // Fetch user info
            List <EGCUser> _userList = new List <EGCUser>();

            foreach (string _curUserID in _userIDList)
            {
                EGCUser _curUserInfo = GetUserWithID(_curUserID);

                if (_curUserInfo != null)
                {
                    _userList.Add(_curUserInfo);
                }
            }

            return(_userList.ToArray());
        }
		public EditorUser (EGCUser _user)
		{
			// Initialize properties
			Identifier		= _user.Identifier;
			Name			= _user.Name;
		}
Example #10
0
 public EGCLocalUser(EGCUser _userInfo, bool _isAuthenticated)
 {
     // Initialize properties
     Info            = _userInfo;
     IsAuthenticated = _isAuthenticated;
 }
Example #11
0
        public void Authenticate(Action <EditorLocalUser> _onCompletion)
        {
            // Check if user has already authenticated
            if (m_localUser != null && m_localUser.IsAuthenticated)
            {
                if (_onCompletion != null)
                {
                    _onCompletion(m_localUser.GetEditorFormatData());
                }

                return;
            }

            // As user isnt logged in, show login prompt
            NPBinding.UI.ShowLoginPromptDialog("Editor Game Center", "Login to start using Game Center.", "user identifier", "password", new string[] { "Log in", "Cancel" }, (string _button, string _loginID, string _password) => {
                bool _failedToLogin = false;

                if (_button.Equals("Cancel"))
                {
                    DebugPRO.Console.LogWarning(Constants.kDebugTag, "[GameServices] User cancelled login prompt.");
                    _failedToLogin = true;
                }
                else if (string.IsNullOrEmpty(_loginID))
                {
                    DebugPRO.Console.LogWarning(Constants.kDebugTag, "[GameServices] Login identifier is null/empty.");
                    _failedToLogin = true;
                }
                else
                {
                    EGCUser _regUserInfo = GetUserWithID(_loginID);

                    // Copy details of logged in user
                    if (_regUserInfo == null)
                    {
                        _regUserInfo = new EGCUser(_loginID);

                        // Add it to registered user list
                        m_registeredUsers.Add(_regUserInfo);
                    }

                    // Update local user info
                    m_localUser = new EGCLocalUser(_regUserInfo, true);
                }

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

                    return;
                }
                else
                {
                    if (_onCompletion != null)
                    {
                        _onCompletion(m_localUser.GetEditorFormatData());
                    }

                    return;
                }
            });
        }
Example #12
0
        public void FilterScoreList(eLeaderboardTimeScope _timeScope, eLeaderboardUserScope _userScope, Range _range)
        {
            // Update range
            Range = _range;

            // User scope based filtering
            List <EGCScore> _usScoreList   = new List <EGCScore>();
            EGCUser         _localUserInfo = EditorGameCenter.Instance.GetLocalUserInfo();

            if (_userScope == eLeaderboardUserScope.GLOBAL)
            {
                _usScoreList.AddRange(m_scores);
            }
            else
            {
                string[] _friendIDList = _localUserInfo.Friends;

                foreach (EGCScore _curScore in m_scores)
                {
                    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
            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]);
            }

            m_lastQueryResults = _finalScore.ToArray();
        }
		public EGCLocalUser (EGCUser _userInfo, bool _isAuthenticated)
		{
			// Initialize properties
			Info				= _userInfo;
			IsAuthenticated		= _isAuthenticated;
		}