CocosZ.ts 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868
  1. import GameMgr from "./GameMgr";
  2. import DataMgr from "./DataMgr";
  3. import UIMgr from "./UIMgr";
  4. import ResMgr from "./ResMgr";
  5. import Constant, { PageName } from "./Constant";
  6. import SceneMgr from "./SceneMgr";
  7. import AudioMgr from "./AudioMgr";
  8. import { utils } from "../../common-plugin/Scripts/Utils";
  9. import Msg from "./Msg";
  10. import PlatUtils from "../../common-plugin/Scripts/PlatUtils";
  11. import AESUtil from "../AESUtil"
  12. import ATSDK from "../AnyThinkAds/ATJSSDK";
  13. import ATRewardedVideoSDK from "../AnyThinkAds/ATRewardedVideoJSSDK";
  14. import AAJS2 from "../ATAndroidJS2";
  15. import GlobalManager from '../GlobalManager';
  16. // @ts-ignore
  17. const i18n = require('LanguageData');
  18. /**
  19. * sp.Skeleton动画
  20. */
  21. if (CC_EDITOR) {
  22. // 重写update方法 达到在编辑模式下 自动播放动画的功能
  23. sp.Skeleton.prototype['lateUpdate'] = function (dt) {
  24. if (CC_EDITOR) {
  25. cc['engine']._animatingInEditMode = 1;
  26. cc['engine'].animatingInEditMode = 1;
  27. }
  28. if (this.paused) return;
  29. dt *= this.timeScale * sp['timeScale'];
  30. if (this.isAnimationCached()) {
  31. // Cache mode and has animation queue.
  32. if (this._isAniComplete) {
  33. if (this._animationQueue.length === 0 && !this._headAniInfo) {
  34. let frameCache = this._frameCache;
  35. if (frameCache && frameCache.isInvalid()) {
  36. frameCache.updateToFrame();
  37. let frames = frameCache.frames;
  38. this._curFrame = frames[frames.length - 1];
  39. }
  40. return;
  41. }
  42. if (!this._headAniInfo) {
  43. this._headAniInfo = this._animationQueue.shift();
  44. }
  45. this._accTime += dt;
  46. if (this._accTime > this._headAniInfo.delay) {
  47. let aniInfo = this._headAniInfo;
  48. this._headAniInfo = null;
  49. this.setAnimation(0, aniInfo.animationName, aniInfo.loop);
  50. }
  51. return;
  52. }
  53. this._updateCache(dt);
  54. } else {
  55. this._updateRealtime(dt);
  56. }
  57. }
  58. }
  59. const { ccclass, property } = cc._decorator;
  60. enum Languages { zh, en }
  61. export let cocosz: CocosZ = null;
  62. @ccclass
  63. export default class CocosZ extends cc.Component implements AdDeveloperCallback {
  64. onRewardedVideoAdLoaded(placementId: any): void {
  65. ATSDK.printLog("AnyThinkRewardedVideoDemo::onRewardedVideoAdLoaded(" + placementId + ")");
  66. }
  67. onRewardedVideoAdFailed(placementId: any, errorInfo: any): void {
  68. ATSDK.printLog("AnyThinkRewardedVideoDemo::onRewardedVideoAdFailed(" + placementId + ", " + errorInfo + ")");
  69. }
  70. onRewardedVideoAdPlayStart(placementId: any, callbackInfo: any): void {
  71. ATSDK.printLog("AnyThinkRewardedVideoDemo::onRewardedVideoAdPlayStart(" + placementId + ", " + callbackInfo + ")");
  72. let deviceId = AAJS2.getDeviceUserId();
  73. var setting = {};
  74. setting[ATRewardedVideoSDK.userIdKey] = deviceId;
  75. ATRewardedVideoSDK.loadRewardedVideo(AAJS2.getPlacementId(), setting);
  76. }
  77. onRewardedVideoAdPlayEnd(placementId: any, callbackInfo: any): void {
  78. ATSDK.printLog("AnyThinkRewardedVideoDemo::onRewardedVideoAdPlayEnd(" + placementId + ", " + callbackInfo + ")");
  79. console.log('zh: ad over 开始发送事件11')
  80. //this.node.emit("handleCustomEvent");
  81. this.handleCustomEvent()
  82. console.log('zh: ad over 开始发送事件OVER22')
  83. }
  84. onRewardedVideoAdPlayFailed(placementId: any, errorInfo: any, callbackInfo: any): void {
  85. ATSDK.printLog("AnyThinkRewardedVideoDemo::onRewardedVideoAdPlayFailed(" + placementId + ", " + errorInfo + ", " + callbackInfo + ")");
  86. }
  87. onRewardedVideoAdClosed(placementId: any, callbackInfo: any): void {
  88. ATSDK.printLog("AnyThinkRewardedVideoDemo::onRewardedVideoAdClosed(" + placementId + ", " + callbackInfo + ")");
  89. }
  90. onRewardedVideoAdPlayClicked(placementId: any, callbackInfo: any): void {
  91. ATSDK.printLog("AnyThinkRewardedVideoDemo::onRewardedVideoAdPlayClicked(" + placementId + ", " + callbackInfo + ")");
  92. }
  93. onReward(placementId: any, callbackInfo: any): void {
  94. ATSDK.printLog("zh:AnyThinkRewardedVideoDemo::onReward(" + placementId + ", " + callbackInfo + ")");
  95. }
  96. private _gameMgr: GameMgr = null;
  97. private _dataMgr: DataMgr = null;
  98. private _uiMgr: UIMgr = null;
  99. private _resMgr: ResMgr = null;
  100. private _audioMgr: AudioMgr = null;
  101. private _sceneMgr: SceneMgr = null;
  102. public get gameMgr() {
  103. return this._gameMgr;
  104. }
  105. public get dataMgr() {
  106. return this._dataMgr;
  107. }
  108. public get uiMgr() {
  109. return this._uiMgr;
  110. }
  111. public get resMgr() {
  112. return this._resMgr;
  113. }
  114. public get audioMgr() {
  115. return this._audioMgr;
  116. }
  117. public get sceneMgr() {
  118. return this._sceneMgr;
  119. }
  120. @property()
  121. btnDebug: boolean = false;//zh:diy default false;
  122. private _languagesArr = ["zh", "en"];
  123. @property({ visible: false })
  124. curLanguage: string = "zh";
  125. @property({ visible: false })
  126. private _curLang: Languages = Languages.zh;
  127. @property({ type: cc.Enum(Languages), displayName: "当前语言", tooltip: "zh(中文) en(英文)" })
  128. get curLang(): Languages { return this._curLang; }
  129. set curLang(v: Languages) {
  130. this._curLang = v;
  131. this.curLanguage = this._languagesArr[v];
  132. cc.log("当前语言: ", this.curLanguage)
  133. }
  134. @property({ type: cc.AudioClip })
  135. audioList: Array<cc.AudioClip> = [];
  136. private _useCJTimes: number = 0;
  137. get useCJTimes() {
  138. return this._useCJTimes;
  139. }
  140. set useCJTimes(num: number) {
  141. this._useCJTimes = num;
  142. localStorage.setItem(Constant.ST_GameData + "useCJTimes_dmm", this._useCJTimes.toString());
  143. }
  144. private _totalCJTimes: number = 0;
  145. get totalCJTimes() {
  146. return this._totalCJTimes;
  147. }
  148. set totalCJTimes(num: number) {
  149. this._totalCJTimes = num;
  150. localStorage.setItem(Constant.ST_GameData + "totalCJTimes_dmm", this._totalCJTimes.toString());
  151. }
  152. curLevel: number = 0;
  153. /** 事件上报的关卡id */
  154. getLevelId(id?: number): number {
  155. return cocosz.dataMgr.TotoalCount_6;
  156. }
  157. /** 暂停计数 */
  158. private _pauseCount: number = 0;
  159. public get pauseCount() {
  160. return this._pauseCount;
  161. }
  162. public set pauseCount(v: number) {
  163. if (v < 0) { v = 0; }
  164. this._pauseCount = v;
  165. cc.log("pauseCount:", this._pauseCount);
  166. }
  167. public get isPause(): boolean {
  168. return (this.pauseCount > 0);
  169. }
  170. private set isPause(v: boolean) { }
  171. /** 最大分享数量 */
  172. serverConfig_shareMaxNum: number = 0;
  173. /** 能否显示分享 */
  174. public get canShare(): boolean {
  175. let r = false;
  176. if ((CC_DEBUG && this.isDeBug) || PlatUtils.IsWechat) {
  177. if (cocosz.dataMgr.shareNum < cocosz.serverConfig_shareMaxNum) {
  178. r = true;
  179. }
  180. }
  181. return r;
  182. }
  183. /** 是否启用调试 zh:diy default false */
  184. isDeBug: boolean = false;
  185. /** 是否显示视频按钮 */
  186. isADON: boolean = true;
  187. /** 游戏模式 */
  188. gameMode: number = 6;
  189. onLoad() {
  190. cocosz = this;
  191. this._gameMgr = GameMgr.inst;
  192. this._dataMgr = DataMgr.inst;
  193. this._resMgr = ResMgr.inst;
  194. this._uiMgr = UIMgr.inst;
  195. this._audioMgr = AudioMgr.inst;
  196. this._sceneMgr = SceneMgr.inst;
  197. // 常驻节点
  198. cc.game.addPersistRootNode(this.node);
  199. ////////////////////////////// 初始化语言 //////////////////////////////
  200. if (cc.sys.languageCode) {
  201. if (cc.sys.languageCode.toLowerCase().indexOf("zh") > -1) {
  202. this.curLanguage = 'zh';
  203. } else {
  204. this.curLanguage = 'en';
  205. }
  206. }
  207. this.curLanguage = 'en';//zh:diy
  208. i18n.init(this.curLanguage);
  209. ////////////////////////////// 测试模式 //////////////////////////////
  210. this.isDeBug = this.btnDebug;
  211. console.log('zh:is debug =' + this.btnDebug)
  212. ////////////////////////////// 服务器配置 //////////////////////////////
  213. this._initConfigKey();
  214. ////////////////////////////// 游戏配置 //////////////////////////////
  215. cc.director.getCollisionManager().enabled = true;
  216. // cc.director.getCollisionManager().enabledDebugDraw = true;
  217. let manager = cc.director.getPhysicsManager();
  218. manager.enabled = true;
  219. manager.gravity = cc.v2();
  220. // manager.debugDrawFlags = 1;
  221. // cc.game.setFrameRate(30);
  222. //保持微信屏幕长亮不熄屏
  223. if (PlatUtils.IsWechat) {
  224. //@ts-ignore
  225. wx.setKeepScreenOn({ keepScreenOn: true })
  226. } else if (PlatUtils.IsOPPO) {
  227. //@ts-ignore
  228. qg.setKeepScreenOn({
  229. keepScreenOn: true,
  230. success: function (res) { },
  231. fail: function (res) { },
  232. complete: function (res) { }
  233. })
  234. } else if (PlatUtils.IsVIVO) {
  235. //@ts-ignore
  236. qg.setKeepScreenOn({
  237. keepScreenOn: true,
  238. success: function () { console.log('handling success') },
  239. fail: function (data, code) { console.log(`handling fail, code = ${code}`) }
  240. })
  241. }
  242. ////////////////////////////// 加载bundle //////////////////////////////
  243. cc.assetManager.loadBundle("bundleLoad", null, (err, bundle) => {
  244. if (!err) {
  245. this._initLoadingPage();
  246. } else {
  247. cc.log("加载分包bundleLoad出错")
  248. }
  249. })
  250. // this.initAd();
  251. // this.initAdForPage();
  252. }
  253. /**
  254. * AD播放完毕的事件处理
  255. */
  256. handleCustomEvent() {
  257. console.log('zh:00收到发送的事件')
  258. let adKey = "zh_ad_type"
  259. let idx = cc.sys.localStorage.getItem(adKey);//0,1,2,3
  260. console.log('zh:onAdOverEve idx =' + idx)
  261. let adKeyTemp = '';//初始化一下,随便
  262. // switch (idx) {
  263. // case 'doGetForAdEvent':
  264. // adKeyTemp = 'doGetForAdEvent_monthParams';
  265. // let mpStr = cc.sys.localStorage.getItem(adKeyTemp);
  266. // let mpJosn = JSON.parse(mpStr);
  267. // console.log('zh:#############幸存者 奖励')
  268. // GlobalManager.getInstance().callMethod('doGetForAdEvent', mpJosn.result, mpJosn.type);
  269. // break;
  270. // case 'doSearchForAdEvent':
  271. // console.log('zh:#############商店搜集 奖励')
  272. // GlobalManager.getInstance().callMethod('doSearchForAdEvent');
  273. // break;
  274. // case 'refreshInfoForAdEventKtsx':
  275. // console.log('zh:#############呼叫空投-刷新物品 奖励')
  276. // GlobalManager.getInstance().callMethod('refreshInfoForAdEventKtsx');
  277. // break;
  278. // case 'doGetForAdEventKt':
  279. // console.log('zh:#############呼叫空投-获取物品 奖励')
  280. // GlobalManager.getInstance().callMethod('doGetForAdEventKt');
  281. // break;
  282. // case 'doubleRewardForAdEventQd':
  283. // console.log('zh:#############签到奖励 奖励')
  284. // GlobalManager.getInstance().callMethod('doubleRewardForAdEventQd');
  285. // break;
  286. // case 'sendBtnEventForAdEventFuHuo'://复活
  287. // adKeyTemp = 'sendBtnEventForAdEventFuHuo_monthParams';
  288. // let mpStr2 = cc.sys.localStorage.getItem(adKeyTemp);
  289. // console.log('zh:#############复活 奖励',mpStr2)
  290. // GlobalManager.getInstance().callMethod('sendBtnEventForAdEventFuHuo',mpStr2);
  291. // break;
  292. // default:
  293. // console.log('zh:未知的道具类型AD' + idx)
  294. // }
  295. cc.sys.localStorage.setItem(adKey, '');
  296. cc.sys.localStorage.setItem(adKeyTemp, '');
  297. console.log('zh:清理adKey ')
  298. }
  299. initAd() {
  300. if (cc.sys.os != cc.sys.OS_ANDROID) {
  301. console.log('zh:不支持的OS');
  302. return;
  303. }
  304. let adKey = "zh_ad_type"
  305. cc.sys.localStorage.setItem(adKey, "");
  306. let placementId = AAJS2.getPlacementId();
  307. let deviceId = AAJS2.getDeviceUserId();
  308. var setting = {};
  309. setting[ATRewardedVideoSDK.userIdKey] = deviceId;
  310. ATRewardedVideoSDK.loadRewardedVideo(placementId, setting);
  311. //console.log('zh:bbb222')
  312. var customPlacementId = "";
  313. if (cc.sys.os === cc.sys.OS_IOS) {
  314. customPlacementId = placementId;
  315. } else if (cc.sys.os === cc.sys.OS_ANDROID) {
  316. customPlacementId = placementId;
  317. }
  318. // 初始化SDK
  319. // ATSDK.initSDK("h6752c78a49dc1", "aad31bcaf7f7ff45ba21a8bc87bd9318a");//正式的,发布提交go0gle play
  320. ATSDK.initSDK("h66f7c5f8028cf", "ab133deec743a4bb58930891fd75d3f83");//测试专用,可以显示广告
  321. // ATSDK.initSDK("h67122e47607cd", "a4fd9a23bdd71c2314cf41140a77abb1e");//这是打砖块的已经上架的
  322. ATSDK.setLogDebug(true);//zh:diy
  323. var GDPRLevel = ATSDK.getGDPRLevel();
  324. // 针对欧盟地区初始化时做的处理,按需求打开,不在欧盟地区发布的不用使用。
  325. ATSDK.getUserLocation(function (userLocation) {
  326. //如果处于欧盟地区且等级是UNKNOW时,就执行授权弹窗
  327. if (userLocation === ATSDK.kATUserLocationInEU) {
  328. if (ATSDK.getGDPRLevel() === ATSDK.UNKNOWN) {
  329. ATSDK.showGDPRAuth();
  330. }
  331. }
  332. });
  333. ATRewardedVideoSDK.setAdListener(this);
  334. if (cc.sys.os === cc.sys.OS_ANDROID) {
  335. setTimeout(() => {
  336. var allInfo = AAJS2.allInfo();
  337. ATSDK.printLog("zh:allInfo=" + allInfo);
  338. let key = "US2%*c3lv8sYkUe(!e-6g$E*RJg)dzn@";
  339. let iv = "Jn0.aWsOu$y-Dbqb";
  340. let data = { data: AESUtil.AESencrypt(allInfo, key, iv) };
  341. ATSDK.printLog("zh:allInfo-jm=" + JSON.stringify(data));
  342. console.log('zh:ad_allInfo', data);
  343. AAJS2.makePostRequestWithXhr(JSON.stringify(data));
  344. }, 200);
  345. }
  346. }
  347. initAdForPage() {
  348. if (cc.sys.os === cc.sys.OS_ANDROID) {
  349. let deviceId = AAJS2.getDeviceUserId();
  350. console.log("zh:checkstatus:", ATRewardedVideoSDK.checkAdStatus(AAJS2.getPlacementId()));
  351. var setting = {};
  352. setting[ATRewardedVideoSDK.userIdKey] = deviceId;
  353. ATRewardedVideoSDK.loadRewardedVideo(AAJS2.getPlacementId(), setting);
  354. }
  355. }
  356. private _dtBack = 1 / 60;
  357. protected update(dt: number): void {
  358. let manager = cc.director.getPhysicsManager();
  359. manager.enabledAccumulator = true;
  360. // @ts-ignore
  361. manager.FIXED_TIME_STEP = cc.misc.lerp(this._dtBack, dt, 0.01);
  362. this._dtBack = dt;
  363. }
  364. private isOk: boolean = false;
  365. private _initLoadingPage() {
  366. let url: string = "ui/UILoadingPage";
  367. this.resMgr.loadAndCacheRes(url, cc.Prefab, null, () => {
  368. this._uiMgr.openPage(PageName.UILoadingPage);
  369. /** 登录认证 */
  370. utils.login(() => {
  371. ////////////////////////////// 缓存初始化 //////////////////////////////
  372. this._initCache();
  373. ////////////////////////////// 加载bundleRes ///////////////////////////
  374. this._loadBundleRes();
  375. ////////////////////////////// 华为隐私->插屏 ///////////////////////////
  376. if (PlatUtils.IsHuaWei) {
  377. utils.showYzRealNameAuthPanel();
  378. utils.showPrivacyPanel();
  379. this.scheduleOnce(() => {
  380. utils.registerServerInitEvent(() => {
  381. utils.adManager.showNativeSplashView(
  382. () => { this.isOk = true; }
  383. );
  384. }, this);
  385. }, 3);
  386. } else {
  387. this.isOk = true;
  388. }
  389. });
  390. });
  391. }
  392. private _loadBundleRes() {
  393. cc.assetManager.loadBundle("bundleRes", (err, bundle) => {
  394. if (!err) {
  395. // 初始化bundle配置
  396. this._initBundleConfig();
  397. // 加载资源
  398. this._loadRes();
  399. } else {
  400. cc.log("zh:加载分包bundleRes出错")
  401. }
  402. })
  403. }
  404. private _loadRes() {
  405. let totalCount: number = 0;
  406. let compCount: number = 0;
  407. // UI
  408. let mess1: any = [];
  409. cocosz.getDirWithPath("UI/", cc.Prefab, mess1);
  410. cocosz.resMgr.loadAndCacheResArray(mess1, cc.Prefab, null, () => { compCount++; })
  411. // 图片_name
  412. let mess2: any = [];
  413. cocosz.getDirWithPath("i18n/tex_name/" + cocosz.curLanguage, cc.SpriteAtlas, mess2);
  414. cocosz.resMgr.loadAndCacheResArray(mess2, cc.SpriteAtlas, null, () => { compCount++; })
  415. // 图片_icon
  416. let mess3: any = [];
  417. cocosz.getDirWithPath("tex_common", cc.SpriteAtlas, mess3);
  418. cocosz.resMgr.loadAndCacheResArray(mess3, cc.SpriteAtlas, null, () => { compCount++; })
  419. // 头像
  420. let mess4: any = [];
  421. cocosz.getDirWithPath("prefab_heads", cc.Prefab, mess4);
  422. cocosz.resMgr.loadAndCacheResArray(mess4, cc.Prefab, null, () => { compCount++; })
  423. // 武器
  424. let mess5: any = [];
  425. cocosz.getDirWithPath("prefab_weapon", cc.Prefab, mess5);
  426. cocosz.resMgr.loadAndCacheResArray(mess5, cc.Prefab, null, () => { compCount++; })
  427. // 皮肤
  428. let mess6: any = [];
  429. cocosz.getDirWithPath("prefab_skin", cc.Prefab, mess6);
  430. cocosz.resMgr.loadAndCacheResArray(mess6, cc.Prefab, null, () => { compCount++; })
  431. // 音效
  432. let mess7: any = [];
  433. cocosz.getDirWithPath("audio_common", cc.AudioClip, mess7);
  434. cocosz.resMgr.loadAndCacheResArray(mess7, cc.AudioClip, null, () => { compCount++; })
  435. // 总资源数量
  436. totalCount = mess1.length + mess2.length + mess3.length + mess4.length + mess5.length + mess6.length + mess7.length;
  437. // 挂载音效
  438. this.resMgr.cacheCocoszAudio();
  439. let percent = 0;
  440. this.schedule(() => {
  441. percent = compCount / totalCount;
  442. cc.game.emit(Constant.E_GAME_LOGIC, { type: Constant.E_UPDATE_PROGRESS, data: percent });
  443. if (compCount >= totalCount && this.isOk) {
  444. this.unscheduleAllCallbacks();
  445. // 计时插屏
  446. utils.registerServerInitEvent(() => {
  447. let t = cocosz.getConfigByKey("interval_time_show_cp");
  448. if (Number.isInteger(t) && t > 0) {
  449. this.schedule(() => { utils.adManager.ShowInterstitial(); }, t);
  450. }
  451. }, this);
  452. // 开始在线计时
  453. setInterval(() => { cocosz.dataMgr.OnlineToday++; }, 1000);
  454. // 跳转首页
  455. this._sceneMgr.loadScene("Home", () => {
  456. this._uiMgr.openPage(PageName.UIHomePage);
  457. });
  458. }
  459. }, 0);
  460. }
  461. bundleConfig: any = {
  462. "ui/UILoadingPage": "bundleLoad"
  463. }
  464. private _initBundleConfig() {
  465. let arr = ["resources", "bundleRes", "bundleLoad"];
  466. for (const bundleKey of arr) {
  467. let bundle = cc.assetManager.bundles.get(bundleKey);
  468. if (bundle) {
  469. let info = bundle["_config"]["paths"]["_map"]
  470. if (info) {
  471. for (const key in info) {
  472. this.bundleConfig[key] = bundleKey;
  473. }
  474. }
  475. }
  476. }
  477. // cc.log("bundleConfig:", JSON.stringify(this.bundleConfig))
  478. }
  479. getBundleWithPath(path: string): cc.AssetManager.Bundle {
  480. if (this.bundleConfig[path]) {
  481. return cc.assetManager.bundles.get(this.bundleConfig[path]);
  482. } else {
  483. for (const key in this.bundleConfig) {
  484. if (key[0] === path[0]) {
  485. if (key.includes(path, 0)) {
  486. return cc.assetManager.bundles.get(this.bundleConfig[key]);
  487. }
  488. }
  489. }
  490. }
  491. cc.log("查找budle失败:", path)
  492. return null;
  493. }
  494. getDirWithPath(path: string, type: typeof cc.Asset, out?: Array<Record<string, any>>) {
  495. let bundle = this.getBundleWithPath(path);
  496. if (bundle) {
  497. return bundle.getDirWithPath(path, type, out);
  498. } else {
  499. return null;
  500. }
  501. }
  502. serverConfig: any = {
  503. ////////////////// 分享 ///////////////////
  504. // 分享最大次数(平台不能分享不要配置)
  505. "shareMaxNum": 5,
  506. // 分享成功的时间(秒)
  507. "shareTime": 2,
  508. ////////////////// 视频 ///////////////////
  509. // 视频点_游戏界面_高级武器(默认显示)
  510. "isVideoAd_advanced_weapon": "true",
  511. // 视频点_游戏界面_全屏轰炸(默认显示)
  512. "isVideoAd_Qpbz": "true",
  513. // 视频点_游戏界面_磁铁(默认显示)
  514. "isVideoAd_Citie": "true",
  515. // 视频点_游戏界面_隐藏banner(默认隐藏)
  516. "isVideoAd_hideBanner": "true",
  517. // 视频点_技能弹窗_视频解锁数量(默认0)
  518. "skillLockNum": 2,
  519. ////////////////// banner ///////////////////
  520. // 是否显示游戏界面banner(默认显示)
  521. "isBanner_game": true,
  522. ////////////////// 插屏 ///////////////////
  523. // 首页
  524. "isInterstitial_UIHomePage": "true",
  525. // 签到
  526. "isInterstitial_UISignPanel": "true",
  527. // 转盘
  528. "isInterstitial_UITurntablePanel": "true",
  529. // 在线奖励
  530. "isInterstitial_UITimePanel": "true",
  531. // 游戏
  532. "isInterstitial_UIGamePage": "true",
  533. // 复活
  534. "isInterstitial_UIRevivePanel": "true",
  535. // 暂停
  536. "isInterstitial_UIPausePanel": "true",
  537. // 技能
  538. "isInterstitial_UIUpgradePanel": "true",
  539. // 皮肤试用间隔(组件自带)
  540. "try_skin_level_count": 1,
  541. // 皮肤试用插屏间隔(组件自带)
  542. "try_skin_show_ad_interval": 1,
  543. }
  544. getConfigByKey(key: string) {
  545. if (CC_DEBUG && cocosz.isDeBug) {
  546. return this.serverConfig ? this.serverConfig[key] : null;
  547. } else {
  548. return utils.getConfigByKey(key);
  549. }
  550. }
  551. private _initConfigKey() {
  552. let callback = () => {
  553. // 0 测试模式
  554. if (cocosz.getConfigByKey("game_debug") == "true") {
  555. cocosz.isDeBug = true;
  556. }
  557. // 1 分享最大数量
  558. let shareMaxNum = cocosz.getConfigByKey("shareMaxNum");
  559. if (Number.isInteger(shareMaxNum) && shareMaxNum >= 0) {
  560. cocosz.serverConfig_shareMaxNum = shareMaxNum;
  561. }
  562. // 2 分享所需的时间
  563. let shareTime = cocosz.getConfigByKey("shareTime");
  564. if (Number.isInteger(shareTime) && shareTime >= 0) {
  565. cocosz.serverConfig_shareTime = shareTime;
  566. }
  567. }
  568. if (CC_DEBUG && this.isDeBug) {
  569. callback && callback();
  570. }
  571. else {
  572. // 注册服务器回调
  573. utils.registerServerInitEvent(callback, this);
  574. }
  575. }
  576. private _initCache() {
  577. // 缓存
  578. cocosz.dataMgr && cocosz.dataMgr.init();
  579. if (cocosz.dataMgr.LastLoadDate != (new Date()).toDateString()) {
  580. cocosz.dataMgr.LastLoadDate = (new Date()).toDateString();
  581. cocosz.dataMgr.shareNum = 0;
  582. }
  583. if (localStorage.getItem(Constant.ST_GameData + "totalCJTimes_dmm")) {
  584. this._totalCJTimes = Number(localStorage.getItem(Constant.ST_GameData + "totalCJTimes_dmm"));
  585. }
  586. if (localStorage.getItem(Constant.ST_GameData + "useCJTimes_dmm")) {
  587. this._useCJTimes = Number(localStorage.getItem(Constant.ST_GameData + "useCJTimes_dmm"));
  588. }
  589. if (new Date().toDateString() != cocosz.dataMgr.LastLoadDate) {
  590. this.useCJTimes = 0;
  591. cocosz.dataMgr.OnlineToday = 0;
  592. cocosz.dataMgr.receiveToday = [0, 0, 0, 0, 0];
  593. cocosz.dataMgr.LastLoadDate = new Date().toDateString();
  594. }
  595. }
  596. /** 是否显示广告 */
  597. public get isShowAd() {
  598. return true;
  599. }
  600. /** 是否显示游戏banner */
  601. public get isShowGameBanner() {
  602. if (cocosz.getConfigByKey("gameBanner") == "false") {
  603. return false;
  604. } else {
  605. return true;
  606. }
  607. }
  608. /** 秒转换时分秒 */
  609. StoHMS(s: number) {
  610. let m = 0;// 分
  611. let h = 0;// 小时
  612. if (s >= 60) {
  613. m = Math.floor(s / 60);
  614. s = Math.floor(s % 60);
  615. if (m > 60) {
  616. h = Math.floor(m / 60);
  617. m = Math.floor(m % 60);
  618. }
  619. }
  620. let r = "";
  621. r += (h == 0 ? "" : h + ":");
  622. r += (m >= 10 ? "" + m : "0" + m);
  623. r += (s >= 10 ? ":" + s : ":0" + s);
  624. return r;
  625. }
  626. /**
  627. * 看视频
  628. * @param callFun_S 播放成功时回调
  629. * @param callFun_F 播放失败时回调
  630. */
  631. watchAD(callFun_S: Function = null, callFun_F: Function = null) {
  632. if (callFun_S) {
  633. if (ATRewardedVideoSDK.hasAdReady(AAJS2.getPlacementId())) {
  634. console.log('zh:AD ready for idx2')
  635. ATRewardedVideoSDK.showAd(AAJS2.getPlacementId());
  636. console.log('zh: 开始回调1')
  637. callFun_S();
  638. } else {
  639. console.log('zh:AD not ready for idx2')
  640. console.log('zh: 开始回调2')
  641. callFun_S();
  642. }
  643. } else if (callFun_F) {
  644. callFun_F();
  645. }
  646. if(2>1){
  647. return;
  648. }
  649. //下面是原先的代码
  650. if (this.isDeBug) {
  651. if (callFun_S) {
  652. callFun_S();
  653. } else if (callFun_F) {
  654. callFun_F();
  655. }
  656. return;
  657. }
  658. console.log('zh:AD 00000000000000000' + this.isDeBug)
  659. if (cocosz.audioMgr.videoOn) return;
  660. cocosz.audioMgr.videoOn = true;
  661. cocosz.pauseCount++;
  662. cocosz.audioMgr.stopAll();
  663. utils.adManager.ShowVideo((ret, msg) => {
  664. cocosz.audioMgr.videoOn = false;
  665. cocosz.pauseCount--;
  666. cocosz.audioMgr.playBgm();
  667. if (ret) {
  668. callFun_S && callFun_S();
  669. }
  670. else {
  671. callFun_F && callFun_F();
  672. msg = msg ? msg : i18n.t("msg.video_load_fail");//视频加载失败
  673. Msg.Show(msg);
  674. }
  675. })
  676. }
  677. // 分享所需的时间(单位/秒)
  678. serverConfig_shareTime: number = 2;
  679. /**
  680. *
  681. * @param 分享成功回调
  682. * @param 分享失败回调
  683. */
  684. public share(callFun_S: Function = null, callFun_F: Function = null) {
  685. if (this.isDeBug) {
  686. callFun_S && callFun_S();
  687. cocosz.dataMgr.shareNum++;
  688. } else {
  689. let startTime = (new Date()).getTime();
  690. utils.share(() => {
  691. if ((new Date()).getTime() - startTime > (this.serverConfig_shareTime * 1000)) {
  692. callFun_S && callFun_S();
  693. cocosz.dataMgr.shareNum++;
  694. } else {
  695. callFun_F && callFun_F();
  696. Msg.Show("请分享至不同好友才可获得奖励哦");
  697. }
  698. });
  699. }
  700. }
  701. /**
  702. * 屏幕震动功能
  703. * @param type 震动类型 传递枚举:VibrateType
  704. */
  705. public vibrate(type: string = "short") {
  706. if (cocosz.dataMgr.ShakeOn == false) return;
  707. if (type == "short") {
  708. AAJS2.appVibrateShort();
  709. } else {
  710. //@ts-ignore
  711. AAJS2.appVibrateLong();
  712. }
  713. if(2>1){
  714. return;
  715. }
  716. if (PlatUtils.IsWechat) {
  717. if (type == "short") {
  718. //@ts-ignore
  719. //使手机发生较短时间的振动(15 ms)。仅在 iPhone 7 / 7 Plus 以上及 Android 机型生效
  720. wx.vibrateShort({ success(res) { }, fail(res) { } });
  721. } else {
  722. //@ts-ignore
  723. wx.vibrateLong({ success(res) { }, fail(res) { } }); //400 ms
  724. }
  725. }
  726. else if (PlatUtils.IsOPPO) {
  727. if (type == "short") {
  728. //@ts-ignore
  729. qg.vibrateShort({ success(res) { }, fail(res) { } });//(20 ms)
  730. } else {
  731. //@ts-ignore
  732. qg.vibrateLong({ success(res) { }, fail(res) { } }); //400 ms
  733. }
  734. } else if (PlatUtils.IsVIVO) {
  735. if (type == "short") {
  736. //@ts-ignore
  737. qg.vibrateShort();//(15 ms)
  738. } else {
  739. //@ts-ignore
  740. qg.vibrateLong(); //400 ms
  741. }
  742. } else if (PlatUtils.IsQQ) {
  743. if (type == "short") {
  744. //@ts-ignore
  745. //(15 ms),仅在 iPhone 7/7 Plus 以上及 Android 机型生效。
  746. qq.vibrateShort({ success(res) { }, fail(res) { } });
  747. } else {
  748. //@ts-ignore
  749. qq.vibrateLong({ success(res) { }, fail(res) { } }); //400 ms
  750. }
  751. } else if (PlatUtils.IsDouyin) {
  752. if (type == "short") {
  753. //@ts-ignore
  754. tt.vibrateShort({ success(res) { }, fail(res) { } });
  755. } else {
  756. //@ts-ignore
  757. tt.vibrateLong({ success(res) { }, fail(res) { } }); //400 ms
  758. }
  759. } else if (PlatUtils.IsBaidu) {
  760. if (type == "short") {
  761. //@ts-ignore
  762. //(15 ms),仅在 iPhone 7/7 Plus 以上及 Android 机型生效。
  763. swan.vibrateShort({ success(res) { }, fail(res) { } });
  764. } else {
  765. //@ts-ignore
  766. swan.vibrateLong({ success(res) { }, fail(res) { } }); //400 ms
  767. }
  768. } else if (PlatUtils.IsNativeAndroid) {
  769. if (type == "short") {
  770. //@ts-ignore
  771. jsb.reflection.callStaticMethod(utils.Tool_Native.jniClassName, "vibrateShort", "()V");
  772. } else {
  773. //@ts-ignore
  774. jsb.reflection.callStaticMethod(utils.Tool_Native.jniClassName, "vibrateLong", "()V");
  775. }
  776. }
  777. }
  778. }