1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
| package com.DefaultCompany.ResLoadPrg;
import android.app.ActivityManager; import android.content.Context; import android.util.Log;
import com.unity3d.player.UnityPlayer;
import org.json.JSONException; import org.json.JSONObject;
public class GameHelper { private static MainActivity m_Activity = null; private static final String m_PlatformObject = "PlatformObject"; private static final String m_MethodName = "OnMessage"; public static String TAG = "GameHelper"; public static void Init(MainActivity activity){ m_Activity = activity; } public static final int PLATFORM_MSG_QQLOGINCALLBACK = 1; public static final int PLATFORM_MSG_WXLOGINCALLBACK = 2; public static void SendPlatformMessageToUnity( int iMsgId, int iParam1, int iParam2, int iParam3, String strParam1, String strParam2, String strParam3){ String jsonString = GetJsonStr(iMsgId,iParam1,iParam2,iParam3,strParam1,strParam2,strParam3); UnityPlayer.UnitySendMessage(m_PlatformObject,m_MethodName,jsonString); }
public static final int PLATFORM_MSG_QQLOGIN = 1; public static final int PLATFORM_MSG_QQLOGOUT = 2; public static final int PLATFORM_MSG_WXLOGIN = 3; public static final int PLATFORM_MSG_WXLOGOUT = 4; public static void SendUnityMessageToPlatform( int iMsgId, int iParam1, int iParam2, int iParam3, int iParam4, String strParam1, String strParam2, String strParam3, String strParam4 ){
Log.d(TAG,"SendUnityMessageToPlatform: iMsgId: " + iMsgId + "\n" + "iParam1" + iParam1 + "\n" + "iParam2" + iParam2 + "\n" + "iParam3" + iParam3 + "\n" + "iParam4" + iParam4 + "\n" + "strParam1" + strParam1 + "\n" + "strParam2" + strParam2 + "\n" + "strParam3" + strParam3 + "\n" + "strParam4" + strParam4);
if(m_Activity == null) { Log.e(TAG,"m_Activity is null"); } switch (iMsgId){ case PLATFORM_MSG_QQLOGIN: TencentQQ.Login(); break; case PLATFORM_MSG_QQLOGOUT: TencentQQ.Logout(); break; case PLATFORM_MSG_WXLOGIN: break; case PLATFORM_MSG_WXLOGOUT: break; } } public static int GetIntFromPlatform(int type){ switch (type){
} return 0; } public static final int PLATFORM_MSG_AUTHORVALID = 1; public static final int PLATFORM_MSG_REFRESHSESSION = 2; public static String GetStringFromPlatform(int type){ switch (type){ case PLATFORM_MSG_AUTHORVALID: return String.valueOf(TencentQQ.CheckAuthorValid()); case PLATFORM_MSG_REFRESHSESSION: return TencentQQ.RefreshSession().toString(); } return ""; } public static long GetLongFromPlatform(int type){ switch (type){ } return 0; } public static long GetLongFromPlatform2( int type, int iParam1, int iParam2, int iParam3, int iParam4, String strParam1, String strParam2, String strParam3, String strParam4 ){ switch (type){
} return 0; } public static String GetJsonStr( int iMsgId, int iParam1, int iParam2, int iParam3, String strParam1, String strParam2, String strParam3){ try { JSONObject object = new JSONObject(); object.put("iMsgId",iMsgId); object.put("iParam1",iParam1); object.put("iParam2",iParam2); object.put("iParam3",iParam3); object.put("strParam1",strParam1); object.put("strParam2",strParam2); object.put("strParam3",strParam3); return object.toString(); } catch (Exception e){ Log.e(TAG,"Json error" + e.toString()); } return ""; } }
|