Ejemplo n.º 1
0
    //=======================================================
    // AssetBundleList
    //=======================================================

    /// <summary>
    /// Convert your custom assetbundlelist to EditorAssetInfo.
    /// Use VersionAssets
    /// </summary>
    public override List <EditorAssetInfo> LoadAssetBundleList(string text)
    {
        var versionList = new List <EditorAssetInfo>();

        var assetList = text.Split("\n"[0]);

        for (int i = 1; i < assetList.Length; i++)
        {
            var asset = new EditorAssetInfo("", 0, i);
            var info  = assetList[i].Split(","[0]);
            if (info == null || info.Length < 6)
            {
                break;
            }

            try {
                asset.Name            = info[0];
                asset.AssetPath       = info[1];
                asset.AssetBundleName = info[2];
                asset.Extension       = info[3];
                asset.Version         = int.Parse(info[4]);
                asset.Size            = float.Parse(info[5]);
                asset.Date            = info[6];
                asset.UnityVersion    = info[7];
                asset.name            = asset.AssetPath;
                asset.Initialize(asset.AssetPath);

                versionList.Add(asset);
            }
            catch (Exception ex) {
                Debug.LogError(ex);
            }
        }
        return(versionList);
    }
    public virtual void UpdateAssetBundleList(Dictionary <string, List <EditorAssetInfo> > assetListDic, Dictionary <string, List <EditorAssetInfo> > versionListDic)
    {
        var date = DateTime.Now.ToString();

        foreach (var asset in assetListDic)
        {
            var list = new List <EditorAssetInfo>();
            versionListDic.TryGetValue(asset.Key, out list);
            if (list == null)
            {
                versionListDic.Add(asset.Key, asset.Value);
                for (int i = 0; i < asset.Value.Count; i++)
                {
                    asset.Value[i].Version = asset.Value[0].Version;
                    asset.Value[i].Date    = date;
                }
            }
            else
            {
                // add new asset
                if (asset.Value.Count != list.Count)
                {
                    for (int i = 0; i < asset.Value.Count; i++)
                    {
                        if (asset.Value[i].OldAssetVersion == 0)
                        {
                            asset.Value[i].Version = 0;
                            list.Add(asset.Value[i]);
                        }
                    }
                }

                for (int i = 0; i < list.Count; i++)
                {
                    list[i].Version = list[i].Version + 1;
                    list[i].Date    = date;
                    Debug.Log("update : " + list[i].Version);
                }
            }
        }
        VersionAssets.Clear();
        var idcounter = 0;

        foreach (var asset in versionListDic)
        {
            for (int i = 0; i < asset.Value.Count; i++)
            {
                var v = new EditorAssetInfo(asset.Value[i]);
                v.depth = 0;
                v.id    = ++idcounter;
                VersionAssets.Add(v);
            }
        }
        VersionAssets.Insert(0, EditorAssetInfo.Root);
    }
    public virtual void ExportAssetBundle(List <EditorAssetInfo> buildAssets, string exportPath, string cachePath, BuildTarget[] platforms, ExportType type, bool exportWithManifest)
    {
        Dictionary <string, EditorAssetInfo> assetDic = new Dictionary <string, EditorAssetInfo>();

        if (type == ExportType.IgnoreDirectoryStructureWithVersion || type == ExportType.KeepDirectoryStructureWithVersion)
        {
            for (int i = 0; i < buildAssets.Count; i++)
            {
                EditorAssetInfo asset = null;
                assetDic.TryGetValue(buildAssets[i].AssetBundleName, out asset);
                if (asset == null)
                {
                    assetDic.Add(Path.GetFileName(buildAssets[i].AssetBundleName), buildAssets[i]);
                }
            }
        }

        for (int i = 0; i < platforms.Length; i++)
        {
            var platform   = platforms[i].ToString();
            var targetPath = FileHelper.pathSlashFix(Path.Combine(cachePath, platform));

            // pick up all of the files of the current platform folder
            var files = FileHelper.AllFilesInDirectory(targetPath, "*");
            if (!exportWithManifest)
            {
                files = files.Where(f => !Path.GetExtension(f.Name).Equals(".manifest")).ToList();
            }

            var dstDir = FileHelper.pathSlashFix(Path.Combine(exportPath, platform));
            if (!Directory.Exists(dstDir))
            {
                Directory.CreateDirectory(dstDir);
            }

            for (int j = 0; j < files.Count; j++)
            {
                if (files[j].Name.Equals(platform))
                {
                    continue;
                }
                var fileName = Path.GetFileNameWithoutExtension(files[j].Name);
                switch (type)
                {
                case ExportType.IgnoreDirectoryStructure: {
                    var src = FileHelper.pathSlashFix(files[j].Name);
                    var dst = FileHelper.pathSlashFix(Path.Combine(dstDir, src.Replace(targetPath + "/", "")));
                    if (File.Exists(dst))
                    {
                        File.Delete(dst);
                    }
                    FileUtil.CopyFileOrDirectory(files[j].FullName, dst);
                }
                break;

                case ExportType.KeepDirectoryStructure: {
                    var src = FileHelper.pathSlashFix(files[j].FullName);
                    var dst = FileHelper.pathSlashFix(Path.Combine(dstDir, src.Replace(targetPath + "/", "")));
                    FileHelper.CreateParentDirectory(dst);
                    if (File.Exists(dst))
                    {
                        File.Delete(dst);
                    }
                    FileUtil.CopyFileOrDirectory(src, dst);
                }
                break;

                case ExportType.IgnoreDirectoryStructureWithVersion: {
                    EditorAssetInfo assetInfo;
                    assetDic.TryGetValue(fileName, out assetInfo);
                    if (assetInfo != null)
                    {
                        var src = FileHelper.pathSlashFix(files[j].Name);
                        var dstDirWithVersion = FileHelper.pathSlashFix(Path.Combine(dstDir, assetInfo.Version.ToString()));
                        var dst = FileHelper.pathSlashFix(Path.Combine(dstDirWithVersion, src.Replace(targetPath + "/", "")));
                        FileHelper.CreateParentDirectory(dst);
                        if (File.Exists(dst))
                        {
                            File.Delete(dst);
                        }
                        FileUtil.CopyFileOrDirectory(files[j].FullName, dst);
                    }
                    else
                    {
                        Debug.LogWarning("EasyAssetBundle: Unknown file. : " + fileName);
                    }
                }
                break;

                case ExportType.KeepDirectoryStructureWithVersion: {
                    EditorAssetInfo assetInfo;
                    assetDic.TryGetValue(fileName, out assetInfo);
                    if (assetInfo != null)
                    {
                        var src = FileHelper.pathSlashFix(files[j].FullName);
                        var dstDirWithVersion = FileHelper.pathSlashFix(Path.Combine(dstDir, assetInfo.Version.ToString()));
                        var dst = FileHelper.pathSlashFix(Path.Combine(dstDirWithVersion, src.Replace(targetPath + "/", "")));
                        FileHelper.CreateParentDirectory(dst);
                        if (File.Exists(dst))
                        {
                            File.Delete(dst);
                        }
                        FileUtil.CopyFileOrDirectory(src, dst);
                    }
                    else
                    {
                        Debug.LogWarning("EasyAssetBundle: Unknown file. :" + fileName);
                    }
                }
                break;
                }
            }
        }
    }