AdManager.ts 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. }
  14. else if (sys.platform == sys.Platform.BYTEDANCE_MINI_GAME) {
  15. AdManager._instance = new AdManager('douyin');
  16. }
  17. else {
  18. AdManager._instance = new AdManager('wechat');
  19. }
  20. }
  21. return AdManager._instance;
  22. }
  23. private currentAdManager: WeChatAdManager | DouYinAdManager | KuaiShouAdManager;
  24. constructor(platform: string) {
  25. sys.Platform.WECHAT_GAME
  26. switch (platform) {
  27. case 'wechat':
  28. this.currentAdManager = new WeChatAdManager();
  29. break;
  30. case 'douyin':
  31. this.currentAdManager = new DouYinAdManager();
  32. break;
  33. case 'kuaihsou':
  34. this.currentAdManager = new KuaiShouAdManager();
  35. break;
  36. default:
  37. console.log('Unsupported platform');
  38. }
  39. }
  40. public showBannerAd() {
  41. if (this.currentAdManager) {
  42. this.currentAdManager.showBannerAd();
  43. }
  44. }
  45. public showRewardVideoAd(successCallback: (res) => void) {
  46. if (this.currentAdManager) {
  47. this.currentAdManager.showRewardVideoAd(successCallback);
  48. }
  49. }
  50. public showInterstitialAd() {
  51. if (this.currentAdManager) {
  52. this.currentAdManager.showInterstitialAd();
  53. }
  54. }
  55. }