Exemplo n.º 1
0
 public void Dispose()
 {
     ReignServices.ScreenSizeChangedCallback -= ReignServices_ScreenSizeChangedCallback;
     if (gifImage != null)
     {
         gifImage.Dispose();
         gifImage = null;
     }
 }
Exemplo n.º 2
0
        private IEnumerator asyncRefresh(AdCreatedCallbackMethod createdCallback)
        {
            if (!Visible)
            {
                yield break;
            }

            string url = "http://ads.mp.mydas.mobi/getAd?";

            url += "&apid=" + apid;            // ID
            url += "&auid=" + deviceID;        // Device UID Hash HEX value
            url += "&ua=" + userAgent;
            url += "&uip=" + externalIP;
            Debug.Log("Ad Request URL: " + url);
            var www = new WWW(url);

            yield return(www);

            if (!string.IsNullOrEmpty(www.error))
            {
                Debug.LogError(www.error);
                if (createdCallback != null)
                {
                    createdCallback(false);
                }
                else if (adEvent != null)
                {
                    adEvent(AdEvents.Error, www.error);
                }
                yield break;
            }

            if (www.text.Contains(@"""error"""))
            {
                Debug.LogError(www.text);
                if (createdCallback != null)
                {
                    createdCallback(false);
                }
                else if (adEvent != null)
                {
                    adEvent(AdEvents.Error, www.text);
                }
                yield break;
            }

            //Debug.Log("Request Text: " + www.text);
            if (string.IsNullOrEmpty(www.text))
            {
                string error = "Invalid server responce! No data!";
                Debug.LogError(error);
                if (createdCallback != null)
                {
                    createdCallback(false);
                }
                else if (adEvent != null)
                {
                    adEvent(AdEvents.Error, error);
                }
                yield break;
            }

            var xml = new XmlSerializer(typeof(Reign.MM_AdXML.Ad));

            using (var data = new MemoryStream(www.bytes))
            {
                adMeta = (Reign.MM_AdXML.Ad)xml.Deserialize(data);
            }

            string imageURL = adMeta.image.url.Content;

            Debug.Log("MMWeb Ad ImageURL: " + imageURL);
            www = new WWW(imageURL);
            yield return(www);

            if (gifImage != null)
            {
                gifImage.Dispose();
                gifImage = null;
            }
            gifImage = new TextureGIF(www.bytes, frameUpdatedCallback);
            if (desc.UseClassicGUI)
            {
                guiTexture = gifImage.CurrentFrame.Texture;
            }
            else
            {
                adImage.sprite = gifImage.CurrentFrame.Sprite;
            }
            var texture = gifImage.CurrentFrame.Texture;

            Debug.Log(string.Format("Ad Image Size: {0}x{1}", texture.width, texture.height));

            SetGravity(gravity);
            if (adEvent != null)
            {
                adEvent(AdEvents.Refreshed, null);
            }
        }
Exemplo n.º 3
0
        private IEnumerator init(AdCreatedCallbackMethod createdCallback)
        {
            // request Ad
            if (testing)
            {
                var www = new WWW("http://media.mydas.mobi/images/rich/T/test_mm/collapsed.gif");
                yield return(www);

                var data = www.bytes;
                if (data == null || data.Length == 0)
                {
                    Debug.LogError("Test Ad failed to loadb");
                    if (createdCallback != null)
                    {
                        createdCallback(false);
                    }
                    yield break;
                }

                gifImage = new TextureGIF(data, frameUpdatedCallback);
                if (desc.UseClassicGUI)
                {
                    guiTexture = gifImage.CurrentFrame.Texture;
                }
                else
                {
                    adImage.sprite = gifImage.CurrentFrame.Sprite;
                }
                SetGravity(gravity);
                var texture = gifImage.CurrentFrame.Texture;
                Debug.Log(string.Format("Ad Image Size: {0}x{1}", texture.width, texture.height));
                if (createdCallback != null)
                {
                    createdCallback(true);
                }
                if (adEvent != null)
                {
                    adEvent(AdEvents.Refreshed, null);
                }
            }
            else
            {
                // get external IP address
                var ipWWW = new WWW("http://checkip.dyndns.org/");
                yield return(ipWWW);

                var match = Regex.Match(ipWWW.text, @"Current IP Address\: (\d*\.\d*\.\d*\.\d*)");
                if (!match.Success)
                {
                    if (createdCallback != null)
                    {
                        createdCallback(false);
                    }
                    yield break;
                }
                externalIP = match.Groups[1].Value;
                Debug.Log("External IP: " + externalIP);

                // load ad
                service.StartCoroutine(asyncRefresh(createdCallback));
            }
        }
Exemplo n.º 4
0
        private IEnumerator asyncRefresh(AdCreatedCallbackMethod createdCallback)
        {
            if (!Visible)
            {
                yield break;
            }

            string url = "http://ads.mp.mydas.mobi/getAd?";

            url += "&apid=" + apid;            // ID
            url += "&auid=" + deviceID;        // Device UID Hash HEX value
            url += "&ua=" + userAgent;
            url += "&uip=" + externalIP;
            Debug.Log("Ad Request URL: " + url);
            var www = new WWW(url);

            yield return(www);

            if (!string.IsNullOrEmpty(www.error))
            {
                Debug.LogError(www.error);
                if (createdCallback != null)
                {
                    createdCallback(false);
                }
                else if (adEvent != null)
                {
                    adEvent(AdEvents.Error, www.error);
                }
                yield break;
            }

            if (www.text.Contains(@"""error"""))
            {
                Debug.LogError(www.text);
                if (createdCallback != null)
                {
                    createdCallback(false);
                }
                else if (adEvent != null)
                {
                    adEvent(AdEvents.Error, www.text);
                }
                yield break;
            }

            //Debug.Log("Request Text: " + www.text);
            if (string.IsNullOrEmpty(www.text))
            {
                string error = "Invalid server responce! No data!";
                Debug.LogError(error);
                if (createdCallback != null)
                {
                    createdCallback(false);
                }
                else if (adEvent != null)
                {
                    adEvent(AdEvents.Error, error);
                }
                yield break;
            }

            try
            {
                var xml = new XmlSerializer(typeof(Reign.MM_AdXML.Ad));
                                #if UNITY_WINRT
                var str = System.Text.Reign.Encoding.Singleton.GetString(www.bytes, 0, www.bytes.Length).Replace(@"[:_mm_campaignid:]&[:_mm_advertiserid:]?", "");
                                #else
                var str = System.Text.Encoding.Default.GetString(www.bytes).Replace(@"[:_mm_campaignid:]&[:_mm_advertiserid:]?", "");
                                #endif
                using (var stream = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(str)))
                {
                    adMeta = (Reign.MM_AdXML.Ad)xml.Deserialize(stream);
                }
            }
            catch (Exception e)
            {
                Debug.LogError(e.Message);
                Debug.LogError("Responce Text: " + www.text);
                if (adEvent != null)
                {
                    adEvent(AdEvents.Error, e.Message);
                }
                yield break;
            }

            string imageURL = adMeta.image.url.Content;
            Debug.Log("MMWeb Ad ImageURL: " + imageURL);
            www = new WWW(imageURL);
            yield return(www);

            if (gifImage != null)
            {
                gifImage.Dispose();
                gifImage = null;
            }
            gifImage = new TextureGIF(www.bytes, frameUpdatedCallback);
            if (desc.UseClassicGUI)
            {
                guiTexture = gifImage.CurrentFrame.Texture;
            }
            else
            {
                adImage.sprite = gifImage.CurrentFrame.Sprite;
            }
            var texture = gifImage.CurrentFrame.Texture;
            Debug.Log(string.Format("Ad Image Size: {0}x{1}", texture.width, texture.height));

            SetGravity(gravity);
            if (adEvent != null)
            {
                adEvent(AdEvents.Refreshed, null);
            }
        }
Exemplo n.º 5
0
		private IEnumerator asyncRefresh(AdCreatedCallbackMethod createdCallback)
		{
			if (!Visible) yield break;

			string url = "http://ads.mp.mydas.mobi/getAd?";
			url += "&apid=" + apid;// ID
			url += "&auid=" + deviceID;// Device UID Hash HEX value
			url += "&ua=" + userAgent;
			url += "&uip=" + externalIP;
			Debug.Log("Ad Request URL: " + url);
			var www = new WWW(url);
			yield return www;

			if (!string.IsNullOrEmpty(www.error))
			{
				Debug.LogError(www.error);
				if (createdCallback != null) createdCallback(false);
				else if (adEvent != null) adEvent(AdEvents.Error, www.error);
				yield break;
			}

			if (www.text.Contains(@"""error"""))
			{
				Debug.LogError(www.text);
				if (createdCallback != null) createdCallback(false);
				else if (adEvent != null) adEvent(AdEvents.Error, www.text);
				yield break;
			}

			//Debug.Log("Request Text: " + www.text);
			if (string.IsNullOrEmpty(www.text))
			{
				string error = "Invalid server responce! No data!";
				Debug.LogError(error);
				if (createdCallback != null) createdCallback(false);
				else if (adEvent != null) adEvent(AdEvents.Error, error);
				yield break;
			}

			try
			{
				var xml = new XmlSerializer(typeof(Reign.MM_AdXML.Ad));
				#if UNITY_WINRT
				var str = System.Text.Reign.Encoding.Singleton.GetString(www.bytes, 0, www.bytes.Length).Replace(@"[:_mm_campaignid:]&[:_mm_advertiserid:]?", "");
				#else
				var str = System.Text.Encoding.Default.GetString(www.bytes).Replace(@"[:_mm_campaignid:]&[:_mm_advertiserid:]?", "");
				#endif
				using (var stream = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(str)))
				{
					adMeta = (Reign.MM_AdXML.Ad)xml.Deserialize(stream);
				}
			}
			catch (Exception e)
			{
				Debug.LogError(e.Message);
				Debug.LogError("Responce Text: " + www.text);
				if (adEvent != null) adEvent(AdEvents.Error, e.Message);
				yield break;
			}

			string imageURL = adMeta.image.url.Content;
			Debug.Log("MMWeb Ad ImageURL: " + imageURL);
			www = new WWW(imageURL);
			yield return www;

			if (gifImage != null)
			{
				gifImage.Dispose();
				gifImage = null;
			}
			gifImage = new TextureGIF(www.bytes, frameUpdatedCallback);
			if (desc.UseClassicGUI) guiTexture = gifImage.CurrentFrame.Texture;
			else adImage.sprite = gifImage.CurrentFrame.Sprite;
			var texture = gifImage.CurrentFrame.Texture;
			Debug.Log(string.Format("Ad Image Size: {0}x{1}", texture.width, texture.height));

			SetGravity(gravity);
			if (adEvent != null) adEvent(AdEvents.Refreshed, null);
		}
Exemplo n.º 6
0
		public void Dispose()
		{
			ReignServices.ScreenSizeChangedCallback -= ReignServices_ScreenSizeChangedCallback;
			if (gifImage != null)
			{
				gifImage.Dispose();
				gifImage = null;
			}
		}
Exemplo n.º 7
0
		private IEnumerator init(AdCreatedCallbackMethod createdCallback)
		{
			// request Ad
			if (testing)
			{
				var www = new WWW("http://media.mydas.mobi/images/rich/T/test_mm/collapsed.gif");
				yield return www;

				var data = www.bytes;
				if (data == null || data.Length == 0)
				{
					Debug.LogError("Test Ad failed to loadb");
					if (createdCallback != null) createdCallback(false);
					yield break;
				}

				gifImage = new TextureGIF(data, frameUpdatedCallback);
				if (desc.UseClassicGUI) guiTexture = gifImage.CurrentFrame.Texture;
				else adImage.sprite = gifImage.CurrentFrame.Sprite;
				SetGravity(gravity);
				var texture = gifImage.CurrentFrame.Texture;
				Debug.Log(string.Format("Ad Image Size: {0}x{1}", texture.width, texture.height));
				if (createdCallback != null) createdCallback(true);
				if (adEvent != null) adEvent(AdEvents.Refreshed, null);
			}
			else
			{
				// get external IP address
				var ipWWW = new WWW("http://checkip.dyndns.org/");
				yield return ipWWW;
				var match = Regex.Match(ipWWW.text, @"Current IP Address\: (\d*\.\d*\.\d*\.\d*)");
				if (!match.Success)
				{
					if (createdCallback != null) createdCallback(false);
					yield break;
				}
				externalIP = match.Groups[1].Value;
				Debug.Log("External IP: " + externalIP);

				// load ad
				service.StartCoroutine(asyncRefresh(createdCallback));
			}
		}