File size: 1,129 Bytes
1e40c2a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
//init the interstitial 

var iAd;
cpmstarAPI(function (api) {
    //console.log("Setting iAD")
    iAd = new api.game.InterstitialView("interstitial");
    iAd.load();
    iAd.addEventListener("ad_opened", function (e) {
        iAdPause(); //Pause the game when ad is open 
    });

    iAd.addEventListener("ad_closed", function (e) {
        setTimeout(function () {
            iAdUnpause(); //Unpause when ad closed.  
        }, 700);
        iAd.load(); //Preload another ad. 
    });
});

function iAdPause() {

}
function iAdUnpause() {
    unityAdFinishedCallback()
}


function requestNewAd() {
    //console.log("requested AD")
    //console.log(iAd)
    if (iAd && iAd.isLoaded()) {
        iAd.show(); //Show loaded ad   
    }
    else {
        if (iAd) iAd.load(); //If no ad available, load another      
        unityAdFinishedCallback()
    }
}

// This function calls Unity to tell the ad finished
function unityAdFinishedCallback() {
    try {
        if (gameInstance)
            gameInstance.SendMessage('MainMenuManagers', 'OnWebCallback');
    }
    catch (error) {
        console.log(error);
    }
}