AdManager.ts 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import { sys } from "cc";
  2. import { WeChatAdManager } from "./WeChatAdManager";
  3. import { DouYinAdManager } from "./DouYinAdManager";
  4. import { KuaiShouAdManager } from "./KuaiShouAdManager";
  5. export class AdManager {
  6. private static _instance: AdManager;
  7. public static getInstance(): AdManager {
  8. if (!AdManager._instance) {
  9. if ((sys.platform == sys.Platform.WECHAT_GAME) && window.ks) {
  10. AdManager._instance = new AdManager('kuaihsou');
  11. } else if (sys.platform == sys.Platform.WECHAT_GAME) {
  12. AdManager._instance = new AdManager('wechat');
  13. } else if (sys.platform == sys.Platform.BYTEDANCE_MINI_GAME) {
  14. AdManager._instance = new AdManager('douyin');
  15. } else {
  16. AdManager._instance = new AdManager('wechat');
  17. }
  18. }
  19. return AdManager._instance;
  20. }
  21. private currentAdManager: WeChatAdManager | DouYinAdManager | KuaiShouAdManager;
  22. constructor(platform: string) {
  23. sys.Platform.WECHAT_GAME
  24. switch (platform) {
  25. case 'wechat':
  26. this.currentAdManager = new WeChatAdManager();
  27. break;
  28. case 'douyin':
  29. this.currentAdManager = new DouYinAdManager();
  30. break;
  31. case 'kuaihsou':
  32. this.currentAdManager = new KuaiShouAdManager();
  33. break;
  34. default:
  35. console.log('Unsupported platform');
  36. }
  37. }
  38. public showBannerAd() {
  39. if (this.currentAdManager) {
  40. this.currentAdManager.showBannerAd();
  41. }
  42. }
  43. public showRewardVideoAd(successCallback: (res) => void) {
  44. if (this.currentAdManager) {
  45. this.currentAdManager.showRewardVideoAd(successCallback);
  46. }
  47. }
  48. public showInterstitialAd() {
  49. if (this.currentAdManager) {
  50. this.currentAdManager.showInterstitialAd();
  51. }
  52. }
  53. }