Пример #1
0
    public void AddShopItem(string productID, bool isConfig = false)//, ProductMetadata meta = null)
    {
        LDebug.Log("========>购买了商品 " + productID);
        //StatisticManager.Instance.DOT( "shop_buy_" + Purchaser.Instance.products.IndexOf( productID ) );

        PurchaserStoreItem result = null;

        //商品购买成功逻辑
        if (ProductsDict.ContainsKey(productID))
        {
            result = ProductsDict[productID];
        }
        else
        {
            var targets = ProductsDict.Where(e => e.Value.AlternativeBuyID == productID);
            if (targets.Count() > 0)
            {
                var target = targets.First();
                result = target.Value;
            }
        }

        if (result != null)
        {
            BuySuccessEvent?.Invoke(result);
        }
    }
Пример #2
0
 //视频完整播放完回调
 private void OnRewardedVideoReceivedRewardEvent(string adUnitId, string label, float amount)
 {
     LDebug.Log("视频完整播放完回调,id:" + adUnitId);
     LDebug.Log("视频完整播放完回调,label:" + label);
     LDebug.Log("视频完整播放完回调,amount:" + amount);
     RewardShowEventHandler?.Invoke(true);
 }
Пример #3
0
    //public void BuyConsumable()
    //{
    //    // Buy the consumable product using its general identifier. Expect a response either
    //    // through ProcessPurchase or OnPurchaseFailed asynchronously.
    //    BuyProductID( kProductIDConsumable );
    //}
    //public void BuyNonConsumable()
    //{
    //    // Buy the non-consumable product using its general identifier. Expect a response either
    //    // through ProcessPurchase or OnPurchaseFailed asynchronously.
    //    BuyProductID( kProductIDNonConsumable );
    //}
    //public void BuySubscription()
    //{
    //    // Buy the subscription product using its the general identifier. Expect a response either
    //    // through ProcessPurchase or OnPurchaseFailed asynchronously.
    //    // Notice how we use the general product identifier in spite of this ID being mapped to
    //    // custom store-specific identifiers above.
    //    BuyProductID( kProductIDSubscription );
    //}


    public void BuyProductID(string productId)
    {
        // If Purchasing has been initialized ...
        if (IsInitialized())
        {
            // ... look up the Product reference with the general product identifier and the Purchasing
            // system's products collection.
            Product product = m_StoreController.products.WithID(productId);

            // If the look up found a product for this device's store and that product is ready to be sold ...
            if (product != null && product.availableToPurchase)
            {
                LDebug.Log(string.Format("Purchasing product asychronously: '{0}'", product.definition.storeSpecificId));
                // ... buy the product. Expect a response either through ProcessPurchase or OnPurchaseFailed
                // asynchronously.
                m_StoreController.InitiatePurchase(product);
            }
            // Otherwise ...
            else
            {
                ProcessPurchaseFailEventHandler?.Invoke(BuyFailReason.ProductError);
                // ... report the product look-up failure situation
                LDebug.Log("BuyProductID: FAIL. Not purchasing product, either is not found or is not available for purchase");
            }
        }
        // Otherwise ...
        else
        {
            ProcessPurchaseFailEventHandler?.Invoke(BuyFailReason.NotInit);
            // ... report the fact Purchasing has not succeeded initializing yet. Consider waiting longer or
            // retrying initiailization.
            LDebug.Log("BuyProductID FAIL. Not initialized.");
        }
    }
Пример #4
0
    // Restore purchases previously made by this customer. Some platforms automatically restore purchases, like Google.
    // Apple currently requires explicit purchase restoration for IAP, conditionally displaying a password prompt.
    public void RestorePurchases()
    {
        // If Purchasing has not yet been set up ...
        if (!IsInitialized())
        {
            // ... report the situation and stop restoring. Consider either waiting longer, or retrying initialization.
            LDebug.Log("RestorePurchases FAIL. Not initialized.");
            return;
        }

        // If we are running on an Apple device ...
        if (Application.platform == RuntimePlatform.IPhonePlayer ||
            Application.platform == RuntimePlatform.OSXPlayer)
        {
            // ... begin restoring purchases
            LDebug.Log("RestorePurchases started ...");

            // Fetch the Apple store-specific subsystem.
            var apple = m_StoreExtensionProvider.GetExtension <IAppleExtensions>();
            // Begin the asynchronous process of restoring purchases. Expect a confirmation response in
            // the Action<bool> below, and ProcessPurchase if there are previously purchased products to restore.
            apple.RestoreTransactions((result) =>
            {
                // The first phase of restoration. If no more responses are received on ProcessPurchase then
                // no purchases are available to be restored.
                LDebug.Log("RestorePurchases continuing: " + result + ". If no further messages, no purchases available to restore.");
            });
        }
        // Otherwise ...
        else
        {
            // We are not running on an Apple device. No work is necessary to restore purchases.
            LDebug.Log("RestorePurchases FAIL. Not supported on this platform. Current = " + Application.platform);
        }
    }
Пример #5
0
        /// <summary>
        /// 同步加载
        /// </summary>
        /// <param name="path">AssetPathManager.Instance.GetStreamAssetDataPath("csv/csvList.csv")</param>
        /// <param name="callBack"></param>
        /// <param name="errorCallBack"></param>
        public static void LoadAsset(string path, Action <UnityWebRequest> callBack, Action <UnityWebRequest> errorCallBack = null)
        {
            Uri uri = new Uri(path);

            LDebug.LogWarning(" >路径: \n AbsoluteUri : " + uri.AbsoluteUri + " \n AbsolutePath: " + uri.AbsolutePath + " \n LocalPath: " + uri.LocalPath);
            using (UnityWebRequest uwr = UnityWebRequest.Get(uri))
            {
                uwr.timeout = 3;
                uwr.disposeUploadHandlerOnDispose      = true;
                uwr.disposeDownloadHandlerOnDispose    = true;
                uwr.disposeCertificateHandlerOnDispose = true;

                uwr.SendWebRequest();

                while (true)
                {
                    if (uwr.isHttpError || uwr.isNetworkError)
                    {
                        LDebug.LogError("  >Error: " + uwr.error + " " + uwr.url);
                        errorCallBack?.Invoke(uwr);
                        return;
                    }
                    else if (uwr.downloadProgress == 1)
                    {
                        LDebug.Log(" >Received: \n" + uwr.downloadHandler.text);
                        callBack?.Invoke(uwr);
                        return;
                    }
                }
            }
        }
Пример #6
0
        /// <summary>
        /// FTP 下载器。同步方法会线程阻塞,用于加载少量文件
        /// </summary>
        /// <param name="ftpIP">FTP服务器IP地址+端口。最后需要带上"/"</param>
        /// <param name="configsNamesList">待加载文件地址,需要带上后缀。例如XXX/Role.csv</param>
        /// <param name="name">FTP服务器登陆用户名</param>
        /// <param name="password">FTP服务器登录密码</param>
        public void DownLoadFromFTP(string ftpIP, string configsPath, string name = null, string password = null)
        {
            var result = FTPDownload(ftpIP + configsPath, userName: name, password: password);

            DocumentAccessor.SaveAsset2LocalFile(AssetPathManager.Instance.GetPersistentDataPath(configsPath, false), result);
            LDebug.Log(">>>" + configsPath + result.Count());
        }
Пример #7
0
    private void InterstitialLoadEventHandler(bool succ)
    {
        InterstitialLoadEvent?.Invoke(succ);
        InterstitialLoadEvent = null;

        LDebug.Log("Interstitial Load Status: " + succ + "! ");
    }
Пример #8
0
 //加载失败
 private void OnRewardedVideoFailedEvent(string adUnitId, string error)
 {
     //MoPub.RequestRewardedVideo(_rewardedVideoAdUnits[0]);
     LDebug.Log("激励视频广告加载失败,id:" + adUnitId);
     LDebug.Log("激励视频广告加载失败,error:" + error);
     RewardShowEventHandler?.Invoke(false);
 }
Пример #9
0
    public override void ShowBanner()
    {
#if IRONSOURCE
        LDebug.Log(">>>>ShowBanner");
        IronSource.Agent.displayBanner();
#endif
    }
Пример #10
0
        private byte[] FTPDownload(string ftpUrl, string savePath = "", string userName = "", string password = "")
        {
            FtpWebRequest request = (FtpWebRequest)WebRequest.Create(new Uri(ftpUrl));

            request.UsePassive = true;
            request.UseBinary  = true;
            request.KeepAlive  = true;

            if (!string.IsNullOrEmpty(userName) && !string.IsNullOrEmpty(password))
            {
                request.Credentials = new NetworkCredential(userName, password);
            }

            request.Method = WebRequestMethods.Ftp.DownloadFile;

            WebResponse webResponse;

            if (!string.IsNullOrEmpty(savePath))
            {
                webResponse = request.GetResponse();
                LDebug.Log("FTP连接状态: " + webResponse);
                DownloadAndSave(webResponse, savePath);
                return(null);
            }
            else
            {
                webResponse = request.GetResponse();
                LDebug.Log("FTP连接状态: " + webResponse);
                return(DownloadAsbyteArray(webResponse));
            }
        }
Пример #11
0
    public void InitializePurchasing()
    {
        // If we have already connected to Purchasing ...
        LDebug.Log("====> If we have already connected to Purchasing ...");
        if (IsInitialized())
        {
            // ... we are done here.
            LDebug.Log("====> ....we are done here.");
            return;
        }

        var productDict = PurchaserDataModel.Instance.ProductsDict;
        // Create a builder, first passing in a suite of Unity provided stores.
        var builder = ConfigurationBuilder.Instance(StandardPurchasingModule.Instance());

        if (Application.platform == RuntimePlatform.IPhonePlayer ||
            Application.platform == RuntimePlatform.OSXPlayer)
        {
            foreach (var product in productDict)
            {
                builder.AddProduct(product.Value.BuyID, ProductType.Consumable, new IDs
                {
                    { product.Value.BuyID, AppleAppStore.Name }
                });

                //Discount Item
                if (!string.IsNullOrEmpty(product.Value.AlternativeBuyID))
                {
                    builder.AddProduct(product.Value.AlternativeBuyID, ProductType.Consumable, new IDs
                    {
                        { product.Value.AlternativeBuyID, AppleAppStore.Name }
                    });
                }
            }
        }
        //Android && PC
        else
        {
            foreach (var product in productDict)
            {
                builder.AddProduct(product.Value.BuyID, ProductType.Consumable, new IDs
                {
                    { product.Value.BuyID, GooglePlay.Name }
                });

                //Discount Item
                if (!string.IsNullOrEmpty(product.Value.AlternativeBuyID))
                {
                    builder.AddProduct(product.Value.AlternativeBuyID, ProductType.Consumable, new IDs
                    {
                        { product.Value.AlternativeBuyID, 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.
        UnityPurchasing.Initialize(this, builder);
    }
Пример #12
0
    private void InterstitialShowEventHandler(bool succ)
    {
        IsAppLeave = false;
        InterstitialPlayEvent?.Invoke(succ);
        InterstitialPlayEvent = null;

        LDebug.Log("Interstitial Show Status: " + succ + "! ");
    }
Пример #13
0
    public override void CreateBanner()
    {
#if IRONSOURCE
        IronSource.Agent.loadBanner(IronSourceBannerSize.BANNER, IronSourceBannerPosition.BOTTOM);
        HideBanner(false);
        LDebug.Log(">>>>CreateBanner");
#endif
    }
Пример #14
0
 //Invoked when the Rewarded Video failed to show
 //@param description - string - contains information about the failure.
 void RewardedVideoAdShowFailedEvent(IronSourceError error)
 {
     LDebug.Log("RewardedVideoAdShowFailedEvent" + "  " + (error != null ? error.getDescription() : "error is null"));
     if (RewardShowEventHandler != null)
     {
         RewardShowEventHandler(false);
     }
 }
Пример #15
0
 //Invoked when the RewardedVideo ad view is about to be closed.
 //Your activity will now regain its focus.
 void RewardedVideoAdClosedEvent()
 {
     LDebug.Log("RewardedVideoAdClosedEvent");
     if (RewardCloseEventHandler != null)
     {
         RewardCloseEventHandler(false);
     }
 }
Пример #16
0
 //Invoked when the ad fails to show.
 //@param description - string - contains information about the failure.
 void InterstitialAdShowFailedEvent(IronSourceError error)
 {
     LDebug.Log("==InterstitialAdShowFailedEvent");
     if (InterstitialShowEventHandler != null)
     {
         InterstitialShowEventHandler(false);
     }
 }
Пример #17
0
 //单击的时候回调
 private void OnInterstitialClickedEvent(string adUnitId)
 {
     LDebug.Log("mopub调试——interstitial单击的时候回调,id:" + adUnitId);
     if (InterstitialShowEventHandler != null)
     {
         InterstitialShowEventHandler(true);
     }
 }
Пример #18
0
 //interstitial读取成功
 private void OnInterstitialLoadedEvent(string adUnitId)
 {
     LDebug.Log("mopub调试——interstitial读取成功");
     if (InterstitialLoadEventHandler != null)
     {
         InterstitialLoadEventHandler(true);
     }
 }
Пример #19
0
        private void InitAppFlyer()
        {
#if APPFLY
            LDebug.Log(">>>AppsFlyer initSDK ");
            AppsFlyer.initSDK("devkey", "appID");
            LDebug.Log(">>>AppsFlyer UNITY_ANDROID initSDK ");
            AppsFlyer.startSDK();
#endif
        }
Пример #20
0
    public override bool IsRewardedVideoAvailable()
    {
#if IRONSOURCE
        LDebug.Log(">>>IsRewardedVideoAvailable  " + IronSource.Agent.isRewardedVideoAvailable());
        return(IronSource.Agent.isRewardedVideoAvailable());
#else
        return(false);
#endif
    }
Пример #21
0
 //关闭激励视频回调
 private void OnRewardedVideoClosedEvent(string adUnitId)
 {
     LDebug.Log("关闭激励视频回调,id:" + adUnitId);
     MoPub.RequestRewardedVideo(_rewardedVideoAdUnits[0]);
     if (RewardCloseEventHandler != null)
     {
         RewardCloseEventHandler(false);
     }
 }
Пример #22
0
 //Invoked when the interstitial ad closed and the user goes back to the application screen.
 void InterstitialAdClosedEvent()
 {
     LDebug.Log("==InterstitialAdClosedEvent");
     if (InterstitialShowEventHandler != null)
     {
         InterstitialShowEventHandler(true);
     }
     CreateInterstitial();
 }
Пример #23
0
        /// <summary>
        /// 反射注册UI回调
        /// </summary>
        /// <param name="_assetsName"></param>
        /// <param name="_className"></param>
        public void RegistFunctionCallFun(string uiPathName, string className)
        {
            if (!String.IsNullOrEmpty(uiPathName) && !_allRegisterUIDict.ContainsKey(uiPathName))
            {
                _allRegisterUIDict.Add(uiPathName, className);
            }

            LDebug.Log("LitFramework UI添加成功 " + uiPathName);
        }
Пример #24
0
    private void RewardCloseEventHandler(bool succ)
    {
        _isPlayReward = false;

        IsAppLeave = false;
        RewardShutDownEventHandler?.Invoke(succ);
        RewardShutDownEventHandler = null;

        LDebug.Log("Reward Close Status " + succ);
    }
Пример #25
0
 //Invoked when the initialization process has failed.
 //@param description - string - contains information about the failure.
 void InterstitialAdLoadFailedEvent(IronSourceError error)
 {
     LDebug.Log("==InterstitialAdLoadFailedEvent");
     if (error != null)
     {
         LDebug.Log(error.getDescription());
     }
     if (InterstitialLoadEventHandler != null)
     {
         InterstitialLoadEventHandler(false);
     }
 }
Пример #26
0
 //interstitial读取失败
 private void OnInterstitialFailedEvent(string adUnitId, string error)
 {
     if (error != null)
     {
         LDebug.Log("OnInterstitialFailedEvent " + error);
     }
     if (InterstitialLoadEventHandler != null)
     {
         InterstitialLoadEventHandler(false);
     }
     LDebug.Log("mopub调试——interstitial读取失败, id:" + adUnitId);
     LDebug.Log("error-----" + error);
 }
Пример #27
0
    public override void HideBanner(bool destroy)
    {
#if IRONSOURCE
        LDebug.Log(">>>>HideBanner");
        if (destroy)
        {
            IronSource.Agent.destroyBanner();
        }
        else
        {
            IronSource.Agent.hideBanner();
        }
#endif
    }
Пример #28
0
    private void Initialized(ProductCollection productCollection)
    {
        LDebug.Log("IAP total count ==>" + productCollection.all.Length);

        for (int i = 0; i < productCollection.all.Length; i++)
        {
            var product = productCollection.all[i];

            LDebug.Log("IAP product storeSpecificId ==>" + product.definition.storeSpecificId);
            LDebug.Log("IAP availableToPurchase ==>" + product.availableToPurchase);

            if (product.definition.storeSpecificId.StartsWith("buy"))
            {
                continue;
            }

            //包含在ProductsDict中的都是正是商品,打折商品ID不会出现在ProductDict中
            if (ProductsDict.ContainsKey(product.definition.storeSpecificId))
            {
                //真正后台配置商品
                ProductsDict[product.definition.storeSpecificId].Name        = product.metadata.localizedTitle;
                ProductsDict[product.definition.storeSpecificId].Price       = product.metadata.localizedPriceString;
                ProductsDict[product.definition.storeSpecificId].Description = product.metadata.localizedDescription;
                ProductsDict[product.definition.storeSpecificId].ProductType = product.definition.type;
            }
            else
            {
                var alternativeItem = ProductsDict.Where(e => e.Value.AlternativeBuyID == product.definition.storeSpecificId);
                //如果该ID被设置为一个打折商品ID
                if (alternativeItem.Count() > 0)
                {
                    var target = alternativeItem.First();
                    target.Value.AlternativePrice = product.metadata.localizedPriceString;
                }
                else
                {
                    ProductsDict.Add(product.definition.storeSpecificId, new PurchaserStoreItem(product.definition.storeSpecificId)
                    {
                        Name        = product.metadata.localizedTitle,
                        Price       = product.metadata.localizedPriceString,
                        Description = product.metadata.localizedDescription,
                        ProductType = product.definition.type,
                    });
                }
            }

            LDebug.Log("IAP localizedTitle ==>" + product.metadata.localizedTitle);
            LDebug.Log("IAP storeSpecificId ==>" + product.definition.storeSpecificId);
        }
    }
Пример #29
0
    //购买不同商品结束后的处理方法 对应定义的商品
    public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs args)
    {
        foreach (var prod in PurchaserDataModel.Instance.ProductsDict)
        {
            // A consumable product has been purchased by this user.
            if (String.Equals(args.purchasedProduct.definition.id, prod.Value.BuyID, StringComparison.Ordinal))
            {
                LDebug.Log(string.Format("ProcessPurchase: Succeed : '{0}'", args.purchasedProduct.definition.id));

                ProcessPurchaseEventHandler?.Invoke(prod.Value.BuyID);

                var     product      = m_StoreController.products.WithID(prod.Value.BuyID);
                string  receipt      = product.receipt;
                string  currency     = product.metadata.isoCurrencyCode;
                int     amount       = decimal.ToInt32(product.metadata.localizedPrice * 100);
                Receipt receiptClass = LitJson.JsonMapper.ToObject <Receipt>(receipt);
                ProcessPurchaseReceiptEventHandler?.Invoke(currency, prod.Value.BuyID, amount, receiptClass);

                // Return a flag indicating whether this product has completely been received, or if the application needs
                // to be reminded of this purchase at next app launch. Use PurchaseProcessingResult.Pending when still
                // saving purchased products to the cloud, and when that save is delayed.
                return(PurchaseProcessingResult.Complete);
            }
            else if (!string.IsNullOrEmpty(prod.Value.AlternativeBuyID) && String.Equals(args.purchasedProduct.definition.id, prod.Value.AlternativeBuyID, StringComparison.Ordinal))
            {
                LDebug.Log(string.Format("ProcessPurchase: Succeed : '{0}'", args.purchasedProduct.definition.id));

                ProcessPurchaseEventHandler?.Invoke(prod.Value.AlternativeBuyID);

                var     product      = m_StoreController.products.WithID(prod.Value.AlternativeBuyID);
                string  receipt      = product.receipt;
                string  currency     = product.metadata.isoCurrencyCode;
                int     amount       = decimal.ToInt32(product.metadata.localizedPrice * 100);
                Receipt receiptClass = LitJson.JsonMapper.ToObject <Receipt>(receipt);
                ProcessPurchaseReceiptEventHandler?.Invoke(currency, prod.Value.AlternativeBuyID, amount, receiptClass);

                // Return a flag indicating whether this product has completely been received, or if the application needs
                // to be reminded of this purchase at next app launch. Use PurchaseProcessingResult.Pending when still
                // saving purchased products to the cloud, and when that save is delayed.
                return(PurchaseProcessingResult.Complete);
            }
        }

        LDebug.Log(string.Format("ProcessPurchase: FAIL. Unrecognized product: '{0}'", args.purchasedProduct.definition.id));

        // Return a flag indicating whether this product has completely been received, or if the application needs
        // to be reminded of this purchase at next app launch. Use PurchaseProcessingResult.Pending when still
        // saving purchased products to the cloud, and when that save is delayed.
        return(PurchaseProcessingResult.Pending);
    }
Пример #30
0
    //
    // --- IStoreListener
    //
    public void OnInitialized(IStoreController controller, IExtensionProvider extensions)
    {
        // Purchasing has succeeded initializing. Collect our Purchasing references.
        LDebug.Log("OnInitialized: PASS");

        // Overall Purchasing system, configured with products for this application.
        m_StoreController = controller;
        // Store specific subsystem, for accessing device-specific store features.
        m_StoreExtensionProvider = extensions;

        if (InitializedEventHandler != null)
        {
            InitializedEventHandler(m_StoreController.products);
        }
    }