示例#1
0
    public static void MenuCopyExport2StreamingAssets()
    {
        /// 删除资源
        if (System.IO.Directory.Exists(TO_PATH))
        {
            System.IO.Directory.Delete(TO_PATH, true);
        }
        if (System.IO.File.Exists(TO_PATH + "../assetsbundle.meta"))
        {
            System.IO.File.Delete(TO_PATH + "../assetsbundle.meta");
        }

        /// 搜索资源
        List <string> paths = new List <string>();

        EditorSearchFile.SearchPath(FROM_PATH, paths, ".ab");
        for (int index = 0; index < paths.Count; index++)
        {
            string path = EditorSearchFile.FilePath(paths[index]);
            path = TO_PATH + path.Substring(path.LastIndexOf("/assetsbundle/") + "/assetsbundle/".Length);
            string name = EditorSearchFile.FileName(paths[index]);
            if (!System.IO.Directory.Exists(path))
            {
                System.IO.Directory.CreateDirectory(path);
            }
            System.IO.File.Copy(paths[index], path + "/" + name + paths[index].Substring(paths[index].LastIndexOf(".")));
        }
        /// AB 资源赋值
        if (System.IO.File.Exists(FROM_PATH + "assetsbundle"))
        {
            System.IO.File.Copy(FROM_PATH + "assetsbundle", TO_PATH + "assetsbundle");
        }

        UnityEditor.AssetDatabase.Refresh();
        UnityEditor.AssetDatabase.SaveAssets();
        /// 刷新
    }
示例#2
0
    // Start is called before the first frame update
    public static void MenuExportConfig()
    {
        List <string> paths = new List <string>();

        List <AssetBundleBuild> build_list = new List <AssetBundleBuild>();

        /// 获得所有配置文件
        EditorSearchFile.SearchPath(CONFIG_PATH, paths, null);


        /// 生成配置文件文本
        for (int index = paths.Count - 1; index >= 0; index--)
        {
            string path        = paths[index].Replace("\\", "/").Replace("//", "/");
            string path_assets = path.Replace("/../Config/", "/_TEMP_CONFIG/");
            if (path_assets.LastIndexOf(".") == -1)
            {
                Debug.LogError(string.Format("Export Config Error > {0}", path));
                continue;
            }
            if (path_assets.LastIndexOf("/.") != -1)
            {
                Debug.LogWarning(string.Format("Export Config Error > {0}", path));
                continue;
            }
            /// 创建目录
            if (!System.IO.Directory.Exists(EditorSearchFile.FilePath(path_assets)))
            {
                System.IO.Directory.CreateDirectory(EditorSearchFile.FilePath(path_assets));
            }

            path_assets  = path_assets.Substring(0, path_assets.LastIndexOf("."));
            path_assets  = path_assets.Substring(path_assets.LastIndexOf("/Assets/") + 1);
            path_assets += ".asset";
            byte[] data = StringSerialize.ByteEncrypt(System.IO.File.ReadAllBytes(path));
            /// 如果相同
            /// 这个文件就不在导出处理
            /// 这样可以节省下来一些时间
            if (System.IO.File.Exists(Application.dataPath + "/../" + path_assets))
            {
                try
                {
                    if (EditorSearchFile.EqualsBytes(data, AssetDatabase.LoadAssetAtPath <StringSerialize>(path_assets).bytes))
                    {
                        Debug.Log(string.Format("Export Config : {0} -> Continue", path));
                        continue;
                    }
                }
                catch { Debug.LogWarning(string.Format("Export Config (隐藏目录): {0} -> Continue", path)); continue; }
            }
            /// 设置 assetsbundle 打包
            AssetBundleBuild buildTemp = new AssetBundleBuild();
            buildTemp.assetNames         = new string[] { path_assets };
            buildTemp.assetBundleVariant = "ab";
            buildTemp.assetBundleName    = path_assets.Replace("Assets/_TEMP_CONFIG/", "").ToLower().Replace(".asset", "");
            build_list.Add(buildTemp);
            Debug.Log(string.Format("Export Config : {0} -> New", path));
            /// 序列化文件
            StringSerialize data_serialize = ScriptableObject.CreateInstance <StringSerialize>();
            data_serialize.bytes     = data;
            data_serialize.isEncrypt = true;
            AssetDatabase.CreateAsset(data_serialize, path_assets);
            AssetDatabase.ImportAsset(path_assets);
            AssetDatabase.AssetPathToGUID(path_assets);
            AssetDatabase.SaveAssets();
        }
        /// 导出 Config 资源
        if (build_list.Count > 0)
        {
            if (!System.IO.Directory.Exists(EXPORT_PATH))
            {
                System.IO.Directory.CreateDirectory(EXPORT_PATH);
            }
#if UNITY_ANDROID
            BuildPipeline.BuildAssetBundles("Export/assetsbundle/config", build_list.ToArray(), BuildAssetBundleOptions.ChunkBasedCompression, BuildTarget.Android);
#endif
#if UNITY_IOS
            BuildPipeline.BuildAssetBundles("Export/assetsbundle/config", build_list.ToArray(), BuildAssetBundleOptions.ChunkBasedCompression, BuildTarget.iOS);
#endif
            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();
        }
    }
示例#3
0
    static void MenuInfoExportClass()
    {
        List <string> unexport   = new List <string>();
        string        pathCsv    = Application.dataPath + "/../Config/Info";
        string        exportFile = Application.dataPath + "/Ling-Script/Util/Info/UtilInfoReaderType.cs";
        List <string> files      = new List <string>();

        EditorSearchFile.SearchPath(pathCsv, files, ".info");
        string text_class = "" +
                            "using UnityEngine;\n" +
                            "using System.Collections;\n" +
                            "using System.Collections.Generic;\n" +
                            "namespace Info\n{\n" +
                            "\tpublic class InfoInfo\n" +
                            "\t{\n" +
                            "\t\tpublic static readonly string[] CLASS_NAME = { {REPACE-0} };\n" +
                            "\t\tpublic static readonly System.Type[] CLASS_TYPE = { {REPACE-1} };\n" +
                            "\t}\n";
        string text_class_name = "";
        string text_class_type = "";

        /// 遍历csv文件
        for (int index = 0; index < files.Count; index++)
        {
            string fileName = EditorSearchFile.FileName(files[index]);

            if (unexport.IndexOf(fileName) != -1)
            {
                continue;
            }

            text_class_name += (string.IsNullOrEmpty(text_class_name) ? "\"" : ", \"") + fileName + "\"";
            text_class_type += (string.IsNullOrEmpty(text_class_type) ? "typeof(Info." : ", typeof(Info.") + fileName + ")";

            /// 检测类中变量是否存在
            string[] lines = System.IO.File.ReadAllLines(files[index]);
            text_class += "\tpublic class " + fileName + " : System.Object\n";
            text_class += "\t{\n";
            for (int i = 0; i < lines.Length; i++)
            {
                if (string.IsNullOrEmpty(lines[i]))
                {
                    continue;
                }
                string[] splits = lines[i].Split('=');
                /// 数据 不够 注释补充
                if (splits.Length <= 1)
                {
                    text_class += "\t\t/// " + lines[i] + "\n";
                    continue;
                }
                splits[0] = splits[0].Trim();
                splits[1] = splits[1].Trim();
                /// 属性
                if (splits[0].IndexOf(" ") == -1)
                {
                    text_class += "\t\tpublic string " + splits[0] + ";\n";
                }
                else
                {
                    text_class += "\t\tpublic " + splits[0] + ";\n";
                }
            }
            text_class += "\t}\n";
        }
        text_class += "}\n";

        text_class = text_class.Replace("{REPACE-0}", text_class_name);
        text_class = text_class.Replace("{REPACE-1}", text_class_type);
        System.IO.File.WriteAllText(exportFile, text_class, new System.Text.UTF8Encoding(false));
    }
示例#4
0
    /// <summary>
    /// 设置图片 样式
    /// </summary>
    /// <param name="iOSFroamt"></param>
    /// <param name="AndroidFroamt"></param>
    static void SettingTexture(TextureImporterFormat iOSFroamt, TextureImporterFormat?AndroidFroamt = null)
    {
        if (null == AndroidFroamt)
        {
            AndroidFroamt = iOSFroamt;
        }
        List <string> fileList = new List <string>();

        /// 遍历 目录 操作
        if (null != Selection.objects)
        {
            for (int index = 0; index < Selection.objects.Length; index++)
            {
                if (null != Selection.objects[index])
                {
                    string path = string.Format("{0}/../{1}", Application.dataPath, AssetDatabase.GetAssetPath(Selection.objects[index]));
                    if (System.IO.Directory.Exists(path))
                    {
                        EditorSearchFile.SearchPath(path, fileList, "");
                    }
                    else
                    {
                        fileList.Add(path);
                    }
                }
            }
        }
        for (int index = 0; index < fileList.Count; index++)
        {
            string path = fileList[index];
            while (path.LastIndexOf("Assets/", System.StringComparison.Ordinal) != 0 && path.LastIndexOf("Assets/", System.StringComparison.Ordinal) != -1)
            {
                path = path.Substring(path.LastIndexOf("Assets/", System.StringComparison.Ordinal));
            }
            UnityEditor.TextureImporter importer = UnityEditor.TextureImporter.GetAtPath(path) as UnityEditor.TextureImporter;
            if (null == importer)
            {
                continue;
            }
            importer.mipmapEnabled = false;
            /// 读取
            TextureImporterPlatformSettings iOS     = importer.GetPlatformTextureSettings("iPhone");
            TextureImporterPlatformSettings Android = importer.GetPlatformTextureSettings("Android");
            /// 重写 设成 true
            Android.overridden           = iOS.overridden = true;
            importer.textureType         = TextureImporterType.Sprite;
            importer.alphaSource         = TextureImporterAlphaSource.FromInput;
            importer.alphaIsTransparency = true;
            importer.npotScale           = TextureImporterNPOTScale.None;
            /// 类型设置
            Android.format = (TextureImporterFormat)AndroidFroamt;
            iOS.format     = iOSFroamt;
            /// 赋值
            importer.SetPlatformTextureSettings(iOS);
            importer.SetPlatformTextureSettings(Android);
            /// LOG
            Debug.Log(string.Format("Setting Texture : [ Android = {1}, iOS = {2} ]{0}", path, AndroidFroamt, iOSFroamt));
            /// 保存
            importer.SaveAndReimport();
        }
    }
示例#5
0
    static void MenuRemoveAB()
    {
        AssetDatabase.RemoveUnusedAssetBundleNames();
        List <string> fileList   = new List <string>();
        List <string> fileRemove = new List <string>();

        /// 遍历 目录 操作
        if (null != Selection.objects)
        {
            for (int index = 0; index < Selection.objects.Length; index++)
            {
                if (null != Selection.objects[index])
                {
                    string path = string.Format("{0}/../{1}", Application.dataPath, AssetDatabase.GetAssetPath(Selection.objects[index]));
                    if (System.IO.Directory.Exists(path))
                    {
                        EditorSearchFile.SearchPath(path, fileList, "");
                    }
                    else
                    {
                        fileList.Add(path);
                    }
                }
            }
        }
        /// 资源剔除处理
        RemoveSameAndUnExportAssets(fileList, fileRemove);
        /// 打印 LOG
        for (int index = 0; index < fileList.Count; index++)
        {
            UnityEditor.AssetImporter importer = UnityEditor.AssetImporter.GetAtPath("Assets" + fileList[index].Substring(fileList[index].IndexOf("/Resources-/")));
            if (null == importer)
            {
                continue;
            }

            /// 为空返回
            if (string.IsNullOrEmpty(importer.assetBundleName) && string.IsNullOrEmpty(importer.assetBundleVariant))
            {
                continue;
            }
            /// 设置
            Debug.Log(string.Format("Remove AssetBundle : {0}.{1}", importer.assetBundleName, importer.assetBundleVariant));
            importer.SetAssetBundleNameAndVariant("", "");
            importer.SaveAndReimport();
        }

        for (int index = 0; index < fileRemove.Count; index++)
        {
            UnityEditor.AssetImporter importer = UnityEditor.AssetImporter.GetAtPath("Assets" + fileRemove[index].Substring(fileRemove[index].IndexOf("/Resources-/")));
            if (null == importer)
            {
                continue;
            }
            /// 没设置 返回
            if (string.IsNullOrEmpty(importer.assetBundleName) && string.IsNullOrEmpty(importer.assetBundleVariant))
            {
                continue;
            }
            /// 的是依赖 返回
            if (importer.assetBundleName.StartsWith("d/"))
            {
                continue;
            }
            /// 设置

            Debug.LogError(string.Format("Remove AssetBundle : {0}.{1}", importer.assetBundleName, importer.assetBundleVariant));
            importer.SetAssetBundleNameAndVariant("", "");
            importer.SaveAndReimport();
        }
    }
示例#6
0
    static void MenuCsvExportClass()
    {
        List <string> unexport   = new List <string>();
        string        pathCsv    = Application.dataPath + "/../Config/Csv";
        string        exportFile = Application.dataPath + "/Ling-Script/Util/Csv/UtilCsvReaderType.cs";
        List <string> fileCsv    = new List <string>();

        EditorSearchFile.SearchPath(pathCsv, fileCsv, ".csv");
        string text_class = "" +
                            "using UnityEngine;\n" +
                            "using System.Collections;\n" +
                            "using System.Collections.Generic;\n" +
                            "namespace CSV\n{\n" +
                            "\tpublic class CSVInfo\n" +
                            "\t{\n" +
                            "\t\tpublic static readonly string[] CLASS_NAME = { {REPACE-0} };\n" +
                            "\t\tpublic static readonly System.Type[] CLASS_TYPE = { {REPACE-1} };\n" +
                            "\t}\n";

        string text_class_name = "";
        string text_class_type = "";

        /// 遍历csv文件
        for (int index = 0; index < fileCsv.Count; index++)
        {
            string fileName = EditorSearchFile.FileName(fileCsv[index]);

            if (unexport.IndexOf(fileName) != -1)
            {
                continue;
            }

            text_class_name += (string.IsNullOrEmpty(text_class_name) ? "\"" : ", \"") + fileName + "\"";
            text_class_type += (string.IsNullOrEmpty(text_class_type) ? "typeof(CSV." : ", typeof(CSV.") + fileName + ")";
            char[] split_char = null;
            switch (fileName)
            {
            case "Dictionary":
            case "DictionaryStatic":
            case "DictionaryLibrary":
                split_char = new char[] { '\t' };
                break;

            default:
                split_char = new char[] { ',' };
                break;
            }
            /// 检测类中变量是否存在
            string[] data  = System.IO.File.ReadAllLines(fileCsv[index]);
            string[] title = data[0].Split(split_char);
            string[] type  = data[1].Split(split_char);
            string[] info  = data[2].Split(split_char);
            for (int i = 0; i < title.Length; i++)
            {
                if (string.IsNullOrEmpty(title[i]))
                {
                    continue;
                }
            }
            text_class += "\tpublic class " + fileName + " : System.Object\n";
            text_class += "\t{\n";
            for (int i = 0; i < title.Length; i++)
            {
                if (string.IsNullOrEmpty(title[i]))
                {
                    continue;
                }
                text_class += "\t\t/// " + (info.Length > i ? info[i] : "") + "\n";
                text_class += "\t\tpublic " + (type.Length > i && !string.IsNullOrEmpty(type[i]) ? type[i] : "string").Replace(" ", "") + " " + title[i] + ";\n";
            }
            text_class += "\t}\n";
        }
        text_class += "}\n";

        text_class = text_class.Replace("{REPACE-0}", text_class_name);
        text_class = text_class.Replace("{REPACE-1}", text_class_type);
        System.IO.File.WriteAllText(exportFile, text_class, new System.Text.UTF8Encoding(false));
    }