Search Unity

iOS 13 Game Center avatar photo

Discussion in 'Scripting' started by andersemil, Jan 13, 2020.

  1. andersemil

    andersemil

    Joined:
    Feb 2, 2015
    Posts:
    112
    Hey,

    Since Apple have reintroduced the avatar animoji/memoji with iOS 13 we would like to use the avatar in our game. When I try to create a sprite from the localUser.image (Texture2D) and apply it to an Image component though, the texture appears as a 76x76 blank image.

    Anyone else got this working?


    Social.localUser.Authenticate ((success, response) => {
    IsAuthenticated = success;
    if (success) {
    IsUnderage = Social.localUser.underage;
    Id = Social.localUser.id;
    UserName = Social.localUser.userName;
    ProfileImageTexture = Social.localUser.image;
    if (ProfileImageTexture != null) {
    ProfileImage.sprite = Sprite.Create (ProfileImageTexture, new Rect (0, 0, ProfileImageTexture.width, ProfileImageTexture.height), new Vector2 (.5f, .5f));
    }
    }



    We're using 2018.4.9f1 and Xcode 10.2. Tested the feature on iPhone X with iOS 13.3 installed.
     
    Last edited: Jan 14, 2020
  2. tonemcbride

    tonemcbride

    Joined:
    Sep 7, 2010
    Posts:
    1,089
  3. andersemil

    andersemil

    Joined:
    Feb 2, 2015
    Posts:
    112
    That specific example relates to Google Play Games, not Apple's Game Center. Besides, I am already accessing userName first and checking that localUser.image is not null. The texture is blank.
     
  4. tonemcbride

    tonemcbride

    Joined:
    Sep 7, 2010
    Posts:
    1,089
    In that case I'm not sure what might be causing it but if I were you I'd probably try a build with the latest Unity. 2018 is pre iOS 13 so there may have been internal Apple changes that have broken it. Your code looks ok to me and matches similar example code I've seen. I'd also double check your Image component is setup properly with the right shader and alpha/colour values set.
     
    andersemil likes this.
  5. andersemil

    andersemil

    Joined:
    Feb 2, 2015
    Posts:
    112
    Yea i'm afraid I need to compile with Xcode 11, which means I will probably have to upgrade Unity since our app does not currently work when compiling with Xcode 11.
     
  6. andersemil

    andersemil

    Joined:
    Feb 2, 2015
    Posts:
    112
    So I ended up writing my own custom plugin which does the job properly where Unity fails.

    I combined ideas from here: https://stackoverflow.com/questions...-unity3d-via-a-c-sharp-script-and-ios-plug-in

    Here: https://developer.apple.com/documentation/gamekit/gkplayer/1521176-loadphotoforsize

    And here: https://github.com/abivz/unity3d-gamekit-identity-plugin

    And the resulting plugin is attached here. It will save a PNG image file of "normal" photo size (which is unspecified, but on my iPhone X with iOS 13 this results in a 512x512 texture) which can then be read in the way described in the first link.
     

    Attached Files:

    Last edited: Jan 15, 2020
    splogic and tonemcbride like this.