native_manager.ts 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. import { _decorator, Component, Node, sys, native, director, Director } from 'cc';
  2. import { waitView } from './Game/waitView';
  3. import { GameMng } from './GameMng';
  4. import { UIManager } from './gcommon/UIManager';
  5. import UITips from './gcommon/UITips';
  6. import { msgManager } from './socket/msgManager';
  7. import { Tools } from './Tools';
  8. const { ccclass, property } = _decorator;
  9. @ccclass('native_manager')
  10. export class native_manager {
  11. public static wxLogin(){
  12. UIManager.AddPrefab(GameMng.Instance.uiloading)
  13. if("ANDROID"==sys.platform){
  14. native.jsbBridgeWrapper.dispatchEventToNative("send_ios_login");
  15. native.jsbBridgeWrapper.removeNativeEventListener("receive_ios_login",native_manager.ios_login)
  16. native.jsbBridgeWrapper.addNativeEventListener("receive_ios_login",native_manager.ios_login);
  17. }else if("IOS"==sys.platform){
  18. native.jsbBridgeWrapper.dispatchEventToNative("send_ios_login");
  19. native.jsbBridgeWrapper.removeNativeEventListener("receive_ios_login",native_manager.ios_login)
  20. native.jsbBridgeWrapper.addNativeEventListener("receive_ios_login",native_manager.ios_login);
  21. }
  22. }
  23. public static ios_login(jsonStr: string): void {
  24. var json_ = JSON.parse(jsonStr);
  25. console.log("wxLogin",jsonStr)
  26. if(jsonStr!=""){
  27. for (const key in json_) {
  28. if (Object.prototype.hasOwnProperty.call(json_, key)) {
  29. const element = json_[key];
  30. console.log("wxLogin",element)
  31. }
  32. }
  33. msgManager.wxlogin(json_.nickname,json_.openId,json_.sex,json_.property,json_.city,json_.country,json_.headimgurl)
  34. }
  35. }
  36. public static share(){
  37. if("ANDROID"==sys.platform){
  38. setTimeout(() => {
  39. var o = native.reflection.callStaticMethod("com/cocos/game/AppActivity", "shareWx", "(Ljava/lang/String;)V",Tools.getShareObj());
  40. }, 1000);
  41. }else if("IOS"==sys.platform){
  42. native.jsbBridgeWrapper.dispatchEventToNative("shareWx",Tools.getShareObj());
  43. }
  44. }
  45. public static check_jump_info(){
  46. native_manager.recv_jump_info();
  47. if("ANDROID"==sys.platform){
  48. native.jsbBridgeWrapper.dispatchEventToNative("check_jump_info");
  49. }else if("IOS"==sys.platform){
  50. director.once(Director.EVENT_AFTER_DRAW,function(){
  51. native.jsbBridgeWrapper.dispatchEventToNative("check_jump_info");
  52. })
  53. }
  54. }
  55. public static recv_jump_info_call(jsonStr: string): void {
  56. var json_ = JSON.parse(jsonStr);
  57. if(json_.firendOpenId){
  58. GameMng.firendOpenId = json_.firendOpenId;
  59. }
  60. console.log("recv_jump_info_call",jsonStr)
  61. waitView.Show("等待加入房间!")
  62. }
  63. public static reward_callback(status: string): void {
  64. console.log("reward_callback",status)
  65. UIManager.removeLoadingLayer()
  66. if(status==="1"){
  67. waitView.Show("等待发放奖励")
  68. GameMng.reward_tong_bi = true;
  69. }else{
  70. UITips.show("非常抱歉,您未获取到广告奖励!");
  71. }
  72. }
  73. public static recv_jump_info(){
  74. if("ANDROID"==sys.platform){
  75. native.jsbBridgeWrapper.removeNativeEventListener("recv_jump_info",native_manager.recv_jump_info_call);
  76. native.jsbBridgeWrapper.addNativeEventListener("recv_jump_info",native_manager.recv_jump_info_call);
  77. }else if("IOS"==sys.platform){
  78. native.jsbBridgeWrapper.removeNativeEventListener("recv_jump_info",native_manager.recv_jump_info_call);
  79. native.jsbBridgeWrapper.addNativeEventListener("recv_jump_info",native_manager.recv_jump_info_call);
  80. }
  81. }
  82. public static hideSplash(){
  83. if("ANDROID"==sys.platform){
  84. setTimeout(() => {
  85. var o = native.reflection.callStaticMethod("com/cocos/game/AppActivity", "hideSplash", "()V");
  86. }, 1000);
  87. }else if("IOS"==sys.platform){
  88. native.jsbBridgeWrapper.dispatchEventToNative("hideSplash");
  89. }
  90. }
  91. public static showRewardVideo(){
  92. if("ANDROID"==sys.platform){
  93. native.jsbBridgeWrapper.dispatchEventToNative("show_reward_video")
  94. native.jsbBridgeWrapper.removeNativeEventListener("reward_callback",native_manager.reward_callback);
  95. native.jsbBridgeWrapper.addNativeEventListener("reward_callback",native_manager.reward_callback);
  96. }else if("IOS"==sys.platform){
  97. native.jsbBridgeWrapper.dispatchEventToNative("show_reward_video")
  98. native.jsbBridgeWrapper.removeNativeEventListener("reward_callback",native_manager.reward_callback);
  99. native.jsbBridgeWrapper.addNativeEventListener("reward_callback",native_manager.reward_callback);
  100. }else{
  101. msgManager.ad_tongbi(1)
  102. }
  103. }
  104. }