コード例 #1
0
        protected virtual void AdDownloadCallback(AdsType adType, bool result, string message)
        {
            if (mCurrentDownload == null)
            {
                if (AdsManager.Debugging)
                {
                    Debug.Log("AdDownload mCurrentDownload is null but there is still have callback");
                }
                return;
            }

            if (adType != mCurrentDownload._Type)
            {
                if (AdsManager.Debugging)
                {
                    Debug.Log("AdDownload callback type " + adType + " does not match current download type " + mCurrentDownload._Type);
                }
                return;
            }

            if (result)
            {
                if (AdsManager.Debugging)
                {
                    Debug.Log("AdDownload " + mCurrentDownload._Type + " id " + mCurrentDownload._Id + " result success");
                }
                mAdLoadState = AdsLoadState.Loaded;
            }
            else
            {
                if (AdsManager.Debugging)
                {
                    Debug.Log("AdDownload " + mCurrentDownload._Type + " id " + mCurrentDownload._Id + " result failed: " + message);
                }
                mAdLoadState = AdsLoadState.Error;
            }
            mCurrentDownload.OnAdAvailabilityUpdate(result);
            mCurrentDownload = null;
        }
コード例 #2
0
 protected virtual void DownloadAd(AdStatusHandler ad)
 {
     mAdLoadState     = AdsLoadState.Downloading;
     mCurrentDownload = ad;
     //Need each adapter to implement it's own code
 }
コード例 #3
0
        IEnumerator CRAutoRequestThread()
        {
            var highPriorityList = mAdHighPriorityList.ToArray();
            var lowPriorityList  = mAdLowPriorityList.ToArray();

            if (highPriorityList.Length <= 0)
            {
                yield break;
            }
            int             offsetIndex         = 0;
            int             errorCount          = 0;
            float           downloadTime        = 0;
            AdStatusHandler lastDownloadHandler = null;

            while (true)
            {
                AdStatusHandler selectedDownload = null;
                for (int i = 0; i < highPriorityList.Length; ++i)
                {
                    if (!highPriorityList[i].IsAvailable(0) && highPriorityList[i] != lastDownloadHandler)
                    {
                        selectedDownload = highPriorityList[i];
                        break;
                    }
                }

                if (selectedDownload == null)
                {
                    for (int i = 0; i < lowPriorityList.Length; ++i)
                    {
                        int index = (offsetIndex + i) % lowPriorityList.Length;
                        if (!lowPriorityList[index].IsAvailable(0) && lowPriorityList[index] != lastDownloadHandler)
                        {
                            selectedDownload = lowPriorityList[index];
                            break;
                        }
                    }
                    ++offsetIndex;
                }

                lastDownloadHandler = selectedDownload;
                if (selectedDownload != null)
                {
                    while (mCurrentFullscreenAd != null || FullscreenAdShowing)
                    {
                        yield return(null);
                    }

                    DownloadAd(selectedDownload);
                    downloadTime = 0;
                    while (mAdLoadState == AdsLoadState.Downloading)
                    {
                        yield return(null);

                        downloadTime += Time.deltaTime;
                        if (downloadTime >= mConfig.GetDownloadTimeout())
                        {
                            mAdLoadState = AdsLoadState.Error;
                            if (selectedDownload != null)
                            {
                                AdDownloadCallback(selectedDownload._Type, false, "timeout");
                            }
                        }
                    }

                    if (mAdLoadState == AdsLoadState.Error)
                    {
                        yield return(new WaitForSeconds(mConfig.GetErrorRetryInterval() + sAdsErrorDelayTime[Mathf.Min(errorCount, sAdsErrorDelayTime.Length - 1)]));

                        ++errorCount;
                    }
                    else
                    {
                        errorCount = 0;
                    }
                }

                yield return(null);
            }
        }