Search Unity

GameCenter Plugin Live! Leaderboards and Achievements!

Discussion in 'iOS and tvOS' started by prime31, Sep 6, 2010.

  1. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @Jacob, does the sample scene voice chat work for you? That would be a good place to start for the voice chat issue. As for the invite issue, I have one more idea:

    - listen to the GameCenterManager.playerAuthenticated event if you are not already
    - in the playerAuthenticated event handler (this occurs right after a user is logged in) call GameCenterMultiplayerBinding.isVOIPAllowed()

    The idea is that as soon as you know who the player is (authentication succeeded) setup the invite handler (which will get done the first time you call any GameCenterMultiplayerBinding methods).
     
  2. Jacob-Williams

    Jacob-Williams

    Joined:
    Jan 30, 2009
    Posts:
    267
    @Prime31 - I finally have voice chat working (almost). If I talk into the iPhone, I can hear the voice on the iPad, but not vice versa. As this is a beta OS and Game Center for iPad is in beta, I am not about to ask you to support it. I will drop it for now, and might revisit if I have the same issue on two iPhones.

    The other issue is the one that bothers me the most. I have taken your advice, but the issue is still there. When the game starts on the second device, nothing shows in the log of the first (host) device, and the matchmaker never shows on the second device. I can cancel that pending invite, and start another, and it works without a problem. My wifi connection here at work is a little sluggish (takes about 3 - 5 seconds to authenticate a user), could this be an issue?
     
  3. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @Jacob, it's hard to say of latency is the issue. I would think that it shouldn't be a problem because GC is designed to work over 3G as well. The invite handler should technically get called even minutes later. Are you at least getting the push notifications?
     
  4. Jacob-Williams

    Jacob-Williams

    Joined:
    Jan 30, 2009
    Posts:
    267
    @Prime31 - Yeah, the push notifications are coming in fine and starting the game like they are supposed to. Is there anything else I can do the help troubleshoot the issue? Would you like to take a look at the project?
     
  5. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @Jacob, if you can send me just the relevant portions of the code that would be fine. Feel free to email them to questions @ prime31.com. I am wondering if using the GameCenter app to launch a game takes you out of the sandbox. I don't have enough iDevices with me at the moment but I will do some testing when I get back near my iPad/iPod.
     
  6. hxx2010

    hxx2010

    Joined:
    Aug 31, 2009
    Posts:
    155
    I would like to add a false alarm,
    But the warning did not appear
    What is wrong?

    GameCenterManager.mm
    Code (csharp):
    1.  
    2. - (void)authenticateLocalPlayer
    3. {
    4.     [[GKLocalPlayer localPlayer] authenticateWithCompletionHandler:^( NSError *error )
    5.     {
    6.         if( error )
    7.         {
    8.             UnitySendMessage( "GameCenterManager", "playerAuthenticationFailed", [[error localizedDescription] UTF8String] );
    9.        
    10.             NSString *msg = nil;
    11.             msg = @"The internet connection appears to be offline.";
    12.             UIAlertView *alert = [[UIAlertView alloc]
    13.                  initWithTitle:@"No network"
    14.                  message:msg
    15.                  delegate:nil
    16.                  cancelButtonTitle:@"Cancel"
    17.                  otherButtonTitles:nil];
    18.              
    19.         }
    20.  
    21.     }];
    22. }
    23.  
    24.  
     
  7. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @hxx2010, you have to show the alert, not just create it. You also need to release the memory associated with it to avoid a leak. Add the following below your *alert declaration:

    [alert show];
    [alert release];
     
  8. hxx2010

    hxx2010

    Joined:
    Aug 31, 2009
    Posts:
    155
    Thank you very much

    I have one question
    How to determine the start of this program is invited to start
    Make sure it is verified directly into the game center
     
    Last edited: Oct 6, 2010
  9. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @hxx2010, if you receive an invite request, the GameCenter matchmaker is automatically launched.
     
  10. hxx2010

    hxx2010

    Joined:
    Aug 31, 2009
    Posts:
    155
    I have here is the GameCenter matchmake test results does not start automatically
    If click on "find activity" button, GameCenter matchmak will start
    I do not know where the problem
     
  11. bumba

    bumba

    Joined:
    Oct 10, 2008
    Posts:
    358
    Im doing this in my Start() function to show the game center button. The problem is the the button is not showing when you enter the scene because the Authentication last to loong. Should i active the button in the Update() method? Or is this not good for performance?

    PHP:
    if(GameCenterBinding.isGameCenterAvailable())
        {
        
            
    GameCenterBinding.authenticateLocalPlayer();
            if(
    GameCenterBinding.isPlayerAuthenticated()){
                
    gameCenterButton.active true;
            }
            
            
        }
     
  12. maglat

    maglat

    Joined:
    Jul 9, 2010
    Posts:
    111
    Dear Prime31 :)

    How can I check after I reported the Achievement "GameCenterBinding.reportAchievement("01",100)" that it realy worked/posted?
    Is there something like "GameCenterBinding.checkAchievement("01") == true"?
     
  13. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @bumba, you will want to subscribe to the following event:

    GameCenterManager.playerAuthenticated



    @maglat, check out the events:

    GameCenterManager.reportAchievementFinished
    GameCenterManager.reportAchievementFailed
     
  14. bumba

    bumba

    Joined:
    Oct 10, 2008
    Posts:
    358
    what do you mean with subscribe? Should i ask in update if(GameCenterManager.playerAuthenticated){do something}
     
  15. maglat

    maglat

    Joined:
    Jul 9, 2010
    Posts:
    111

    I'm a bit noobish.
    How do I call that events above after I started my "GameCenterBinding.reportAchievement("01",100);" post?
     
  16. hxx2010

    hxx2010

    Joined:
    Aug 31, 2009
    Posts:
    155
    How to determine the multiplayer game is ready, and officially start the race
    How to determine this multiplayer game is the number of players and competitions, and a certain order to the players arranged
    Because in my multiplayer game, each player I need to set different initial position
     
  17. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @bumba and @maglat, here is a nice tutorial on events. Don't mind the C# if you don't use it because subscribing to events is identical in JS and C#. The test scenes all have examples of subscribing to events and it is really, really easy and massively powerful. I highly recommend you get very comfortable with events (not just for the plugins but for your games as well). They provide a nice way to have different scripts on different GameObjects communicate with each other very efficiently. Here is an example:

    Code (csharp):
    1. void Start()
    2. {
    3.     // Listen to the playerAuthenticated event.  (+= means add me as an event subscriber)
    4.     // All event listeners MUST be removed before this object is disposed!
    5.     GameCenterManager.playerAuthenticated += playerAuthenticated;
    6. }
    7.  
    8.  
    9. void OnDisable()
    10. {
    11.     // Remove all the event handlers (-= means remove me as an event subscriber)
    12.     GameCenterManager.playerAuthenticated -= playerAuthenticated;
    13. }
    14.  
    15.  
    16. void playerAuthenticated()
    17. {
    18.     Debug.Log( "playerAuthenticated event fired" );
    19. }
    @hxx2010, I believe I already answered your question via email but just to be thorough here is the response. You will want to first listen for the GameCenterMultiplayerManager.matchmakerFoundMatch event which will let you know when to start the match. At this point, at least minPlayers have successfully joined the match and are connected and the event will tell you exactly how many players have joined. From there you are clear to do as you please with your now connected iDevices
     
  18. maglat

    maglat

    Joined:
    Jul 9, 2010
    Posts:
    111
    @prime

    I really have to lern this! Many thanks for your great work in answering in such a great way and teaching us :D
     
  19. damien

    damien

    Joined:
    Jun 17, 2009
    Posts:
    32
    I'm getting the "This game is not recognized by Game Center." error when attempting to authenticate.
    I've gone through the thread and have done the following things:

    • Added GameCenterManager prefab to my scene.
    • Enabled Game Center in iTunes Connect.
    • Signed out of Game Center.
    • Deleted and reinstalled app.
    • Made sure it's a debug build.
    • Made sure bundle names and version numbers match.

    Here's my possibly unique scenario though. I've created a new version of an old game in iTunes Connect without uploading the binary. Game Center is enabled in the new version, not the current version.

    Am I missing something?

    SOLVED
    I had to click Build from the Build Settings screen and choose to replace the build folder.
     
    Last edited: Oct 8, 2010
  20. ezone

    ezone

    Joined:
    Mar 28, 2008
    Posts:
    331
    Hi Prime - when posting scores and achievements to Game Center I am seeing a 3 sec (average) pause where the Unity view is frozen (audio continues to play) and sometimes up to 9 secs. Not sure if this has anything to do with it but I'm connecting to GC over 3G.
     
    Last edited: Oct 8, 2010
  21. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @ezone, there are some posts on the Apple dev forums about this as well. The core and achievement posting is all happening on a background thread so it shouldn't lock up the GUI too much but there is something Apple is doing that locks things up. I highly recommend submitting a bug report to Apple. The more they get the faster it gets fixed.
     
  22. EskemaGames

    EskemaGames

    Joined:
    Jun 23, 2010
    Posts:
    319
    Master prime ;) I have a question, I'm trying to set a delegate to get a list of achievements

    Code (csharp):
    1.  
    2. private List<GameCenterAchievement> achievementData;
    3. GameCenterManager.achievementsLoaded += delegate( List<GameCenterAchievement> achievementData )
    4.         {
    5.             this.achievementData = achievementData;
    6.         };
    7.  
    But this isn't working

    Code (csharp):
    1.  
    2. Debug.Log(achievementData[0].completed);
    3.  
    There's no data, Am I missing something? besides the ahievementmetadata (wich works perfectly), I need to know what achievements are unlocked/completed
     
  23. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @Eskema, you are using C#?!?! I'll have to look out the window to make sure the sky isn't falling! The achievementsLoaded event should get fired after successfully authenticating and after you call GameCenterBinding.getAchievements().

    Try using the code below and see what the log tells you:

    Code (csharp):
    1. void Start()
    2. {
    3.     // Listen to the achievementsLoaded event
    4.     GameCenterManager.achievementsLoaded -= achievementsLoaded;
    5. }
    6.  
    7.  
    8. void OnDisable()
    9. {
    10.     // Remove the event handler
    11.     GameCenterManager.achievementsLoaded -= achievementsLoaded;
    12. }
    13.  
    14.  
    15. void achievementsLoaded( List<GameCenterAchievement> achievements )
    16. {
    17.     this.achievementData = achievementData;
    18.    
    19.     Debug.Log( "achievementsLoaded" );
    20.     foreach( GameCenterAchievement s in achievements )
    21.         Debug.Log( s );
    22. }
     
  24. EskemaGames

    EskemaGames

    Joined:
    Jun 23, 2010
    Posts:
    319
    Last time I looked out the window I saw..... nevermind. Ok let's get to the point. After I logged and receive the visual notification of gamecenter, I've called the getscores and getachievementsmetadata, everything is working propertly.
    The getachievements only fires the debug.log(achievementsload), nothing more, the list is empty. I've tried to call first the getachievements, and later suscribe the delegate, and also tried the reverse method, first set the delegate and later call getachievements.

    I'm only using the gamecentermanager prefab, is the eventlistener prefab needed on the scene?
     
  25. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @Eskema, are you sure you have posted an achievement? Until you post one it will be blank.
     
  26. EskemaGames

    EskemaGames

    Joined:
    Jun 23, 2010
    Posts:
    319
    You need to post an achievement?, I thought the achievements works the same way as the achievement metadata, you create them in itunes and then you can download the data and check the values
    If is totally needed to post the achievement first, what's the use of the achievements class then? I need to know if an achievement is completed or not to activate it in the code
     
  27. Flex

    Flex

    Joined:
    May 18, 2010
    Posts:
    3
    Hey,
    I have problem with testing gamecenter integration in my game. Im using this awesome plugin ( cheers Prime31 ! )
    I have "***Sandbox***" login menu but after log I get "This game is not recogniezed by Game Center".
    I enabled GameCenter in "Manage GameCenter" tab @ itunnesconnect
    I can't click damn "Enable for this version" button in "Current Version" tab @ itunnesconnect, button is inactive all the time! ( i even check html code of page, there is no javascript attached to that button )

    Any ideas ?
     
  28. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @Eskema, there are two different things at play here:

    retrieveAchievementMetadata will get the exact data from iTunesConnect that you setup
    getAchievements will get the current players status in completing those achievements.

    If you never report an achievement for the player getAchievements will always be empty.


    @Flex, be sure your game has a unique (non *) bundle identifier in iTunes Connect otherwise you won't be able to add Game Center to it.
     
  29. EskemaGames

    EskemaGames

    Joined:
    Jun 23, 2010
    Posts:
    319
    Thanks master Prime :) one last question.
    My idea is to put a button to enable/disable gamecenter, and we have the playerautenticated to log in, but I don't see any method to disconnect the player from gamecenter, I saw the playerloggedout callback to notify the player disconnection, but none method to actually log out the player, something like Gamecenter.disconnnect();
    Gamecenter don't offer a method to disconnect the players?
     
  30. svm5

    svm5

    Joined:
    May 14, 2009
    Posts:
    25
    Our app Croquet just went live the other day with Multiplayer, Leaderboards and Achievements using the GameCenter Plugin. Check it out at www.croquetapp.com
     
  31. bumba

    bumba

    Joined:
    Oct 10, 2008
    Posts:
    358
    thanks a lot for your help.

    I have another problem. in my GameCenterManager Script in the mainmenu i make this:

    function Awake () {
    DontDestroyOnLoad (this);
    }

    But when i return to the mainmenu i have 2 gameCenterManager scripts. How to avoid that?
     
  32. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @Eskema, there is no way to logout of GameCenter except through the official GC app. Send Apple a feature request (lots and lots of us did this too) so they give us a logout function if you want it.

    @svm5, looking good! I'm downloading it right now.

    @bumba, you can either put the GameCenterManager in a scene that you only load once (maybe an initial splash screen if you have one) or just put it in its own scene and use Application.LoadLevelAdditive to ensure it only loads once. If you don't need it in your other scenes you could also allow it to be destroyed.
     
  33. EskemaGames

    EskemaGames

    Joined:
    Jun 23, 2010
    Posts:
    319
    Just as I expected, I will send a feature request to apple, once again thanks for your time :)
     
  34. bumba

    bumba

    Joined:
    Oct 10, 2008
    Posts:
    358
    GameCenterManager is only in my MainMenu scene as a prefab and it will survive when i change scenes because of the function
    DontDestroyOnLoad (). The problem now is when i return to the mainmenu (change from level scene to mainmenu scene) the origin GameCenterManager is there and my survived GameCenterManager from the scene switch(because of DontDestroyOnLoad ). How to avoid that? Is there a unity function for that problem?
     
  35. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @bumba, you can do something really simple such as create a scene with the prefab in it that will be the first scene (before your MainMenu). All that scene needs to do is load your MainMenu scene. That should take care of it for you.
     
  36. bumba

    bumba

    Joined:
    Oct 10, 2008
    Posts:
    358
    good idea :) thanks
     
  37. Flex

    Flex

    Joined:
    May 18, 2010
    Posts:
    3
    Thx for help, its ok now.

    I have one more question is there any function in plugin that creates "Achievement complete!" pop up when player complete achievement ?

    I know there is reportAchievement function but its just send info to gamecenter, i didnt notice ant classic apple UI pop up with my achievement icon.

    Thx in advance
    Flex
     
  38. JamesMobot

    JamesMobot

    Joined:
    Jul 8, 2010
    Posts:
    170
    Supports Ipad Game Center!!

    I suppose i can't say much more than what is already known due to the apple NDA on betas. But, I just tested and your game center plugin is working perfect for ipad.

    Loaded unlocked some achievements and posted some high scores!!

    Nice to know we can get our iPad apps ready for release day one of game centers iPad debut!
    I plan to submit my ipad game now so i can release it on that day.
    (building on sdk 4.1 seems to work fine since I have heard some people are having some denied apps built with the beta sdk)

    Again nice job.
     
  39. EskemaGames

    EskemaGames

    Joined:
    Jun 23, 2010
    Posts:
    319
    This is something that you need to handle by yourself, gamecenter only notifies you about the achievement state, you need to create your own pop up
     
  40. Flex

    Flex

    Joined:
    May 18, 2010
    Posts:
    3
    Do you have any ideas how to create such pop up? I think it should be some subview of main view, so it could be rendered even if scene is changing? Any samples or sugestions ?
     
  41. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @Flex, personally, I would make an AchievementNotification prefab in Unity. Maybe a simple texture that fits your game and a GUIText. Maybe have it animate or fade in, then fade out and destroy itself. If you will be reusing it often, you can keep the prefab around.
     
  42. jackshiels

    jackshiels

    Joined:
    Feb 29, 2008
    Posts:
    357
    How long is the sale on - I will need to buy soon! Wether we get it or not depends on a few issues, but we probably will.
     
  43. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @jackshiels, its on sale until I get the final features implemented. It is still missing the uber-advanced multiplayer system with player classes and such. There is no ETA just yet for the update because I want to get the Etcetera Plugin out in the wild first.
     
  44. damien

    damien

    Joined:
    Jun 17, 2009
    Posts:
    32
    How do I get connected player's names?
     
  45. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @damien, you want the GameCenterBinding.playerAlias() method.
     
  46. damien

    damien

    Joined:
    Jun 17, 2009
    Posts:
    32
    Oh. That's not in the docs. Thanks.

    So if I want to display connected player's names to each other, I have to create a method to send them?
     
    Last edited: Oct 12, 2010
  47. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @damien, it's the 4th method listed in the docs. :)
     
  48. damien

    damien

    Joined:
    Jun 17, 2009
    Posts:
    32
    I was in the multiplayer section, my bad :)
     
  49. damien

    damien

    Joined:
    Jun 17, 2009
    Posts:
    32
    I'm using the matchmakerFoundMatch event to start the game on both devices, with the first order of business being to send their player name to each other. The problem is 1 device can reach that point faster than the other and will send the name before the other device is ready, so that device will never get the message. Am I forced to keep resending the name until I manually return a confirmation from the receiving device, or am I missing something?

    PS. I'm sending the data reliably.
     
  50. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @damien, try listening to the GameCenterMultiplayerManager.playerConnected event as well. Once you get that one you should be clear to send the names back and forth.