예제 #1
0
        /// <summary>
        /// Authenticates the Game Center local player. Call this as soon as the game is initialized.
        /// <br></br>
        /// Raises the LocalPlayerAuthenticated and LocalPlayerAuthencationFailed events on completion.
        /// <br></br>
        /// Once the local player is authenticated, you can get the <c>LocalPlayer</c> property.
        /// </summary>
        public static void AuthenticateLocalPlayer()
        {
            var gkLocalPlayer = GKLocalPlayer.LocalPlayer();

            if (gkLocalPlayer.RespondsToSelector("authenticateHandler"))
            {
                // ios 6.0 new call
                gkLocalPlayer.authenticateHandler = delegate(UIViewController viewController, NSError error) {
                    if (viewController != null)
                    {
                        _localPlayer = null;
                        UIApplication.deviceRootViewController.PresentViewController(viewController, true, null);
                    }
                    else
                    {
                        _CheckLocalPlayer(error);
                        error = null;
                    }
                };
            }
            else
            {
                // deprecated in ios 6.0
                gkLocalPlayer.Authenticate(delegate(NSError error) {
                    _CheckLocalPlayer(error);
                    error = null;
                });
            }
        }
예제 #2
0
        public void Register()
        {
            if (_registered)
            {
                return;
            }

            GKLocalPlayer.LocalPlayer().RegisterListener(this);

            _registered = true;
        }
예제 #3
0
        private static void _CheckLocalPlayer(NSError error)
        {
            var gkLocalPlayer = GKLocalPlayer.LocalPlayer();

            if (gkLocalPlayer.authenticated)
            {
                // create wrapper and dispatch event
                _localPlayer = NSObjectWrapper.CreateWrapper(typeof(LocalPlayer), gkLocalPlayer, gkLocalPlayer.playerID) as LocalPlayer;
                if (_localPlayerAuthenticatedHandlers != null)
                {
                    _localPlayerAuthenticatedHandlers(null, EventArgs.Empty);
                }
            }
            else
            {
                // set it to null and dispatch event
                _localPlayer = null;
                if (_localPlayerAuthenticationFailedHandlers != null)
                {
                    _localPlayerAuthenticationFailedHandlers(null, new U3DXTErrorEventArgs(error));
                }
            }
        }