Ejemplo n.º 1
0
        public static void Patch(string platform)
        {
            var p        = Application.dataPath + DevCacheDirectory + platform + AssetBundlePath.kSlash + AssetBundlePath.kPackCfg;
            var jsonData = File.ReadAllText(p);
            var cfg      = new PackageCfg();

            EditorJsonUtility.FromJsonOverwrite(jsonData, cfg);

            var tmpDir = Application.dataPath + "/tempDir";

            if (Directory.Exists(tmpDir))
            {
                Directory.Delete(tmpDir, true);
            }
            var patchCfg = new PackageCfg();

            patchCfg.PatchVersion = PackEditorWin.GetCfg().PatchVersion;
            var parentPath = Application.dataPath + DevCacheDirectory + platform;

            var codePatchFile = parentPath + AssetBundlePath.kSlash + AssetBundlePath.kCodePatchFile;

            if (File.Exists(codePatchFile))
            {
                cfg.Files.Add(new FileCfg(CommonTool.CalFileMD5(codePatchFile), AssetBundlePath.kCodePatchFile));
            }
            for (int i = 0; i < cfg.Files.Count; ++i)
            {
                var f   = cfg.Files[i];
                var md5 = CommonTool.CalFileMD5(parentPath + AssetBundlePath.kSlash + f.Path);
                if (Path.GetExtension(f.Path) == AssetBundleMgr.instance.kPatchFileExt || md5 != f.MD5 && Path.GetExtension(f.Path) != AssetBundlePath.kPackCfgSuffix)
                {
                    patchCfg.Files.Add(new FileCfg(md5, f.Path));

                    var t = tmpDir + AssetBundlePath.kSlash + f.Path;
                    if (!Directory.Exists(Path.GetDirectoryName(t)))
                    {
                        Directory.CreateDirectory(Path.GetDirectoryName(t));
                    }
                    File.Copy(parentPath + AssetBundlePath.kSlash + f.Path, t);
                }
            }
            if (patchCfg.Files.Count != 0)
            {
                using (var sw = File.CreateText(tmpDir + AssetBundlePath.kSlash + AssetBundlePath.kPatchCfg))
                {
                    sw.Write(EditorJsonUtility.ToJson(patchCfg));
                }
                ZipHelper.ZipDirectoryDirect(tmpDir, Application.dataPath + DiffPatchDirectory + platform + AssetBundlePath.kPatchZipRes);
                TimeLogger.LogYellow(platform + "差异包生成成功");

                if (Directory.Exists(tmpDir))
                {
                    Directory.Delete(tmpDir, true);
                }
            }
            else
            {
                Debug.LogError("no different patch");
            }
        }
Ejemplo n.º 2
0
        public static void PackUncompressAndroidAB()
        {
            EditorUtility.DisplayProgressBar("", "", 0);

            DeleteDirectoryChild(Application.streamingAssetsPath);

            //Resources本地文件
            var p = "Assets/Resources/" + AssetBundlePath.kVersionCfg;

            if (File.Exists(p))
            {
                File.Delete(p);
            }
            var d         = ScriptableObject.CreateInstance <VersionCfg>();
            var editorCfg = PackEditorWin.GetCfg();

            d.CurVersion = editorCfg.CurVersion;
            AssetDatabase.CreateAsset(d, p);
            AssetDatabase.SaveAssets();

            //android
            var path         = Application.dataPath + DevCacheDirectory + AssetBundlePath.kAndroid;
            var codeFilePath = path + AssetBundlePath.kSlash + AssetBundlePath.kCodePatchFile;

            if (File.Exists(codeFilePath))
            {
                File.Delete(codeFilePath);
            }
            GeneratePackageCfg(path);
            ZipHelper.ZipDirectoryDirect(path, Application.streamingAssetsPath + AssetBundlePath.kSlash + AssetBundlePath.kAndroidZipRes);

            //windows
            path         = Application.dataPath + DevCacheDirectory + AssetBundlePath.kWindows;
            codeFilePath = path + AssetBundlePath.kSlash + AssetBundlePath.kCodePatchFile;
            if (File.Exists(codeFilePath))
            {
                File.Delete(codeFilePath);
            }
            GeneratePackageCfg(path);
            ZipHelper.ZipDirectoryDirect(path, Application.streamingAssetsPath + AssetBundlePath.kSlash + AssetBundlePath.kWindowsZipRes);

            EditorUtility.ClearProgressBar();
            TimeLogger.LogYellow("压缩完成");
            AssetDatabase.Refresh();
        }
Ejemplo n.º 3
0
        public static void CreateAssetBundle()
        {
            foreach (var guid in Selection.assetGUIDs)
            {
                var p = AssetDatabase.GUIDToAssetPath(guid);

                if (AssetBundlePath.kAssetBundle == Path.GetFileName(p))
                {
                    Debug.LogError("directory name error " + AssetBundlePath.kAssetBundle);
                    return;
                }
                if (!Directory.Exists(p))
                {
                    Debug.LogError("not directory " + p);
                    return;
                }
                var           isOk = false;
                var           l    = p.Split('/');
                StringBuilder sb   = new StringBuilder();
                for (int i = l.Length - 1; i >= 0; --i)
                {
                    if (l[i] == AssetBundlePath.kAssetBundle)
                    {
                        isOk = true;
                        break;
                    }
                    sb.Insert(0, l[i] + (i != l.Length - 1 ? "/" : ""));
                }
                if (!isOk)
                {
                    Debug.LogError(string.Format("directory {0} not Assetbundle child directory", p));
                    return;
                }
                var abName = sb.ToString() + AssetBundlePath.kBundleSuffix;
                abName = abName.ToLower();

                var directory = Directory.CreateDirectory(Path.GetFullPath(p));
                if (0 != directory.GetDirectories().Length)
                {
                    Debug.LogError(string.Format("direcory {0} is not leaf node", p));
                }
                var files = directory.GetFiles();
                for (int i = 0; i < files.Length; ++i)
                {
                    var file = files[i];

                    if (IsSpriteExtension(Path.GetExtension(file.Name)))
                    {
                        var ti = AssetImporter.GetAtPath(p + '/' + file.Name) as TextureImporter;
                        if (ti.textureType == TextureImporterType.Sprite)
                        {
                            ti.spritePackingTag = sb.ToString() + ".packTag";
                        }
                        ti.assetBundleName = abName;
                        if (ti.assetBundleName != abName)
                        {
                            ti.SaveAndReimport();
                        }
                    }
                    else if (IsSuffixAssetBundle(Path.GetExtension(file.Name)))
                    {
                        var ti = AssetImporter.GetAtPath(p + '/' + file.Name);
                        ti.assetBundleName = abName;
                        if (ti.assetBundleName != abName)
                        {
                            ti.SaveAndReimport();
                        }
                    }
                }
                var abEntry = new AssetBundleBuild();
                abEntry.assetBundleName = abName;
                abEntry.assetNames      = AssetDatabase.GetAssetPathsFromAssetBundle(abName);

                var abArray = new AssetBundleBuild[1] {
                    abEntry
                };

                BuildPipeline.BuildAssetBundles(Application.dataPath + DevCacheDirectory + AssetBundlePath.kWindows, abArray, BuildAssetBundleOptions.UncompressedAssetBundle, BuildTarget.StandaloneWindows64);
                BuildPipeline.BuildAssetBundles(Application.dataPath + DevCacheDirectory + AssetBundlePath.kAndroid, abArray, BuildAssetBundleOptions.UncompressedAssetBundle, BuildTarget.Android);
                //BuildPipeline.BuildAssetBundles(Application.dataPath + DevCacheDirectory + AssetBundlePath.kIos, BuildAssetBundleOptions.UncompressedAssetBundle, BuildTarget.iOS);
                AssetDatabase.Refresh();
                TimeLogger.LogYellow("打包完成");
            }
        }