Ejemplo n.º 1
0
    private void OnClick()
    {
        switch (buttonType)
        {
        case WatchAdsButtonType.RewardCurrency:
            MonetizationManager.ShowRewardedAd(OnShowAdResult);
            break;

        default:
            MonetizationManager.ShowAd(adsPlacement, OnShowAdResult);
            break;
        }
    }
Ejemplo n.º 2
0
    public void WatchAdsRespawn()
    {
        var character = BaseNetworkGameCharacter.Local as CharacterEntity;

        if (character == null)
        {
            return;
        }

        if (character.watchAdsCount >= GameplayManager.Singleton.watchAdsRespawnAvailable)
        {
            character.CmdRespawn(false);
            return;
        }
        MonetizationManager.ShowAd(GameInstance.Singleton.watchAdsRespawnPlacement, OnWatchAdsRespawnResult);
    }
Ejemplo n.º 3
0
    void Start()
    {
        if (!ins)
        {
            ins = this;
            DontDestroyOnLoad(this);
        }
        else
        {
            Destroy(this);
        }

#if UNITY_ANDROID
        continueAdId = !testMode ? "ca-app-pub-5324115406353383/8922305346" : "ca-app-pub-3940256099942544/5224354917";
#elif UNITY_IOS
        continueAdId = "ca-app-pub-3940256099942544/1712485313";
#else
        continueAdId = "unexpected_platform";
#endif

        MobileAds.Initialize(initStatus => { });

        continueAd = CreateRewardedAd(continueAdId);
    }
Ejemplo n.º 4
0
 private void Update()
 {
     button.interactable = MonetizationManager.IsAdsReady(AdsPlacement);
 }
    private static PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs e)
    {
        // NOTE: this code does not account for purchases that were pending and are
        // delivered on application start.
        // Production code should account for such case:
        // More: https://docs.unity3d.com/ScriptReference/Purchasing.PurchaseProcessingResult.Pending.html

        if (!MonetizationManager.IsPurchasingInitialized())
        {
            return(PurchaseProcessingResult.Complete);
        }

        // Test edge case where product is unknown
        if (e.purchasedProduct == null)
        {
            Debug.LogWarning("Attempted to process purchasewith unknown product. Ignoring");
            return(PurchaseProcessingResult.Complete);
        }

        // Test edge case where purchase has no receipt
        if (string.IsNullOrEmpty(e.purchasedProduct.receipt))
        {
            Debug.LogWarning("Attempted to process purchase with no receipt: ignoring");
            return(PurchaseProcessingResult.Complete);
        }

        Debug.Log("Processing transaction: " + e.purchasedProduct.transactionID);

        // Deserialize receipt
        var receipt = PurchaseReceipts.FromJson(e.purchasedProduct.receipt);

        if (receipt.Store.Equals("GooglePlay"))
        {
            var payload = GooglePayloadData.FromJson(receipt.Payload);
            PlayFabClientAPI.ValidateGooglePlayPurchase(new ValidateGooglePlayPurchaseRequest()
            {
                // Pass in currency code in ISO format
                CurrencyCode = e.purchasedProduct.metadata.isoCurrencyCode,
                // Convert and set Purchase price
                PurchasePrice = (uint)(e.purchasedProduct.metadata.localizedPrice * 100),
                // Pass in the receipt
                ReceiptJson = payload.json,
                // Pass in the signature
                Signature = payload.signature
            }, result => Debug.Log("Validation successful!"),
                                                        error => Debug.LogError("Validation failed: " + error.GenerateErrorReport())
                                                        );
        }
        else if (receipt.Store.Equals("AppleAppStore"))
        {
            PlayFabClientAPI.ValidateIOSReceipt(new ValidateIOSReceiptRequest()
            {
                // Pass in currency code in ISO format
                CurrencyCode = e.purchasedProduct.metadata.isoCurrencyCode,
                // Convert and set Purchase price
                PurchasePrice = (int)(e.purchasedProduct.metadata.localizedPrice * 100),
                // Pass in payload
                ReceiptData = receipt.Payload
            }, result => Debug.Log("Validation successful!"),
                                                error => Debug.LogError("Validation failed: " + error.GenerateErrorReport())
                                                );
        }

        return(PurchaseProcessingResult.Complete);
    }