|
|
@@ -9,12 +9,23 @@ import ATSDKMgr from "./ATSDKMgr";
|
|
|
export class ATNative extends zgSingleton {
|
|
|
|
|
|
private ATNativeJS: any;
|
|
|
+
|
|
|
+ /** 信息流广告类型 0 弹窗里 1 最底部 2 新车奖励 3 底部小窗口 */
|
|
|
+ private nativeAdType: number = 4;
|
|
|
+ /** 信息流广告状态 */
|
|
|
+ private nativeAdState: NativeAdState = 0;
|
|
|
+ /** 是否加载显示 */
|
|
|
+ private ifLoadShow: boolean = false;
|
|
|
+
|
|
|
/** 初始化 */
|
|
|
init() {
|
|
|
this.ATNativeJS = cc["ATNativeJS"];
|
|
|
this.ATNativeJS.proxy = this;;
|
|
|
this.ATNativeJS.init();
|
|
|
- this.loadNative();
|
|
|
+
|
|
|
+ if (this.nativeAdState == NativeAdState.Unload) {
|
|
|
+ this.loadNative(4);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/** 广告位id */
|
|
|
@@ -26,21 +37,151 @@ export class ATNative extends zgSingleton {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ //广告逻辑部分------------------------------------------------------------------------
|
|
|
+ /** 检测是否插屏预备好*/
|
|
|
+ hasAdReady() {
|
|
|
+ return this.ATNativeJS.hasAdReady();
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 加载信息流广告
|
|
|
* @param type 类型对应不同位置
|
|
|
- * @param show 是否加载完显示显示
|
|
|
+ * @param ifLoadshow 是否加载完显示显示
|
|
|
*/
|
|
|
- loadNative(type = 4, show = false) {
|
|
|
- this.ATNativeJS.loadNative(type, show);
|
|
|
+ loadNative(type = 4, ifLoadshow = false) {
|
|
|
+
|
|
|
+ this.nativeAdType = type;
|
|
|
+ this.ifLoadShow = ifLoadshow;
|
|
|
+
|
|
|
+ this.nativeAdState = NativeAdState.Loading;
|
|
|
+
|
|
|
+ //加载原生广告时需要传入广告展示的宽高
|
|
|
+ var frameSize = cc.view.getFrameSize();
|
|
|
+ let frameWidth = frameSize.width;
|
|
|
+ let frameHeight = frameSize.height;
|
|
|
+ var per = frameWidth / 750
|
|
|
+ var sw = per * 656;
|
|
|
+ var sh = per * 440;
|
|
|
+
|
|
|
+ if (this.nativeAdType == 2) {
|
|
|
+ sw *= 0.9
|
|
|
+ sh *= 0.8
|
|
|
+ }
|
|
|
+ else if (this.nativeAdType == 3) {
|
|
|
+ sw *= 0.9
|
|
|
+ sh *= 0.75
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ sw *= 0.9
|
|
|
+ sh *= 0.75
|
|
|
+ }
|
|
|
+ this.ATNativeJS.loadNative(sw, sh);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 显示原生广告
|
|
|
- * @param type 0 弹窗里 1 最底部 2 新车奖励 3 底部小窗口
|
|
|
+ * @param type 0 弹窗里 1 最底部 2 新车奖励 3 底部小窗口 4 最底部
|
|
|
+ */
|
|
|
+ showNative(type: number) {
|
|
|
+
|
|
|
+ if (this.nativeAdState == NativeAdState.Show) {
|
|
|
+ //如果已经显示则不调用显示
|
|
|
+ }
|
|
|
+ else {
|
|
|
+
|
|
|
+ if (this.hasAdReady()) {
|
|
|
+ if (this.nativeAdType != type) {
|
|
|
+ this.destroyNative();
|
|
|
+ this.loadNative(type, true);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ console.log("===[ShowNative", type);
|
|
|
+ //加载原生广告时需要传入广告展示的宽高
|
|
|
+ let frameSize = cc.view.getFrameSize();
|
|
|
+ let frameWidth = frameSize.width;
|
|
|
+ let frameHeight = frameSize.height;
|
|
|
+
|
|
|
+ //获取基本的宽高
|
|
|
+ let per = frameWidth / 750
|
|
|
+ let width = per * 656
|
|
|
+ let height = per * 440
|
|
|
+ let fontSize = 12
|
|
|
+
|
|
|
+ //设置位置宽高
|
|
|
+ let pos_y = 0
|
|
|
+ if (type == 0) {
|
|
|
+ // posy = this.frameHeight * 0.5 - 100
|
|
|
+ pos_y = frameHeight * 0.45
|
|
|
+ }
|
|
|
+ else if (type == 1) {
|
|
|
+ // posy = this.frameHeight * 0.5 + 280
|
|
|
+ pos_y = frameHeight * 0.625
|
|
|
+ }
|
|
|
+ else if (type == 2) {
|
|
|
+ // posy = this.frameHeight * 0.5 + 210
|
|
|
+ pos_y = frameHeight * 0.595
|
|
|
+ width *= 0.9
|
|
|
+ height *= 0.8
|
|
|
+ fontSize = 8
|
|
|
+ }
|
|
|
+ else if (type == 3) {
|
|
|
+ // posy = this.frameHeight * 0.5 + 420
|
|
|
+ pos_y = frameHeight * 0.69
|
|
|
+ width *= 0.9
|
|
|
+ height *= 0.75
|
|
|
+ fontSize = 8
|
|
|
+ }
|
|
|
+ else if (type == 4) {
|
|
|
+ pos_y = frameHeight * 0.75;
|
|
|
+ width *= 1.1;
|
|
|
+ }
|
|
|
+
|
|
|
+ let pos_x = (frameWidth - width) * 0.5
|
|
|
+ this.ATNativeJS.showNative(pos_x, pos_y, width, height);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ //如果正在加载中,则不处理
|
|
|
+ if (this.nativeAdState == NativeAdState.Loading) {
|
|
|
+ //正在加载不重复加载
|
|
|
+ this.ifLoadShow = true;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ this.loadNative(type, true)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 销毁baaner */
|
|
|
+ destroyNative() {
|
|
|
+
|
|
|
+ this.nativeAdState = NativeAdState.Close;
|
|
|
+
|
|
|
+ this.ATNativeJS.destroyNative();
|
|
|
+ this.loadNative(this.nativeAdType);
|
|
|
+ }
|
|
|
+
|
|
|
+ //广告回调部分------------------------------------------------------------------------
|
|
|
+ /**
|
|
|
+ * 原生广告加载成功
|
|
|
+ * @param {*} placementId
|
|
|
+ */
|
|
|
+ onNativeAdLoaded(placementId) {
|
|
|
+ this.nativeAdState = NativeAdState.LoadSuccess;
|
|
|
+ if (this.ifLoadShow) {
|
|
|
+ this.showNative(this.nativeAdType);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 原生广告加载失败
|
|
|
+ * @param {*} placementId 广告位id
|
|
|
+ * @param {*} errorInfo 错误信息
|
|
|
*/
|
|
|
- showNative(type) {
|
|
|
- this.ATNativeJS.showNative(type);
|
|
|
+ onNativeAdLoadFail(placementId, errorInfo) {
|
|
|
+ this.nativeAdState = NativeAdState.LoadFail;
|
|
|
+ // ATJSSDK.printLog("AnyThinkNativeDemo::onNativeAdLoadFail(" + placementId + ", " + errorInfo + ")");
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -49,6 +190,9 @@ export class ATNative extends zgSingleton {
|
|
|
* @param callbackInfo
|
|
|
*/
|
|
|
onNativeAdShow(placementId, callbackInfo) {
|
|
|
+
|
|
|
+ this.nativeAdState = NativeAdState.Show;
|
|
|
+
|
|
|
// 2021/06/03(勿删)此处为星云埋点,先注释,待接口调通,恢复
|
|
|
// let data = JSON.parse(callbackInfo)
|
|
|
// HttpMgr.Inst.updateADLog(3, placementId, data.adunit_format, data.network_type, data.network_placement_id,
|
|
|
@@ -56,14 +200,28 @@ export class ATNative extends zgSingleton {
|
|
|
// data.adsource_isheaderbidding, data.publisher_revenue, data.precision, data.ecpm_level);
|
|
|
}
|
|
|
|
|
|
- /** 销毁baaner */
|
|
|
- destroyNative() {
|
|
|
- this.ATNativeJS.destroyNative();
|
|
|
- this.loadNative();
|
|
|
+ /**
|
|
|
+ * 原生广告被点击
|
|
|
+ * @param placementId 广告位Id
|
|
|
+ * @param callbackInfo 回调信息
|
|
|
+ */
|
|
|
+ onNativeAdClick(placementId, callbackInfo) {
|
|
|
+ // ATJSSDK.printLog("AnyThinkNativeDemo::onNativeAdClick(" + placementId + ", " + callbackInfo + ")");
|
|
|
}
|
|
|
+}
|
|
|
|
|
|
- /** 当前是否有banner显示 */
|
|
|
- getIsNativeShow() {
|
|
|
- return this.ATNativeJS.nativeShow
|
|
|
- }
|
|
|
+/** 原生信息流广告状态 */
|
|
|
+export enum NativeAdState {
|
|
|
+ /** 未加载 */
|
|
|
+ Unload = 0,
|
|
|
+ /** 加载中 */
|
|
|
+ Loading = 1,
|
|
|
+ /** 加载成功 */
|
|
|
+ LoadSuccess = 2,
|
|
|
+ /** 加载失败 */
|
|
|
+ LoadFail = 3,
|
|
|
+ /** 显示状态 */
|
|
|
+ Show = 4,
|
|
|
+ /** 关闭状态 */
|
|
|
+ Close = 5
|
|
|
}
|