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);
Exemplo n.º 2
0
        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 <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
 }
Exemplo n.º 4
0
 public UnityTask <List <CatalogItem> > GetCatalog()
 {
     if (this.cachedCatalog != null)
     {
         return(UnityTask <List <CatalogItem> > .Run(this.GetCachedCatalog()));
     }
     else
     {
         return(UnityTask <List <CatalogItem> > .Run(this.FetchCatalog()));
     }
 }
Exemplo n.º 5
0
        public static UnityTask <OkResult> HandleError(System.Exception exception)
        {
            UnityTask <OkResult> result = null;

            #if USING_UNITY_PURCHASING && !UNITY_XBOXONE
            result = result ?? HandlePurchasingError(exception as PurchasingException);
            result = result ?? HandlePurchasingInitializationError(exception as PurchasingInitializationException);
            result = result ?? HandlePurchasingInitializationTimeOutError(exception as PurchasingInitializationTimeOutException);
            #endif

            return(result ?? HandlePlayFabError(exception as PlayFabException));
        }
Exemplo n.º 6
0
        public void Release()
        {
            if (this.operation.IsValid() == false)
            {
                Debug.LogWarning("Cannot release a null or unloaded asset.");
                return;
            }

            Addressables.Release(this.operation);
            this.operation  = default(AsyncOperationHandle);
            this.cachedTask = null;
        }
Exemplo n.º 7
0
        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)));
            }
        }
Exemplo n.º 8
0
        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);
            }
        }
Exemplo n.º 9
0
 public UnityTask <LoginResult> LoginWithFacebook(bool createAccount, GetPlayerCombinedInfoRequestParams combinedInfoParams)
 {
     return(UnityTask <LoginResult> .Run(this.LoginWithFacebookCoroutine(createAccount, combinedInfoParams, null)));
 }
Exemplo n.º 10
0
 public UnityTask <LoginResult> LoginWithFacebook(bool createAccount, GetPlayerCombinedInfoRequestParams combinedInfoParams, List <string> facebookPermissions)
 {
     return(UnityTask <LoginResult> .Run(this.LoginWithFacebookCoroutine(createAccount, combinedInfoParams, facebookPermissions)));
 }
Exemplo n.º 11
0
 public UnityTask <LoginResult> LoginWithFacebook(bool createAccount)
 {
     return(UnityTask <LoginResult> .Run(this.LoginWithFacebookCoroutine(createAccount, null, null)));
 }
Exemplo n.º 12
0
 public UnityTask <LoginResult> LoginWithFacebook(bool createAccount, List <string> facebookPermissions)
 {
     return(UnityTask <LoginResult> .Run(this.LoginWithFacebookCoroutine(createAccount, null, facebookPermissions)));
 }
Exemplo n.º 13
0
 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)));
 }
Exemplo n.º 14
0
 public UnityTask <PlayFabResultCommon> UnlinkDeviceId(string deviceId)
 {
     return(UnityTask <PlayFabResultCommon> .Run(UnlinkDeviceIdIterator(deviceId)));
 }
Exemplo n.º 15
0
 public UnityTask <YesNoResult> ShowYesNo(string title, string body)
 {
     return(UnityTask <YesNoResult> .Run(this.ShowYesNoInternal(title, body)));
 }
Exemplo n.º 16
0
 public UnityTask <bool> Initialize()
 {
     return(UnityTask <bool> .Run(this.InitializeCoroutine()));
 }
Exemplo n.º 17
0
        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);
            }
        }
Exemplo n.º 18
0
 public UnityTask <bool> PurchaseStoreItem(string storeId, StoreItem storeItem, Action showStore = null)
 {
     return(UnityTask <bool> .Run(this.PurchaseStoreItemInternal(storeId, storeItem, showStore)));
 }
Exemplo n.º 19
0
 public UnityTask <bool> ChangeDisplayName(string newDisplayName)
 {
     return(UnityTask <bool> .Run(this.ChangeDisplayNameCoroutine(newDisplayName)));
 }
Exemplo n.º 20
0
        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.");
                }
            }
        }
Exemplo n.º 21
0
        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)));
        }
Exemplo n.º 22
0
 public UnityTask <LinkFacebookAccountResult> LinkFacebook()
 {
     return(UnityTask <LinkFacebookAccountResult> .Run(this.LinkFacebookCoroutine()));
 }
Exemplo n.º 23
0
 public UnityTask <LeftRightResult> Show(string title, string body, string leftButtonText, string rightButtonText)
 {
     return(UnityTask <LeftRightResult> .Run(this.ShowInternal(title, body, leftButtonText, rightButtonText)));
 }
Exemplo n.º 24
0
 private UnityTask <string> GetFacebookAccessToken()
 {
     return(UnityTask <string> .Run(this.GetFacebookAccessTokenCoroutine()));
 }
Exemplo n.º 25
0
        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);
            }
        }
Exemplo n.º 26
0
 public UnityTask <bool> ChangeDisplayNameWithPopup()
 {
     return(UnityTask <bool> .Run(this.ChangeDisplayNameWithPopupCoroutine()));
 }
Exemplo n.º 27
0
        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);
            }
        }
Exemplo n.º 28
0
 public UnityTask <OkResult> ShowOk(string title, string body)
 {
     return(UnityTask <OkResult> .Run(this.ShowOkInternal(title, body)));
 }
Exemplo n.º 29
0
        public T GetCloudScrtipResult <T>(UnityTask <ExecuteCloudScriptResult> result)
        {
            string functionResult = result.Value.FunctionResult != null?result.Value.FunctionResult.ToString() : null;

            return(PF.SerializerPlugin.DeserializeObject <T>(functionResult));
        }