Unity 自动导出 AndroidStudio 项目

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/wdsdsdsds/article/details/50607889

思路很简单,unity可以导出为 eclipse 项目,可以在外面创建一个空的 AndroidStudio 项目,然后将导出的 eclipse 项目的文件放到对应的 AndroidStudio 项目中。
代码

    [MenuItem("Export/AndroidStudio")]
    public static void ExportGoogleProject ()
    {
        //项目路径
        string project_path = Config.PROJECT_GOOGLE + "/" + PlayerSettings.productName;

        bool exist = Directory.Exists (project_path);
        if (!exist) {
            //先将模版文件,拷贝过劳
            EditorUtils.copyFolder (Config.PROJECT_STUDIO_TEMPLATE_PROJECT, project_path);
        }

        //编译出 eclipse 项目
        BuildPipeline.BuildPlayer (EditorUtils.GetBuildScenes ().ToArray (), Config.PROJECT_GOOGLE_EXPORT, BuildTarget.Android, BuildOptions.AcceptExternalModificationsToPlayer);

        //将导出的 eclipse 项目的文件放到对应的 AndroidStudio 项目中
        EditorUtils.copyFolder (Config.PROJECT_GOOGLE_EXPORT + "/" + PlayerSettings.productName + "/assets", project_path + "/app/src/main/assets");
        EditorUtils.copyFolder (Config.PROJECT_GOOGLE_EXPORT + "/" + PlayerSettings.productName + "/res", project_path + "/app/src/main/res");
        EditorUtils.copyFolder (Config.PROJECT_GOOGLE_EXPORT + "/" + PlayerSettings.productName + "/src", project_path + "/app/src/main/java");

        EditorUtils.copyFolder (Config.PROJECT_GOOGLE_EXPORT + "/" + PlayerSettings.productName + "/libs", project_path + "/app/libs");

        //拷贝 Manifest 文件
        bool existManifest = Directory.Exists (project_path + "/app/src/main/AndroidManifest.xml");
        if (existManifest) {
            AndroidManifestModify.mergeManifestFile (project_path + "/app/src/main", Config.PROJECT_GOOGLE_EXPORT + "/" + PlayerSettings.productName);
        } else {
            EditorUtils.copyFile (Config.PROJECT_GOOGLE_EXPORT + "/" + PlayerSettings.productName + "/AndroidManifest.xml", project_path + "/app/src/main/AndroidManifest.xml");
        }

        //删除 eclipse 项目文件
        EditorUtils.DeleteDir (Config.PROJECT_GOOGLE_EXPORT);
    }

路径配置文件

    dpublic class Config 
    {
        public static string DATA_PATH = Application.dataPath + "/../";
        public static string PROJECT_IOS = DATA_PATH + "Project/iOS";
        public static string PROJECT_ANDROID = DATA_PATH + "Project/Android";
        public static string PROJECT_GOOGLE = DATA_PATH + "Project/Google";
        public static string PROJECT_GOOGLE_EXPORT = DATA_PATH + "Project/export";
        public static string PROJECT_STUDIO_TEMPLATE_PROJECT = DATA_PATH + "TemplateProject";
    }

Demo : http://pan.baidu.com/s/1i3YWhPr

没有更多推荐了,返回首页