Search Unity

UWP Achievements 2017

Discussion in 'Windows' started by cocacough, Oct 1, 2018.

  1. cocacough

    cocacough

    Joined:
    Jul 1, 2015
    Posts:
    78
    Hi,

    I've been looking through the documentation/forums but don't seem to see much info on how to implement Achievements 2017 on UWP. Any one willing to show a sample or point me in the right direction?

    Code (CSharp):
    1.  
    2. public void UnlockWSAAchievement(int id, uint progress = 100)
    3. {
    4.         //Debug.Log(currUser.Id + " " + currUser.UID + " " + id);
    5.     if (currUser == null || !currUser.IsSignedIn)
    6.     {
    7.         return;
    8.     }
    9.  
    10.     Debug.LogError("Achievement: " + ((AchievementType)(id - 1)) + " Progress: " + progress);
    11.  
    12.     try
    13.     {
    14.         //ConvertAchievementID is jutst to convert the ID to my achievement enum
    15.         //Cant compile because this line gives me an error
    16.         AchievementService.UpdateAchievementAsync(currUser.XboxUserId, ConvertAchievementID(id), 100);
    17.     }
    18.     catch (System.Exception ex)
    19.     {
    20.         Debug.LogError(ex.Message);
    21.     }
    22. }
    23.  
    I tried using AchievementService.UpdateAchievementAsync but it returns a Task so I'm not sure how to go about implementing it. It tells me an object reference is required for the non-static field, method or property 'AchievementService.UpdateAchievementAsync(string, string, uint)'

    Thanks
     
    Last edited: Oct 1, 2018
  2. cocacough

    cocacough

    Joined:
    Jul 1, 2015
    Posts:
    78
    Bumping this thread. Would really like a little help here. Thank you.
     
    Last edited: Oct 15, 2018
  3. cocacough

    cocacough

    Joined:
    Jul 1, 2015
    Posts:
    78
    So I tried this
    Code (CSharp):
    1.     public async Task UnlockWSAAchievement(int id, uint progress = 100)
    2.     {
    3.         //Debug.Log(currUser.Id + " " + currUser.UID + " " + id);
    4. #if ENABLE_WINMD_SUPPORT
    5.         if (currUser == null || !currUser.IsSignedIn)
    6.         {
    7.             return;
    8.         }
    9. #endif
    10.         Debug.LogError("Achievement: " + ((AchievementType)(id - 1)) + " Progress: " + progress);
    11.  
    12.         try
    13.         {
    14.             return AchievementService.UpdateAchievementAsync(currUser.XboxUserId, ConvertAchievementID(id), 100);
    15.         }
    16.         catch (System.Exception ex)
    17.         {
    18.             Debug.LogError(ex.Message);
    19.         }
    20. }
    But it's asking me to use await instead. When I use await, I would have to change all my methods which checks for unlocking achievements to async Tasks (and I have many methods which checks). Is there really no other way for achievements?

    I was recommended to use a XboxLiveContext object but the xboxLiveContext does not have a definition for AchievementService
     
    Last edited: Oct 15, 2018