public UnityTask <int> GetInventoryCount(string itemId) { return(UnityTask <int> .Run(GetInventoryCountCoroutine())); IEnumerator <int> GetInventoryCountCoroutine() { var inventory = this.GetInventoryItems(); while (inventory.IsDone == false) { yield return(default(int)); } List <ItemInstance> items = inventory.Value; int count = 0; for (int i = 0; i < items.Count; i++) { if (items[i].ItemId == itemId) { int?remainingUses = items[i].RemainingUses; if (remainingUses.HasValue) { count += remainingUses.Value; } } } yield return(count); } }
public UnityTask <T> Load() { #if UNITY_EDITOR if (typeof(T).IsSubclassOf(typeof(Component)) || typeof(T) == typeof(GameObject)) { Debug.LogWarningFormat("You are loading LastAsset<{0}> as if it were a resource, you should instead use Instantiate instead of Load.", typeof(T).Name); } #endif if (this.cachedTask != null) { return(this.cachedTask); } else { return(UnityTask <T> .Run(Coroutine())); } IEnumerator <T> Coroutine() { if (typeof(T) == typeof(Sprite)) { this.operation = UnityEngine.AddressableAssets.Addressables.LoadAssetAsync <Sprite>(this.RuntimeKey); } else { this.operation = UnityEngine.AddressableAssets.Addressables.LoadAssetAsync <UnityEngine.Object>(this.RuntimeKey); } while (this.operation.IsDone == false && this.operation.Status != AsyncOperationStatus.Failed) { yield return(default);
public UnityTask <bool> RegisterForPushNotifications() { #if UNITY_ANDROID && USING_ANDROID_FIREBASE_MESSAGING return(UnityTask <bool> .Run(this.RegisterForAndroidPushNotificationsCoroutine())); #elif UNITY_IOS return(UnityTask <bool> .Run(this.RegisterForIosPushNotificationsCoroutine())); #else return(UnityTask <bool> .Run(this.UnsupportedPlatfromCoroutine())); #endif }
public UnityTask <List <CatalogItem> > GetCatalog() { if (this.cachedCatalog != null) { return(UnityTask <List <CatalogItem> > .Run(this.GetCachedCatalog())); } else { return(UnityTask <List <CatalogItem> > .Run(this.FetchCatalog())); } }
public UnityTask <List <StoreItem> > GetStore(string storeId, bool forceRefresh = false) { if (forceRefresh) { this.cachedStores.Remove(storeId); } if (this.cachedStores.ContainsKey(storeId)) { return(UnityTask <List <StoreItem> > .Run(this.GetCachedStore(storeId))); } else { return(UnityTask <List <StoreItem> > .Run(this.FetchStore(storeId))); } }
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); } }
public static UnityTask <Result> Do <Request, Result>(Request request, Action <Request, Action <Result>, Action <PlayFabError>, object, Dictionary <string, string> > playfabFunction) where Request : class where Result : class { return(UnityTask <Result> .Run(DoIterator(request, playfabFunction))); }
public UnityTask <LeftRightResult> Show(string title, string body, string leftButtonText, string rightButtonText) { return(UnityTask <LeftRightResult> .Run(this.ShowInternal(title, body, leftButtonText, rightButtonText))); }
private IEnumerator <bool> PurchaseStoreItemInternal(string storeId, StoreItem storeItem, Action showStore) { bool isIapItem = storeItem.GetVirtualCurrenyPrice("RM") > 0; if (isIapItem) { #if USING_UNITY_PURCHASING && !UNITY_XBOXONE // Making sure we're properly initialized if (this.IsInitialized == false) { var initialize = this.Initialize(); while (initialize.IsDone == false) { yield return(default(bool)); } // Early out if initialization failed if (initialize.HasError || this.IsInitialized == false) { if (initialize.HasError) { PlayFabMessages.HandleError(initialize.Exception); } yield return(false); yield break; } } var iapPurchaseItem = Lost.IAP.UnityPurchasingManager.Instance.PurchaseProduct(storeItem.ItemId); while (iapPurchaseItem.IsDone == false) { yield return(default(bool)); } if (iapPurchaseItem.HasError) { PlayFabMessages.HandleError(iapPurchaseItem.Exception); } else { if (Debug.isDebugBuild || Application.isEditor) { var purchase = UnityTask <bool> .Run(this.DebugPurchaseStoreItem(iapPurchaseItem.Value)); while (purchase.IsDone == false) { yield return(default(bool)); } yield return(purchase.Value); } else { var purchase = UnityTask <bool> .Run(this.ProcessPurchaseCoroutine(iapPurchaseItem.Value, storeId)); while (purchase.IsDone == false) { yield return(default(bool)); } yield return(purchase.Value); } } #else throw new NotImplementedException("Trying to buy IAP Store Item when USING_UNITY_PURCHASING is not defined!"); #endif } else { string virtualCurrency = storeItem.GetVirtualCurrencyId(); int storeItemCost = storeItem.GetCost(virtualCurrency); bool hasSufficientFunds = PF.VC[virtualCurrency] >= storeItemCost; if (hasSufficientFunds == false) { var messageBoxDialog = PlayFabMessages.ShowInsufficientCurrency(); while (messageBoxDialog.IsDone == false) { yield return(default(bool)); } if (messageBoxDialog.Value == YesNoResult.Yes) { showStore?.Invoke(); } yield break; } var coroutine = this.Do(new PurchaseItemRequest { ItemId = storeItem.ItemId, Price = storeItemCost, VirtualCurrency = virtualCurrency, StoreId = storeId, }); while (coroutine.keepWaiting) { yield return(default(bool)); } bool isSuccessful = coroutine.Value != null; if (isSuccessful) { PF.Inventory.InvalidateUserInventory(); } yield return(isSuccessful); } }
public UnityTask <bool> ChangeDisplayNameWithPopup() { return(UnityTask <bool> .Run(this.ChangeDisplayNameWithPopupCoroutine())); }
private UnityTask <string> GetFacebookAccessToken() { return(UnityTask <string> .Run(this.GetFacebookAccessTokenCoroutine())); }
public UnityTask <LoginResult> LoginWithFacebook(bool createAccount, GetPlayerCombinedInfoRequestParams combinedInfoParams, List <string> facebookPermissions) { return(UnityTask <LoginResult> .Run(this.LoginWithFacebookCoroutine(createAccount, combinedInfoParams, facebookPermissions))); }
public UnityTask <LoginResult> LoginWithFacebook(bool createAccount, List <string> facebookPermissions) { return(UnityTask <LoginResult> .Run(this.LoginWithFacebookCoroutine(createAccount, null, facebookPermissions))); }
public UnityTask <PurchaseResult> ShowStoreItem(bool automaticallyPerformPurchase, string storeId, StoreItem storeItem, Sprite icon, string title, string description, Action insufficientFundsStore = null) { this.automaticallyPerformPurchase = automaticallyPerformPurchase; return(UnityTask <PurchaseResult> .Run(Coroutine())); IEnumerator <PurchaseResult> Coroutine() { // resetting the result, and caching the items this.result = PurchaseResult.Cancel; this.storeId = storeId; this.storeItem = storeItem; // Figuring out which currecy this item costs string virtualCurrencyId = null; foreach (var virtualCurrencyPrice in storeItem.VirtualCurrencyPrices) { if (virtualCurrencyPrice.Value > 0) { virtualCurrencyId = virtualCurrencyPrice.Key; } } if (virtualCurrencyId == null) { Debug.LogErrorFormat("StoreItem {0} has unknown currency.", storeItem.ItemId); yield return(PurchaseResult.Cancel); yield break; } bool isIapItem = virtualCurrencyId == "RM"; // Turning on the correct button this.iapBuyButton.gameObject.SafeSetActive(isIapItem); this.virtualCurrencyBuyButton.gameObject.SafeSetActive(!isIapItem); if (isIapItem) { string purchasePrice = string.Empty; #if USING_UNITY_PURCHASING && !UNITY_XBOXONE purchasePrice = IAP.UnityPurchasingManager.Instance.GetLocalizedPrice(storeItem.ItemId); #else purchasePrice = string.Format("${0}.{1:D2}", currencyPrice / 100, currencyPrice % 100); #endif this.iapBuyButtonText.text = purchasePrice; } else { int virtualCurrencyPrice = storeItem.GetVirtualCurrenyPrice(virtualCurrencyId); bool hasSufficientFunds = PF.VC[virtualCurrencyId] >= virtualCurrencyPrice; if (hasSufficientFunds == false && insufficientFundsStore != null) { var insufficientFundsMessage = PlayFabMessages.ShowInsufficientCurrency(); while (insufficientFundsMessage.IsDone == false) { yield return(default(PurchaseResult)); } if (insufficientFundsMessage.Value == YesNoResult.Yes) { insufficientFundsStore.Invoke(); } else { yield return(PurchaseResult.Cancel); yield break; } } this.virtualCurrencyBuyButton.interactable = hasSufficientFunds; this.virtualCurrencyBuyButtonIcon.sprite = this.GetSprite(virtualCurrencyId); this.virtualCurrencyBuyButtonText.text = virtualCurrencyPrice.ToString(); } // Setting the item image/texts this.storeItemIcon.sprite = icon; this.storeItemTitle.text = title; this.storeItemDescription.text = description; this.Dialog.Show(); // waiting for it to start showing while (this.Dialog.IsShowing == false) { yield return(default(PurchaseResult)); } // waiting for it to return to the hidden state while (this.Dialog.IsHidden == false) { yield return(default(PurchaseResult)); } yield return(this.result); } }
public UnityTask <bool> Initialize() { return(UnityTask <bool> .Run(this.InitializeCoroutine())); }
public UnityTask <PlayFabResultCommon> UnlinkDeviceId(string deviceId) { return(UnityTask <PlayFabResultCommon> .Run(UnlinkDeviceIdIterator(deviceId))); }
public UnityTask <LoginResult> LoginWithFacebook(bool createAccount) { return(UnityTask <LoginResult> .Run(this.LoginWithFacebookCoroutine(createAccount, null, null))); }
public UnityTask <StringInputResult> Show(string title, string body, string startingText, int maxCharacterCount = 0) { this.inputField.characterLimit = maxCharacterCount; return(UnityTask <StringInputResult> .Run(this.ShowInternal(title, body, startingText))); }
public UnityTask <LoginResult> LoginWithFacebook(bool createAccount, GetPlayerCombinedInfoRequestParams combinedInfoParams) { return(UnityTask <LoginResult> .Run(this.LoginWithFacebookCoroutine(createAccount, combinedInfoParams, null))); }
public UnityTask <T> Instantiate(Transform parent = null, bool reset = true) { #if UNITY_EDITOR if (typeof(T).IsSubclassOf(typeof(Component)) == false && typeof(T) != typeof(GameObject)) { Debug.LogWarningFormat("You are Instantiating LastAsset<{0}> as if it were a GameObject, you should instead use Load instead of Instantiate.", typeof(T).Name); } #endif return(UnityTask <T> .Run(Coroutine())); IEnumerator <T> Coroutine() { var instantiateOperation = Addressables.InstantiateAsync(this.RuntimeKey, parent); while (instantiateOperation.IsDone == false && instantiateOperation.Status != AsyncOperationStatus.Failed) { yield return(default(T)); } if (instantiateOperation.Status == AsyncOperationStatus.Failed) { Debug.LogErrorFormat("Unable to successfully instantiate asset {0} of type {1}", this.AssetGuid, typeof(T).Name); yield return(default(T)); yield break; } var gameObject = instantiateOperation.Result; if (gameObject != null && reset) { gameObject.transform.Reset(); } if (typeof(T) == typeof(GameObject)) { yield return(gameObject as T); } else if (typeof(T).IsSubclassOf(typeof(Component))) { if (gameObject == null) { Debug.LogErrorFormat("LazyAsset {0} is not of type GameObject, so can't get Component {1} from it.", this.AssetGuid, typeof(T).Name); yield break; } var component = gameObject?.GetComponent <T>(); if (component == null) { Debug.LogErrorFormat("LazyAsset {0} does not have Component {1} on it.", this.AssetGuid, typeof(T).Name); yield break; } yield return(component); } else { Debug.LogError("LazyAssetT hit unknown if/else situtation."); } } }
public UnityTask <LinkFacebookAccountResult> LinkFacebook() { return(UnityTask <LinkFacebookAccountResult> .Run(this.LinkFacebookCoroutine())); }
public UnityTask <T> Load() { #if UNITY_EDITOR if (typeof(T).IsSubclassOf(typeof(Component)) || typeof(T) == typeof(GameObject)) { Debug.LogWarningFormat("You are loading LastAsset<{0}> as if it were a resource, you should instead use Instantiate instead of Load.", typeof(T).Name); } #endif if (this.cachedTask != null) { return(this.cachedTask); } else { return(UnityTask <T> .Run(Coroutine())); } IEnumerator <T> Coroutine() { if (typeof(T) == typeof(Sprite)) { this.operation = Addressables.LoadAssetAsync <Sprite>(this.RuntimeKey); } else { this.operation = Addressables.LoadAssetAsync <UnityEngine.Object>(this.RuntimeKey); } while (this.operation.IsDone == false && this.operation.Status != AsyncOperationStatus.Failed) { yield return(default(T)); } if (this.operation.Status == AsyncOperationStatus.Failed) { Debug.LogErrorFormat("Unable to successfully load asset {0} of type {1}", this.AssetGuid, typeof(T).Name); yield return(default(T)); yield break; } T value; if (typeof(T).IsSubclassOf(typeof(Component))) { var gameObject = operation.Result as GameObject; if (gameObject == null) { Debug.LogErrorFormat("LazyAsset {0} is not of type GameObject, so can't get Component {1} from it.", this.AssetGuid, typeof(T).Name); yield break; } value = gameObject?.GetComponent <T>(); if (value == null) { Debug.LogErrorFormat("LazyAsset {0} does not have Component {1} on it.", this.AssetGuid, typeof(T).Name); yield break; } } else { value = operation.Result as T; if (value == null) { Debug.LogErrorFormat("LazyAsset {0} is not of type {1}.", this.AssetGuid, typeof(T).Name); yield break; } } this.cachedTask = UnityTask <T> .Empty(value); yield return(value); } }
public UnityTask <bool> ChangeDisplayName(string newDisplayName) { return(UnityTask <bool> .Run(this.ChangeDisplayNameCoroutine(newDisplayName))); }
public UnityTask <OkResult> ShowOk(string title, string body) { return(UnityTask <OkResult> .Run(this.ShowOkInternal(title, body))); }
public UnityTask <YesNoResult> ShowYesNo(string title, string body) { return(UnityTask <YesNoResult> .Run(this.ShowYesNoInternal(title, body))); }
public UnityTask <bool> PurchaseStoreItem(string storeId, StoreItem storeItem, Action showStore = null) { return(UnityTask <bool> .Run(this.PurchaseStoreItemInternal(storeId, storeItem, showStore))); }