| | |
| | | import com.cy.yyjia.sdk.listener.InitListener; |
| | | import com.cy.yyjia.sdk.listener.LoginListener; |
| | | import com.cy.yyjia.sdk.listener.LogoutListener; |
| | | import com.cy.yyjia.sdk.listener.MarketListener; |
| | | import com.cy.yyjia.sdk.listener.PayListener; |
| | | import com.cy.yyjia.sdk.listener.ShareListener; |
| | | import com.secondworld.sdk.utils.CallBackState; |
| | | import com.secondworld.sdk.utils.CodeA2U; |
| | | import com.secondworld.sdk.utils.LogUtil; |
| | | |
| | | import org.json.JSONException; |
| | | import org.json.JSONObject; |
| | | |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | |
| | | public class MySdkMgr extends PlatformSdkMgr { |
| | | |
| | |
| | | case UNKNOWN: { |
| | | if (GTGameMain.I.activity != null) |
| | | init(GTGameMain.I.activity); |
| | | Toast.makeText(GameApp.I, "正在初始化中,请稍等", Toast.LENGTH_LONG).show(); |
| | | Toast.makeText(GameAppProxy.app, "正在初始化中,请稍等", Toast.LENGTH_LONG).show(); |
| | | break; |
| | | } |
| | | case SUCCEED: { |
| | |
| | | break; |
| | | } |
| | | case LOADING: { |
| | | Toast.makeText(GameApp.I, "正在初始化中,请稍等", Toast.LENGTH_LONG).show(); |
| | | Toast.makeText(GameAppProxy.app, "正在初始化中,请稍等", Toast.LENGTH_LONG).show(); |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | |
| | | public void setListener() { |
| | | args = new HashMap<>(); |
| | | // 初始化监听 |
| | | SdkManager.getInstance().setInitListener(new InitListener() { |
| | | @Override |
| | | public void onSuccess() { |
| | | sdkInitState = SdkInitState.SUCCEED; |
| | | LogUtil.debug("SdkManager", "成功"); |
| | | args.clear(); |
| | | args.put("code", CodeA2U.PlatformInitOk); |
| | | UnityMsgHandler.sendMessageToUnity(args); |
| | | LogUtil.debug("SdkManager", "初始化成功"); |
| | | UnityMsgHandler.sendMessageToUnity(CodeA2U.PlatformInitOk); |
| | | } |
| | | |
| | | @Override |
| | | public void onError(String msg) { |
| | | sdkInitState = SdkInitState.FAILED; |
| | | LogUtil.e("SdkManager", "失败:" + msg); |
| | | args.clear(); |
| | | args.put("code", CodeA2U.PlatformInitFail); |
| | | UnityMsgHandler.sendMessageToUnity(args); |
| | | LogUtil.e("SdkManager", "初始化失败:" + msg); |
| | | UnityMsgHandler.sendMessageToUnity(CodeA2U.PlatformInitFail); |
| | | } |
| | | }); |
| | | |
| | |
| | | SdkManager.getInstance().setLoginListener(new LoginListener() { |
| | | @Override |
| | | public void onSuccess() { |
| | | LogUtil.e("SdkManager", "登录成功"); |
| | | try { |
| | | args.clear(); |
| | | JSONObject info = new JSONObject(); |
| | | info.put("account", SdkManager.getInstance().getUid()); |
| | | info.put("game_id", SdkManager.getInstance().getGameId()+""); |
| | | info.put("session_id", SdkManager.getInstance().getSessionId()); |
| | | args.put("info", info); |
| | | UnityMsgHandler.sendMessageToUnity(CodeA2U.PlatformLoginOk, args); |
| | | } catch (JSONException e) { |
| | | e.printStackTrace(); |
| | | LogUtil.e("SdkManager 登录成功", e); |
| | | } |
| | | } |
| | | |
| | | //注册成功 |
| | | @Override |
| | | public void onSuccess(Boolean isNewReg, String reg_type) { |
| | | LogUtil.e("SdkManager", "注册成功" + " isNewReg:" + isNewReg + " type:" + reg_type); |
| | | args.clear(); |
| | | args.put("code", CodeA2U.PlatformLoginOk); |
| | | args.put("account", SdkManager.getInstance().getUid()); |
| | | args.put("game_id", SdkManager.getInstance().getGameId()); |
| | | args.put("session_id", SdkManager.getInstance().getSessionId()); |
| | | UnityMsgHandler.sendMessageToUnity(args); |
| | | args.put("reg_type", reg_type); |
| | | UnityMsgHandler.sendMessageToUnity(CodeA2U.PlatformRegisterOk, args); |
| | | } |
| | | |
| | | @Override |
| | | public void onError(String s) { |
| | | args.clear(); |
| | | args.put("code", CodeA2U.PlatformLoginFail); |
| | | UnityMsgHandler.sendMessageToUnity(args); |
| | | LogUtil.e("SdkManager", "登录失败:" + s); |
| | | UnityMsgHandler.sendMessageToUnity(CodeA2U.PlatformLoginFail); |
| | | } |
| | | |
| | | @Override |
| | | public void onCancel() { |
| | | args.clear(); |
| | | args.put("code", CodeA2U.PlatformLoginFail); |
| | | UnityMsgHandler.sendMessageToUnity(args); |
| | | UnityMsgHandler.sendMessageToUnity(CodeA2U.PlatformLoginFail); |
| | | } |
| | | }); |
| | | |
| | |
| | | @Override |
| | | public void onSuccess(String status, String orderId) { |
| | | LogUtil.debug("SdkManager", "onSuccess status:" + status + ",orderId:" + orderId); |
| | | UnityMsgHandler.sendMessageToUnity(CodeA2U.PlatformPayOk); |
| | | } |
| | | |
| | | @Override |
| | | public void onError() { |
| | | LogUtil.e("SdkManager", "onError"); |
| | | UnityMsgHandler.sendMessageToUnity(CodeA2U.PlatformPayFail); |
| | | } |
| | | |
| | | @Override |
| | | public void onCancel() { |
| | | LogUtil.debug("SdkManager", "onCancel"); |
| | | UnityMsgHandler.sendMessageToUnity(CodeA2U.PlatformPayCancel); |
| | | } |
| | | }); |
| | | |
| | |
| | | @Override |
| | | public void onSuccess() { |
| | | //注销成功,需要把游戏切换回登陆前的场景,并重新弹出登录框等操作 |
| | | args.clear(); |
| | | args.put("code", CodeA2U.PlatformLogoutOk); |
| | | UnityMsgHandler.sendMessageToUnity(args); |
| | | UnityMsgHandler.sendMessageToUnity(CodeA2U.PlatformLogoutOk); |
| | | } |
| | | |
| | | @Override |
| | |
| | | } |
| | | }); |
| | | |
| | | //分享回调 |
| | | SdkManager.getInstance().setShareListener(new ShareListener() { |
| | | @Override |
| | | public void onSuccess(String type) { |
| | | Map<String, Object> args = new HashMap<>(); |
| | | args.put("state", CallBackState.Success); |
| | | UnityMsgHandler.sendMessageToUnity(CodeA2U.ShareState, args); |
| | | LogUtil.debug("分享回调", "onSuccess:" + type); |
| | | } |
| | | |
| | | @Override |
| | | public void onError(String type, String msg) { |
| | | Map<String, Object> args = new HashMap<>(); |
| | | args.put("state", CallBackState.Error); |
| | | UnityMsgHandler.sendMessageToUnity(CodeA2U.ShareState, args); |
| | | LogUtil.debug("分享回调", "type:" + type + ";msg:" + msg); |
| | | } |
| | | |
| | | @Override |
| | | public void onCancel(String type) { |
| | | Map<String, Object> args = new HashMap<>(); |
| | | args.put("state", CallBackState.Cancel); |
| | | UnityMsgHandler.sendMessageToUnity(CodeA2U.ShareState, args); |
| | | LogUtil.debug("分享回调", type + ":onCancel"); |
| | | } |
| | | }); |
| | | |
| | | //评分回调 |
| | | SdkManager.getInstance().setMarketListener(new MarketListener() { |
| | | @Override |
| | | public void onSuccess() { |
| | | Map<String, Object> args = new HashMap<>(); |
| | | args.put("state", CallBackState.Success); |
| | | UnityMsgHandler.sendMessageToUnity(CodeA2U.ReviewState, args); |
| | | LogUtil.debug("评分回调", "成功"); |
| | | } |
| | | |
| | | @Override |
| | | public void onError(String s) { |
| | | Map<String, Object> args = new HashMap<>(); |
| | | args.put("state", CallBackState.Error); |
| | | UnityMsgHandler.sendMessageToUnity(CodeA2U.ReviewState, args); |
| | | LogUtil.debug("评分回调", "失败:" + s); |
| | | } |
| | | |
| | | @Override |
| | | public void onCancel() { |
| | | Map<String, Object> args = new HashMap<>(); |
| | | args.put("state", CallBackState.Cancel); |
| | | UnityMsgHandler.sendMessageToUnity(CodeA2U.ReviewState, args); |
| | | LogUtil.debug("评分回调", "取消"); |
| | | } |
| | | }); |
| | | |
| | | //设置dubug模式 |
| | | SdkManager.getInstance().setDebug(BuildConfig.DEBUG); |
| | | } |