@chiyou/minigame-framework 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (114) hide show
  1. package/README.md +66 -0
  2. package/dist/Framework/Adapter/AdAdapter/AbsAdAdapter.d.ts +78 -0
  3. package/dist/Framework/Adapter/AdAdapter/AbsAdAdapter.js +230 -0
  4. package/dist/Framework/Adapter/AdAdapter/AdAdapterBilibili.d.ts +31 -0
  5. package/dist/Framework/Adapter/AdAdapter/AdAdapterBilibili.js +224 -0
  6. package/dist/Framework/Adapter/AdAdapter/AdAdapterDouYin.d.ts +34 -0
  7. package/dist/Framework/Adapter/AdAdapter/AdAdapterDouYin.js +524 -0
  8. package/dist/Framework/Adapter/AdAdapter/AdAdapterHonor.d.ts +34 -0
  9. package/dist/Framework/Adapter/AdAdapter/AdAdapterHonor.js +631 -0
  10. package/dist/Framework/Adapter/AdAdapter/AdAdapterHuaWei.d.ts +33 -0
  11. package/dist/Framework/Adapter/AdAdapter/AdAdapterHuaWei.js +460 -0
  12. package/dist/Framework/Adapter/AdAdapter/AdAdapterJingDong.d.ts +31 -0
  13. package/dist/Framework/Adapter/AdAdapter/AdAdapterJingDong.js +227 -0
  14. package/dist/Framework/Adapter/AdAdapter/AdAdapterKuaiShou.d.ts +33 -0
  15. package/dist/Framework/Adapter/AdAdapter/AdAdapterKuaiShou.js +458 -0
  16. package/dist/Framework/Adapter/AdAdapter/AdAdapterOppo.d.ts +35 -0
  17. package/dist/Framework/Adapter/AdAdapter/AdAdapterOppo.js +770 -0
  18. package/dist/Framework/Adapter/AdAdapter/AdAdapterTapTap.d.ts +33 -0
  19. package/dist/Framework/Adapter/AdAdapter/AdAdapterTapTap.js +519 -0
  20. package/dist/Framework/Adapter/AdAdapter/AdAdapterVivo.d.ts +33 -0
  21. package/dist/Framework/Adapter/AdAdapter/AdAdapterVivo.js +492 -0
  22. package/dist/Framework/Adapter/AdAdapter/AdAdapterWeiXin.d.ts +33 -0
  23. package/dist/Framework/Adapter/AdAdapter/AdAdapterWeiXin.js +695 -0
  24. package/dist/Framework/Adapter/AdAdapter/AdAdapterXiaoMi.d.ts +34 -0
  25. package/dist/Framework/Adapter/AdAdapter/AdAdapterXiaoMi.js +597 -0
  26. package/dist/Framework/Adapter/AdAdapter/AdAdapterZhiFuBao.d.ts +33 -0
  27. package/dist/Framework/Adapter/AdAdapter/AdAdapterZhiFuBao.js +458 -0
  28. package/dist/Framework/Adapter/PlatformAdapter/AbsPlatformAdapter.d.ts +51 -0
  29. package/dist/Framework/Adapter/PlatformAdapter/AbsPlatformAdapter.js +17 -0
  30. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterBilibili.d.ts +45 -0
  31. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterBilibili.js +555 -0
  32. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterDesktopBrowser.d.ts +44 -0
  33. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterDesktopBrowser.js +148 -0
  34. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterDouYin.d.ts +48 -0
  35. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterDouYin.js +715 -0
  36. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterHonor.d.ts +44 -0
  37. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterHonor.js +296 -0
  38. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterHuaWei.d.ts +45 -0
  39. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterHuaWei.js +284 -0
  40. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterJingDong.d.ts +44 -0
  41. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterJingDong.js +283 -0
  42. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterKuaiShou.d.ts +43 -0
  43. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterKuaiShou.js +406 -0
  44. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterOppo.d.ts +43 -0
  45. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterOppo.js +248 -0
  46. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterTapTap.d.ts +44 -0
  47. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterTapTap.js +517 -0
  48. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterVivo.d.ts +44 -0
  49. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterVivo.js +295 -0
  50. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterWeiXin.d.ts +55 -0
  51. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterWeiXin.js +964 -0
  52. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterXiaoMi.d.ts +44 -0
  53. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterXiaoMi.js +295 -0
  54. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterZhiFuBao.d.ts +44 -0
  55. package/dist/Framework/Adapter/PlatformAdapter/PlatformAdapterZhiFuBao.js +393 -0
  56. package/dist/Framework/Definition/AdDefinition.d.ts +130 -0
  57. package/dist/Framework/Definition/AdDefinition.js +208 -0
  58. package/dist/Framework/Definition/FrameworkBase.d.ts +13 -0
  59. package/dist/Framework/Definition/FrameworkBase.js +23 -0
  60. package/dist/Framework/Definition/PrivacyDefinition.d.ts +51 -0
  61. package/dist/Framework/Definition/PrivacyDefinition.js +70 -0
  62. package/dist/Framework/Definition/SocialDefinition.d.ts +16 -0
  63. package/dist/Framework/Definition/SocialDefinition.js +2 -0
  64. package/dist/Framework/Definition/SystemDefinition.d.ts +43 -0
  65. package/dist/Framework/Definition/SystemDefinition.js +28 -0
  66. package/dist/Framework/Definition/UIDefinition.d.ts +6 -0
  67. package/dist/Framework/Definition/UIDefinition.js +7 -0
  68. package/dist/Framework/Definition/UserDefinition.d.ts +14 -0
  69. package/dist/Framework/Definition/UserDefinition.js +10 -0
  70. package/dist/Framework/Manager/AdMgr.d.ts +57 -0
  71. package/dist/Framework/Manager/AdMgr.js +684 -0
  72. package/dist/Framework/Manager/AudioMgr.d.ts +28 -0
  73. package/dist/Framework/Manager/AudioMgr.js +265 -0
  74. package/dist/Framework/Manager/BaseMgr.d.ts +18 -0
  75. package/dist/Framework/Manager/BaseMgr.js +114 -0
  76. package/dist/Framework/Manager/EventMgr.d.ts +18 -0
  77. package/dist/Framework/Manager/EventMgr.js +90 -0
  78. package/dist/Framework/Manager/ExcelMgr.d.ts +24 -0
  79. package/dist/Framework/Manager/ExcelMgr.js +156 -0
  80. package/dist/Framework/Manager/LifeCycleMgr.d.ts +20 -0
  81. package/dist/Framework/Manager/LifeCycleMgr.js +110 -0
  82. package/dist/Framework/Manager/NodePoolMgr.d.ts +53 -0
  83. package/dist/Framework/Manager/NodePoolMgr.js +279 -0
  84. package/dist/Framework/Manager/PrivacyMgr.d.ts +15 -0
  85. package/dist/Framework/Manager/PrivacyMgr.js +176 -0
  86. package/dist/Framework/Manager/ResMgr.d.ts +49 -0
  87. package/dist/Framework/Manager/ResMgr.js +337 -0
  88. package/dist/Framework/Manager/SocialMgr.d.ts +23 -0
  89. package/dist/Framework/Manager/SocialMgr.js +220 -0
  90. package/dist/Framework/Manager/SystemMgr.d.ts +24 -0
  91. package/dist/Framework/Manager/SystemMgr.js +222 -0
  92. package/dist/Framework/Manager/TimerMgr.d.ts +11 -0
  93. package/dist/Framework/Manager/TimerMgr.js +63 -0
  94. package/dist/Framework/Manager/UIMgr.d.ts +33 -0
  95. package/dist/Framework/Manager/UIMgr.js +223 -0
  96. package/dist/Framework/Manager/UserMgr.d.ts +15 -0
  97. package/dist/Framework/Manager/UserMgr.js +148 -0
  98. package/dist/Framework/Utils/BezierUtils.d.ts +49 -0
  99. package/dist/Framework/Utils/BezierUtils.js +247 -0
  100. package/dist/Framework/Utils/CSVUtils.d.ts +35 -0
  101. package/dist/Framework/Utils/CSVUtils.js +341 -0
  102. package/dist/Framework/Utils/LogUtils.d.ts +7 -0
  103. package/dist/Framework/Utils/LogUtils.js +32 -0
  104. package/dist/Framework/Utils/NumberUtils.d.ts +16 -0
  105. package/dist/Framework/Utils/NumberUtils.js +44 -0
  106. package/dist/Framework/Utils/TaskUtils.d.ts +10 -0
  107. package/dist/Framework/Utils/TaskUtils.js +24 -0
  108. package/dist/Framework/Utils/TimeUtils.d.ts +19 -0
  109. package/dist/Framework/Utils/TimeUtils.js +33 -0
  110. package/dist/Framework/Utils/WXBizDataCryptUtils.d.ts +12 -0
  111. package/dist/Framework/Utils/WXBizDataCryptUtils.js +37 -0
  112. package/dist/index.d.ts +30 -0
  113. package/dist/index.js +35 -0
  114. package/package.json +40 -0
package/README.md ADDED
@@ -0,0 +1,66 @@
1
+ # MiniGameFramework
2
+
3
+ 基于 Cocos Creator 3.x 的小游戏开发框架,支持多平台发布。
4
+
5
+ ## 特性
6
+
7
+ - 🚀 **模块化架构** - 将游戏功能分解为独立的 Manager
8
+ - 🔌 **多平台支持** - 微信、抖音、快手、支付宝、B站、TapTap 等 12+ 平台
9
+ - 📦 **资源管理** - 按批次预加载资源,支持异步加载和缓存管理
10
+ - 🎯 **生命周期管理** - 统一管理游戏的冷启动、热启动、前台/后台切换
11
+ - 🔐 **隐私合规** - 内置隐私协议、用户登录、数据加密等合规功能
12
+ - 📢 **广告系统** - 支持插屏、激励视频、Banner、原生、Portal 等广告
13
+ - 💬 **事件系统** - 基于观察者模式的事件中心,实现模块间解耦通信
14
+
15
+ ## 安装
16
+
17
+ ```bash
18
+ npm install @chiyou/minigame-framework
19
+ ```
20
+
21
+ ## 使用
22
+
23
+ ### 在 Cocos Creator 项目中使用
24
+
25
+ 1. 在 Cocos Creator 的 `package.json` 中添加依赖:
26
+
27
+ ```json
28
+ {
29
+ "dependencies": {
30
+ "@chiyou/minigame-framework": "^1.0.0"
31
+ }
32
+ }
33
+ ```
34
+
35
+ 2. 构建项目时 Cocos Creator 会自动安装依赖
36
+
37
+ 3. 在代码中导入需要使用的模块:
38
+
39
+ ```typescript
40
+ import { ResMgr, UIMgr, EventMgr } from '@chiyou/minigame-framework';
41
+ ```
42
+
43
+ ### 预置的平台适配器
44
+
45
+ | 平台 | PlatformID |
46
+ |------|------------|
47
+ | 微信小游戏 | `ID_MiniGame_WeiXin` |
48
+ | 抖音小游戏 | `ID_MiniGame_DouYin` |
49
+ | 快手小游戏 | `ID_MiniGame_KuaiShou` |
50
+ | 支付宝小游戏 | `ID_MiniGame_ZhiFuBao` |
51
+ | B站小游戏 | `ID_MiniGame_Bilibili` |
52
+ | TapTap | `ID_MiniGame_TapTap` |
53
+ | 京东小游戏 | `ID_MiniGame_JingDong` |
54
+ | 小米快游戏 | `ID_QuickGame_XiaoMi` |
55
+ | OPPO 快游戏 | `ID_QuickGame_Oppo` |
56
+ | 荣耀快游戏 | `ID_QuickGame_Honor` |
57
+ | vivo 快游戏 | `ID_QuickGame_Vivo` |
58
+ | 华为快游戏 | `ID_QuickGame_HuaWei` |
59
+
60
+ ## 文档
61
+
62
+ 详细文档请参考:[小游戏新项目开发指南](https://github.com/chiyou/minigame-framework)
63
+
64
+ ## License
65
+
66
+ MIT
@@ -0,0 +1,78 @@
1
+ import { Component } from "cc";
2
+ import { BannerAd_Info, BannerAd_PlatformInfo, CustomAd_Info, CustomAd_PlatformInfo, PortalAd_PlatformInfo } from "../../Definition/AdDefinition";
3
+ import { ScreenInfo } from "../../Definition/SystemDefinition";
4
+ import { AdMgr } from "../../Manager/AdMgr";
5
+ import { AbsPlatformAdapter } from "../PlatformAdapter/AbsPlatformAdapter";
6
+ export declare enum InterstitialAdStatus {
7
+ Status_Error = -1,
8
+ Status_Init = 0,
9
+ Status_Loaded = 1,
10
+ Status_StartToWatch = 2,
11
+ Status_Watching = 3,
12
+ Status_Watched = 4,
13
+ Status_Destroyed = 5
14
+ }
15
+ export declare enum RewardedVideoAdStatus {
16
+ Status_Error = -1,
17
+ Status_Init = 0,
18
+ Status_Loaded = 1,
19
+ Status_StartToWatch = 2,
20
+ Status_Watching = 3,
21
+ Status_Watched = 4,
22
+ Status_Destroyed = 5
23
+ }
24
+ export type BannerAdPosition = {
25
+ realWidth: number;
26
+ realHeight: number;
27
+ left: number;
28
+ top: number;
29
+ };
30
+ export type CustomAdPosition = {
31
+ realWidth: number;
32
+ realHeight: number;
33
+ left: number;
34
+ top: number;
35
+ };
36
+ export type PortalAdPosition = {
37
+ realWidth: number;
38
+ realHeight: number;
39
+ left: number;
40
+ top: number;
41
+ };
42
+ export declare abstract class AbsAdAdapter extends Component {
43
+ protected static TAG: string;
44
+ protected screenInfo: ScreenInfo;
45
+ protected adMgr: AdMgr;
46
+ protected platformAdapter: AbsPlatformAdapter;
47
+ protected onLoad(): void;
48
+ onInit(screenInfo: ScreenInfo, adMgr: AdMgr, interstitialAdUnitId: string, interstitialAdCallback: Function, rewardedVideoAdUnitId: string, rewardedVideoAdCallback: Function): void;
49
+ abstract init(interstitialAdUnitId: string, interstitialAdCallback: Function, rewardedVideoAdUnitId: string, rewardedVideoAdCallback: Function): void;
50
+ abstract createBannerAd(adUnitId: string): boolean;
51
+ abstract destroyBannerAd(adUnitId: string): void;
52
+ abstract showBannerAd(adUnitId: string): void;
53
+ abstract hideBannerAd(adUnitId: string): void;
54
+ abstract createInterstitialAd(): void;
55
+ abstract showInterstitialAd(): void;
56
+ abstract destroyInterstitialAd(): void;
57
+ abstract isIntersititialAdShowing(): boolean;
58
+ protected abstract _loadInterstitialAd(isShowImmediately: boolean): void;
59
+ protected abstract _showInterstitialAd(): void;
60
+ abstract createRewardedVideoAd(): void;
61
+ abstract showRewardedVideoAd(): void;
62
+ abstract destroyRewardedVideoAd(): void;
63
+ abstract isRewardedVideoAdLoaded(): boolean;
64
+ abstract isRewardedVideoAdShowing(): boolean;
65
+ protected abstract _loadRewardedVideoAd(isShowImmediately: boolean): void;
66
+ protected abstract _showRewardedVideoAd(): void;
67
+ abstract createCustomAd(adUnitId: string): boolean;
68
+ abstract destroyCustomAd(adUnitId: string): void;
69
+ abstract showCustomAd(adUnitId: string): void;
70
+ abstract hideCustomAd(adUnitId: string): void;
71
+ abstract createPortalAd(adUnitId: string): void;
72
+ abstract destroyPortalAd(adUnitId: string): void;
73
+ abstract showPortalAd(adUnitId: string): void;
74
+ abstract hidePortalAd(adUnitId: string): void;
75
+ calcBannerAdPosition(bannerAdInfo: BannerAd_Info, bannerAdPlatformInfo: BannerAd_PlatformInfo): BannerAdPosition;
76
+ calcCustomAdPosition(customAdInfo: CustomAd_Info, customAdPlatformInfo: CustomAd_PlatformInfo): CustomAdPosition;
77
+ calcPortalAdPosition(portalAdPlatformInfo: PortalAd_PlatformInfo): PortalAdPosition;
78
+ }
@@ -0,0 +1,230 @@
1
+ import { Component } from "cc";
2
+ import { BannerAd_XPosition, BannerAd_YPosition, CustomAd_XPosition, CustomAd_YPosition } from "../../Definition/AdDefinition";
3
+ import { BaseMgr } from "../../Manager/BaseMgr";
4
+ export var InterstitialAdStatus;
5
+ (function (InterstitialAdStatus) {
6
+ InterstitialAdStatus[InterstitialAdStatus["Status_Error"] = -1] = "Status_Error";
7
+ InterstitialAdStatus[InterstitialAdStatus["Status_Init"] = 0] = "Status_Init";
8
+ InterstitialAdStatus[InterstitialAdStatus["Status_Loaded"] = 1] = "Status_Loaded";
9
+ InterstitialAdStatus[InterstitialAdStatus["Status_StartToWatch"] = 2] = "Status_StartToWatch";
10
+ InterstitialAdStatus[InterstitialAdStatus["Status_Watching"] = 3] = "Status_Watching";
11
+ InterstitialAdStatus[InterstitialAdStatus["Status_Watched"] = 4] = "Status_Watched";
12
+ InterstitialAdStatus[InterstitialAdStatus["Status_Destroyed"] = 5] = "Status_Destroyed";
13
+ })(InterstitialAdStatus || (InterstitialAdStatus = {}));
14
+ export var RewardedVideoAdStatus;
15
+ (function (RewardedVideoAdStatus) {
16
+ RewardedVideoAdStatus[RewardedVideoAdStatus["Status_Error"] = -1] = "Status_Error";
17
+ RewardedVideoAdStatus[RewardedVideoAdStatus["Status_Init"] = 0] = "Status_Init";
18
+ RewardedVideoAdStatus[RewardedVideoAdStatus["Status_Loaded"] = 1] = "Status_Loaded";
19
+ RewardedVideoAdStatus[RewardedVideoAdStatus["Status_StartToWatch"] = 2] = "Status_StartToWatch";
20
+ RewardedVideoAdStatus[RewardedVideoAdStatus["Status_Watching"] = 3] = "Status_Watching";
21
+ RewardedVideoAdStatus[RewardedVideoAdStatus["Status_Watched"] = 4] = "Status_Watched";
22
+ RewardedVideoAdStatus[RewardedVideoAdStatus["Status_Destroyed"] = 5] = "Status_Destroyed";
23
+ })(RewardedVideoAdStatus || (RewardedVideoAdStatus = {}));
24
+ export class AbsAdAdapter extends Component {
25
+ constructor() {
26
+ super(...arguments);
27
+ this.screenInfo = null;
28
+ this.adMgr = null;
29
+ this.platformAdapter = null;
30
+ }
31
+ onLoad() {
32
+ }
33
+ onInit(screenInfo, adMgr, interstitialAdUnitId, interstitialAdCallback, rewardedVideoAdUnitId, rewardedVideoAdCallback) {
34
+ this.screenInfo = screenInfo;
35
+ this.adMgr = adMgr;
36
+ this.platformAdapter = BaseMgr.Instance.getPlatformAdapter();
37
+ this.init(interstitialAdUnitId, interstitialAdCallback, rewardedVideoAdUnitId, rewardedVideoAdCallback);
38
+ }
39
+ calcBannerAdPosition(bannerAdInfo, bannerAdPlatformInfo) {
40
+ let xPosition = bannerAdInfo.xPosition;
41
+ let yPosition = bannerAdInfo.yPosition;
42
+ let xMargin = bannerAdPlatformInfo.xMargin;
43
+ let yMargin = bannerAdPlatformInfo.yMargin;
44
+ let width = bannerAdPlatformInfo.width;
45
+ let height = bannerAdPlatformInfo.height;
46
+ let adScaleRatio = bannerAdPlatformInfo.scaleRatio;
47
+ let left = 0;
48
+ let top = 0;
49
+ let realWidth = 0;
50
+ let realHeight = 0;
51
+ if (adScaleRatio === 0) {
52
+ realWidth = width;
53
+ if (this.screenInfo !== null) {
54
+ realWidth = this.screenInfo.windowWidth - xMargin * 2;
55
+ }
56
+ realHeight = height * realWidth / width;
57
+ left = xMargin;
58
+ switch (yPosition) {
59
+ case BannerAd_YPosition.Top:
60
+ top = yMargin;
61
+ break;
62
+ case BannerAd_YPosition.Center:
63
+ top = yMargin;
64
+ if (this.screenInfo !== null) {
65
+ top = this.screenInfo.windowHeight / 2 - realHeight / 2;
66
+ }
67
+ break;
68
+ case BannerAd_YPosition.Bottom:
69
+ top = yMargin;
70
+ if (this.screenInfo !== null) {
71
+ top = this.screenInfo.windowHeight - realHeight - yMargin;
72
+ }
73
+ break;
74
+ }
75
+ }
76
+ else {
77
+ realWidth = width * adScaleRatio;
78
+ realHeight = height * adScaleRatio;
79
+ switch (yPosition) {
80
+ case BannerAd_YPosition.Top:
81
+ top = yMargin;
82
+ break;
83
+ case BannerAd_YPosition.Center:
84
+ top = yMargin;
85
+ if (this.screenInfo !== null) {
86
+ top = this.screenInfo.windowHeight / 2 - realHeight / 2;
87
+ }
88
+ break;
89
+ case BannerAd_YPosition.Bottom:
90
+ top = yMargin;
91
+ if (this.screenInfo !== null) {
92
+ top = this.screenInfo.windowHeight - realHeight - yMargin;
93
+ }
94
+ break;
95
+ }
96
+ switch (xPosition) {
97
+ case BannerAd_XPosition.Left:
98
+ left = xMargin;
99
+ break;
100
+ case BannerAd_XPosition.Center:
101
+ left = xMargin;
102
+ if (this.screenInfo !== null) {
103
+ left = this.screenInfo.windowWidth / 2 - realWidth / 2;
104
+ }
105
+ break;
106
+ case BannerAd_XPosition.Right:
107
+ left = xMargin;
108
+ if (this.screenInfo !== null) {
109
+ left = this.screenInfo.windowWidth - realWidth - xMargin;
110
+ }
111
+ break;
112
+ }
113
+ }
114
+ let posInfo = {
115
+ realWidth: realWidth,
116
+ realHeight: realHeight,
117
+ left: left,
118
+ top: top,
119
+ };
120
+ return posInfo;
121
+ }
122
+ calcCustomAdPosition(customAdInfo, customAdPlatformInfo) {
123
+ let xPosition = customAdInfo.xPostion;
124
+ let yPosition = customAdInfo.yPostion;
125
+ let xMargin = customAdPlatformInfo.xMargin;
126
+ let yMargin = customAdPlatformInfo.yMargin;
127
+ let width = customAdPlatformInfo.width;
128
+ let height = customAdPlatformInfo.height;
129
+ let adScaleRatio = customAdPlatformInfo.scaleRatio;
130
+ let top = 0;
131
+ let left = 0;
132
+ let realWidth = 0;
133
+ let realHeight = 0;
134
+ if (adScaleRatio === 0) {
135
+ realWidth = width;
136
+ if (this.screenInfo !== null) {
137
+ realWidth = this.screenInfo.windowWidth - xMargin * 2;
138
+ }
139
+ realHeight = height * realWidth / width;
140
+ left = xMargin;
141
+ switch (yPosition) {
142
+ case CustomAd_YPosition.Top:
143
+ top = yMargin;
144
+ break;
145
+ case CustomAd_YPosition.Center:
146
+ top = yMargin;
147
+ if (this.screenInfo !== null) {
148
+ top = this.screenInfo.windowHeight / 2 - realHeight / 2;
149
+ }
150
+ break;
151
+ case CustomAd_YPosition.Bottom:
152
+ top = yMargin;
153
+ if (this.screenInfo !== null) {
154
+ top = this.screenInfo.windowHeight - realHeight - yMargin;
155
+ }
156
+ break;
157
+ }
158
+ }
159
+ else {
160
+ realWidth = width * adScaleRatio;
161
+ realHeight = height * adScaleRatio;
162
+ switch (yPosition) {
163
+ case CustomAd_YPosition.Top:
164
+ top = yMargin;
165
+ break;
166
+ case CustomAd_YPosition.Center:
167
+ top = 0;
168
+ if (this.screenInfo !== null) {
169
+ top = this.screenInfo.windowHeight / 2 - realHeight / 2;
170
+ }
171
+ break;
172
+ case CustomAd_YPosition.Bottom:
173
+ top = 0;
174
+ if (this.screenInfo !== null) {
175
+ top = this.screenInfo.windowHeight - realHeight - yMargin;
176
+ }
177
+ break;
178
+ }
179
+ switch (xPosition) {
180
+ case CustomAd_XPosition.Left:
181
+ left = xMargin;
182
+ break;
183
+ case CustomAd_XPosition.Center:
184
+ left = 0;
185
+ if (this.screenInfo !== null) {
186
+ left = this.screenInfo.windowWidth / 2 - realWidth / 2;
187
+ }
188
+ break;
189
+ case CustomAd_XPosition.Right:
190
+ left = 0;
191
+ if (this.screenInfo !== null) {
192
+ left = this.screenInfo.windowWidth - realWidth - xMargin;
193
+ }
194
+ break;
195
+ }
196
+ }
197
+ let posInfo = {
198
+ realWidth: realWidth,
199
+ realHeight: realHeight,
200
+ left: left,
201
+ top: top,
202
+ };
203
+ return posInfo;
204
+ }
205
+ calcPortalAdPosition(portalAdPlatformInfo) {
206
+ let width = portalAdPlatformInfo.width;
207
+ let height = portalAdPlatformInfo.height;
208
+ let adScaleRatio = portalAdPlatformInfo.scaleRatio;
209
+ let top = 0;
210
+ let left = 0;
211
+ let realWidth = 0;
212
+ let realHeight = 0;
213
+ realWidth = width * adScaleRatio;
214
+ realHeight = height * adScaleRatio;
215
+ top = 0;
216
+ left = 0;
217
+ if (this.screenInfo !== null) {
218
+ left = this.screenInfo.windowWidth / 2 - realWidth / 2;
219
+ top = this.screenInfo.windowHeight / 2 - realHeight / 2;
220
+ }
221
+ let posInfo = {
222
+ realWidth: realWidth,
223
+ realHeight: realHeight,
224
+ left: left,
225
+ top: top,
226
+ };
227
+ return posInfo;
228
+ }
229
+ }
230
+ AbsAdAdapter.TAG = "AbsAdAdapter";
@@ -0,0 +1,31 @@
1
+ import { AbsAdAdapter } from "./AbsAdAdapter";
2
+ export declare class AdAdapterBilibili extends AbsAdAdapter {
3
+ static TAG: string;
4
+ private blRewardedVideoAd;
5
+ init(interstitialAdUnitId: string, interstitialAdCallback: Function, rewardedVideoAdUnitId: string, rewardedVideoAdCallback: Function): void;
6
+ createBannerAd(adUnitId: string): boolean;
7
+ destroyBannerAd(adUnitId: string): void;
8
+ showBannerAd(adUnitId: string): void;
9
+ hideBannerAd(adUnitId: string): void;
10
+ createInterstitialAd(): void;
11
+ showInterstitialAd(): void;
12
+ destroyInterstitialAd(): void;
13
+ isIntersititialAdShowing(): boolean;
14
+ protected _loadInterstitialAd(isShowImmediately: boolean): void;
15
+ protected _showInterstitialAd(): void;
16
+ createRewardedVideoAd(): void;
17
+ showRewardedVideoAd(): void;
18
+ destroyRewardedVideoAd(): void;
19
+ isRewardedVideoAdLoaded(): boolean;
20
+ isRewardedVideoAdShowing(): boolean;
21
+ protected _loadRewardedVideoAd(isShowImmediately: boolean): void;
22
+ protected _showRewardedVideoAd(): void;
23
+ createCustomAd(adUnitId: string): boolean;
24
+ destroyCustomAd(adUnitId: string): void;
25
+ showCustomAd(adUnitId: string): void;
26
+ hideCustomAd(adUnitId: string): void;
27
+ createPortalAd(adUnitId: string): void;
28
+ destroyPortalAd(adUnitId: string): void;
29
+ showPortalAd(adUnitId: string): void;
30
+ hidePortalAd(adUnitId: string): void;
31
+ }
@@ -0,0 +1,224 @@
1
+ import { RewardedVideoAd_Callback_Status } from "../../Definition/AdDefinition";
2
+ import { LogUtils } from "../../Utils/LogUtils";
3
+ import { AbsAdAdapter, RewardedVideoAdStatus } from "./AbsAdAdapter";
4
+ class BLRewardedVideoAd {
5
+ constructor(adUnitId, callback) {
6
+ this.unitId = adUnitId;
7
+ this.ad = null;
8
+ this.status = RewardedVideoAdStatus.Status_Destroyed;
9
+ this.callback = callback;
10
+ this.errorListener = null;
11
+ this.loadListener = null;
12
+ this.closeListener = null;
13
+ this.isShowImmediately = false;
14
+ }
15
+ destroy() {
16
+ if (this.ad !== null) {
17
+ if (this.errorListener !== null) {
18
+ this.ad.offError(this.errorListener);
19
+ this.errorListener = null;
20
+ }
21
+ if (this.loadListener !== null) {
22
+ this.ad.offLoad(this.loadListener);
23
+ this.loadListener = null;
24
+ }
25
+ if (this.closeListener !== null) {
26
+ this.ad.offClose(this.closeListener);
27
+ this.closeListener = null;
28
+ }
29
+ this.ad.destroy();
30
+ this.ad = null;
31
+ }
32
+ this.isShowImmediately = false;
33
+ this.status = RewardedVideoAdStatus.Status_Destroyed;
34
+ }
35
+ }
36
+ export class AdAdapterBilibili extends AbsAdAdapter {
37
+ constructor() {
38
+ super(...arguments);
39
+ this.blRewardedVideoAd = null;
40
+ }
41
+ init(interstitialAdUnitId, interstitialAdCallback, rewardedVideoAdUnitId, rewardedVideoAdCallback) {
42
+ LogUtils.Instance.log(AdAdapterBilibili.TAG, "init()");
43
+ this.blRewardedVideoAd = new BLRewardedVideoAd(rewardedVideoAdUnitId, rewardedVideoAdCallback);
44
+ }
45
+ createBannerAd(adUnitId) {
46
+ return false;
47
+ }
48
+ destroyBannerAd(adUnitId) {
49
+ }
50
+ showBannerAd(adUnitId) {
51
+ }
52
+ hideBannerAd(adUnitId) {
53
+ }
54
+ createInterstitialAd() {
55
+ }
56
+ showInterstitialAd() {
57
+ }
58
+ destroyInterstitialAd() {
59
+ }
60
+ isIntersititialAdShowing() {
61
+ return false;
62
+ }
63
+ _loadInterstitialAd(isShowImmediately) {
64
+ }
65
+ _showInterstitialAd() {
66
+ }
67
+ createRewardedVideoAd() {
68
+ this.destroyRewardedVideoAd();
69
+ LogUtils.Instance.log(AdAdapterBilibili.TAG, "createRewardedVideoAd() adUnitId=" + this.blRewardedVideoAd.unitId);
70
+ let rewardedVideoAd = window["bl"].createRewardedVideoAd({
71
+ adUnitId: this.blRewardedVideoAd.unitId
72
+ });
73
+ LogUtils.Instance.log(AdAdapterBilibili.TAG, "bl.createRewardedVideoAd() " + (rewardedVideoAd !== null ? "success" : "fail"));
74
+ LogUtils.Instance.log("", rewardedVideoAd);
75
+ if (!rewardedVideoAd) {
76
+ this.blRewardedVideoAd.status = RewardedVideoAdStatus.Status_Error;
77
+ this.blRewardedVideoAd.callback(RewardedVideoAd_Callback_Status.Status_Error);
78
+ return;
79
+ }
80
+ this.blRewardedVideoAd.ad = rewardedVideoAd;
81
+ this.blRewardedVideoAd.status = RewardedVideoAdStatus.Status_Init;
82
+ this.blRewardedVideoAd.errorListener = (err) => {
83
+ LogUtils.Instance.log(AdAdapterBilibili.TAG, "blRewardedVideoAd.ad.onError()");
84
+ if (err) {
85
+ LogUtils.Instance.log("", err);
86
+ }
87
+ if (this.blRewardedVideoAd.status !== RewardedVideoAdStatus.Status_Watching) {
88
+ this.blRewardedVideoAd.status = RewardedVideoAdStatus.Status_Error;
89
+ this.blRewardedVideoAd.callback(RewardedVideoAd_Callback_Status.Status_Error);
90
+ }
91
+ };
92
+ this.blRewardedVideoAd.ad.onError(this.blRewardedVideoAd.errorListener);
93
+ this.blRewardedVideoAd.loadListener = () => {
94
+ LogUtils.Instance.log(AdAdapterBilibili.TAG, "blRewardedVideoAd.ad.onLoad()");
95
+ this.blRewardedVideoAd.status = RewardedVideoAdStatus.Status_Loaded;
96
+ if (this.blRewardedVideoAd.isShowImmediately) {
97
+ this.blRewardedVideoAd.isShowImmediately = false;
98
+ this._showRewardedVideoAd();
99
+ }
100
+ };
101
+ this.blRewardedVideoAd.ad.onLoad(this.blRewardedVideoAd.loadListener);
102
+ this.blRewardedVideoAd.closeListener = (res) => {
103
+ let isEnded = (res !== null) ? res.isEnded : false;
104
+ LogUtils.Instance.log(AdAdapterBilibili.TAG, "blRewardedVideoAd.ad.onClose()");
105
+ LogUtils.Instance.log("", "isEnded=" + isEnded);
106
+ this.blRewardedVideoAd.status = RewardedVideoAdStatus.Status_Watched;
107
+ if (isEnded) {
108
+ this.blRewardedVideoAd.callback(RewardedVideoAd_Callback_Status.Status_Complete);
109
+ }
110
+ else {
111
+ this.blRewardedVideoAd.callback(RewardedVideoAd_Callback_Status.Status_Giveup);
112
+ }
113
+ this.scheduleOnce(() => {
114
+ if (this.blRewardedVideoAd.status !== RewardedVideoAdStatus.Status_Loaded) {
115
+ this._loadRewardedVideoAd(false);
116
+ }
117
+ }, 2);
118
+ };
119
+ this.blRewardedVideoAd.ad.onClose(this.blRewardedVideoAd.closeListener);
120
+ this.scheduleOnce(() => {
121
+ if (this.blRewardedVideoAd.status !== RewardedVideoAdStatus.Status_Loaded) {
122
+ this._loadRewardedVideoAd(false);
123
+ }
124
+ }, 2);
125
+ }
126
+ showRewardedVideoAd() {
127
+ LogUtils.Instance.log(AdAdapterBilibili.TAG, "showRewardedVideoAd()");
128
+ if (this.blRewardedVideoAd.ad === null) {
129
+ return;
130
+ }
131
+ LogUtils.Instance.log(AdAdapterBilibili.TAG, "blRewardedVideoAd.status=" + RewardedVideoAdStatus[this.blRewardedVideoAd.status]);
132
+ switch (this.blRewardedVideoAd.status) {
133
+ case RewardedVideoAdStatus.Status_Destroyed:
134
+ case RewardedVideoAdStatus.Status_Watching:
135
+ case RewardedVideoAdStatus.Status_StartToWatch:
136
+ break;
137
+ case RewardedVideoAdStatus.Status_Loaded:
138
+ this._showRewardedVideoAd();
139
+ break;
140
+ case RewardedVideoAdStatus.Status_Watched:
141
+ case RewardedVideoAdStatus.Status_Error:
142
+ case RewardedVideoAdStatus.Status_Init:
143
+ this._loadRewardedVideoAd(true);
144
+ break;
145
+ default:
146
+ break;
147
+ }
148
+ }
149
+ destroyRewardedVideoAd() {
150
+ LogUtils.Instance.log(AdAdapterBilibili.TAG, "destroyRewardedVideoAd()");
151
+ this.blRewardedVideoAd.destroy();
152
+ }
153
+ isRewardedVideoAdLoaded() {
154
+ if (this.blRewardedVideoAd.ad === null) {
155
+ return false;
156
+ }
157
+ if (this.blRewardedVideoAd.status === RewardedVideoAdStatus.Status_Loaded) {
158
+ return true;
159
+ }
160
+ return false;
161
+ }
162
+ isRewardedVideoAdShowing() {
163
+ if (this.blRewardedVideoAd.ad === null) {
164
+ return false;
165
+ }
166
+ if (this.blRewardedVideoAd.status === RewardedVideoAdStatus.Status_Watching) {
167
+ return true;
168
+ }
169
+ return false;
170
+ }
171
+ _loadRewardedVideoAd(isShowImmediately) {
172
+ this.blRewardedVideoAd.isShowImmediately = isShowImmediately;
173
+ LogUtils.Instance.log(AdAdapterBilibili.TAG, "blRewardedVideoAd.ad.load()");
174
+ this.blRewardedVideoAd.ad.load().then(() => {
175
+ LogUtils.Instance.log(AdAdapterBilibili.TAG, "blRewardedVideoAd.ad.load() success");
176
+ }).catch((err) => {
177
+ LogUtils.Instance.log(AdAdapterBilibili.TAG, "blRewardedVideoAd.ad.load() error");
178
+ if (err) {
179
+ LogUtils.Instance.log("", err);
180
+ }
181
+ });
182
+ }
183
+ _showRewardedVideoAd() {
184
+ if (this.blRewardedVideoAd.status !== RewardedVideoAdStatus.Status_Loaded) {
185
+ return;
186
+ }
187
+ this.blRewardedVideoAd.status = RewardedVideoAdStatus.Status_StartToWatch;
188
+ LogUtils.Instance.log(AdAdapterBilibili.TAG, "blRewardedVideoAd.ad.show()");
189
+ this.blRewardedVideoAd.ad.show()
190
+ .then(() => {
191
+ LogUtils.Instance.log(AdAdapterBilibili.TAG, "blRewardedVideoAd.ad.show() success");
192
+ if (this.blRewardedVideoAd.status === RewardedVideoAdStatus.Status_StartToWatch) {
193
+ this.blRewardedVideoAd.status = RewardedVideoAdStatus.Status_Watching;
194
+ this.blRewardedVideoAd.callback(RewardedVideoAd_Callback_Status.Status_Watching);
195
+ }
196
+ }).catch((err) => {
197
+ LogUtils.Instance.log(AdAdapterBilibili.TAG, "blRewardedVideoAd.ad.show() error");
198
+ if (err) {
199
+ LogUtils.Instance.log("", err);
200
+ }
201
+ if (this.blRewardedVideoAd.status === RewardedVideoAdStatus.Status_StartToWatch) {
202
+ this.blRewardedVideoAd.status = RewardedVideoAdStatus.Status_Loaded;
203
+ }
204
+ });
205
+ }
206
+ createCustomAd(adUnitId) {
207
+ return false;
208
+ }
209
+ destroyCustomAd(adUnitId) {
210
+ }
211
+ showCustomAd(adUnitId) {
212
+ }
213
+ hideCustomAd(adUnitId) {
214
+ }
215
+ createPortalAd(adUnitId) {
216
+ }
217
+ destroyPortalAd(adUnitId) {
218
+ }
219
+ showPortalAd(adUnitId) {
220
+ }
221
+ hidePortalAd(adUnitId) {
222
+ }
223
+ }
224
+ AdAdapterBilibili.TAG = "AdAdapterBilibili";
@@ -0,0 +1,34 @@
1
+ import { AbsAdAdapter } from './AbsAdAdapter';
2
+ export declare class AdAdapterDouYin extends AbsAdAdapter {
3
+ static TAG: string;
4
+ private ttInterstitialAd;
5
+ private ttRewardedVideoAd;
6
+ private ttBannerAds;
7
+ init(interstitialAdUnitId: string, interstitialAdCallback: Function, rewardedVideoAdUnitId: string, rewardedVideoAdCallback: Function): void;
8
+ createBannerAd(adUnitId: string): boolean;
9
+ destroyBannerAd(adUnitId: string): void;
10
+ showBannerAd(adUnitId: string): void;
11
+ hideBannerAd(adUnitId: string): void;
12
+ createInterstitialAd(): void;
13
+ private _createInterstitialAd;
14
+ showInterstitialAd(): void;
15
+ destroyInterstitialAd(): void;
16
+ isIntersititialAdShowing(): boolean;
17
+ protected _loadInterstitialAd(isShowImmediately: boolean): void;
18
+ protected _showInterstitialAd(): void;
19
+ createRewardedVideoAd(): void;
20
+ showRewardedVideoAd(): void;
21
+ destroyRewardedVideoAd(): void;
22
+ isRewardedVideoAdLoaded(): boolean;
23
+ isRewardedVideoAdShowing(): boolean;
24
+ protected _loadRewardedVideoAd(isShowImmediately: boolean): void;
25
+ protected _showRewardedVideoAd(): void;
26
+ createCustomAd(adUnitId: string): boolean;
27
+ destroyCustomAd(adUnitId: string): void;
28
+ showCustomAd(adUnitId: string): void;
29
+ hideCustomAd(adUnitId: string): void;
30
+ createPortalAd(adUnitId: string): void;
31
+ destroyPortalAd(adUnitId: string): void;
32
+ showPortalAd(adUnitId: string): void;
33
+ hidePortalAd(adUnitId: string): void;
34
+ }