コード例 #1
0
        //Start Native Banner Callbacks.
        //below methods called from native code for Banner Ad.
        public void _OnAdColonyAdViewLoaded(string paramJson)
        {
            Debug.Log("AdColony.Wrapper._OnAdColonyAdViewLoaded called.");
            Hashtable values = (AdColonyJson.Decode(paramJson) as Hashtable);

            if (values == null)
            {
                Debug.LogError("Unable to parse parameters in _OnAdColonyAdViewLoaded, " + (paramJson ?? "null"));
                return;
            }

            AdColonyAdView adColonyAdView = GetAdColonyAdViewFromHashtable(values);

            if (adColonyAdView == null)
            {
                Debug.LogError("Unable to create ad within _OnAdColonyAdViewLoaded, " + (paramJson ?? "null"));
                return;
            }

            if (Ads.OnAdViewLoaded != null)
            {
                if (adColonyAdView != null)
                {
                    Ads.OnAdViewLoaded(adColonyAdView);
                }
                else
                {
                    Debug.LogError(Constants.AdsMessageErrorUnableToRebuildAd);
                }
            }
        }
コード例 #2
0
 public void PerformAdColonyAction(Asteroid asteroid)
 {
     if (asteroid == asteroidConfigure)
     {
         ConfigureAds();
     }
     else if (asteroid == asteroidRequest)
     {
         RequestAd();
     }
     else if (asteroid == asteroidPlay)
     {
         PlayAd();
     }
     else if (asteroid == asteroidAdViewRequest)
     {
         RequestBannerAd();
         asteroidAdViewRequest.Show();
     }
     else if (asteroid == asteroidAdViewDestroy)
     {
         if (arrayList.Count != 0)
         {
             AdColony.AdColonyAdView adView = (AdColony.AdColonyAdView)arrayList[0];
             adView.DestroyAdView();
             arrayList.Remove(adView);
             if (arrayList.Count != 0)
             {
                 asteroidAdViewDestroy.Show();
             }
         }
     }
 }
コード例 #3
0
        //Start internal private methods of Native Banner Callbacks.
        private AdColonyAdView GetAdColonyAdViewFromHashtable(Hashtable values)
        {
            string id = null;

            if (values != null && values.ContainsKey("id"))
            {
                id = values["id"] as string;
            }

            AdColonyAdView ad = null;

            if (id != null)
            {
                if (adcolonyAdViewDictionary.ContainsKey(id))
                {
                    ad = adcolonyAdViewDictionary[id];
                    ad.UpdateValues(values);
                }
                else
                {
                    ad = new AdColonyAdView(values);
                    adcolonyAdViewDictionary[id] = ad;
                }
            }
            return(ad);
        }
コード例 #4
0
    void Start()
    {
        GameObject configureObj = GameObject.FindGameObjectWithTag(Constants.AsteroidConfigureTag);

        asteroidConfigure = configureObj.GetComponent <Asteroid>();

        GameObject requestObj = GameObject.FindGameObjectWithTag(Constants.AsteroidRequestTag);

        asteroidRequest = requestObj.GetComponent <Asteroid>();

        GameObject playObj = GameObject.FindGameObjectWithTag(Constants.AsteroidPlayTag);

        asteroidPlay = playObj.GetComponent <Asteroid>();

        GameObject adViewRequstObj = GameObject.FindGameObjectWithTag(Constants.AsteroidAdViewRequest);

        asteroidAdViewRequest = adViewRequstObj.GetComponent <Asteroid>();
        GameObject adViewDestroyObj = GameObject.FindGameObjectWithTag(Constants.AsteroidAdViewDestroy);

        asteroidAdViewDestroy = adViewDestroyObj.GetComponent <Asteroid>();

        // Only configure asteroid is available at start.
        asteroidConfigure.Show();
        asteroidRequest.Hide();
        asteroidPlay.Hide();
        asteroidAdViewRequest.Hide();
        asteroidAdViewDestroy.Hide();

        // ----- AdColony Ads -----

        AdColony.Ads.OnConfigurationCompleted += (List <AdColony.Zone> zones_) =>
        {
            Debug.Log("AdColony.Ads.OnConfigurationCompleted called");

            if (zones_ == null || zones_.Count <= 0)
            {
                // Show the configure asteroid again.
                asteroidConfigure.Show();
            }
            else
            {
                // Successfully configured... show the request ad asteroid.
                asteroidRequest.Show();
                asteroidAdViewRequest.Show();
            }
        };

        AdColony.Ads.OnRequestInterstitial += (AdColony.InterstitialAd ad_) =>
        {
            Debug.Log("AdColony.Ads.OnRequestInterstitial called");
            Ad = ad_;

            // Successfully requested ad... show the play ad asteroid.
            asteroidPlay.Show();
        };

        AdColony.Ads.OnRequestInterstitialFailedWithZone += (string zoneId) =>
        {
            Debug.Log("AdColony.Ads.OnRequestInterstitialFailedWithZone called, zone: " + zoneId);

            // Request Ad failed... show the request ad asteroid.
            asteroidRequest.Show();
        };

        AdColony.Ads.OnOpened += (AdColony.InterstitialAd ad_) =>
        {
            Debug.Log("AdColony.Ads.OnOpened called");

            // Ad started playing... show the request ad asteroid for the next ad.
            asteroidRequest.Show();
        };

        AdColony.Ads.OnClosed += (AdColony.InterstitialAd ad_) =>
        {
            Debug.Log("AdColony.Ads.OnClosed called, expired: " + ad_.Expired);
            ad_.DestroyAd();
        };

        AdColony.Ads.OnExpiring += (AdColony.InterstitialAd ad_) =>
        {
            Debug.Log("AdColony.Ads.OnExpiring called");
            Ad = null;

            // Current ad expired... show the request ad asteroid.
            asteroidRequest.Show();
            asteroidPlay.Hide();
        };

        AdColony.Ads.OnIAPOpportunity += (AdColony.InterstitialAd ad_, string iapProductId_, AdColony.AdsIAPEngagementType engagement_) =>
        {
            Debug.Log("AdColony.Ads.OnIAPOpportunity called");
        };

        AdColony.Ads.OnRewardGranted += (string zoneId, bool success, string name, int amount) =>
        {
            Debug.Log(string.Format("AdColony.Ads.OnRewardGranted called\n\tzoneId: {0}\n\tsuccess: {1}\n\tname: {2}\n\tamount: {3}", zoneId, success, name, amount));
        };

        AdColony.Ads.OnCustomMessageReceived += (string type, string message) =>
        {
            Debug.Log(string.Format("AdColony.Ads.OnCustomMessageReceived called\n\ttype: {0}\n\tmessage: {1}", type, message));
        };

        //Banner events.
        AdColony.Ads.OnAdViewOpened += (AdColony.AdColonyAdView ad_) =>
        {
            Debug.Log("AdColony.SampleApps.OnAdViewOpened called");
        };
        AdColony.Ads.OnAdViewLoaded += (AdColony.AdColonyAdView ad_) =>
        {
            Debug.Log("AdColony.SampleApps.OnAdViewLoaded called");
            asteroidAdViewDestroy.Show();
            arrayList.Add(ad_);
            adView = ad_;

            // Show or hide the ad view(this is optional; the banner is shown by default)

            /* Setting 2 timers of 5 and 10 seconds, after 5 sec calling
             * the ad view's hide method that is defined below and after 10 sec calling the ad view's show method that is defined below.*/
            Invoke("HideAdView", 5.0f);
            Invoke("ShowAdView", 10.0f);
        };

        AdColony.Ads.OnAdViewFailedToLoad += (AdColony.AdColonyAdView ad_) =>
        {
            Debug.Log("AdColony.SampleApps.OnAdViewFailedToLoad called with Zone id:" + ad_.ZoneId + " " + ad_.adPosition);
            asteroidAdViewRequest.Show();
        };
        AdColony.Ads.OnAdViewClosed += (AdColony.AdColonyAdView ad_) =>
        {
            Debug.Log("AdColony.SampleApps.OnAdViewClosed called");
        };
        AdColony.Ads.OnAdViewClicked += (AdColony.AdColonyAdView ad_) =>
        {
            Debug.Log("AdColony.SampleApps.OnAdViewClicked called");
        };
        AdColony.Ads.OnAdViewLeftApplication += (AdColony.AdColonyAdView ad_) =>
        {
            Debug.Log("AdColony.SampleApps.OnAdViewLeftApplication called");
        };
    }