Advertisement
Guest User

PlayFab Flow

a guest
Aug 16th, 2017
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.63 KB | None | 0 0
  1. void Start(){
  2.         if (GameCenter.isConnected)
  3.             LoginToPlayFabWithGameCenter ();
  4.         else
  5.             LoginToPlayFabWithDevice ();
  6.     }
  7.  
  8.     void LoginToPlayFabWithGameCenter(){
  9.         //When there is absolutely no account created on PlayFab, this works as expected: A new Account is created linked to the GameCenter.id
  10.         //Now, when there is already an account created linked to the device ID only, a new account won't be created. Instead, PlayFabId returns that account ID; as if they were linked - but they're not
  11.         PlayFabClientAPI.LoginWithGameCenter (
  12.             CreateAccount = true,
  13.             TitleId = PlayFabSettings.TitleId,
  14.             PlayerId = GameCenter.id,
  15.             OnLoginWithGameCenterSuccess, OnLoginWithGameCenterError
  16.         );
  17.     }
  18.  
  19.     void OnLoginWithGameCenterSuccess(LoginResult result){
  20.         Debug.Log (result.PlayFabId);
  21.         LinkDeviceID ();
  22.     }
  23.  
  24.     void LinkDeviceID(){
  25.         //This returns successfully, but the link between this device and the GameCenter account is not shown in the Game Manager
  26.         PlayFabClientAPI.LinkIOSDeviceID(
  27.             DeviceId = SystemInfo.deviceUniqueIdentifier,
  28.             DeviceModel = SystemInfo.deviceModel,
  29.             OS = SystemInfo.operatingSystem,
  30.             ForceLink = true,
  31.             OnLinkDeviceIdSuccessful, OnLinkDeviceIdError
  32.         );
  33.     }
  34.  
  35.     void LoginToPlayFabWithDevice(){
  36.         //Exactly the same behaviour as with LoginToPlayFabWithGameCenter
  37.         //When there is absolutely no account created on PlayFab, this works as expected: A new Account is created linked to the DeviceId
  38.         //Now, when there is already an account created linked to the GameCenter only, a new account won't be created. Instead, PlayFabId returns that account ID; as if they were linked - but they're not
  39.         PlayFabClientAPI.LoginWithIOSDeviceID(
  40.             CreateAccount = true,
  41.             TitleId = PlayFabSettings.TitleId,
  42.             DeviceId = SystemInfo.deviceUniqueIdentifier,
  43.             DeviceModel = SystemInfo.deviceModel,
  44.             OS = SystemInfo.operatingSystem,
  45.             OnLoginWithDeviceIdSuccess, OnLoginWithDeviceIDError
  46.         ); 
  47.     }
  48.  
  49.     void OnLoginWithDeviceIdSuccess(LoginResult result){
  50.         Debug.Log (result.PlayFabId);
  51.         StartCoroutine (LoginToGameCenter ());
  52.     }
  53.  
  54.     IEnumerator LoginToGameCenter(){
  55.         while (true) {
  56.             if (GameCenter.isConnected) {
  57.                 LoginToPlayFabWithGameCenter2 ();
  58.                 break;
  59.             }
  60.             WaitForSeconds (x);
  61.         }
  62.     }
  63.  
  64.     //=====Code repeated just to ilustrate the different paths=====
  65.  
  66.     void LoginToPlayFabWithGameCenter2(){
  67.         //With CreateAccount being false and no account existing linked to GameCenter, this should return an error. But it does not
  68.         //Instead, it logs me in to the same account I am already logged in: The one linked to the device ID only
  69.         PlayFabClientAPI.LoginWithGameCenter (
  70.             CreateAccount = false,
  71.             TitleId = PlayFabSettings.TitleId,
  72.             PlayerId = GameCenter.id,
  73.             OnLoginWithGameCenterSuccess2, OnLoginWithGameCenterError
  74.         );
  75.     }
  76.  
  77.     void OnLoginWithGameCenterSuccess2(LoginResult result){
  78.         Debug.Log (result.PlayFabId);
  79.         LinkDeviceID2 ();
  80.     }
  81.  
  82.     void LinkDeviceID2(){
  83.         //This call would only make sense if an actual account had been created in the first place, but it was not.
  84.         //That is why I try to link this GameCenter account to the deviceID account I'm logged in
  85.         PlayFabClientAPI.LinkIOSDeviceID(
  86.             DeviceId = SystemInfo.deviceUniqueIdentifier,
  87.             DeviceModel = SystemInfo.deviceModel,
  88.             OS = SystemInfo.operatingSystem,
  89.             ForceLink = true,
  90.             OnLinkDeviceIdSuccessful, OnLinkDeviceIdError
  91.         );
  92.         LinkGameCenterID ();
  93.     }
  94.  
  95.     void LinkGameCenterID(){
  96.         //Again, this returns successfully, but the link is not shown in the Game Manager
  97.         PlayFabClientAPI.LinkGameCenterAccount (
  98.             GameCenterId = GameCenter.id
  99.         , OnLinkGameCenterSuccessful, OnLinkGameServiceError);
  100.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement