Пример #1
0
    private float GetPrice(IapManager.InAppPurchaseItemType item)
    {
        if (!Singleton <IapManager> .IsInstantiated() || !Singleton <IapManager> .Instance.ReadyForTransaction)
        {
            return(0f);
        }
        string prodId = Singleton <IapManager> .Instance.GetProductIdByItem(item);

        if (!string.IsNullOrEmpty(prodId))
        {
            IAPProductInfo iapproductInfo = null;
            foreach (IAPProductInfo x in Singleton <IapManager> .Instance.ProductList)
            {
                if (x.productId == prodId)
                {
                    iapproductInfo = x;
                    break;
                }
            }
            if (iapproductInfo == null)
            {
                return(0f);
            }
            string s = (!string.IsNullOrEmpty(iapproductInfo.unformattedPrice)) ? iapproductInfo.unformattedPrice : iapproductInfo.formattedPrice;
            try
            {
                return(float.Parse(s));
            }
            catch
            {
                return(0f);
            }
        }
        return(0f);
    }
Пример #2
0
    private void OnProductListReceived(List <IAPProductInfo> products, string error)
    {
        if (products != null && products.Count > 0)
        {
            string prodId = Singleton <IapManager> .Instance.GetProductIdByItem(this.m_purchaseType);

            IAPProductInfo iapproductInfo = null;
            foreach (IAPProductInfo x in Singleton <IapManager> .Instance.ProductList)
            {
                if (x.productId == prodId)
                {
                    iapproductInfo = x;
                    break;
                }
            }
            if (iapproductInfo != null && string.IsNullOrEmpty(iapproductInfo.formattedPrice))
            {
                this.SetPriceIndicator(Shop.PriceIndicator.Price, iapproductInfo.formattedPrice);
            }
            else
            {
                this.SetPriceIndicator(Shop.PriceIndicator.NotConnected, null);
            }
        }
        else
        {
            this.SetPriceIndicator(Shop.PriceIndicator.NotConnected, null);
        }
    }
Пример #3
0
    private void OnEnable()
    {
        if (!Singleton <IapManager> .IsInstantiated())
        {
            this.SetPriceIndicator(Shop.PriceIndicator.NotConnected, null);
        }
        else if (Singleton <IapManager> .Instance.IsItemPurchased(this.m_purchaseType))
        {
            this.SetPriceIndicator(Shop.PriceIndicator.Purchased, null);
        }
        else if (Singleton <IapManager> .Instance.ProductList == null)
        {
            this.FetchProductInfo();
        }
        else
        {
            string prodId = Singleton <IapManager> .Instance.GetProductIdByItem(this.m_purchaseType);

            IAPProductInfo iapproductInfo = null;
            if (!string.IsNullOrEmpty(prodId))
            {
                foreach (IAPProductInfo x in Singleton <IapManager> .Instance.ProductList)
                {
                    if (x.productId == prodId)
                    {
                        iapproductInfo = x;
                        break;
                    }
                }
            }
            if (Singleton <IapManager> .Instance.IsItemPurchased(this.m_purchaseType))
            {
                this.SetPriceIndicator(Shop.PriceIndicator.Purchased, null);
            }
            else if (iapproductInfo != null && !string.IsNullOrEmpty(iapproductInfo.formattedPrice))
            {
                this.SetPriceIndicator(Shop.PriceIndicator.Price, iapproductInfo.formattedPrice);
            }
            else
            {
                this.SetPriceIndicator(Shop.PriceIndicator.NotConnected, null);
            }
        }
        IapManager.onPurchaseSucceeded += this.UnlockScreen;
        IapManager.onPurchaseFailed    += this.UnlockScreen;
    }
Пример #4
0
    private string GetFormattedPrice()
    {
        if (Singleton <IapManager> .Instance.ProductList != null)
        {
            string prodId = Singleton <IapManager> .Instance.GetProductIdByItem(this.m_purchaseType);

            if (!string.IsNullOrEmpty(prodId))
            {
                IAPProductInfo iapproductInfo = null;
                foreach (IAPProductInfo x in Singleton <IapManager> .Instance.ProductList)
                {
                    if (x.productId == prodId)
                    {
                        iapproductInfo = x;
                        break;
                    }
                }
                return((iapproductInfo == null || iapproductInfo.formattedPrice == null) ? null : Singleton <IapManager> .Instance.PreparePrice(iapproductInfo.formattedPrice));
            }
        }
        return(null);
    }