コード例 #1
0
ファイル: Purchaser.cs プロジェクト: k0j1/UnityScript
    public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs args)
    {
        //@Angelo: here is the result of a successful purchase of a consumable (100 coins, in our case), in the Editor once you press the "Buy" button you'll immediately see the
        //"ProcessPurchase: PASS" message on the Console. On a device you would see the OS pop-up confirming the purchase
        // A consumable product has been purchased by this user.
        // 消費型の購入が成功した結果でここにくる。
        // エディタでは、「Buy」と押すと、すぐにコンソールに「ProcessPurchase: PASS」と表示される。
        // 本来デバイスでは、ポップアップで購入確認ウィンドウが出る。
        if (String.Equals(args.purchasedProduct.definition.id, kProductIDConsumable, StringComparison.Ordinal))
        {
            Debug.Log(string.Format("ProcessPurchase: PASS. Product: '{0}'", args.purchasedProduct.definition.id));            //If the consumable item has been successfully purchased, add 100 coins to the player's in-game score.ScoreManager.score += 100;
            // ここに消費アイテムを買った時の処理を入れる
            // TODO:
            // ポイント加算
            string receipt = getReceiptPayload(args.purchasedProduct.receipt);
            if (string.IsNullOrEmpty(receipt))
            {
                // 不正?想定外?
            }
            else
            {
                // (ここで付与)

                // ポイント表示
                //Text strPointText = GameObject.Find("MyPoints").GetComponent<Text>();
                if (!m_Ads)
                {
                    Debug.Log("m_Ads = null");
                    m_Ads = GameObject.Find("UnityAds").GetComponent <UnityAds>();
                }
                if (m_Ads)
                {
                    // 1000ptを獲得
                    SettingManager.SaveGameTotalPoint(m_nPurGetPoint);
                    Debug.Log("ポイント購入 +1000pt テキスト更新");
                    m_Ads.DispPoint();
                }
            }
        }

        //@Angelo: Same here for a non-consumable (in our chase, the old lady character)
        // Or ... a non-consumable product has been purchased by this user.
        // ここも非消費型での同じ感じ
        else if (String.Equals(args.purchasedProduct.definition.id, kProductIDNonConsumable, StringComparison.Ordinal))
        {
            Debug.Log(string.Format("ProcessPurchase: PASS. Product: '{0}'", args.purchasedProduct.definition.id));
            // ここに非消費アイテムを買った時の処理を入れる
            // TODO:
        }        // Or ... a subscription product has been purchased by this user.
        else if (String.Equals(args.purchasedProduct.definition.id, kProductIDSubscription, StringComparison.Ordinal))
        {
            Debug.Log(string.Format("ProcessPurchase: PASS. Product: '{0}'", args.purchasedProduct.definition.id));
        }        // Or ... an unknown product has been purchased by this user. Fill in additional products here.
        else
        {
            Debug.Log(string.Format("ProcessPurchase: FAIL. Unrecognized product: '{0}'", args.purchasedProduct.definition.id));
        }        // Return a flag indicating wither this product has completely been received, or if the application needs to be reminded of this purchase at next app launch. Is useful when saving purchased products to the cloud, and when that save is delayed.
        return(PurchaseProcessingResult.Complete);
    }