Jelajahi Sumber

广告修改

woso_javan 2 bulan lalu
induk
melakukan
ba586f6c41

+ 5 - 5
assets/core_tgx/base/ad/AdvertMgr.ts

@@ -1,7 +1,5 @@
 import { _decorator, Node, Prefab, instantiate, Component, Camera, UITransform, v3, game, view, screen, tween, Vec3 } from 'cc';
-import { EventDispatcher } from '../../easy_ui_framework/EventDispatcher';
-import { ADEvent } from './ADEvent';
-import { AudioMgr } from '../AudioMgr';
+
 import { tgxUITips } from 'db://assets/core_tgx/tgx';
 import { GtagMgr, GtagType } from 'db://assets/core_tgx/base/GtagMgr';
 const { ccclass, property } = _decorator;
@@ -27,8 +25,9 @@ export class AdvertMgr {
 
     /** 显示插屏广告*/
     showInterstitial(cb?: () => void): void {
+
         try {
-            window['showAd']('Interstitial').then(() => {
+            window['showAd']('interstitial').then(() => {
 
             }).catch(() => {
                 // GtagMgr.inst.doGameDot(GtagType.ad_error);
@@ -40,8 +39,9 @@ export class AdvertMgr {
 
     /** 显示激励广告*/
     showReawardVideo(cb?: () => void): void {
+
         try {
-            window["showAd"]('Reward')
+            window["showAd"]('rewarded')
                 .then(() => {
                     if (cb) cb();
                 })

+ 44 - 36
assets/scripts/GlobalMgr.ts

@@ -13,63 +13,71 @@ export class GlobalMgr {
 
     //初始化__woso 挂载到window对象上
     public initilize() {
-        window['__woso'] = {
-            SoundMr: {
+        window["youxi"] = {
+            SoundManager: {
                 pauseAll: () => {
-                    GlobalMgr.instance.pauseAllSounds();
+                    // console.log("暂停游戏所有声音 oh~~~~~~~~~~~");
+                    AudioMgr.inst.toggleBgMusic(false);
+                    AudioMgr.inst.toggleSoundEffects(false);
                 },
                 resumeAll: () => {
-                    GlobalMgr.instance.resumeAllSounds();
+                    // console.log("恢复游戏所有声音 emo~~~~~~~~~~");
+                    AudioMgr.inst.toggleBgMusic(true);
+                    AudioMgr.inst.toggleSoundEffects(true);
                 }
             },
             TargetedAds: {
                 open: () => {
-                    GlobalMgr.instance.openAd();
+                    console.log("开启广告");
+                    AdvertMgr.instance.openAd = true;
                 },
                 clos: () => {
-                    GlobalMgr.instance.closeAd();
+                    console.log("关闭广告");
+                    AdvertMgr.instance.openAd = false;
                 }
             },
             Fps: {
                 setfps: (value) => {
-                    GlobalMgr.instance.setfps(value);
+                    // GlobalMgr.instance.setfps(value);
                 }
             }
         };
     }
 
-    // 暂停所有声音
-    pauseAllSounds() {
-        // console.log("暂停游戏所有声音 oh~~~~~~~~~~~");
-        AudioMgr.inst.toggleBgMusic(false);
-        AudioMgr.inst.toggleSoundEffects(false);
-    }
-    // 恢复所有声音
-    resumeAllSounds() {
-        // console.log("恢复游戏所有声音 emo~~~~~~~~~~");
-        AudioMgr.inst.toggleBgMusic(true);
-        AudioMgr.inst.toggleSoundEffects(true);
-    }
+    // // 暂停所有声音
+    // pauseAllSounds() {
+    //     // console.log("暂停游戏所有声音 oh~~~~~~~~~~~");
+    //     AudioMgr.inst.toggleBgMusic(false);
+    //     AudioMgr.inst.toggleSoundEffects(false);
+    // }
+    // // 恢复所有声音
+    // resumeAllSounds() {
+    //     // console.log("恢复游戏所有声音 emo~~~~~~~~~~");
+    //     AudioMgr.inst.toggleBgMusic(true);
+    //     AudioMgr.inst.toggleSoundEffects(true);
+    // }
 
-    //开启广告
-    openAd() {
-        AdvertMgr.instance.openAd = true;
-    }
+    // //开启广告
+    // openAd() {
+    //     console.log("开启广告");
+    //     AdvertMgr.instance.openAd = true;
+    // }
 
-    //关闭广告
-    closeAd() {
-        AdvertMgr.instance.openAd = false;
-    }
+    // //关闭广告
+    // closeAd() {
+    //     console.log("关闭广告");
+    //     AdvertMgr.instance.openAd = false;
+    // }
 
-    //设置帧率
-    setfps(value) {
-        console.log("设置帧率:", value);
-    }
+    // //设置帧率
+    // setfps(value) {
+    //     console.log("设置帧率:", value);
+    // }
 
-    timeTest() {
-        setTimeout(() => {
-            window['__woso'].SoundMr.pauseAll();
-        }, 2000);
-    }
+    // timeTest() {
+    //     setTimeout(() => {
+    //         window.__woso.SoundMr.pauseAll();
+    //     }, 2000);
+    // }
 
 }

+ 1 - 1
assets/start/Config/GlobalConfig.ts

@@ -1,5 +1,5 @@
 export const GlobalConfig = {
-    isDebug: true,
+    isDebug: false,
     initilizeLevel: 1,//初始关卡
     levelTotal: 50,   //最大关卡等级
 }

+ 1 - 0
assets/start/Start.ts

@@ -61,6 +61,7 @@ export class Start extends Component {
         } catch (error) {
 
         }
+
         if (!GlobalConfig.isDebug) {
             AdvertMgr.instance.showInterstitial();
         }

+ 66 - 9
build-templates/web-mobile/index.html

@@ -58,8 +58,9 @@
   <script src="src/import-map.json" type="systemjs-importmap" charset="utf-8"> </script>
 
   <script>
+    // adInstance = null
     // 动态加载外部脚本的方法
-    function loadScript(url) {
+    loadScript = function (url) {
       return new Promise((resolve, reject) => {
         const script = document.createElement('script');
         script.src = url;
@@ -78,28 +79,81 @@
         var adSdkConfig = {
           el: document.querySelector("GameDiv"),
           client: 'cpsense-cd',
-          is_test: false
+          is_test: true
         };
         var adInstance = new adSdk(adSdkConfig);
         window.adInstance = adInstance;
+        window.CPSenseShowAd = {
+          showAd: function (type) {
+            return new Promise((resolve, reject) => {
+              if (type === 'interstitial') {
+                adInstance.interstitialAd({
+                  beforeAd: function () {
+                    console.log("The ad starts playing")
+                  },
+                  afterAd: function () {
+                    console.log("The ad ends playing")
+                    resolve({
+                      result: 'success',
+                      message: 'Interstitial ad closed'
+                    });
+                  },
+                  error: function (n) {
+                    console.log("error", n);
+                    reject(new Error('Interstitial ad error'));
+                  }
+                });
+              } else if (type === 'rewarded') {
+                adInstance.rewardAd({
+                  beforeAd: function () {
+                    console.log("The ad starts playing, and the game should pause."),
+                      window.youxi.SoundManager.pauseAll();
+                  },
+                  adDismissed: function () {
+                    console.log("Player dismissed the ad before completion."),
+                      window.youxi.SoundManager.resumeAll();
+                    reject(new Error('Interstitial ad error'));
+                  },
+                  adViewed: function () {
+                    console.log("Ad was viewed and closed."),
+                      window.youxi.SoundManager.resumeAll();
+                    resolve({
+                      result: 'success',
+                      message: 'Interstitial ad closed'
+                    });
+                  },
+                  error: function (n) {
+                    console.log("error", n);
+                    window.youxi.SoundManager.resumeAll();
+                    reject(new Error('Interstitial ad error'));
+                  }
+                })
+              } else {
+                reject(new Error('Invalid ad type'));
+              }
+            });
+          }
+        };
+
+        console.log('AD initialized successfully');
+
 
-        // 加载项目主入口
-        return System.import('./index.js');
       })
       .then(() => {
-        console.log('Game initialized successfully');
+        // 加载项目主入口
+        return System.import('./index.js');
       })
       .catch(err => {
         console.error('Error during initialization:', err);
       });
-  </script>
 
-  <script src=""></script>
-  <script>
+
     // 外部广告调用
     window.showAd = function (type) {
+      type = type.toLowerCase();
       return new Promise((resolve, reject) => {
-        window.__woso.showAd(type)
+
+        window.CPSenseShowAd.showAd(type)
           .then((res) => {
             // 为游戏返回广告结果
             console.log(res);
@@ -110,16 +164,19 @@
             reject(err);
           });
       });
+
     };
 
     // 回调测试
     function TopCallback() {
+
       //sound
       if (window.__woso.SoundManager.isSound) {
         window.youxi.SoundManager.resumeAll();
       } else {
         window.youxi.SoundManager.pauseAll();
       }
+
     }
   </script>