Пример #1
0
        /// <summary>
        /// Download banner texture and audio clip
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        private IEnumerator PrepareAd(string url)
        {
            m_isAdPrepared = true;

            // Fetch banner texture
            m_isBannerTextureLoaded = false;

            string bannerUrl = m_currentAd.GetBannerImageUrl();

            if (!string.IsNullOrEmpty(bannerUrl))
            {
                m_adContainsBanner = true;
                m_network.GetTextureFromSource(bannerUrl, TextureReceivedCallback);

                float timeOut = Time.realtimeSinceStartup + VSettings.BaseTimeOut;
                while (!m_isBannerTextureLoaded)
                {
                    if (Time.realtimeSinceStartup > timeOut)
                    {
                        m_network.CancelCalls();
                        OnError("Texture loading timed out");
                        yield break;
                    }
                    yield return(null);
                }
            }
            else
            {
                m_adContainsBanner = false;
            }

            // Fetch audio clip
            m_isAudioClipLoaded = false;

            if (!string.IsNullOrEmpty(url))
            {
                m_network.GetAudioClipFromSource(url, AudioClipReceivedCallback);

                float timeOut = Time.realtimeSinceStartup + VSettings.BaseTimeOut;
                while (m_isAudioClipLoaded)
                {
                    if (Time.realtimeSinceStartup > timeOut)
                    {
                        m_network.CancelCalls();
                        OnError("Ad audio loading timed out");
                        yield break;
                    }
                    yield return(null);
                }
            }
            else
            {
                OnError("Ad URL is empty");
            }
        }
Пример #2
0
        /// <summary>
        /// Callback for getting audio source URL.
        /// </summary>
        /// <param name="response"></param>
        /// <param name="error"></param>
        private void SourceReceivedCallback(string response, string error)
        {
            m_isSongSourceLoaded = true;

            if (!string.IsNullOrEmpty(error))
            {
                OnError("Network error");
                return;
            }

            var    N      = SimpleJSON.JSON.Parse(response);
            string source = N["music"]["source"];

            m_network.GetAudioClipFromSource(source, AudioClipReceivedCallback);
        }