import { _decorator, Component, Node, sys, native, director, Director } from 'cc'; import { waitView } from './Game/waitView'; import { GameMng } from './GameMng'; import { UIManager } from './gcommon/UIManager'; import UITips from './gcommon/UITips'; import { msgManager } from './socket/msgManager'; import { Tools } from './Tools'; const { ccclass, property } = _decorator; @ccclass('native_manager') export class native_manager { public static wxLogin(){ UIManager.AddPrefab(GameMng.Instance.uiloading) if("ANDROID"==sys.platform){ native.jsbBridgeWrapper.dispatchEventToNative("send_ios_login"); native.jsbBridgeWrapper.removeNativeEventListener("receive_ios_login",native_manager.ios_login) native.jsbBridgeWrapper.addNativeEventListener("receive_ios_login",native_manager.ios_login); }else if("IOS"==sys.platform){ native.jsbBridgeWrapper.dispatchEventToNative("send_ios_login"); native.jsbBridgeWrapper.removeNativeEventListener("receive_ios_login",native_manager.ios_login) native.jsbBridgeWrapper.addNativeEventListener("receive_ios_login",native_manager.ios_login); } } public static ios_login(jsonStr: string): void { var json_ = JSON.parse(jsonStr); console.log("wxLogin",jsonStr) if(jsonStr!=""){ for (const key in json_) { if (Object.prototype.hasOwnProperty.call(json_, key)) { const element = json_[key]; console.log("wxLogin",element) } } msgManager.wxlogin(json_.nickname,json_.openId,json_.sex,json_.property,json_.city,json_.country,json_.headimgurl) } } public static share(){ if("ANDROID"==sys.platform){ setTimeout(() => { var o = native.reflection.callStaticMethod("com/cocos/game/AppActivity", "shareWx", "(Ljava/lang/String;)V",Tools.getShareObj()); }, 1000); }else if("IOS"==sys.platform){ native.jsbBridgeWrapper.dispatchEventToNative("shareWx",Tools.getShareObj()); } } public static check_jump_info(){ native_manager.recv_jump_info(); if("ANDROID"==sys.platform){ native.jsbBridgeWrapper.dispatchEventToNative("check_jump_info"); }else if("IOS"==sys.platform){ director.once(Director.EVENT_AFTER_DRAW,function(){ native.jsbBridgeWrapper.dispatchEventToNative("check_jump_info"); }) } } public static recv_jump_info_call(jsonStr: string): void { var json_ = JSON.parse(jsonStr); if(json_.firendOpenId){ GameMng.firendOpenId = json_.firendOpenId; } console.log("recv_jump_info_call",jsonStr) waitView.Show("等待加入房间!") } public static reward_callback(status: string): void { console.log("reward_callback",status) UIManager.removeLoadingLayer() if(status==="1"){ waitView.Show("等待发放奖励") GameMng.reward_tong_bi = true; }else{ UITips.show("非常抱歉,您未获取到广告奖励!"); } } public static recv_jump_info(){ if("ANDROID"==sys.platform){ native.jsbBridgeWrapper.removeNativeEventListener("recv_jump_info",native_manager.recv_jump_info_call); native.jsbBridgeWrapper.addNativeEventListener("recv_jump_info",native_manager.recv_jump_info_call); }else if("IOS"==sys.platform){ native.jsbBridgeWrapper.removeNativeEventListener("recv_jump_info",native_manager.recv_jump_info_call); native.jsbBridgeWrapper.addNativeEventListener("recv_jump_info",native_manager.recv_jump_info_call); } } public static hideSplash(){ if("ANDROID"==sys.platform){ setTimeout(() => { var o = native.reflection.callStaticMethod("com/cocos/game/AppActivity", "hideSplash", "()V"); }, 1000); }else if("IOS"==sys.platform){ native.jsbBridgeWrapper.dispatchEventToNative("hideSplash"); } } public static showRewardVideo(){ if("ANDROID"==sys.platform){ native.jsbBridgeWrapper.dispatchEventToNative("show_reward_video") native.jsbBridgeWrapper.removeNativeEventListener("reward_callback",native_manager.reward_callback); native.jsbBridgeWrapper.addNativeEventListener("reward_callback",native_manager.reward_callback); }else if("IOS"==sys.platform){ native.jsbBridgeWrapper.dispatchEventToNative("show_reward_video") native.jsbBridgeWrapper.removeNativeEventListener("reward_callback",native_manager.reward_callback); native.jsbBridgeWrapper.addNativeEventListener("reward_callback",native_manager.reward_callback); }else{ msgManager.ad_tongbi(1) } } }