123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- import { _decorator, SpriteFrame, sys } from "cc";
- import { gameManager } from "./run/gameManager";
- //管理广告、分享、SDK相关内容的组件
- export class SdkUtil {
- public static platform: string = 'cocos'; //平台
- public static imgAd: SpriteFrame = null!;
- public static imgShare: SpriteFrame = null!;
- public static isDebugMode: boolean = false;
- public static onlineInterval: number = -1;
- public static isEnableVibrate: boolean = true;
- public static isCheckOffline: boolean = false; //登录后会检查是否展示登录界面,而且只检查一次
- public static isWatchVideoAd: boolean = false;//是否正在播放广告
- public static isEnableMoving: boolean = false;//是否允许屏幕上下移动
- public static isEnableZoom: boolean = false;//是否允许屏幕缩放
- public static arrLockDiary = [];//未解锁日记
- public static vibrateInterval: number = 100;//两次震动之间的间隔,AppActivity里面的震动间隔也是100
- public static vibratePreTime: number = 0;//上次震动时间
- public static videoAd:any =null;
- /**
- * 自定义事件统计
- *
- * @param {string} eventType
- * @param {object} objParams
- */
- public static customEventStatistics(eventType: string, objParams?: any) {
- eventType = eventType.toString();
- if (!objParams) {
- objParams = {};
- }
- // console.log({'eventType': eventType},{'objParams': objParams});
- if (this.platform === 'wx') {
- //@ts-ignore
- if (window['wx'] && window['wx']['aldSendEvent']) {
- //@ts-ignore
- window.wx['aldSendEvent'](eventType, objParams);
- }
- }
- //@ts-ignore
- if (this.platform === 'cocos' && window.cocosAnalytics && window.cocosAnalytics.isInited()) {
- console.log("###统计", eventType, objParams);
- //@ts-ignore
- window.cocosAnalytics.CACustomEvent.onStarted(eventType, objParams);
- }
- }
- /**
- * 微信分享
- *
- * @static
- * @param {string} title
- * @param {string} imageUrl
- * @returns
- * @memberof SdkUtil
- */
- public static shareGame(title: string, imageUrl: string) {
- //@ts-ignore
- if (!window.wx) {
- return;
- }
- //@ts-ignore
- wx.showShareMenu({
- withShareTicket: true,
- complete: () => {
- }
- });
- //@ts-ignore
- if (wx.aldOnShareAppMessage) {
- //@ts-ignore
- wx.aldOnShareAppMessage(function () {
- // 用户点击了“转发”按钮
- return {
- title: title,
- imageUrl: imageUrl,
- };
- });
- } else {
- //@ts-ignore
- wx.onShareAppMessage(function () {
- // 用户点击了“转发”按钮
- return {
- title: title,
- imageUrl: imageUrl,
- };
- });
- }
- }
-
- /**
- * 抖音激励视频
- *
- * @static
- * @param {string} _adUnitId
- * @param {Function} call_back
- * @returns
- * @memberof SdkUtil
- */
- public static showVideoAd(_adUnitId: string, call_back) {
- if(gameManager.isTestUser){
- call_back({"isEnded":true})
- return
- }
- if(sys.platform==sys.Platform.BYTEDANCE_MINI_GAME){
- gameManager.Singleton.showLoadingLevel()
- SdkUtil.videoAd = tt.createRewardedVideoAd({adUnitId: _adUnitId});
- SdkUtil.videoAd.onLoad(() => {
- SdkUtil.videoAd.show();
- console.log("广告加载完成");
- });
- SdkUtil.videoAd.onClose((res) => {
- call_back(res)
- SdkUtil.videoAd.destroy()
- gameManager.Singleton.hideLoadingLevel()
- });
- SdkUtil.videoAd.onError((res) => {
- call_back({isEnded:false})
- SdkUtil.videoAd.destroy()
- gameManager.Singleton.hideLoadingLevel()
- });
- SdkUtil.videoAd.load()
- }
- }
- }
|