Search Unity

[FREE] Game Center Access Point for iOS

Discussion in 'Assets and Asset Store' started by gavinb80, Aug 13, 2020.

  1. gavinb80

    gavinb80

    Joined:
    Nov 4, 2012
    Posts:
    98
    Hi all,

    My current game is an iPhone / iPad app and as it was targeting iOS 14 (due to being developed on a DTK) I thought I'd try to include support for the new GKAccessPoint.

    I've started creating a new plugin (my first foray into Objective-C).

    It's free of charge as I don't see any real value in selling it, and I was hoping someone(s) would be able to help test.

    It should be as simple as importing the attached unity package, then in your C# script add:

    Code (CSharp):
    1. using GameCenterAccessPoint;
    To show the access point icon, from one of your scripts call:

    Code (CSharp):
    1. AccessPoint.ShowAccessPoint(true, GKAccessPointLocation.GKAccessPointLocationTopTrailing);
    This will display the highlights banner first, followed by the user icon in the top left corner.

    If you don't want the highlights banner:

    Code (CSharp):
    1.     AccessPoint.ShowHighlights(false); //true or false depending on if you want to display highlights banner first
    2. AccessPoint.ShowAccessPoint(true, GKAccessPointLocation.GKAccessPointLocationTopTrailing);
    Available positions are:

    Code (CSharp):
    1. GKAccessPointLocationTopLeading,  //top left
    2. GKAccessPointLocationTopTrailing, //top right
    3. GKAccessPointLocationBottomLeading, //bottom left
    4. GKAccessPointLocationBottomTrailing //bottom righr
    Once the access point is visible, you can get the rect that the access point occupies:

    Code (CSharp):
    1. CGRect _rect = AccessPoint.GetAccessPointFrameInScreenCoord();
    2. print($"Width: {_rect.size.width}");
    3. print($"Origin X: {_rect.origin.x}");

    I will try to add some more functionality, but any feedback would be appreciated.


    *update 1 - I've added the ability to manually trigger the Game Center popover:

    Code (CSharp):
    1. AccessPoint.Trigger();
    * note - it does require iOS 14 / MacOs 11

    Access Point visible (top right)
    IMG_41B87549AC4E-1.jpeg

    Highlights banner
    IMG_3EECF4505E27-1.jpeg

    Game Center popover open
    IMG_706A26A6C34F-1.jpeg
     

    Attached Files:

    Last edited: Aug 13, 2020
  2. jason_yak

    jason_yak

    Joined:
    Aug 25, 2016
    Posts:
    531
    These are untested but *should* be right. Would be handy to wrap any in compiler checks if you're wanting to add the new API code but still compiling for iOS13 in the interim.

    #include <Availability.h>
    #include <TargetConditionals.h>

    #if defined(__IPHONE_14_0) && TARGET_OS_IOS && __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_14_0
    #define IOS_14_OR_NEWER
    #endif

    #if defined(__TVOS_14_0) && TARGET_OS_TV && __TV_OS_VERSION_MIN_REQUIRED >= __TVOS_14_0
    #define TVOS_14_OR_NEWER
    #endif

    #if defined(__MAC_11_0) && TARGET_OS_OSX && __MAC_OS_X_VERSION_MIN_REQUIRED >= __MAC_11_0
    #define MACOS_11_OR_NEWER
    #endif

    #if IOS_14_OR_NEWER
    // use some iOS14 only API
    #endif
     
    Last edited: Aug 17, 2020
    gavinb80 likes this.
  3. gavinb80

    gavinb80

    Joined:
    Nov 4, 2012
    Posts:
    98
    Brilliant, thank you. I’ll do so
     
  4. gavinb80

    gavinb80

    Joined:
    Nov 4, 2012
    Posts:
    98
    That worked, it runs against ios14 and 13. Thank you @jason_yak
     
    jason_yak likes this.
  5. Zilk

    Zilk

    Joined:
    May 10, 2014
    Posts:
    333
    Can you share the updated version ? :)
     
  6. gavinb80

    gavinb80

    Joined:
    Nov 4, 2012
    Posts:
    98
    I sure can, I am just testing something then I’ll upload it.
     
    Zilk likes this.
  7. Zilk

    Zilk

    Joined:
    May 10, 2014
    Posts:
    333
    Did you get it working? :)
     
    P00pHip likes this.
  8. gavinb80

    gavinb80

    Joined:
    Nov 4, 2012
    Posts:
    98
    Hi,

    I've not had a proper chance to test due to some other commitments, here is the latest build though, if you have time to test it that would be great.

    Regards
     

    Attached Files:

  9. Zilk

    Zilk

    Joined:
    May 10, 2014
    Posts:
    333
    Will give it a go, awesome work and thanks for sharing!
     
    gavinb80 likes this.
  10. gavinb80

    gavinb80

    Joined:
    Nov 4, 2012
    Posts:
    98
    I’ve had a few issues hiding the Access Point once it’s been shown ( I want it in the menu but not the main game screen ). Seems several people are having the same issue, so once I figure it out I will upload a new version
     
  11. gavinb80

    gavinb80

    Joined:
    Nov 4, 2012
    Posts:
    98
    I've made a few updates:
    • Tidied up code
    • Sorted issue with access point always showing in top right corder
    • Fixed issue with macros not picking up wrong IOS version
    • Fixed code to hide access point
    I hope you can make use, and let me know bugs
     

    Attached Files:

    fedemg15 and AcidArrow like this.
  12. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,739
    Is GetAccessPointFrameInScreenCoord working? It seems all of its values return zero.
     
  13. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,739
    Since the best I could guess was that something was going wrong when trying to mirror the CGRect in C# land, I just made it output 4 floats instead.

    Code (csharp):
    1.     void _getAccessPointFrameInScreenCoord(float* x, float* y, float* w, float* h)
    2.     {
    3.         CGRect area = [GameCenterAccessPoint getAccessPointFrameInScreenCoord];
    4.         CGRect boundsarea = [GameCenterAccessPoint getBounds];
    5.         *x = area.origin.x / boundsarea.size.width;
    6.         *y = area.origin.y / boundsarea.size.height;
    7.         *w = area.size.width / boundsarea.size.width;
    8.         *h = area.size.height / boundsarea.size.height;
    9.     }
    (I'm also dividing my bounds width and height to more easily convert to viewport coords in Unity).

    Now the next problem is that isVisible doesn't seem to work (always returns false) and I'm unsure what the problem is.
     
    Last edited: Dec 9, 2020
  14. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,739
    Just an update in case someone else goes through this, it seems isVisible is buggy and it may even be Apple's fault, so we ended up checking if the w value in _getAccessPointFrameInScreenCoord is > 0 instead, and it seems to work pretty well.
     
  15. tummygames

    tummygames

    Joined:
    Dec 12, 2017
    Posts:
    10
    Is there support for arm64? I tried to add it to project but no luck..
    Is there final version of it available?
     
  16. gavinb80

    gavinb80

    Joined:
    Nov 4, 2012
    Posts:
    98
    Apologies, been absent for some personal reasons. I've not had chance to work on my game, or on this project but will be updating soon.

    if you still need help, please drop me a message
     
  17. alanvitek

    alanvitek

    Joined:
    Aug 20, 2013
    Posts:
    7
    Hey everyone! Thanks for all the great work on this @gavinb80 ! Using this for my game on iOS15 - noticed there were some issues with the triggers (Xcode would not compile the game unless I commented out lines 50,51,59,60 and 67 in GameCenterAccessPoint.cs)

    One question I have - the current setup defaults to what looks like the Player profile - how would I go about changing this to showing for example a single leaderboard (as outlined here: https://developer.apple.com/documentation/gamekit/displaying_the_game_center_dashboard )

    Thanks!