gradlew.bat批处理生成apk

Android Studio工程的目录下都会有一个gradlew.bat,只要配置好app下的build.gradle,使用这个批处理可以快速编译生成apk,编写自动化生成工具等。
使用unity导出android工程编译apk为例,如果全部手动操作是个繁琐的过程,使用这个gradlew.bat可以免去许多麻烦操作。先配置好build.gradle,主要配置signingConfigs和buildTypes,如下例子:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "com.dfddf.dfddf.dfdfd"
        minSdkVersion 15
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    signingConfigs {
        debug {
            storeFile file('dsdsds.jks')
            storePassword "sdsds"
            keyAlias "sdsds"
            keyPassword "sdsds"
        }
        release {
            storeFile file('dsdsds.jks')
            storePassword "sdsds"
            keyAlias "sdsds"
            keyPassword "sdsds"
        }
    }
    buildTypes {
        release {
            minifyEnabled false
            zipAlignEnabled false
            shrinkResources false
            signingConfig signingConfigs.release
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    sourceSets {
        main {
            jniLibs.srcDirs = ['libs']
        }
    }

    lintOptions {
        abortOnError false
    }
}
repositories {
    flatDir {
        dirs 'libs'
    }
}
dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation files('libs/fastjson-1.1.52.android.jar')
    implementation files('libs/jpush-android-2.0.5.jar')
    implementation files('libs/SaaS_GameAnalytics_Android_SDK_V4.0.13.jar')
    implementation files('libs/unity-classes.jar')
    implementation files('libs/android-support-v7-recyclerview.jar')
    implementation(name:'NoxSDK-3.6',ext:'aar')
}

从unity导出android工程,还有各种文件的复制删除操作等可以直接C#实现:

using UnityEngine;
using System.Collections;
using UnityEditor;
using System.IO;
using System.Xml;
using System.Text;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System;

public class SmallTools
{
    [DllImport("user32.dll")]
    public static extern void SwitchToThisWindow(IntPtr hWnd, bool fAltTab);

    [MenuItem("Tools/SmallTools/BuildAndroidProject")]
    static void BuildAndroidProject()
    {
        try
        {
            string xmlVersion = @"E:\xukong_en\GameClient_AssetBundles";
            DirectoryInfo dInfo = Directory.CreateDirectory(xmlVersion);
            FileInfo[] fInfos = dInfo.GetFiles();
            for (int i = 0, j = fInfos.Length; i < j; i++)
            {
                if (fInfos[i].Name.StartsWith("GameResourceVersion"))
                {
                    xmlVersion += (@"\" + fInfos[i].Name);
                }
            }
            XmlDocument xml = new XmlDocument();
            xml.Load(xmlVersion);
            XmlNode xNode = xml.SelectSingleNode("ResourceVersionInfo");
            string bigVersion = xNode.Attributes.GetNamedItem("ApplicableGameVersion").Value;
            string smallVersion = xNode.Attributes.GetNamedItem("LatestInternalResourceVersion").Value;
            bigVersion = bigVersion.Replace(".", "_");
            string curVersion = bigVersion + "_" + smallVersion;
            string resoucesPath = string.Format(@"E:\xukong_en\GameClient_AssetBundles\Packed\{0}\android", curVersion);
            if (!Directory.Exists(resoucesPath))
            {
                Debug.LogError(string.Format("路径{0}不存在", resoucesPath));
                return;
            }
            EditorUtility.DisplayProgressBar("复制资源", "正在复制0%", 0);
            string androidPro = @"E:\xukong_en\GameClient_Android\Genesis";
            DirectoryOperate(androidPro,true,false);
            string sAssets = @"E:\xukong_en\Assets\StreamingAssets";
            DirectoryOperate(sAssets);
            dInfo = Directory.CreateDirectory(resoucesPath);
            fInfos = dInfo.GetFiles("*", SearchOption.AllDirectories);
            string copyToPath = @"E:\xukong_en\Assets\StreamingAssets\android";
            for (int i = 0, j = fInfos.Length; i < j; i++)
            {
                float process = (float)i / j;
                EditorUtility.DisplayProgressBar("复制资源", string.Format("正在复制{0}%", process * 100), process);
                string file = fInfos[i].FullName.Replace(resoucesPath, copyToPath);
                string fullPath = Path.GetDirectoryName(file);
                if (!Directory.Exists(fullPath))
                {
                    Directory.CreateDirectory(fullPath);
                }
                File.Copy(fInfos[i].FullName, file, true);
            }
            EditorUtility.ClearProgressBar();
            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();
            string err = BuildPipeline.BuildPlayer(new string[] { "Assets/Launch.unity" }, "E:/xukong_en/GameClient_Android", BuildTarget.Android, BuildOptions.AcceptExternalModificationsToPlayer);
            if (string.IsNullOrEmpty(err))
            {
                //---------------------拷贝到eclipse android工程
                EditorUtility.DisplayProgressBar("拷贝到AndroidStudio工程", "正在拷贝0%", 0);
                string eclipseProj = @"D:\androidStudio-workspace\xukong_dingliangame\app\src\main\assets";//@"D:\eclipse-workspace2\XuKong_DingLian\assets";
                DirectoryOperate(eclipseProj);
                string genesisPath = @"E:\xukong_en\GameClient_Android\Genesis\assets";
                dInfo = Directory.CreateDirectory(genesisPath);
                fInfos = dInfo.GetFiles("*", SearchOption.AllDirectories);
                for (int i = 0, j = fInfos.Length; i < j; i++)
                {
                    string file = fInfos[i].FullName.Replace(genesisPath, eclipseProj);
                    string fullPath = Path.GetDirectoryName(file);
                    if (!Directory.Exists(fullPath))
                    {
                        Directory.CreateDirectory(fullPath);
                    }
                    File.Copy(fInfos[i].FullName, file, true);
                    float proc = (float)i / j;
                    EditorUtility.DisplayProgressBar("拷贝到AndroidStudio工程", string.Format("正在拷贝{0}%", proc * 100), proc);
                }
                EditorUtility.ClearProgressBar();
                EditorUtility.DisplayDialog("导出android工程", "导出完成,点击OK开始生成apk", "OK");

                GradlewBatBuild();
                //string exeName = @"D:\adt-bundle-windows-x86_64-20140702\eclipse\eclipse.exe";
                //System.Diagnostics.Process[] processes = System.Diagnostics.Process.GetProcessesByName("eclipse");
                //if(processes.Length <= 0)
                //    System.Diagnostics.Process.Start(exeName);
                //else
                //{
                //    IntPtr handle = processes[0].MainWindowHandle;
                //    SwitchToThisWindow(handle, true); // 激活,显示在最前
                //}
            }
        }
        catch (System.Exception e)
        {
            Debug.LogError(e);
        }
    }

    static void DirectoryOperate(string path,bool delete = true,bool create = true)
    {
        try
        {
            if (delete && Directory.Exists(path))
                Directory.Delete(path, true);
            if (create)
                Directory.CreateDirectory(path);
        }
        catch(System.Exception e)
        {
            Debug.LogError(e);
        }
    }

    //[MenuItem("Tools/SmallTools/GradlewBatBuild")]
    static void GradlewBatBuild()
    {
        string path = @"D:\androidStudio-workspace\xukong_dingliangame\app\build\outputs\apk\release";
        DirectoryOperate(path);
        System.Diagnostics.Process proc = new System.Diagnostics.Process();
        proc.StartInfo.WorkingDirectory = @"D:\androidStudio-workspace\xukong_dingliangame\";
        proc.StartInfo.FileName = "gradlew.bat";
        proc.StartInfo.Arguments = "assembleRelease";
        proc.Start();
        proc.WaitForExit();
        proc.Close();
        proc.Dispose();
        proc = System.Diagnostics.Process.Start("explorer.exe", path);
        proc.WaitForExit();
        proc.Close();
        proc.Dispose();
    }

    [MenuItem("Tools/SmallTools/SetUiTexure")]
    static void SetUiTexure()
    {
        string path = @"Assets/Main/UI/UITextures";
        string path_cn = @"Assets\Main\Localization\ChineseSimplified\UI\UITextures";
        string path_tw = @"Assets\Main\Localization\ChineseTraditional\UI\UITextures";
        string path_en = @"Assets\Main\Localization\English\UI\UITextures";
        string[] allPaths = AssetDatabase.GetAllAssetPaths();
        EditorUtility.DisplayProgressBar("设置ui贴图", "正在设置0%", 0);
        for (int i = 0, j = allPaths.Length; i < j; i++)
        {
            float process = (float)i / j;
            EditorUtility.DisplayProgressBar("设置ui贴图", string.Format("正在设置{0}%", process * 100), process);
            if (!allPaths[i].Contains(path) &&
                !allPaths[i].Contains(path_cn) &&
                !allPaths[i].Contains(path_tw) &&
                !allPaths[i].Contains(path_en))
                continue;
            string ext = System.IO.Path.GetExtension(allPaths[i]);
            if (ext != ".png" && ext != ".jpg")
                continue;
            TextureImporter aImp = TextureImporter.GetAtPath(allPaths[i]) as TextureImporter;
            aImp.textureType = TextureImporterType.Advanced;
            aImp.grayscaleToAlpha = false;
            aImp.alphaIsTransparency = true;
            aImp.isReadable = false;
            aImp.mipmapEnabled = false;
            aImp.wrapMode = TextureWrapMode.Clamp;
            aImp.SaveAndReimport();
        }
        EditorUtility.ClearProgressBar();
        EditorUtility.DisplayDialog("设置ui贴图", "设置完成", "OK");
        AssetDatabase.SaveAssets();
        AssetDatabase.Refresh();
    }

    [MenuItem("Tools/SmallTools/CheckAssetGuid")]
    static void CheckAssetGuid()
    {
        XmlDocument xmlDocument = new XmlDocument();
        xmlDocument.Load(@"E:\xukong_en\Assets\GameFramework\Editor\AssetBundleCollection.xml");
        XmlNode xmlRoot = xmlDocument.SelectSingleNode("UnityGameFramework");
        xmlRoot = xmlRoot.SelectSingleNode("AssetBundleCollection");
        xmlRoot = xmlRoot.SelectSingleNode("Assets");
        XmlNodeList xmlNodeDictionaryList = xmlRoot.ChildNodes;
        EditorUtility.DisplayProgressBar("检查资源guid", "正在检查0%", 0);
        for (int i = 0, j = xmlNodeDictionaryList.Count; i < j; i++)
        {
            float process = (float)i / j;
            EditorUtility.DisplayProgressBar("检查资源guid", string.Format("正在检查{0}%", process * 100), process);
            XmlNode xmlNodeString = xmlNodeDictionaryList.Item(i);
            XmlNode bName = xmlNodeString.Attributes.GetNamedItem("AssetBundleName");
            string uid = xmlNodeString.Attributes.GetNamedItem("Guid").Value;
            string aPath = AssetDatabase.GUIDToAssetPath(uid);
            if(string.IsNullOrEmpty(aPath))
            {
                Debug.LogError(string.Format("===============>guid 失效guid={0}uid,AssetBundle {1}",uid, bName.Value));
            }
            else
            {
                Debug.LogError(aPath);
            }
        }
        EditorUtility.ClearProgressBar();
        EditorUtility.DisplayDialog("检查资源guid", "检查完成", "OK");
        AssetDatabase.SaveAssets();
        AssetDatabase.Refresh();
    }

    [MenuItem("Tools/SmallTools/UpdateAssetBundleCollection")]
    static void UpdateAssetBundleCollection()
    {
        string xmlDocumentPath = @"E:\xukong_en\Assets\GameFramework\Editor\AssetBundleCollection.xml";
        XmlDocument xmlDocument = new XmlDocument();
        xmlDocument.Load(xmlDocumentPath);
        XmlNode xmlRoot = xmlDocument.SelectSingleNode("UnityGameFramework");
        xmlRoot = xmlRoot.SelectSingleNode("AssetBundleCollection");
        xmlRoot = xmlRoot.SelectSingleNode("Assets");
        XmlNodeList xmlNodeDictionaryList = xmlRoot.ChildNodes;
        List<string> current = new List<string>();
        List<XmlNode> removeNode = new List<XmlNode>();
        string[] allAssets = AssetDatabase.GetAllAssetPaths();
        EditorUtility.DisplayProgressBar("分析AssetBundleCollection.xml", "正在分析0%", 0);
        for (int i = 0, j = xmlNodeDictionaryList.Count; i < j; i++)
        {
            float process = (float)i / j;
            EditorUtility.DisplayProgressBar("分析AssetBundleCollection.xml", string.Format("正在分析{0}%", process * 100), process);
            XmlNode xmlNodeString = xmlNodeDictionaryList.Item(i);
            string uid = xmlNodeString.Attributes.GetNamedItem("Guid").Value;
            string aPath = AssetDatabase.GUIDToAssetPath(uid);
            if (string.IsNullOrEmpty(uid) || !File.Exists(@"E:\xukong_en\" + aPath.Replace("/",@"\")))
            {
                removeNode.Add(xmlNodeString);
                continue;
            }
            current.Add(uid);
        }
        EditorUtility.DisplayProgressBar("删除无用资源", "正在删除0%", 0);
        for (int i = 0, j = removeNode.Count; i < j; i++)
        {
            float process = (float)i / j;
            EditorUtility.DisplayProgressBar("删除无用资源", string.Format("正在删除{0}%", process * 100), process);
            xmlRoot.RemoveChild(removeNode[i]);
        }
        EditorUtility.DisplayProgressBar("添加新增资源", "正在添加0%", 0);
        for (int i = 0,j = allAssets.Length;i<j;i++)
        {
            float process = (float)i / j;
            EditorUtility.DisplayProgressBar("添加新增资源", string.Format("正在添加{0}%", process * 100), process);
            string guid = AssetDatabase.AssetPathToGUID(allAssets[i]);
            if (current.Contains(guid))
                continue;
            XmlNode xNode = xmlRoot.ChildNodes.Item(0).Clone();
            xNode.Attributes.GetNamedItem("Guid").Value = guid;
            XmlAttribute xAttr = xNode.Attributes.GetNamedItem("AssetBundleName") as XmlAttribute;
            if(null != xAttr)
                xNode.Attributes.Remove(xAttr);
            xmlRoot.AppendChild(xNode);
        }
        xmlDocument.Save(xmlDocumentPath);
        EditorUtility.ClearProgressBar();
        EditorUtility.DisplayDialog("更新AssetBundleCollection.xml", "更新完成", "OK");
        AssetDatabase.SaveAssets();
        AssetDatabase.Refresh();
    }

    [MenuItem("Tools/SmallTools/SetAssetVariant")]
    static void SetAssetVariant()
    {
        XmlDocument xmlDocument = new XmlDocument();
        xmlDocument.Load(@"E:\xukong_en\Assets\GameFramework\Editor\AssetBundleCollection.xml");
        XmlNode xmlRoot = xmlDocument.SelectSingleNode("UnityGameFramework");
        xmlRoot = xmlRoot.SelectSingleNode("AssetBundleCollection");
        xmlRoot = xmlRoot.SelectSingleNode("Assets");
        XmlNodeList xmlNodeDictionaryList = xmlRoot.ChildNodes;
        EditorUtility.DisplayProgressBar("设置资源变体", "正在设置0%", 0);
        for (int i = 0, j = xmlNodeDictionaryList.Count; i < j; i++)
        {
            float process = (float)i / j;
            EditorUtility.DisplayProgressBar("设置资源变体", string.Format("正在设置{0}%", process * 100), process);
            XmlNode xmlNodeString = xmlNodeDictionaryList.Item(i);
            string uid = xmlNodeString.Attributes.GetNamedItem("Guid").Value;
            string aPath = AssetDatabase.GUIDToAssetPath(uid);
            AssetImporter aImp = AssetImporter.GetAtPath(aPath);
            if(null == aImp)
            {
                Debug.LogError("=============>>导入资源失败:" + aPath);
                continue;
            }
            XmlNode variant = xmlNodeString.Attributes.GetNamedItem("AssetBundleVariant");
            XmlNode bName = xmlNodeString.Attributes.GetNamedItem("AssetBundleName");
            try
            {
                if (null == variant)
                {
                    aImp.assetBundleName = bName.Value;
                    aImp.assetBundleVariant = null;
                }
                else
                {
                    aImp.assetBundleName = bName.Value;
                    aImp.assetBundleVariant = variant.Value;
                }
                aImp.SaveAndReimport();
            }
            catch(System.Exception e)
            {
                Debug.LogError("path:" + aPath);
                Debug.LogError(e);
            }
        }
        EditorUtility.ClearProgressBar();
        EditorUtility.DisplayDialog("设置资源变体", "设置完成", "OK");
        AssetDatabase.SaveAssets();
        AssetDatabase.Refresh();
    }

    //[MenuItem("Tools/SmallTools/TestSerializedObject")]
    //static void TestSerializedObject()
    //{
    //    Object obj = Selection.activeObject;
    //    if (null == obj) return;
    //    string path = AssetDatabase.GetAssetPath(obj);
    //    if (System.IO.Path.GetExtension(path) != ".prefab")
    //        return;
    //    GameObject go = obj as GameObject;
    //    UILabel[] labels = go.GetComponentsInChildren<UILabel>(true);
    //    for(int i = 0,j =labels.Length;i < j;i++)
    //    {
    //        SerializedObject sObj = new SerializedObject(labels[i]);
    //        SerializedProperty sp = sObj.FindProperty("mFontSize");
    //        sObj.Update();
    //        sp.intValue -= 2;
    //        Debug.LogError(sp.intValue);
    //        Debug.LogError(sObj.ApplyModifiedProperties());
    //    }
    //    AssetDatabase.SaveAssets();
    //    AssetDatabase.Refresh();
    //    //Object prefabObj = PrefabUtility.GetPrefabObject(obj);
    //    //SerializedObject sObj = new SerializedObject(prefabObj);
    //    //sObj.
    //}

    [MenuItem("Tools/SmallTools/ChangeAtlases")]
    static void ChangeAtlases()
    {
        UnityEngine.Object atlObj = AssetDatabase.LoadAssetAtPath("Assets/Main/Localization/English/UI/Atlases/Graphic.prefab", typeof(UnityEngine.Object));
        if (null == atlObj)
        {
            Debug.LogError("无法加载图集资源");
            return;
        }
        string path = @"Assets/Main/Prefabs/UI";
        string[] allPaths = AssetDatabase.GetAllAssetPaths();
        EditorUtility.DisplayProgressBar("设置图集", "正在设置0%", 0);
        for (int i = 0, j = allPaths.Length; i < j; i++)
        {
            float process = (float)i / j;
            EditorUtility.DisplayProgressBar("设置图集", string.Format("正在设置{0}%", process * 100), process);
            if (!allPaths[i].Contains(path))
                continue;
            if (System.IO.Path.GetExtension(allPaths[i]) != ".prefab")
                continue;
            GameObject go = AssetDatabase.LoadAssetAtPath(allPaths[i], typeof(UnityEngine.Object)) as GameObject;
            if (null == go)
                continue;
            UISprite[] sprites = go.GetComponentsInChildren<UISprite>(true);
            for (int a = 0, b = sprites.Length; a < b; a++)
            {
                if (null == sprites[a].atlas || 
                    string.IsNullOrEmpty(sprites[a].atlas.name) ||
                    "Graphic" != sprites[a].atlas.name)
                    continue;
                SerializedObject sObj = new SerializedObject(sprites[a]);
                SerializedProperty sp = sObj.FindProperty("mAtlas");
                if (null == sp)
                    continue;
                sObj.Update();
                sp.objectReferenceValue = atlObj;
                Debug.LogError(sObj.ApplyModifiedProperties());
            }
        }
        EditorUtility.ClearProgressBar();
        EditorUtility.DisplayDialog("设置图集", "设置完成", "OK");
        AssetDatabase.SaveAssets();
        AssetDatabase.Refresh();
    }

    [MenuItem("Tools/SmallTools/ChangeFontSize")]
    static void ChangeFontSize()
    {
        UnityEngine.Object fontObj = AssetDatabase.LoadAssetAtPath("Assets/Main/Localization/English/Fonts/MainFont.ttf", typeof(UnityEngine.Object));
        if (null == fontObj)
        {
            Debug.LogError("无法加载字体资源");
            return;
        }
        string path = @"Assets/Main/Prefabs/UI";
        string[] allPaths = AssetDatabase.GetAllAssetPaths();
        EditorUtility.DisplayProgressBar("设置ui字体大小","正在设置0%",0);
        for(int i = 0,j = allPaths.Length;i<j;i++)
        {
            float process = (float)i / j;
            EditorUtility.DisplayProgressBar("设置ui字体大小", string.Format("正在设置{0}%", process * 100), process);
            if (!allPaths[i].Contains(path))
                continue;
            if (System.IO.Path.GetExtension(allPaths[i]) != ".prefab")
                continue;
            GameObject go = AssetDatabase.LoadAssetAtPath(allPaths[i],typeof(UnityEngine.Object)) as GameObject;
            if (null == go)
                continue;
            UILabel[] labels = go.GetComponentsInChildren<UILabel>(true);
            for(int a = 0,b = labels.Length;a < b;a++)
            {
                SerializedObject sObj = new SerializedObject(labels[a]);
                SerializedProperty sp = sObj.FindProperty("mTrueTypeFont");
                //SerializedProperty sp = sObj.FindProperty("mOverflow");
                if (null == sp)
                    continue;
                sObj.Update();
                //SerializedProperty sp = sObj.FindProperty("mFontSize");
                //sp.intValue -= 2;
                //sp.intValue = (int)UILabel.Overflow.ResizeHeight;
                sp.objectReferenceValue = fontObj;
                sp = sObj.FindProperty("mFont");
                sp.objectReferenceValue = null;

                Debug.LogError(sObj.ApplyModifiedProperties());
                //Debug.LogError(go.name + " // " + labels[a].name + " // " + sObj.ApplyModifiedProperties());
            }
        }
        EditorUtility.ClearProgressBar();
        EditorUtility.DisplayDialog("设置ui字体大小", "设置完成","OK");
        AssetDatabase.SaveAssets();
        AssetDatabase.Refresh();
    }

    [MenuItem("Tools/SmallTools/DoDefaultDictionary2xml")]
    static void DoDefaultDictionary2xml()
    {
        
        Dictionary<string, string> dic = new Dictionary<string, string>();
        using (FileStream fs = File.Open(@"E:\gameclient\Assets\Main\Publisher\DefaultDictionary.txt", FileMode.Open))
        {
            StreamReader sr = new StreamReader(fs, Encoding.Unicode);
            string lineText = null;
            while (!string.IsNullOrEmpty(lineText = sr.ReadLine()))
            {
                if (lineText.StartsWith("#"))
                    continue;
                string[] texts = lineText.Split('\t');
                if(texts.Length == 4)
                {
                    dic.Add(texts[1], texts[3]);
                }
                else
                {
                    Debug.LogError("Error: " + lineText);
                }
            }
            XmlDocument xmlDocument = new XmlDocument();
            xmlDocument.Load(@"E:\gameclient\Assets\Main\Publisher\DefaultDictionary.xml");
            XmlNode xmlRoot = xmlDocument.SelectSingleNode("Dictionaries");
            XmlNodeList xmlNodeDictionaryList = xmlRoot.ChildNodes;
            EditorUtility.DisplayProgressBar("转表", "已完成0%", 0);
            for (int i = 0,j = xmlNodeDictionaryList.Count; i < j; i++)
            {
                EditorUtility.DisplayProgressBar("转表", "已完成0%", (float)i/j);
                if (xmlNodeDictionaryList[i].Attributes.GetNamedItem("Language").Value != "English")
                    continue;
                XmlNodeList keyValues = xmlNodeDictionaryList[i].ChildNodes;
                string key = null;
               for(int a = 0,b = keyValues.Count;a < b;a++)
                {
                    key = keyValues[a].Attributes.GetNamedItem("Key").Value;
                    if(!dic.ContainsKey(key))
                    {
                        Debug.LogError("Error: dic have no key " + key);
                        continue;
                    }
                    keyValues[a].Attributes.GetNamedItem("Value").Value = dic[key];
                }
            }
            EditorUtility.ClearProgressBar();
            EditorUtility.DisplayDialog("转表","转表完成","好的~退下");
            xmlDocument.Save(@"E:\gameclient\Assets\Main\Publisher\DefaultDictionary.xml");
            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();
        }
    }

    [MenuItem("Tools/SmallTools/DefaultDictionary2txt")]
    static void DoDefaultDictionary2txt()
    {
        UnityEngine.Object obj = Selection.activeObject;
        string objPath = null;
        if(null != obj)
        {
            objPath = AssetDatabase.GetAssetPath(obj);
        }
        if(null != objPath && Path.GetExtension(objPath) == ".xml")
        {
            TextAsset ta = AssetDatabase.LoadAssetAtPath(objPath,typeof(TextAsset)) as TextAsset;
            if(null == ta)
            {
                return;
            }
            XmlDocument xmlDocument = new XmlDocument();
            xmlDocument.LoadXml(ta.text);
            XmlNode xmlRoot = xmlDocument.SelectSingleNode("Dictionaries");
            XmlNodeList xmlNodeDictionaryList = xmlRoot.ChildNodes;
            using (FileStream fs = File.Create(Application.dataPath + objPath.Replace("Assets", "").Replace("xml", "txt")))
            {
                using (System.IO.StreamWriter sw = new StreamWriter(fs))
                {
                    sw.WriteLine("#\t字典配置表");
                    sw.WriteLine("#\tKey\t\tValue");
                    sw.WriteLine("#\tstring\t\tstring");
                    sw.WriteLine("#\t字典主键\t策划备注\t字典内容,可使用转义符");
                    for (int i = 0; i < xmlNodeDictionaryList.Count; i++)
                    {
                        XmlNode xmlNode = xmlNodeDictionaryList.Item(i);
                        if (xmlNode.Name != "Dictionary")
                        {
                            continue;
                        }
                        XmlNodeList xmlNodeStringList = xmlNode.ChildNodes;
                        for (int j = 0; j < xmlNodeStringList.Count; j++)
                        {
                            XmlNode xmlNodeString = xmlNodeStringList.Item(j);
                            if (xmlNodeString.Name != "String")
                            {
                                continue;
                            }
                            string key = xmlNodeString.Attributes.GetNamedItem("Key").Value;
                            string value = xmlNodeString.Attributes.GetNamedItem("Value").Value;
                            //sw.WriteLine("    " + key + "     " + value);
                            sw.WriteLine("\t" + key + "\t\t" + value);
                        }
                    }
                }
            }

        }
    }

    //[MenuItem("Tools/SmallTools/PrintAssetsGuid")]
    //static void PrintAssetsGuid()
    //{
    //    UnityEngine.Object obj = Selection.activeObject;
    //    if (null == obj)
    //        return;
    //    string path = AssetDatabase.GetAssetPath(obj);
    //    string guid = AssetDatabase.AssetPathToGUID(path);
    //    Debug.LogError(string.Format("path: {0} guid: {1}",path,guid));
    //}
}

unity打包资源包后,只需选择菜单BuildAndroidProject即可一键生成apk。

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 204,732评论 6 478
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 87,496评论 2 381
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 151,264评论 0 338
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,807评论 1 277
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,806评论 5 368
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,675评论 1 281
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 38,029评论 3 399
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,683评论 0 258
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 41,704评论 1 299
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,666评论 2 321
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,773评论 1 332
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,413评论 4 321
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 39,016评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,978评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,204评论 1 260
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 45,083评论 2 350
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,503评论 2 343

推荐阅读更多精彩内容