CocosZ.ts 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726
  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 {
  64. private _gameMgr: GameMgr = null;
  65. private _dataMgr: DataMgr = null;
  66. private _uiMgr: UIMgr = null;
  67. private _resMgr: ResMgr = null;
  68. private _audioMgr: AudioMgr = null;
  69. private _sceneMgr: SceneMgr = null;
  70. public get gameMgr() {
  71. return this._gameMgr;
  72. }
  73. public get dataMgr() {
  74. return this._dataMgr;
  75. }
  76. public get uiMgr() {
  77. return this._uiMgr;
  78. }
  79. public get resMgr() {
  80. return this._resMgr;
  81. }
  82. public get audioMgr() {
  83. return this._audioMgr;
  84. }
  85. public get sceneMgr() {
  86. return this._sceneMgr;
  87. }
  88. @property()
  89. btnDebug: boolean = false;//zh:diy default false;
  90. private _languagesArr = ["zh", "en"];
  91. @property({ visible: false })
  92. curLanguage: string = "zh";
  93. @property({ visible: false })
  94. private _curLang: Languages = Languages.zh;
  95. @property({ type: cc.Enum(Languages), displayName: "当前语言", tooltip: "zh(中文) en(英文)" })
  96. get curLang(): Languages { return this._curLang; }
  97. set curLang(v: Languages) {
  98. this._curLang = v;
  99. this.curLanguage = this._languagesArr[v];
  100. cc.log("当前语言: ", this.curLanguage)
  101. }
  102. @property({ type: cc.AudioClip })
  103. audioList: Array<cc.AudioClip> = [];
  104. private _useCJTimes: number = 0;
  105. get useCJTimes() {
  106. return this._useCJTimes;
  107. }
  108. set useCJTimes(num: number) {
  109. this._useCJTimes = num;
  110. localStorage.setItem(Constant.ST_GameData + "useCJTimes_dmm", this._useCJTimes.toString());
  111. }
  112. private _totalCJTimes: number = 0;
  113. get totalCJTimes() {
  114. return this._totalCJTimes;
  115. }
  116. set totalCJTimes(num: number) {
  117. this._totalCJTimes = num;
  118. localStorage.setItem(Constant.ST_GameData + "totalCJTimes_dmm", this._totalCJTimes.toString());
  119. }
  120. curLevel: number = 0;
  121. /** 事件上报的关卡id */
  122. getLevelId(id?: number): number {
  123. return cocosz.dataMgr.TotoalCount_6;
  124. }
  125. /** 暂停计数 */
  126. private _pauseCount: number = 0;
  127. public get pauseCount() {
  128. return this._pauseCount;
  129. }
  130. public set pauseCount(v: number) {
  131. if (v < 0) { v = 0; }
  132. this._pauseCount = v;
  133. cc.log("pauseCount:", this._pauseCount);
  134. }
  135. public get isPause(): boolean {
  136. return (this.pauseCount > 0);
  137. }
  138. private set isPause(v: boolean) { }
  139. /** 最大分享数量 */
  140. serverConfig_shareMaxNum: number = 0;
  141. /** 能否显示分享 */
  142. public get canShare(): boolean {
  143. let r = false;
  144. if ((CC_DEBUG && this.isDeBug) || PlatUtils.IsWechat) {
  145. if (cocosz.dataMgr.shareNum < cocosz.serverConfig_shareMaxNum) {
  146. r = true;
  147. }
  148. }
  149. return r;
  150. }
  151. /** 是否启用调试 zh:diy default false */
  152. isDeBug: boolean = false;
  153. /** 是否显示视频按钮 */
  154. isADON: boolean = true;
  155. /** 游戏模式 */
  156. gameMode: number = 6;
  157. onLoad() {
  158. cocosz = this;
  159. this._gameMgr = GameMgr.inst;
  160. this._dataMgr = DataMgr.inst;
  161. this._resMgr = ResMgr.inst;
  162. this._uiMgr = UIMgr.inst;
  163. this._audioMgr = AudioMgr.inst;
  164. this._sceneMgr = SceneMgr.inst;
  165. // 常驻节点
  166. cc.game.addPersistRootNode(this.node);
  167. ////////////////////////////// 初始化语言 //////////////////////////////
  168. if (cc.sys.languageCode) {
  169. if (cc.sys.languageCode.toLowerCase().indexOf("zh") > -1) {
  170. this.curLanguage = 'zh';
  171. } else {
  172. this.curLanguage = 'en';
  173. }
  174. }
  175. this.curLanguage = 'en';//zh:diy
  176. i18n.init(this.curLanguage);
  177. ////////////////////////////// 测试模式 //////////////////////////////
  178. this.isDeBug = this.btnDebug;
  179. console.log('zh:is debug =' + this.btnDebug)
  180. ////////////////////////////// 服务器配置 //////////////////////////////
  181. this._initConfigKey();
  182. ////////////////////////////// 游戏配置 //////////////////////////////
  183. cc.director.getCollisionManager().enabled = true;
  184. // cc.director.getCollisionManager().enabledDebugDraw = true;
  185. let manager = cc.director.getPhysicsManager();
  186. manager.enabled = true;
  187. manager.gravity = cc.v2();
  188. // manager.debugDrawFlags = 1;
  189. // cc.game.setFrameRate(30);
  190. //保持微信屏幕长亮不熄屏
  191. if (PlatUtils.IsWechat) {
  192. //@ts-ignore
  193. wx.setKeepScreenOn({ keepScreenOn: true })
  194. } else if (PlatUtils.IsOPPO) {
  195. //@ts-ignore
  196. qg.setKeepScreenOn({
  197. keepScreenOn: true,
  198. success: function (res) { },
  199. fail: function (res) { },
  200. complete: function (res) { }
  201. })
  202. } else if (PlatUtils.IsVIVO) {
  203. //@ts-ignore
  204. qg.setKeepScreenOn({
  205. keepScreenOn: true,
  206. success: function () { console.log('handling success') },
  207. fail: function (data, code) { console.log(`handling fail, code = ${code}`) }
  208. })
  209. }
  210. ////////////////////////////// 加载bundle //////////////////////////////
  211. cc.assetManager.loadBundle("bundleLoad", null, (err, bundle) => {
  212. if (!err) {
  213. this._initLoadingPage();
  214. } else {
  215. cc.log("加载分包bundleLoad出错")
  216. }
  217. })
  218. }
  219. initAdForPage() {
  220. if (cc.sys.os === cc.sys.OS_ANDROID) {
  221. let deviceId = AAJS2.getDeviceUserId();
  222. console.log("zh:checkstatus:", ATRewardedVideoSDK.checkAdStatus(AAJS2.getPlacementId()));
  223. var setting = {};
  224. setting[ATRewardedVideoSDK.userIdKey] = deviceId;
  225. ATRewardedVideoSDK.loadRewardedVideo(AAJS2.getPlacementId(), setting);
  226. }
  227. }
  228. private _dtBack = 1 / 60;
  229. protected update(dt: number): void {
  230. let manager = cc.director.getPhysicsManager();
  231. manager.enabledAccumulator = true;
  232. // @ts-ignore
  233. manager.FIXED_TIME_STEP = cc.misc.lerp(this._dtBack, dt, 0.01);
  234. this._dtBack = dt;
  235. }
  236. private isOk: boolean = false;
  237. private _initLoadingPage() {
  238. let url: string = "ui/UILoadingPage";
  239. this.resMgr.loadAndCacheRes(url, cc.Prefab, null, () => {
  240. this._uiMgr.openPage(PageName.UILoadingPage);
  241. /** 登录认证 */
  242. utils.login(() => {
  243. ////////////////////////////// 缓存初始化 //////////////////////////////
  244. this._initCache();
  245. ////////////////////////////// 加载bundleRes ///////////////////////////
  246. this._loadBundleRes();
  247. ////////////////////////////// 华为隐私->插屏 ///////////////////////////
  248. if (PlatUtils.IsHuaWei) {
  249. utils.showYzRealNameAuthPanel();
  250. utils.showPrivacyPanel();
  251. this.scheduleOnce(() => {
  252. utils.registerServerInitEvent(() => {
  253. utils.adManager.showNativeSplashView(
  254. () => { this.isOk = true; }
  255. );
  256. }, this);
  257. }, 3);
  258. } else {
  259. this.isOk = true;
  260. }
  261. });
  262. });
  263. }
  264. private _loadBundleRes() {
  265. cc.assetManager.loadBundle("bundleRes", (err, bundle) => {
  266. if (!err) {
  267. // 初始化bundle配置
  268. this._initBundleConfig();
  269. // 加载资源
  270. this._loadRes();
  271. } else {
  272. cc.log("zh:加载分包bundleRes出错")
  273. }
  274. })
  275. }
  276. private _loadRes() {
  277. let totalCount: number = 0;
  278. let compCount: number = 0;
  279. // UI
  280. let mess1: any = [];
  281. cocosz.getDirWithPath("UI/", cc.Prefab, mess1);
  282. cocosz.resMgr.loadAndCacheResArray(mess1, cc.Prefab, null, () => { compCount++; })
  283. // 图片_name
  284. let mess2: any = [];
  285. cocosz.getDirWithPath("i18n/tex_name/" + cocosz.curLanguage, cc.SpriteAtlas, mess2);
  286. cocosz.resMgr.loadAndCacheResArray(mess2, cc.SpriteAtlas, null, () => { compCount++; })
  287. // 图片_icon
  288. let mess3: any = [];
  289. cocosz.getDirWithPath("tex_common", cc.SpriteAtlas, mess3);
  290. cocosz.resMgr.loadAndCacheResArray(mess3, cc.SpriteAtlas, null, () => { compCount++; })
  291. // 头像
  292. let mess4: any = [];
  293. cocosz.getDirWithPath("prefab_heads", cc.Prefab, mess4);
  294. cocosz.resMgr.loadAndCacheResArray(mess4, cc.Prefab, null, () => { compCount++; })
  295. // 武器
  296. let mess5: any = [];
  297. cocosz.getDirWithPath("prefab_weapon", cc.Prefab, mess5);
  298. cocosz.resMgr.loadAndCacheResArray(mess5, cc.Prefab, null, () => { compCount++; })
  299. // 皮肤
  300. let mess6: any = [];
  301. cocosz.getDirWithPath("prefab_skin", cc.Prefab, mess6);
  302. cocosz.resMgr.loadAndCacheResArray(mess6, cc.Prefab, null, () => { compCount++; })
  303. // 音效
  304. let mess7: any = [];
  305. cocosz.getDirWithPath("audio_common", cc.AudioClip, mess7);
  306. cocosz.resMgr.loadAndCacheResArray(mess7, cc.AudioClip, null, () => { compCount++; })
  307. // 总资源数量
  308. totalCount = mess1.length + mess2.length + mess3.length + mess4.length + mess5.length + mess6.length + mess7.length;
  309. // 挂载音效
  310. this.resMgr.cacheCocoszAudio();
  311. let percent = 0;
  312. this.schedule(() => {
  313. percent = compCount / totalCount;
  314. cc.game.emit(Constant.E_GAME_LOGIC, { type: Constant.E_UPDATE_PROGRESS, data: percent });
  315. if (compCount >= totalCount && this.isOk) {
  316. this.unscheduleAllCallbacks();
  317. // 计时插屏
  318. utils.registerServerInitEvent(() => {
  319. let t = cocosz.getConfigByKey("interval_time_show_cp");
  320. if (Number.isInteger(t) && t > 0) {
  321. this.schedule(() => { utils.adManager.ShowInterstitial(); }, t);
  322. }
  323. }, this);
  324. // 开始在线计时
  325. setInterval(() => { cocosz.dataMgr.OnlineToday++; }, 1000);
  326. // 跳转首页
  327. this._sceneMgr.loadScene("Home", () => {
  328. this._uiMgr.openPage(PageName.UIHomePage);
  329. });
  330. }
  331. }, 0);
  332. }
  333. bundleConfig: any = {
  334. "ui/UILoadingPage": "bundleLoad"
  335. }
  336. private _initBundleConfig() {
  337. let arr = ["resources", "bundleRes", "bundleLoad"];
  338. for (const bundleKey of arr) {
  339. let bundle = cc.assetManager.bundles.get(bundleKey);
  340. if (bundle) {
  341. let info = bundle["_config"]["paths"]["_map"]
  342. if (info) {
  343. for (const key in info) {
  344. this.bundleConfig[key] = bundleKey;
  345. }
  346. }
  347. }
  348. }
  349. // cc.log("bundleConfig:", JSON.stringify(this.bundleConfig))
  350. }
  351. getBundleWithPath(path: string): cc.AssetManager.Bundle {
  352. if (this.bundleConfig[path]) {
  353. return cc.assetManager.bundles.get(this.bundleConfig[path]);
  354. } else {
  355. for (const key in this.bundleConfig) {
  356. if (key[0] === path[0]) {
  357. if (key.includes(path, 0)) {
  358. return cc.assetManager.bundles.get(this.bundleConfig[key]);
  359. }
  360. }
  361. }
  362. }
  363. cc.log("查找budle失败:", path)
  364. return null;
  365. }
  366. getDirWithPath(path: string, type: typeof cc.Asset, out?: Array<Record<string, any>>) {
  367. let bundle = this.getBundleWithPath(path);
  368. if (bundle) {
  369. return bundle.getDirWithPath(path, type, out);
  370. } else {
  371. return null;
  372. }
  373. }
  374. serverConfig: any = {
  375. ////////////////// 分享 ///////////////////
  376. // 分享最大次数(平台不能分享不要配置)
  377. "shareMaxNum": 5,
  378. // 分享成功的时间(秒)
  379. "shareTime": 2,
  380. ////////////////// 视频 ///////////////////
  381. // 视频点_游戏界面_高级武器(默认显示)
  382. "isVideoAd_advanced_weapon": "true",
  383. // 视频点_游戏界面_全屏轰炸(默认显示)
  384. "isVideoAd_Qpbz": "true",
  385. // 视频点_游戏界面_磁铁(默认显示)
  386. "isVideoAd_Citie": "true",
  387. // 视频点_游戏界面_隐藏banner(默认隐藏)
  388. "isVideoAd_hideBanner": "true",
  389. // 视频点_技能弹窗_视频解锁数量(默认0)
  390. "skillLockNum": 2,
  391. ////////////////// banner ///////////////////
  392. // 是否显示游戏界面banner(默认显示)
  393. "isBanner_game": true,
  394. ////////////////// 插屏 ///////////////////
  395. // 首页
  396. "isInterstitial_UIHomePage": "true",
  397. // 签到
  398. "isInterstitial_UISignPanel": "true",
  399. // 转盘
  400. "isInterstitial_UITurntablePanel": "true",
  401. // 在线奖励
  402. "isInterstitial_UITimePanel": "true",
  403. // 游戏
  404. "isInterstitial_UIGamePage": "true",
  405. // 复活
  406. "isInterstitial_UIRevivePanel": "true",
  407. // 暂停
  408. "isInterstitial_UIPausePanel": "true",
  409. // 技能
  410. "isInterstitial_UIUpgradePanel": "true",
  411. // 皮肤试用间隔(组件自带)
  412. "try_skin_level_count": 1,
  413. // 皮肤试用插屏间隔(组件自带)
  414. "try_skin_show_ad_interval": 1,
  415. }
  416. getConfigByKey(key: string) {
  417. if (CC_DEBUG && cocosz.isDeBug) {
  418. return this.serverConfig ? this.serverConfig[key] : null;
  419. } else {
  420. return utils.getConfigByKey(key);
  421. }
  422. }
  423. private _initConfigKey() {
  424. let callback = () => {
  425. // 0 测试模式
  426. if (cocosz.getConfigByKey("game_debug") == "true") {
  427. cocosz.isDeBug = true;
  428. }
  429. // 1 分享最大数量
  430. let shareMaxNum = cocosz.getConfigByKey("shareMaxNum");
  431. if (Number.isInteger(shareMaxNum) && shareMaxNum >= 0) {
  432. cocosz.serverConfig_shareMaxNum = shareMaxNum;
  433. }
  434. // 2 分享所需的时间
  435. let shareTime = cocosz.getConfigByKey("shareTime");
  436. if (Number.isInteger(shareTime) && shareTime >= 0) {
  437. cocosz.serverConfig_shareTime = shareTime;
  438. }
  439. }
  440. if (CC_DEBUG && this.isDeBug) {
  441. callback && callback();
  442. }
  443. else {
  444. // 注册服务器回调
  445. utils.registerServerInitEvent(callback, this);
  446. }
  447. }
  448. private _initCache() {
  449. // 缓存
  450. cocosz.dataMgr && cocosz.dataMgr.init();
  451. if (cocosz.dataMgr.LastLoadDate != (new Date()).toDateString()) {
  452. cocosz.dataMgr.LastLoadDate = (new Date()).toDateString();
  453. cocosz.dataMgr.shareNum = 0;
  454. }
  455. if (localStorage.getItem(Constant.ST_GameData + "totalCJTimes_dmm")) {
  456. this._totalCJTimes = Number(localStorage.getItem(Constant.ST_GameData + "totalCJTimes_dmm"));
  457. }
  458. if (localStorage.getItem(Constant.ST_GameData + "useCJTimes_dmm")) {
  459. this._useCJTimes = Number(localStorage.getItem(Constant.ST_GameData + "useCJTimes_dmm"));
  460. }
  461. if (new Date().toDateString() != cocosz.dataMgr.LastLoadDate) {
  462. this.useCJTimes = 0;
  463. cocosz.dataMgr.OnlineToday = 0;
  464. cocosz.dataMgr.receiveToday = [0, 0, 0, 0, 0];
  465. cocosz.dataMgr.LastLoadDate = new Date().toDateString();
  466. }
  467. }
  468. /** 是否显示广告 */
  469. public get isShowAd() {
  470. return true;
  471. }
  472. /** 是否显示游戏banner */
  473. public get isShowGameBanner() {
  474. if (cocosz.getConfigByKey("gameBanner") == "false") {
  475. return false;
  476. } else {
  477. return true;
  478. }
  479. }
  480. /** 秒转换时分秒 */
  481. StoHMS(s: number) {
  482. let m = 0;// 分
  483. let h = 0;// 小时
  484. if (s >= 60) {
  485. m = Math.floor(s / 60);
  486. s = Math.floor(s % 60);
  487. if (m > 60) {
  488. h = Math.floor(m / 60);
  489. m = Math.floor(m % 60);
  490. }
  491. }
  492. let r = "";
  493. r += (h == 0 ? "" : h + ":");
  494. r += (m >= 10 ? "" + m : "0" + m);
  495. r += (s >= 10 ? ":" + s : ":0" + s);
  496. return r;
  497. }
  498. /**
  499. * 看视频
  500. * @param callFun_S 播放成功时回调
  501. * @param callFun_F 播放失败时回调
  502. */
  503. watchAD(callFun_S: Function = null, callFun_F: Function = null) {
  504. if (callFun_S) {
  505. if (ATRewardedVideoSDK.hasAdReady(AAJS2.getPlacementId())) {
  506. console.log('zh:AD ready for idx2')
  507. ATRewardedVideoSDK.showAd(AAJS2.getPlacementId());
  508. console.log('zh: 开始回调1')
  509. callFun_S();
  510. } else {
  511. console.log('zh:AD not ready for idx2')
  512. console.log('zh: 开始回调2')
  513. callFun_S();
  514. }
  515. } else if (callFun_F) {
  516. callFun_F();
  517. }
  518. if(2>1){
  519. return;
  520. }
  521. //下面是原先的代码
  522. if (this.isDeBug) {
  523. if (callFun_S) {
  524. callFun_S();
  525. } else if (callFun_F) {
  526. callFun_F();
  527. }
  528. return;
  529. }
  530. console.log('zh:AD 00000000000000000' + this.isDeBug)
  531. if (cocosz.audioMgr.videoOn) return;
  532. cocosz.audioMgr.videoOn = true;
  533. cocosz.pauseCount++;
  534. cocosz.audioMgr.stopAll();
  535. utils.adManager.ShowVideo((ret, msg) => {
  536. cocosz.audioMgr.videoOn = false;
  537. cocosz.pauseCount--;
  538. cocosz.audioMgr.playBgm();
  539. if (ret) {
  540. callFun_S && callFun_S();
  541. }
  542. else {
  543. callFun_F && callFun_F();
  544. msg = msg ? msg : i18n.t("msg.video_load_fail");//视频加载失败
  545. Msg.Show(msg);
  546. }
  547. })
  548. }
  549. // 分享所需的时间(单位/秒)
  550. serverConfig_shareTime: number = 2;
  551. /**
  552. *
  553. * @param 分享成功回调
  554. * @param 分享失败回调
  555. */
  556. public share(callFun_S: Function = null, callFun_F: Function = null) {
  557. if (this.isDeBug) {
  558. callFun_S && callFun_S();
  559. cocosz.dataMgr.shareNum++;
  560. } else {
  561. let startTime = (new Date()).getTime();
  562. utils.share(() => {
  563. if ((new Date()).getTime() - startTime > (this.serverConfig_shareTime * 1000)) {
  564. callFun_S && callFun_S();
  565. cocosz.dataMgr.shareNum++;
  566. } else {
  567. callFun_F && callFun_F();
  568. Msg.Show("请分享至不同好友才可获得奖励哦");
  569. }
  570. });
  571. }
  572. }
  573. /**
  574. * 屏幕震动功能
  575. * @param type 震动类型 传递枚举:VibrateType
  576. */
  577. public vibrate(type: string = "short") {
  578. if (cocosz.dataMgr.ShakeOn == false) return;
  579. if (type == "short") {
  580. AAJS2.appVibrateShort();
  581. } else {
  582. //@ts-ignore
  583. AAJS2.appVibrateLong();
  584. }
  585. if(2>1){
  586. return;
  587. }
  588. if (PlatUtils.IsWechat) {
  589. if (type == "short") {
  590. //@ts-ignore
  591. //使手机发生较短时间的振动(15 ms)。仅在 iPhone 7 / 7 Plus 以上及 Android 机型生效
  592. wx.vibrateShort({ success(res) { }, fail(res) { } });
  593. } else {
  594. //@ts-ignore
  595. wx.vibrateLong({ success(res) { }, fail(res) { } }); //400 ms
  596. }
  597. }
  598. else if (PlatUtils.IsOPPO) {
  599. if (type == "short") {
  600. //@ts-ignore
  601. qg.vibrateShort({ success(res) { }, fail(res) { } });//(20 ms)
  602. } else {
  603. //@ts-ignore
  604. qg.vibrateLong({ success(res) { }, fail(res) { } }); //400 ms
  605. }
  606. } else if (PlatUtils.IsVIVO) {
  607. if (type == "short") {
  608. //@ts-ignore
  609. qg.vibrateShort();//(15 ms)
  610. } else {
  611. //@ts-ignore
  612. qg.vibrateLong(); //400 ms
  613. }
  614. } else if (PlatUtils.IsQQ) {
  615. if (type == "short") {
  616. //@ts-ignore
  617. //(15 ms),仅在 iPhone 7/7 Plus 以上及 Android 机型生效。
  618. qq.vibrateShort({ success(res) { }, fail(res) { } });
  619. } else {
  620. //@ts-ignore
  621. qq.vibrateLong({ success(res) { }, fail(res) { } }); //400 ms
  622. }
  623. } else if (PlatUtils.IsDouyin) {
  624. if (type == "short") {
  625. //@ts-ignore
  626. tt.vibrateShort({ success(res) { }, fail(res) { } });
  627. } else {
  628. //@ts-ignore
  629. tt.vibrateLong({ success(res) { }, fail(res) { } }); //400 ms
  630. }
  631. } else if (PlatUtils.IsBaidu) {
  632. if (type == "short") {
  633. //@ts-ignore
  634. //(15 ms),仅在 iPhone 7/7 Plus 以上及 Android 机型生效。
  635. swan.vibrateShort({ success(res) { }, fail(res) { } });
  636. } else {
  637. //@ts-ignore
  638. swan.vibrateLong({ success(res) { }, fail(res) { } }); //400 ms
  639. }
  640. } else if (PlatUtils.IsNativeAndroid) {
  641. if (type == "short") {
  642. //@ts-ignore
  643. jsb.reflection.callStaticMethod(utils.Tool_Native.jniClassName, "vibrateShort", "()V");
  644. } else {
  645. //@ts-ignore
  646. jsb.reflection.callStaticMethod(utils.Tool_Native.jniClassName, "vibrateLong", "()V");
  647. }
  648. }
  649. }
  650. }