Ejemplo n.º 1
0
    //
    // --- IStoreListener
    //
    public void OnInitialized(IStoreController controller, IExtensionProvider extensions)
    {
        //WarnDialog.showWarnDialog("OnInitialized: PASS");
        // Purchasing has succeeded initializing. Collect our Purchasing references.
        Debug.Log("OnInitialized: PASS");

        // Overall Purchasing system, configured with products for this application.
        m_StoreController = controller;
        productInfos      = new Dictionary <int, ProductInfo>();

        //把产品的价格显示在界面
        foreach (Product product in controller.products.all)
        {
            ProductInfo productInfo = new ProductInfo();
            productInfo.id          = int.Parse(product.definition.id);
            productInfo.storeId     = product.definition.storeSpecificId;
            productInfo.price       = product.metadata.localizedPrice;
            productInfo.priceString = product.metadata.localizedPriceString;
            productInfo.available   = product.availableToPurchase;
            productInfos.Add(productInfo.id, productInfo);

            if (productInfo.id == 1)
            {
                oneDollarToPrice = product.metadata.localizedPrice;

                currency = product.metadata.localizedPriceString.Replace(product.metadata.localizedPrice.ToString(), "|").Split('|')[0];
            }
            //product.
            //string log = "product.availableToPurchase:"+product.availableToPurchase+","+product.definition.
            Debug.Log("product.availableToPurchase:" + product.availableToPurchase);
            Debug.Log("product.definition.enabled:" + product.definition.enabled);
            Debug.Log("product.definition.id:" + product.definition.id);
            Debug.Log("product.definition.storeSpecificId:" + product.definition.storeSpecificId);
            Debug.Log("product.definition.type:" + product.definition.type);
            Debug.Log("product.hasReceipt:" + product.hasReceipt);
            Debug.Log("roduct.metadata.isoCurrencyCode:" + product.metadata.isoCurrencyCode);
            Debug.Log("product.metadata.localizedDescription:" + product.metadata.localizedDescription);
            Debug.Log("product.metadata.localizedPrice:" + product.metadata.localizedPrice);
            Debug.Log("product.metadata.localizedPriceString:" + product.metadata.localizedPriceString);
            Debug.Log("product.metadata.localizedTitle:" + product.metadata.localizedTitle);
            Debug.Log("product.receipt:" + product.receipt);
            Debug.Log("product.transactionID:" + product.transactionID);
        }

        // Store specific subsystem, for accessing device-specific store features.
        m_StoreExtensionProvider = extensions;

        initCallBack.Invoke(true);
    }
Ejemplo n.º 2
0
    public void InitializePurchasing(InitCallBack initCallBack, Dictionary <int, string> products)
    {
        // If we have already connected to Purchasing ...
        if (IsInitialized())
        {
            // ... we are done here.
            initCallBack.Invoke(true);
            return;
        }
        this.initCallBack = initCallBack;
        // Create a builder, first passing in a suite of Unity provided stores.
        var builder = ConfigurationBuilder.Instance(StandardPurchasingModule.Instance());

        //添加商品ID和类型 对应定义的商品ID

        foreach (KeyValuePair <int, string> kv in products)
        {
            builder.AddProduct(kv.Key.ToString(), ProductType.Consumable, new IDs
            {
                { kv.Value, GooglePlay.Name }
            });
        }


        //builder.AddProduct(product_1, ProductType.Consumable, new IDs
        //    {
        //    {"s_1", GooglePlay.Name }
        //    });
        //builder.AddProduct(product_2, ProductType.Consumable, new IDs
        //    {
        //    {"s_2", GooglePlay.Name }
        //    });
        //builder.AddProduct(product_3, ProductType.Consumable, new IDs
        //    {
        //    {"s_3", GooglePlay.Name }
        //    });
        //builder.AddProduct(product_6, ProductType.Consumable, new IDs
        //{
        //{"s_6", GooglePlay.Name }
        //});


        // Kick off the remainder of the set-up with an asynchrounous call, passing the configuration
        // and this class' instance. Expect a response either in OnInitialized or OnInitializeFailed.
        //WarnDialog.showWarnDialog("Initialize before");
        UnityPurchasing.Initialize(this, builder);
        //UnityPurchasing.I

        //WarnDialog.showWarnDialog("Initialize end");
    }