@chiyou/minigame-framework 1.4.9 → 1.4.11

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chiyou/minigame-framework",
3
- "version": "1.4.9",
3
+ "version": "1.4.11",
4
4
  "description": "基于 Cocos Creator 3.x 的小游戏开发框架,支持多平台发布",
5
5
  "main": "src/index.ts",
6
6
  "types": "src/index.ts",
@@ -54,10 +54,10 @@ export type AdPlatformUnitInfo = {
54
54
  }
55
55
 
56
56
  export type AdPlatformSettingInfo = {
57
- launchNoAdInterval_permanentAd: number;
58
- launchNoAdInterval_interstitialAd: number;
59
- registerUser_interstitialAd_IntervalBase: number;
60
- retainUser_interstitialAd_IntervalBase: number;
57
+ permanentAd_firstShowInterval_registerUser: number;
58
+ permanentAd_firstShowInterval_retainUser: number;
59
+ interstitialAd_showIntervalBase_registerUser: number;
60
+ interstitialAd_showIntervalBase_retainUser: number;
61
61
  }
62
62
 
63
63
  //BannerAd
@@ -67,6 +67,9 @@ export class AdMgr extends BaseMgr {
67
67
  /** 内容区域底部 */
68
68
  private static contentBottom: number = 0;
69
69
 
70
+ private static interstitialAdIntervalBase: number = 60000;
71
+ private static permanentAdFirstShowInterval: number = 60000;
72
+
70
73
  private rewardedVideoAdCallbackToBusinessStatusSet: Set<RewardedVideoAd_Callback_Status> = new Set<RewardedVideoAd_Callback_Status>(
71
74
  [
72
75
  RewardedVideoAd_Callback_Status.Status_LoadError,
@@ -136,7 +139,7 @@ export class AdMgr extends BaseMgr {
136
139
  AdMgr.adPlatformSettingMap = adPlatformSettingMap;
137
140
 
138
141
  let adAdapterImpl: AbsAdAdapter = null;
139
- switch (BaseMgr.Instance.getCurrentPlatformID()) {
142
+ switch (currentPlatformID) {
140
143
  case PlatformID.ID_MiniGame_WeiXin:
141
144
  adAdapterImpl = this.node.addComponent(AdAdapterWeiXin);
142
145
  break;
@@ -348,6 +351,24 @@ export class AdMgr extends BaseMgr {
348
351
 
349
352
  /** 创建所有广告实例 */
350
353
  public createAds(): void {
354
+ if (this.userMgr === null) {
355
+ this.userMgr = ServiceLocator.Instance.get<UserMgr>("UserMgr");
356
+ }
357
+
358
+ AdMgr.interstitialAdIntervalBase = 60000;
359
+ AdMgr.permanentAdFirstShowInterval = 60;
360
+ let currentPlatformID: PlatformID = this.getCurrentPlatformID();
361
+ if (AdMgr.adPlatformSettingMap.has(currentPlatformID) && AdMgr.adPlatformSettingMap.get(currentPlatformID) !== null) {
362
+ let adPlatformSettingInfo: AdPlatformSettingInfo = AdMgr.adPlatformSettingMap.get(currentPlatformID);
363
+ AdMgr.interstitialAdIntervalBase = adPlatformSettingInfo.interstitialAd_showIntervalBase_retainUser;
364
+ AdMgr.permanentAdFirstShowInterval = adPlatformSettingInfo.permanentAd_firstShowInterval_retainUser;
365
+
366
+ if (this.userMgr && this.userMgr.isNewUser()) {
367
+ AdMgr.interstitialAdIntervalBase = adPlatformSettingInfo.interstitialAd_showIntervalBase_registerUser;
368
+ AdMgr.permanentAdFirstShowInterval = adPlatformSettingInfo.permanentAd_firstShowInterval_registerUser;
369
+ }
370
+ }
371
+
351
372
  this.createInterstitialAd();
352
373
  this.createRewardedVideoAd();
353
374
  this.createPortalAd();
@@ -535,29 +556,12 @@ export class AdMgr extends BaseMgr {
535
556
  return;
536
557
  }
537
558
 
538
- let launchNoAdInterval: number = 0;
539
- let interstitialAdIntervalBase: number = 60000;
540
- if (AdMgr.adPlatformSettingMap.has(this.getCurrentPlatformID())) {
541
- let adPlatformSettingInfo: AdPlatformSettingInfo = AdMgr.adPlatformSettingMap.get(this.getCurrentPlatformID());
542
- launchNoAdInterval = adPlatformSettingInfo.launchNoAdInterval_interstitialAd;
543
-
544
- interstitialAdIntervalBase = adPlatformSettingInfo.retainUser_interstitialAd_IntervalBase;
545
-
546
- if (this.userMgr === null) {
547
- this.userMgr = ServiceLocator.Instance.get<UserMgr>("UserMgr");
548
- }
549
-
550
- if (this.userMgr && this.userMgr.isNewUser()) {
551
- interstitialAdIntervalBase = adPlatformSettingInfo.registerUser_interstitialAd_IntervalBase;
552
- }
559
+ if (this.userMgr === null) {
560
+ this.userMgr = ServiceLocator.Instance.get<UserMgr>("UserMgr");
553
561
  }
554
- let interstitialAdInterval: number = interstitialAdIntervalBase * AdMgr.interstitialAd_nowIntervalCount;
555
562
 
563
+ let interstitialAdInterval: number = AdMgr.interstitialAdIntervalBase * AdMgr.interstitialAd_nowIntervalCount;
556
564
  let now: number = new Date().getTime();
557
- if (now - AdMgr.launchTime < launchNoAdInterval) {
558
- AdMgr.interstitialAdCallback(InterstitialAd_Callback_Status.Status_InsufficientInterval);
559
- return;
560
- }
561
565
  if (now - AdMgr.lastInterstitialAdTimestamp < interstitialAdInterval) {
562
566
  AdMgr.interstitialAdCallback(InterstitialAd_Callback_Status.Status_InsufficientInterval);
563
567
  return;
@@ -823,14 +827,9 @@ export class AdMgr extends BaseMgr {
823
827
  /** 显示所有常驻广告 */
824
828
  public showAllPermanentAd(): void {
825
829
  let delay: number = 0;
826
-
827
- let currentPlatformID: PlatformID = this.getCurrentPlatformID();
828
- if (AdMgr.adPlatformSettingMap.has(currentPlatformID)) {
829
- let launchNoAdInterval: number = AdMgr.adPlatformSettingMap.get(currentPlatformID).launchNoAdInterval_permanentAd;
830
- let now: number = new Date().getTime();
831
- if (now - AdMgr.launchTime < launchNoAdInterval) {
832
- delay = Math.floor((launchNoAdInterval - (now - AdMgr.launchTime)) / 1000);
833
- }
830
+ let now: number = new Date().getTime();
831
+ if (now - AdMgr.launchTime < AdMgr.permanentAdFirstShowInterval) {
832
+ delay = Math.floor((AdMgr.permanentAdFirstShowInterval - (now - AdMgr.launchTime)) / 1000);
834
833
  }
835
834
 
836
835
  if (!AdMgr.isPermanentAdShowing) {
@@ -3,6 +3,7 @@ import { LogUtils } from "../Utils/LogUtils";
3
3
  import { ServiceLocator } from "../Utils/ServiceLocator";
4
4
  import { BaseMgr } from "./BaseMgr";
5
5
  import { EventMgr } from "./EventMgr";
6
+ import { LaunchCategory } from "../Definition/AnalyticsDefinition";
6
7
  import type { AnalyticsMgr } from "./AnalyticsMgr";
7
8
 
8
9
  /** 生命周期管理器 */
@@ -181,7 +182,7 @@ export class LifeCycleMgr extends BaseMgr {
181
182
  }
182
183
 
183
184
  /** 获取冷启动场景信息 */
184
- public getColdStartSceneInfo(): { scene: string; category: string } | null {
185
+ public getColdStartSceneInfo(): { scene: string; category: LaunchCategory } | null {
185
186
  if (this.getPlatformAdapter() === null) {
186
187
  return null;
187
188
  }
@@ -190,7 +191,7 @@ export class LifeCycleMgr extends BaseMgr {
190
191
  }
191
192
 
192
193
  /** 获取热启动场景信息 */
193
- public getWarmStartSceneInfo(): { scene: string; category: string } | null {
194
+ public getWarmStartSceneInfo(): { scene: string; category: LaunchCategory } | null {
194
195
  if (this.getPlatformAdapter() === null) {
195
196
  return null;
196
197
  }
@@ -199,7 +200,7 @@ export class LifeCycleMgr extends BaseMgr {
199
200
  }
200
201
 
201
202
  /** 获取当前启动场景分类(兼容原 isLaunchFromXxx 逻辑) */
202
- public getLaunchCategory(): string | null {
203
+ public getLaunchCategory(): LaunchCategory | null {
203
204
  if (this.getPlatformAdapter() === null) {
204
205
  return null;
205
206
  }
@@ -208,11 +209,11 @@ export class LifeCycleMgr extends BaseMgr {
208
209
  }
209
210
 
210
211
  /** 判断是否从指定分类启动 */
211
- public isLaunchFrom(category: string): boolean {
212
+ public isLaunchFrom(category: LaunchCategory): boolean {
212
213
  if (this.getPlatformAdapter() === null) {
213
214
  return false;
214
215
  }
215
216
 
216
- return this.getPlatformAdapter().isLaunchFrom(category as any);
217
+ return this.getPlatformAdapter().isLaunchFrom(category);
217
218
  }
218
219
  }