private IEnumerator <bool> ChangeDisplayNameCoroutine(string newDisplayName) { var updateDisplayName = PF.Do(new UpdateUserTitleDisplayNameRequest { DisplayName = newDisplayName, }); while (updateDisplayName.IsDone == false) { yield return(default(bool)); } // Early out if we got an error if (updateDisplayName.HasError) { PlayFabMessages.HandleError(updateDisplayName.Exception); yield return(false); yield break; } // TODO [bgish]: Fire off DisplayName changed event? // Updating the display name this.DisplayName = newDisplayName; yield return(true); }
private IEnumerator <List <CatalogItem> > FetchCatalog() { if (string.IsNullOrEmpty(getCatalogRequest.CatalogVersion)) { getCatalogRequest.CatalogVersion = PF.CatalogVersion; } var getCatalog = PF.Do <GetCatalogItemsRequest, GetCatalogItemsResult>(getCatalogRequest, PlayFabClientAPI.GetCatalogItems); while (getCatalog.IsDone == false) { yield return(null); } // Caching off the store in case the user requests it again this.cachedCatalog = getCatalog.Value?.Catalog; if (this.cachedCatalog != null) { foreach (var item in this.cachedCatalog) { this.catalogItemDictionary.Add(item.ItemId, item); } } yield return(this.cachedCatalog); }
private IEnumerator <List <StoreItem> > FetchStore(string storeId) { if (string.IsNullOrEmpty(getStoreRequest.CatalogVersion)) { getStoreRequest.CatalogVersion = PF.CatalogVersion; } getStoreRequest.StoreId = storeId; var getStore = PF.Do <GetStoreItemsRequest, GetStoreItemsResult>(getStoreRequest, PlayFabClientAPI.GetStoreItems); while (getStore.IsDone == false) { yield return(null); } var store = getStore.Value?.Store; // Caching off the store in case the user requests it again if (store != null) { this.cachedStores.Add(storeId, store); } yield return(store); }
public UnityTask <PlayFabLoginResultCommon> LoginWithEmail(bool createAccount, string email, string password, GetPlayerCombinedInfoRequestParams combinedInfoParams = null) { if (createAccount) { return(PF.Do <RegisterPlayFabUserRequest, PlayFabLoginResultCommon>( new RegisterPlayFabUserRequest { Email = email, Password = password, InfoRequestParameters = this.GetCombinedInfoRequest(combinedInfoParams), RequireBothUsernameAndEmail = false, }, PlayFabClientAPI.RegisterPlayFabUser)); } else { return(PF.Do <LoginWithEmailAddressRequest, PlayFabLoginResultCommon>( new LoginWithEmailAddressRequest { Email = email, Password = password, InfoRequestParameters = this.GetCombinedInfoRequest(combinedInfoParams), }, PlayFabClientAPI.LoginWithEmailAddress)); } }
private IEnumerator <bool> RegisterForAndroidPushNotificationsCoroutine() { Firebase.Messaging.FirebaseMessaging.TokenReceived += this.OnTokenReceived; Firebase.Messaging.FirebaseMessaging.MessageReceived += this.OnMessageReceived; int retryCount = 0; while (this.deviceToken == null) { retryCount++; if (retryCount >= RetryCountMax) { yield break; } // Waiting before we retry again... float waitTime = 0.0f; while (waitTime < RetryWaitTime) { yield return(default(bool)); waitTime += UnityEngine.Time.deltaTime; } } var register = PF.Do(new PlayFab.ClientModels.AndroidDevicePushNotificationRegistrationRequest { DeviceToken = this.deviceToken }); while (register.IsDone == false) { yield return(default(bool)); } if (register.HasError) { var playfabError = register.Exception as PlayFabException; if (playfabError != null) { UnityEngine.Debug.Log("Error Registering for Android Push Notifications!"); UnityEngine.Debug.Log(playfabError.Error.Error); UnityEngine.Debug.Log(playfabError.Error.ErrorMessage); UnityEngine.Debug.Log(playfabError.Error.ErrorDetails); } } else { // Saving that we've registed this user for PushNotifications with PlayFab successfully LostPlayerPrefs.GetString(HasRegisteredUserForPushNotificationsKey, PF.User.PlayFabId); UnityEngine.Debug.Log("Push Notification Registration Successful!"); yield return(true); } yield return(true); }
public UnityTask <UpdateCharacterDataResult> UpdateCharacterData(string characterId, Dictionary <string, string> data) { return(PF.Do <UpdateCharacterDataRequest, UpdateCharacterDataResult>(new UpdateCharacterDataRequest { CharacterId = characterId, Data = data, }, PlayFabClientAPI.UpdateCharacterData)); }
private UnityTask <PurchaseItemResult> Do(PurchaseItemRequest request) { if (string.IsNullOrEmpty(request.CatalogVersion)) { request.CatalogVersion = PF.CatalogVersion; } return(PF.Do <PurchaseItemRequest, PurchaseItemResult>(request, PlayFabClientAPI.PurchaseItem)); }
public UnityTask <GetCharacterDataResult> GetCharacterData(string characterId, List <string> keys) { return(PF.Do <GetCharacterDataRequest, GetCharacterDataResult>(new GetCharacterDataRequest { CharacterId = characterId, Keys = keys, }, PlayFabClientAPI.GetCharacterData)); }
public UnityTask <SendAccountRecoveryEmailResult> SendAccountRecoveryEmail(string email, string emailTemplateId) { return(PF.Do <SendAccountRecoveryEmailRequest, SendAccountRecoveryEmailResult>( new SendAccountRecoveryEmailRequest { Email = email, EmailTemplateId = emailTemplateId, }, PlayFabClientAPI.SendAccountRecoveryEmail)); }
public UnityTask <ExecuteCloudScriptResult> Execute(string functionName, object functionParameters = null) { return(PF.Do(new ExecuteCloudScriptRequest { FunctionName = functionName, RevisionSelection = CloudScriptRevisionOption.Specific, SpecificRevision = PF.CloudScriptRevision, GeneratePlayStreamEvent = true, FunctionParameter = functionParameters, })); }
public UnityTask <LoginResult> LoginWithDeviceId(bool createAccount, string deviceId, GetPlayerCombinedInfoRequestParams combinedInfoParams = null) { if (Application.isEditor || Platform.IsIosOrAndroid == false) { return(PF.Do <LoginWithCustomIDRequest, LoginResult>( new LoginWithCustomIDRequest { CreateAccount = createAccount, CustomId = deviceId, InfoRequestParameters = this.GetCombinedInfoRequest(combinedInfoParams), }, PlayFabClientAPI.LoginWithCustomID)); } else if (Platform.CurrentDevicePlatform == DevicePlatform.iOS) { return(PF.Do <LoginWithIOSDeviceIDRequest, LoginResult>( new LoginWithIOSDeviceIDRequest { CreateAccount = createAccount, DeviceId = deviceId, DeviceModel = SystemInfo.deviceModel, OS = SystemInfo.operatingSystem, InfoRequestParameters = this.GetCombinedInfoRequest(combinedInfoParams), }, PlayFabClientAPI.LoginWithIOSDeviceID)); } else if (Platform.CurrentDevicePlatform == DevicePlatform.Android) { return(PF.Do <LoginWithAndroidDeviceIDRequest, LoginResult>( new LoginWithAndroidDeviceIDRequest { CreateAccount = createAccount, AndroidDeviceId = deviceId, AndroidDevice = SystemInfo.deviceModel, OS = SystemInfo.operatingSystem, InfoRequestParameters = this.GetCombinedInfoRequest(combinedInfoParams), }, PlayFabClientAPI.LoginWithAndroidDeviceID)); } else { throw new NotImplementedException(); } }
private IEnumerator <bool> ChangeDisplayNameWithPopupCoroutine() { var stringInputBox = PlayFabMessages.ShowChangeDisplayNameInputBox(PF.User.DisplayName); while (stringInputBox.IsDone == false) { yield return(default(bool)); } if (stringInputBox.Value == StringInputResult.Cancel) { yield return(false); yield break; } var updateDisplayName = PF.Do(new UpdateUserTitleDisplayNameRequest { DisplayName = StringInputBox.Instance.Text, }); while (updateDisplayName.IsDone == false) { yield return(default(bool)); } // Early out if we got an error if (updateDisplayName.HasError) { PlayFabMessages.HandleError(updateDisplayName.Exception); yield return(false); yield break; } // TODO [bgish]: Fire off DisplayName changed event? // Updating the display name this.DisplayName = StringInputBox.Instance.Text; yield return(true); }
public UnityTask <List <ItemInstance> > GetInventoryItems() { if (this.usersInventory != null) { return(UnityTask <List <ItemInstance> > .Empty(this.usersInventory)); } else { return(UnityTask <List <ItemInstance> > .Run(GetInventoryItemsCoroutine())); } IEnumerator <List <ItemInstance> > GetInventoryItemsCoroutine() { // If it's already running, then wait for it to finish if (this.getInventoryCoroutineRunning) { while (this.getInventoryCoroutineRunning) { yield return(default(List <ItemInstance>)); } yield return(this.usersInventory); yield break; } this.getInventoryCoroutineRunning = true; var playfabGetInventory = PF.Do(new GetUserInventoryRequest()); while (playfabGetInventory.IsDone == false) { yield return(default(List <ItemInstance>)); } this.getInventoryCoroutineRunning = false; yield return(this.usersInventory); } }
private IEnumerator <PlayFabResultCommon> UnlinkDeviceIdIterator(string deviceId) { if (Application.isEditor || Platform.IsIosOrAndroid == false) { var coroutine = PF.Do <UnlinkCustomIDRequest, UnlinkCustomIDResult>(new UnlinkCustomIDRequest { CustomId = deviceId }, PlayFabClientAPI.UnlinkCustomID); while (coroutine.MoveNext()) { yield return(coroutine.Current as PlayFabResultCommon); } } else if (Platform.CurrentDevicePlatform == DevicePlatform.iOS) { var coroutine = PF.Do <UnlinkIOSDeviceIDRequest, UnlinkIOSDeviceIDResult>(new UnlinkIOSDeviceIDRequest { DeviceId = deviceId }, PlayFabClientAPI.UnlinkIOSDeviceID); while (coroutine.MoveNext()) { yield return(coroutine.Current as PlayFabResultCommon); } } else if (Platform.CurrentDevicePlatform == DevicePlatform.Android) { var coroutine = PF.Do <UnlinkAndroidDeviceIDRequest, UnlinkAndroidDeviceIDResult>(new UnlinkAndroidDeviceIDRequest { AndroidDeviceId = deviceId }, PlayFabClientAPI.UnlinkAndroidDeviceID); while (coroutine.MoveNext()) { yield return(coroutine.Current as PlayFabResultCommon); } } else { throw new NotImplementedException(); } }
private IEnumerator <LinkFacebookAccountResult> LinkFacebookCoroutine() { var accessToken = this.GetFacebookAccessToken(); while (accessToken.IsDone == false) { yield return(default(LinkFacebookAccountResult)); } var request = new LinkFacebookAccountRequest { AccessToken = accessToken.Value }; var link = PF.Do <LinkFacebookAccountRequest, LinkFacebookAccountResult>(request, PlayFabClientAPI.LinkFacebookAccount); while (link.IsDone == false) { yield return(default(LinkFacebookAccountResult)); } yield return(link.Value); }
private IEnumerator <LoginResult> LoginWithFacebookCoroutine(bool createAccount, GetPlayerCombinedInfoRequestParams combinedInfoParams, List <string> facebookPermissions) { #if !USING_FACEBOOK_SDK throw new FacebookException("USING_FACEBOOK_SDK is not defined! Check your AppSettings."); #else // Making sure all passed in facebook permissions are appended to the global list if (facebookPermissions != null) { foreach (var facebookPermission in facebookPermissions) { this.FacebookPermissions.AddIfUnique(facebookPermission); } } var accessToken = this.GetFacebookAccessToken(); while (accessToken.IsDone == false) { yield return(default(LoginResult)); } var facebookLoginRequest = new LoginWithFacebookRequest { AccessToken = accessToken.Value, CreateAccount = createAccount, InfoRequestParameters = this.GetCombinedInfoRequest(combinedInfoParams), }; var facebookLogin = PF.Do <LoginWithFacebookRequest, LoginResult>(facebookLoginRequest, PlayFabClientAPI.LoginWithFacebook); while (facebookLogin.IsDone == false) { yield return(default(LoginResult)); } yield return(facebookLogin.Value); #endif }
public UnityTask <ListUsersCharactersResult> GetUserCharacters() { return(PF.Do <ListUsersCharactersRequest, ListUsersCharactersResult>(new ListUsersCharactersRequest(), PlayFabClientAPI.GetAllUsersCharacters)); }
private IEnumerator RefreshLeaderboardCoroutine(int?startPosition) { // Setting any profile constraints this.profileContraints.ShowDisplayName = true; this.profileContraints.ShowAvatarUrl = this.shouldShowAvatarUrl; if (startPosition.HasValue == false) { this.moreBottomEntriesExist = true; this.moreTopEntiresExist = true; } if (this.isFriendLeaderboard) { if (this.isCenteredAroundPlayer && startPosition.HasValue == false) { var leaderboard = PF.Do(new GetFriendLeaderboardAroundPlayerRequest { IncludeFacebookFriends = this.includeFacebookFriends, IncludeSteamFriends = this.includeSteamFriends, MaxResultsCount = this.maxResultsCount, StatisticName = this.leaderboardName, ProfileConstraints = this.profileContraints, }); yield return(leaderboard); this.AppendLeaderboardResults(leaderboard, leaderboard.HasError == false ? leaderboard.Value.Leaderboard : null); } else { var leaderboard = PF.Do(new GetFriendLeaderboardRequest { IncludeFacebookFriends = this.includeFacebookFriends, IncludeSteamFriends = this.includeSteamFriends, MaxResultsCount = this.maxResultsCount, StatisticName = this.leaderboardName, StartPosition = startPosition.HasValue ? startPosition.Value : 0, ProfileConstraints = this.profileContraints, }); yield return(leaderboard); this.AppendLeaderboardResults(leaderboard, leaderboard.HasError == false ? leaderboard.Value.Leaderboard : null); } } else { if (this.isCenteredAroundPlayer && startPosition.HasValue == false) { var leaderboard = PF.Do(new GetLeaderboardAroundPlayerRequest { MaxResultsCount = this.maxResultsCount, StatisticName = this.leaderboardName, ProfileConstraints = this.profileContraints, }); yield return(leaderboard); this.AppendLeaderboardResults(leaderboard, leaderboard.HasError == false ? leaderboard.Value.Leaderboard : null); } else { var leaderboard = PF.Do(new GetLeaderboardRequest { MaxResultsCount = this.maxResultsCount, StatisticName = this.leaderboardName, StartPosition = startPosition.HasValue ? startPosition.Value : 0, ProfileConstraints = this.profileContraints, }); yield return(leaderboard); this.AppendLeaderboardResults(leaderboard, leaderboard.HasError == false ? leaderboard.Value.Leaderboard : null); } } // Testing is we should put the current player in the center of the leaderboard if (startPosition.HasValue == false && this.isCenteredAroundPlayer) { for (int i = 0; i < this.entries.Count; i++) { if (this.entries[i].PlayFabId == PF.User.PlayFabId) { this.CenterOnIndex(i); } } } }
private IEnumerator <bool> RegisterForIosPushNotificationsCoroutine() { var notifications = UnityEngine.iOS.NotificationType.Alert | UnityEngine.iOS.NotificationType.Badge | UnityEngine.iOS.NotificationType.Sound; UnityEngine.iOS.NotificationServices.RegisterForNotifications(notifications, true); int retryCount = 0; while (this.deviceToken == null) { if (this.deviceToken == null && UnityEngine.iOS.NotificationServices.deviceToken != null) { this.deviceToken = System.BitConverter.ToString(UnityEngine.iOS.NotificationServices.deviceToken).Replace("-", "").ToLower(); } retryCount++; if (retryCount >= RetryCountMax) { yield break; } // Waiting before we retry again... float waitTime = 0.0f; while (waitTime < RetryWaitTime) { yield return(default(bool)); waitTime += UnityEngine.Time.deltaTime; } } // if we got here and still no deviceToken, then we timed out if (this.deviceToken == null) { UnityEngine.Debug.LogError("PlayFabIOSPushHandler timed out waiting for the deviceToken."); // cleaning up this iOS push notification handler so it doesn't take up any cycles yield break; } string registeredUser = LostPlayerPrefs.GetString(HasRegisteredUserForPushNotificationsKey, null); // Checking if we're already successfully registed this user with PlayFab for push notifications if (registeredUser == PF.User.PlayFabId) { CoroutineRunner.Instance.StartCoroutine(this.CheckForIosPushNotificationsCoroutine()); yield return(true); yield break; } var register = PF.Do(new PlayFab.ClientModels.RegisterForIOSPushNotificationRequest { DeviceToken = this.deviceToken }); while (register.IsDone == false) { yield return(default(bool)); } if (register.HasError) { var playfabError = register.Exception as PlayFabException; if (playfabError != null) { UnityEngine.Debug.Log("Error Registering for iOS Push Notifications!"); UnityEngine.Debug.Log(playfabError.Error.Error); UnityEngine.Debug.Log(playfabError.Error.ErrorMessage); UnityEngine.Debug.Log(playfabError.Error.ErrorDetails); } } else { // Saving that we've registed this user for PushNotifications with PlayFab successfully LostPlayerPrefs.GetString(HasRegisteredUserForPushNotificationsKey, PF.User.PlayFabId); CoroutineRunner.Instance.StartCoroutine(this.CheckForIosPushNotificationsCoroutine()); UnityEngine.Debug.Log("Push Notification Registration Successful!"); yield return(true); } }
public UnityTask <GetUserInventoryResult> RefreshVirtualCurrency() { return(PF.Do(new GetUserInventoryRequest())); }
public UnityTask <UnlinkFacebookAccountResult> UnlinkFacebook() { return(PF.Do <UnlinkFacebookAccountRequest, UnlinkFacebookAccountResult>(new UnlinkFacebookAccountRequest(), PlayFabClientAPI.UnlinkFacebookAccount)); }
private IEnumerator <bool> ProcessPurchaseCoroutine(PurchaseEventArgs e, string storeId) { var catalogItem = PF.Catalog.GetCatalogItem(e.purchasedProduct.definition.id); Debug.AssertFormat(catalogItem != null, "Couln't find CatalogItem {0}", e.purchasedProduct.definition.id); Debug.AssertFormat(e.purchasedProduct.hasReceipt, "Purchased item {0} doesn't have a receipt", e.purchasedProduct.definition.id); var receipt = (Dictionary <string, object>)Lost.AppConfig.MiniJSON.Json.Deserialize(e.purchasedProduct.receipt); Debug.AssertFormat(receipt != null, "Unable to parse receipt {0}", e.purchasedProduct.receipt); var store = (string)receipt["Store"]; var transactionId = (string)receipt["TransactionID"]; var payload = (string)receipt["Payload"]; Debug.AssertFormat(string.IsNullOrEmpty(store) == false, "Unable to parse store from {0}", e.purchasedProduct.receipt); Debug.AssertFormat(string.IsNullOrEmpty(transactionId) == false, "Unable to parse transactionID from {0}", e.purchasedProduct.receipt); Debug.AssertFormat(string.IsNullOrEmpty(payload) == false, "Unable to parse payload from {0}", e.purchasedProduct.receipt); var currencyCode = e.purchasedProduct.metadata.isoCurrencyCode; var purchasePrice = this.GetPurchasePrice(e); bool wasSuccessfull = false; if (Platform.CurrentDevicePlatform == DevicePlatform.iOS) { var validate = PF.Do(new ValidateIOSReceiptRequest() { CurrencyCode = currencyCode, PurchasePrice = purchasePrice, ReceiptData = payload, }); while (validate.IsDone == false) { yield return(default(bool)); } if (validate.HasError) { Debug.LogErrorFormat("Unable to validate iOS IAP Purchase: {0}", validate?.Exception?.ToString()); this.LogErrorReceiptFailedInfo(catalogItem, e); Debug.LogErrorFormat("ReceiptData = " + payload); PlayFabMessages.HandleError(validate.Exception); } else { wasSuccessfull = true; } } else if (Platform.CurrentDevicePlatform == DevicePlatform.Android) { var details = (Dictionary <string, object>)Lost.AppConfig.MiniJSON.Json.Deserialize(payload); Debug.AssertFormat(details != null, "Unable to parse Receipt Payload {0}", payload); Debug.AssertFormat(details.ContainsKey("json"), "Receipt Payload doesn't have \"json\" key: {0}", payload); Debug.AssertFormat(details.ContainsKey("signature"), "Receipt Payload doesn't have \"signature\" key: {0}", payload); var receiptJson = (string)details["json"]; var signature = (string)details["signature"]; var validate = PF.Do(new ValidateGooglePlayPurchaseRequest() { CurrencyCode = currencyCode, PurchasePrice = (uint)purchasePrice, ReceiptJson = receiptJson, Signature = signature, }); while (validate.IsDone == false) { yield return(default(bool)); } if (validate.HasError) { Debug.LogErrorFormat("Unable to validate Google Play IAP Purchase: {0}", validate?.Exception?.ToString()); this.LogErrorReceiptFailedInfo(catalogItem, e); Debug.LogErrorFormat("Receipt Json = " + receiptJson); Debug.LogErrorFormat("Signature = " + signature); PlayFabMessages.HandleError(validate.Exception); } else { wasSuccessfull = true; } } else { Debug.LogErrorFormat("Tried to make IAP Purchase on Unknown Platform {0}", Application.platform.ToString()); } if (wasSuccessfull == false) { yield break; } float price = catalogItem.GetVirtualCurrenyPrice("RM") / 100.0f; string itemId = e.purchasedProduct.definition.id; string itemType = catalogItem.ItemClass; string level = SceneManager.GetActiveScene().name; Analytics.AnalyticsEvent.IAPTransaction(storeId, price, itemId, itemType, level, transactionId, new Dictionary <string, object> { { "localized_price", e.purchasedProduct.metadata.localizedPrice }, { "iso_currency_code", e.purchasedProduct.metadata.isoCurrencyCode }, { "store", store }, }); PF.Inventory.InvalidateUserInventory(); yield return(true); }