package com.secondworld.demo; import android.app.Activity; import android.os.Bundle; import android.widget.RelativeLayout; import androidx.annotation.NonNull; import com.secondworld.sdk.GTGameMain; import com.secondworld.sdk.GameActivityProxy; import com.secondworld.sdk.GameAppProxy; import com.secondworld.sdk.UnityMsgHandler; import com.secondworld.sdk.utils.CodeU2A; import com.secondworld.sdk.utils.LogUtil; import com.secondworld.sdk.utils.WebViewUtil; import org.json.JSONException; import org.json.JSONObject; public class MainActivity extends Activity { private static Class proxyClass= GTGameMain.class; GameActivityProxy proxy; //注册代理类 public static void registerProxy(Class proxyClass) { MainActivity.proxyClass = proxyClass; } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); GameAppProxy.isDemo=true; setContentView(R.layout.activity_main); RelativeLayout webContainer = findViewById(com.secondworld.sdk.R.id.webContainer); WebViewUtil.I.init(this, webContainer); try { if (proxyClass != null) { proxy = proxyClass.newInstance(); proxy.onCreate(this); } else LogUtil.w("GameActivity", "proxyClass 不存在"); } catch (IllegalAccessException | InstantiationException e) { e.printStackTrace(); LogUtil.e("GameActivity", e); } //addEvent(); } private void addEvent() { findViewById(R.id.login).setOnClickListener((v -> { JSONObject json = new JSONObject(); try { json.put("code", CodeU2A.PlatformLogin); } catch (JSONException e) { e.printStackTrace(); } UnityMsgHandler.onUnityMessage(json.toString()); })); findViewById(R.id.pay).setOnClickListener((v -> { JSONObject json = new JSONObject(); try { json.put("sid","10"); json.put("serverName","bt2server"); json.put("roleName","hahaha"); json.put("roleID","123"); json.put("money","110"); json.put("vipLevel","5"); json.put("level","10"); json.put("familyName","hengha"); json.put("createTime",""); json.put("code", CodeU2A.PlatformPay); json.put("cpInfo", "com.sanxiagame.zmjgp099"); json.put("orderId", System.currentTimeMillis() / 1000 + ""); json.put("sid", "1"); json.put("roleID", "test_role"); json.put("title", "goods_100"); json.put("mount", "0.009999999776482582"); } catch (JSONException e) { e.printStackTrace(); } UnityMsgHandler.onUnityMessage(json.toString()); })); findViewById(R.id.btnA).setOnClickListener(v -> { JSONObject json = new JSONObject(); try { json.put("code", CodeU2A.RequestPermission); json.put("permission", "android.permission.RECORD_AUDIO"); } catch (JSONException e) { e.printStackTrace(); } UnityMsgHandler.onUnityMessage(json.toString()); }); findViewById(R.id.btnB).setOnClickListener(v -> { JSONObject json = new JSONObject(); try { json.put("sid","bt2"); json.put("serverName","bt2server"); json.put("roleName","hahaha"); json.put("roleID","123"); json.put("money","110"); json.put("vipLevel","5"); json.put("level","10"); json.put("familyName","hengha"); json.put("createTime",""); json.put("code", CodeU2A.CreateRole); } catch (JSONException e) { e.printStackTrace(); } UnityMsgHandler.onUnityMessage(json.toString()); }); } private void unityMessage(int code) { JSONObject json = new JSONObject(); try { json.put("code", code); } catch (JSONException e) { e.printStackTrace(); } UnityMsgHandler.onUnityMessage(json.toString()); } @Override protected void onStart() { super.onStart(); if (proxy != null) proxy.onStart(); } @Override protected void onResume() { super.onResume(); if (proxy != null) proxy.onResume(); } @Override protected void onPause() { super.onPause(); if (proxy != null) proxy.onPause(); } @Override protected void onStop() { super.onStop(); if (proxy != null) proxy.onStop(); } @Override protected void onDestroy() { super.onDestroy(); if (proxy != null) proxy.onDestroy(); } @Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { super.onRequestPermissionsResult(requestCode, permissions, grantResults); if (proxy != null) proxy.onRequestPermissionsResult(requestCode, permissions, grantResults); } }