liuxue
2021-07-29 7e2df20ccc7cdfb528d309369460a4f3d66afdf1
SdkProject/library/src/main/java/com/secondworld/sdk/UnityMsgHandler.java
@@ -58,7 +58,7 @@
            int code = _json.getInt("code");
            ICommand command = allCommand.get(code);
            if (command == null)
                LogUtil.w("onUnityMessage", "未知命令" + code);
                LogUtil.e("onUnityMessage", "未知命令" + code);
            else
                command.process(_json);
        } catch (Exception e) {
@@ -74,7 +74,7 @@
     */
    public static List<String> getClassName(String packageName) throws IOException {
        List<String> classNameList = new ArrayList<String>();
        DexFile df = new DexFile(GameApp.I.getPackageCodePath());//通过DexFile查找当前的APK中可执行文件
        DexFile df = new DexFile(GameAppProxy.app.getPackageCodePath());//通过DexFile查找当前的APK中可执行文件
        Enumeration<String> enumeration = df.entries();//获取df中的元素  这里包含了所有可执行的类名 该类名包含了包名+类名的方式
        while (enumeration.hasMoreElements()) {//遍历
            String className = (String) enumeration.nextElement();
@@ -85,14 +85,27 @@
        return classNameList;
    }
    public static void sendMessageToUnity(Map<String, Object> jsonMap) {
        if (jsonMap == null || jsonMap.isEmpty()) {
    public static void sendMessageToUnity(int code) {
        UnityMsgHandler.sendMessageToUnity(code,null);
    }
    /**
     * 发送消息到unity
     *
     * @param args
     */
    public static void sendMessageToUnity(int code, Map<String, Object> args) {
        if (args == null)
            args = new HashMap<>();
        args.put("code", code);
        JSONObject jsonObject = new JSONObject(args);
        if (GameAppProxy.isDemo()) {
            LogUtil.debug("发送消息到unity", jsonObject.toString());
            return;
        }
        JSONObject _jsonObject = new JSONObject(jsonMap);
        UnityPlayer.UnitySendMessage(StaticDefine.UnityGameObjectName,
                StaticDefine.UnityHandleFuncName,
                _jsonObject.toString());
                jsonObject.toString());
    }
}