Esempio n. 1
0
    public static void ShowAd()
    {
        Debug.Log(DateTimeOffset.UtcNow.ToUnixTimeSeconds());
        Debug.Log(secondsSinceLastAd);

        Debug.Log("Differentce " + (DateTimeOffset.UtcNow.ToUnixTimeSeconds() - secondsSinceLastAd));

        // check limit
        if (throttleGamesBetweenAds <= gamesSinceLastAd ||
            (DateTimeOffset.UtcNow.ToUnixTimeSeconds() - secondsSinceLastAd) >= throttleSecondsBetweenAds)
        {
            // if an ad is available, display it!
            if (adLoaded)
            {
                TopAds.ShowAd(appAdUnitID);
            }
            else
            {
                // Request a new one and display when ready :)
                TopAds.RequestAd(appAdUnitID);

                // display as soon as an ad is ready
                displayAdAsSoonAsLoadedNextTime = true;
            }

            adLoaded = false;
        }
    }
Esempio n. 2
0
    public static void ShowAd()
    {
        //DONE
        // TopAds methods must be called with a unique "string" ad unit id
        // For your test app that id is "f4280fh0318rf0h2"
        // However, when releasing the SDK to other studios, their ad unit id will be different
        // Please find a flexible way to allow studios to provide their ad unit id to your VoodooSauce SDK

        //-----------------ANSWER---------------------

        /*
         * If I were doing this for production I'd argue for using a WebRequest to a list of all our clients' ad unit id.
         * Like something on GoogleSheet.
         * That way we'd be able to update the table without having to upgrade the game
         * In the meantime I'm using a ScriptableObject for easy use for the rest of the team.
         */
        //------------------------------------------

        // Before an ad is available to display, you must call TopAds.RequestAd
        // You must call RequestAd each time before an ad is ready to display

        // RequestAd will make a "fake" request for an ad that will take 0 to 10 seconds to complete
        // Afterwards, either the OnAdLoadedEvent or OnAdFailedEvent will be invoked
        // Please implement an autorequest system that ensures an ad is always ready to be displayed
        // Keep in mind that RequestAd can fail multiple times in a row

        //-----------------ANSWER---------------------

        /*
         * See LoadAd() and LoadAdCoroutine()
         */
        //------------------------------------------

        // If an ad is loaded correctly, clicking on the "Show Ad" button within Unity-VoodooSauceTestApp
        // should display a fake ad popup that you can close.
        if (Time.unscaledTime < lastAdShownTime + secondsBetweenAds)
        {
            Debug.LogWarning((secondsBetweenAds - (Time.unscaledTime - lastAdShownTime)).ToString() + " seconds to wait remaining before ad can be displayed");
            return;
        }
        if (currentGameIndex < lastAdShownGameIndex + gamesBetweenAds)
        {
            Debug.LogWarning((gamesBetweenAds - (currentGameIndex - lastAdShownGameIndex)).ToString() + " games to play remaining before ad can be displayed");
            return;
        }
        if (adLoaded)
        {
            TopAds.ShowAd(adUnitIDList[0]);
        }


        // Track in TopAnalytics when an ad is displayed.  Hint: TopAds.OnAdShownEvent

        //-----------------ANSWER---------------------

        /*
         * See OnAdShown()
         */
        //------------------------------------------
    }
Esempio n. 3
0
 static public void RevokeConsent()
 {
     TopAds.RevokeConsent();
     TopAnalytics.InitWithConsent(false);
     if (!PlayerPrefs.HasKey("consent") || PlayerPrefs.GetInt("consent") != 0)
     {
         PlayerPrefs.SetInt("consent", 0);
         PlayerPrefs.Save();
     }
 }
Esempio n. 4
0
 static public void GrantConsent()
 {
     TopAds.GrantConsent();
     TopAnalytics.InitWithConsent(true);
     if (!PlayerPrefs.HasKey("consent") || PlayerPrefs.GetInt("consent") == 0)
     {
         PlayerPrefs.SetInt("consent", 1);
         PlayerPrefs.Save();
     }
 }
Esempio n. 5
0
 /// <summary>
 /// displaying the ad,
 /// </summary>
 public void DisplayAd()
 {
     if (m_isABufferedAdReady)
     {
         TopAds.ShowAd(AdUnitIdWrapper.Instance.adUnitId);
     }
     else if (!m_currentWaitingForAd)
     {
         StartCoroutine(WaitForAdRoutine(() => {
             TopAds.ShowAd(AdUnitIdWrapper.Instance.adUnitId);
         }));
     }
 }
Esempio n. 6
0
    /**
     * this is a delegate of TopAds.OnAdFailedEvent to keep VoodooSauce aware when an ad is still
     * not available, which means we should keep trying
     * Auto requesting until OnAdLoadedEvent is called
     */
    private static void OnAdFailedEvent()
    {
        // if we already have an ad ready, we don't try with a new one :)
        if (adLoaded)
        {
            return;
        }

        // otherwise, we send another request
        TopAds.RequestAd(appAdUnitID);

        Debug.Log("An Ad is not available yet");
    }
Esempio n. 7
0
    public static void SetGDPRConsent(bool gdprConsent)
    {
        TopAnalytics.InitWithConsent(gdprConsent);

        TopAds.InitializeSDK();
        if (gdprConsent)
        {
            TopAds.GrantConsent();
        }
        else
        {
            TopAds.RevokeConsent();
        }
    }
Esempio n. 8
0
    /**
     * this is a delegate of TopAds.OnAdLoadedEvent to keep VoodooSauce aware when an ad is available
     * or it should keep trying
     */
    private static void OnAdLoadedEvent()
    {
        // stop retrying and display with click on show
        adLoaded = true;
        Debug.Log("An Ad is available");


        // did the user click show and we don't have an ad ready?
        if (displayAdAsSoonAsLoadedNextTime)
        {
            displayAdAsSoonAsLoadedNextTime = false;
            TopAds.ShowAd(appAdUnitID);
        }
    }
Esempio n. 9
0
    public static void ShowAd(string adId)
    {
        // TopAds methods must be called with a unique "string" ad unit id
        // For your test app that id is "f4280fh0318rf0h2"
        // However, when releasing the SDK to other studios, their ad unit id will be different
        // Please find a flexible way to allow studios to provide their ad unit id to your VoodooSauce SDK

        // Before an ad is available to display, you must call TopAds.RequestAd
        // You must call RequestAd each time before an ad is ready to display
        TopAds.OnAdLoadedEvent += delegate()
        {
            System.Diagnostics.Debug.WriteLine("The ad is loaded");

            TopAds.ShowAd(adId);
        };

        TopAds.OnAdShownEvent += delegate()
        {
            System.Diagnostics.Debug.WriteLine("The ad has been shown");

            lastTimeAdShown = DateTime.Now;
            gamesShown      = 0;
        };

        TopAds.OnAdFailedEvent += delegate()
        {
            System.Diagnostics.Debug.WriteLine("The ad failed to load or show, please refer to the SDK documentation for further details");
        };

        DateTime lastTime = lastTimeAdShown.AddSeconds(Convert.ToDouble(secondsBetweenAds));

        if (DateTime.Now.CompareTo(lastTime) >= 0 &&
            gamesShown >= gamesBetweenAds)
        {
            TopAds.RequestAd(adId);
        }

        // RequestAd will make a "fake" request for an ad that will take 0 to 10 seconds to complete
        // Afterwards, either the OnAdLoadedEvent or OnAdFailedEvent will be invoked
        // Please implement an autorequest system that ensures an ad is always ready to be displayed
        // Keep in mind that RequestAd can fail multiple times in a row

        // If an ad is loaded correctly, clicking on the "Show Ad" button within Unity-VoodooSauceTestApp
        // should display a fake ad popup that you can close.


        // Track in TopAnalytics when an ad is displayed.  Hint: TopAds.OnAdShownEvent
    }
Esempio n. 10
0
 // Before calling methods in TopAds and TopAnalytics you must call their init methods
 // TopAds requires the TopAds prefab to be created in the scene
 // You also need to collect user GDPR consent and pass that boolean value to TopAds and TopAnalytics
 // You can collect this consent by displaying a popup to the user at the start of the game and then storing that value for future use
 public static void StartGame()
 {
     UnityEngine.Assertions.Assert.IsTrue(RGPDManager.RgpdConsentalue.HasValue);
     TopAds.InitializeSDK();
     TopAnalytics.InitWithConsent(RGPDManager.RgpdConsentalue.Value);
     if (RGPDManager.RgpdConsentalue.Value)
     {
         TopAds.GrantConsent();
     }
     else
     {
         TopAds.RevokeConsent();
     }
     // Track in TopAnalytics that a game has started
     TopAnalytics.TrackEvent(GAME_STARTED_EVENT);
     TopAds.OnAdShownEvent += TopAds_OnAdShownEvent;
 }
Esempio n. 11
0
    void Init()
    {
        //Instatiate TopAds Prefab
        TopAdsBehaviour topAds = Instantiate(topAdsPrefab);

        DontDestroyOnLoad(topAds.gameObject);

        //Initialize TopAds
        TopAds.InitializeSDK();

        //Set VoodooSauce tracking events
        TopAds.OnAdLoadedEvent += VoodooSauce.OnAdLoaded;
        TopAds.OnAdFailedEvent += VoodooSauce.OnAdLoadingFail;
        TopAds.OnAdShownEvent  += VoodooSauce.OnAdShown;

        //Set ad id list
        VoodooSauce.SetAdUnitIDs(adUnitIDList);

        //Display toast
        _ShowAndroidToastMessage("Hello Voodoo!");

        //Line added to see RGPD PopUp in Editor at every launch
#if UNITY_EDITOR
        PlayerPrefs.DeleteAll();
#endif

        //We check in playerPref if consent is granted or revoked
        //If consent hasn't granted nor revoked we ask for it
        if (!PlayerPrefs.HasKey("consent"))
        {
            Instantiate(GDPRPopUpPrefab);
        }
        else
        {
            if (PlayerPrefs.GetInt("consent") != 0)
            {
                VoodooSauce.GrantConsent();
            }
            else
            {
                VoodooSauce.RevokeConsent();
            }
            GoToMainScene();
        }
    }
Esempio n. 12
0
 static IEnumerator LoadAdCoroutine()
 {
     adLoaded  = false;
     addFailed = false;
     while (!adLoaded)
     {
         Debug.Log("request new ad");
         TopAds.RequestAd(adUnitIDList[0]);
         while (!adLoaded && !addFailed)
         {
             yield return(null);
         }
         if (addFailed)
         {
             addFailed = false;
         }
     }
     loadingAdCoroutine = null;
 }
Esempio n. 13
0
    // TODO Before calling methods in TopAds and TopAnalytics you must call their init methods
    // TopAds requires the TopAds prefab to be created in the scene
    // TODO You also need to collect user GDPR consent and pass that boolean value to TopAds and TopAnalytics
    // You can collect this consent by displaying a popup to the user at the start of the game and then storing that value for future use


    /**
     * @requires calling the Initialize method first
     */
    public static void StartGame()
    {
        /**
         * GDPR CONSENT
         * We Asynchronously Collect this consent by displaying a popup to the user
         * we pass the consent to the SDK in the initialization Method alongslide the app ID
         * @see An example at [MainCanvasScript.cs]
         */

        // use the ConsentGiven to init TopAnalytics
        TopAnalytics.InitWithConsent(ConsentGiven);

        // init TopAds
        TopAds.InitializeSDK();


        // Grant/Revoke TopAds based on consentGiven value
        if (ConsentGiven)
        {
            TopAds.GrantConsent();
        }
        else
        {
            TopAds.RevokeConsent();
        }

        // Track in TopAnalytics that a game has started
        TopAnalytics.TrackEvent("Game_started");


        // Delegate TopAds events to listeners to ensure that we always have an ad ready :)
        TopAds.OnAdLoadedEvent += OnAdLoadedEvent;
        TopAds.OnAdFailedEvent += OnAdFailedEvent;
        TopAds.OnAdShownEvent  += OnAdShownEvent;


        // we request an ad to prepare for the ShowAd Event :)
        TopAds.RequestAd(appAdUnitID);


        gamesSinceLastAd++;
    }
Esempio n. 14
0
    /*
     * ************************************************
     *
     * TopAds Action events
     * Ad readiness/display events
     *
     * An autorequest system that ensures an ad is always ready to be displayed
     *
     * ************************************************
     */

    /**
     * this is a delegate of TopAds.OnAdShownEvent
     * Track in TopAnalytics when an ad is displayed.
     */
    private static void OnAdShownEvent()
    {
        // Track in TopAnalytics when an ad is displayed.
        TopAnalytics.TrackEvent("ad_displayed");

        // since ad is displayed, we turn this to false and to allow requesting a new one
        adLoaded = false;

        // Prepare for the next ad
        TopAds.RequestAd(appAdUnitID);


        Debug.Log("Ad shown, requesting for next time");


        gamesSinceLastAd = 0;
        // The number of seconds that have elapsed since 1970-01-01T00:00:00Z.
        // needed to compare later
        secondsSinceLastAd = DateTimeOffset.UtcNow.ToUnixTimeSeconds();
    }
Esempio n. 15
0
 /// <summary>
 /// action of starting RequestAd
 /// </summary>
 void BufferAd()
 {
     TopAds.RequestAd(AdUnitIdWrapper.Instance.adUnitId);
 }